*** empty log message ***
[gnus] / lisp / gnus.el
1 ;;; gnus.el --- a newsreader for GNU Emacs
2 ;; Copyright (C) 1987,88,89,90,93,94,95 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;;      Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 ;;; Commentary:
25
26 ;; Although Gnus looks suspiciously like GNUS, it isn't quite the same
27 ;; beast. Most internal structures have been changed. If you have
28 ;; written packages that depend on any of the hash tables,
29 ;; `gnus-newsrc-alist', `gnus-killed-assoc', marked lists, the .newsrc
30 ;; buffer, or internal knowledge of the `nntp-header-' macros, or
31 ;; dependence on the buffers having a certain format, your code will
32 ;; fail.
33
34 ;;; Code:
35
36 (require 'mail-utils)
37 (require 'timezone)
38 (require 'nnheader)
39
40 ;; Site dependent variables. These variables should be defined in
41 ;; paths.el.
42
43 (defvar gnus-default-nntp-server nil
44   "Specify a default NNTP server.
45 This variable should be defined in paths.el, and should never be set
46 by the user.
47 If you want to change servers, you should use `gnus-select-method'.
48 See the documentation to that variable.")
49
50 (defconst gnus-backup-default-subscribed-newsgroups 
51   '("news.announce.newusers" "news.groups.questions" "gnu.emacs.gnus")
52   "Default default new newsgroups the first time Gnus is run.
53 Should be set in paths.el, and shouldn't be touched by the user.")
54
55 (defvar gnus-local-domain nil
56   "Local domain name without a host name.
57 The DOMAINNAME environment variable is used instead if it is defined.
58 If the `system-name' function returns the full Internet name, there is
59 no need to set this variable.")
60
61 (defvar gnus-local-organization nil
62   "String with a description of what organization (if any) the user belongs to.
63 The ORGANIZATION environment variable is used instead if it is defined.
64 If this variable contains a function, this function will be called
65 with the current newsgroup name as the argument. The function should
66 return a string.
67
68 In any case, if the string (either in the variable, in the environment
69 variable, or returned by the function) is a file name, the contents of
70 this file will be used as the organization.")
71
72 (defvar gnus-use-generic-from nil
73   "If nil, the full host name will be the system name prepended to the domain name.
74 If this is a string, the full host name will be this string.
75 If this is non-nil, non-string, the domain name will be used as the
76 full host name.")
77
78 (defvar gnus-use-generic-path nil
79   "If nil, use the NNTP server name in the Path header.
80 If stringp, use this; if non-nil, use no host name (user name only).")
81
82
83 ;; Customization variables
84
85 (defvar gnus-select-method 
86   (list 'nntp (or (getenv "NNTPSERVER") 
87                   (if (and gnus-default-nntp-server
88                            (not (string= gnus-default-nntp-server "")))
89                       gnus-default-nntp-server)
90                   (system-name)))
91   "*Default method for selecting a newsgroup.
92 This variable should be a list, where the first element is how the
93 news is to be fetched, the second is the address. 
94
95 For instance, if you want to get your news via NNTP from
96 \"flab.flab.edu\", you could say:
97
98 (setq gnus-select-method '(nntp \"flab.flab.edu\"))
99
100 If you want to use your local spool, say:
101
102 (setq gnus-select-method (list 'nnspool (system-name)))
103
104 If you use this variable, you must set `gnus-nntp-server' to nil.
105
106 There is a lot more to know about select methods and virtual servers -
107 see the manual for details.")
108
109 ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
110 (defvar gnus-post-method nil
111   "*Preferred method for posting USENET news.
112 If this variable is nil, Gnus will use the current method to decide
113 which method to use when posting.  If it is non-nil, it will override
114 the current method.  This method will not be used in mail groups and
115 the like, only in \"real\" newsgroups.
116
117 The value must be a valid method as discussed in the documentation of
118 `gnus-select-method'.")
119
120 (defvar gnus-refer-article-method nil
121   "*Preferred method for fetching an article by Message-ID.
122 If you are reading news from the local spool (with nnspool), fetching
123 articles by Message-ID is painfully slow. By setting this method to an
124 nntp method, you might get acceptable results.
125
126 The value of this variable must be a valid select method as discussed
127 in the documentation of `gnus-select-method'")
128
129 (defvar gnus-secondary-select-methods nil
130   "*A list of secondary methods that will be used for reading news.
131 This is a list where each element is a complete select method (see
132 `gnus-select-method').  
133
134 If, for instance, you want to read your mail with the nnml backend,
135 you could set this variable:
136
137 (setq gnus-secondary-select-methods '((nnml \"\")))")
138
139 (defvar gnus-secondary-servers nil
140   "*List of NNTP servers that the user can choose between interactively.
141 To make Gnus query you for a server, you have to give `gnus' a
142 non-numeric prefix - `C-u M-x gnus', in short.")
143
144 (defvar gnus-nntp-server nil
145   "*The name of the host running the NNTP server.
146 This variable is semi-obsolete. Use the `gnus-select-method'
147 variable instead.")
148
149 (defvar gnus-nntp-service "nntp"
150   "*NNTP service name (\"nntp\" or 119).
151 This is an obsolete variable, which is scarcely used. If you use an
152 nntp server for your newsgroup and want to change the port number
153 used to 899, you would say something along these lines:
154
155  (setq gnus-select-method '(nntp \"my.nntp.server\" (nntp-port-number 899)))")
156
157 (defvar gnus-startup-file "~/.newsrc"
158   "*Your `.newsrc' file.
159 `.newsrc-SERVER' will be used instead if that exists.")
160
161 (defvar gnus-init-file "~/.gnus"
162   "*Your Gnus elisp startup file.
163 If a file with the .el or .elc suffixes exist, it will be read
164 instead.") 
165
166 (defvar gnus-group-faq-directory
167   "/ftp@mirrors.aol.com:/pub/rtfm/usenet/"
168   "*Directory where the group FAQs are stored.
169 This will most commonly be on a remote machine, and the file will be
170 fetched by ange-ftp.
171
172 Note that Gnus uses an aol machine as the default directory.  If this
173 feels fundamentally unclean, just think of it as a way to finally get
174 something of value back from them.
175
176 If the default site is too slow, try one of these:
177
178    North America: ftp.uu.net                     /usenet/news.answers
179                   mirrors.aol.com                /pub/rtfm/usenet
180                   ftp.seas.gwu.edu               /pub/rtfm
181                   rtfm.mit.edu                   /pub/usenet/news.answers
182    Europe:        ftp.uni-paderborn.de           /pub/FAQ
183                   ftp.Germany.EU.net             /pub/newsarchive/news.answers
184                   ftp.sunet.se                   /pub/usenet
185    Asia:          nctuccca.edu.tw                /USENET/FAQ
186                   hwarang.postech.ac.kr          /pub/usenet/news.answers
187                   ftp.hk.super.net               /mirror/faqs")
188
189 (defvar gnus-group-archive-directory
190   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/" 
191   "*The address of the (ding) archives.")
192
193 (defvar gnus-group-recent-archive-directory
194   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
195   "*The address of the most recent (ding) articles.")
196
197 (defvar gnus-default-subscribed-newsgroups nil
198   "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
199 It should be a list of strings.
200 If it is `t', Gnus will not do anything special the first time it is
201 started; it'll just use the normal newsgroups subscription methods.")
202
203 (defvar gnus-use-cross-reference t
204   "*Non-nil means that cross referenced articles will be marked as read.
205 If nil, ignore cross references.  If t, mark articles as read in
206 subscribed newsgroups. If neither t nor nil, mark as read in all
207 newsgroups.") 
208
209 (defvar gnus-use-dribble-file t
210   "*Non-nil means that Gnus will use a dribble file to store user updates.
211 If Emacs should crash without saving the .newsrc files, complete
212 information can be restored from the dribble file.")
213
214 (defvar gnus-asynchronous nil
215   "*If non-nil, Gnus will supply backends with data needed for async article fetching.")
216
217 (defvar gnus-asynchronous-article-function nil
218   "*Function for picking articles to pre-fetch, possibly.")
219
220 (defvar gnus-score-file-single-match-alist nil
221   "*Alist mapping regexps to lists of score files.
222 Each element of this alist should be of the form
223         (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
224
225 If the name of a group is matched by REGEXP, the corresponding scorefiles
226 will be used for that group.
227 The first match found is used, subsequent matching entries are ignored (to
228 use multiple matches, see gnus-score-file-multiple-match-alist).
229
230 These score files are loaded in addition to any files returned by
231 gnus-score-find-score-files-function (which see).")
232
233 (defvar gnus-score-file-multiple-match-alist nil
234   "*Alist mapping regexps to lists of score files.
235 Each element of this alist should be of the form
236         (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... )
237
238 If the name of a group is matched by REGEXP, the corresponding scorefiles
239 will be used for that group.
240 If multiple REGEXPs match a group, the score files corresponding to each
241 match will be used (for only one match to be used, see
242 gnus-score-file-single-match-alist).
243
244 These score files are loaded in addition to any files returned by
245 gnus-score-find-score-files-function (which see).")
246
247
248 (defvar gnus-score-file-suffix "SCORE"
249   "*Suffix of the score files.")
250
251 (defvar gnus-adaptive-file-suffix "ADAPT"
252   "*Suffix of the adaptive score files.")
253
254 (defvar gnus-score-find-score-files-function 'gnus-score-find-bnews
255   "*Function used to find score files.
256 The function will be called with the group name as the argument, and
257 should return a list of score files to apply to that group.  The score
258 files do not actually have to exist.
259
260 Predefined values are:
261
262 gnus-score-find-single: Only apply the group's own score file.
263 gnus-score-find-hierarchical: Also apply score files from parent groups.
264 gnus-score-find-bnews: Apply score files whose names matches.
265
266 See the documentation to these functions for more information.
267
268 This variable can also be a list of functions to be called.  Each
269 function should either return a list of score files, or a list of
270 score alists.")
271
272 (defvar gnus-score-interactive-default-score 1000
273   "*Scoring commands will raise/lower the score with this number as the default.")
274
275 (defvar gnus-large-newsgroup 200
276   "*The number of articles which indicates a large newsgroup.
277 If the number of articles in a newsgroup is greater than this value,
278 confirmation is required for selecting the newsgroup.")
279
280 ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
281 (defvar gnus-no-groups-message "No news is horrible news"
282   "*Message displayed by Gnus when no groups are available.")
283
284 (defvar gnus-use-long-file-name (not (memq system-type '(usg-unix-v xenix)))
285   "*Non-nil means that the default name of a file to save articles in is the group name.
286 If it's nil, the directory form of the group name is used instead.
287
288 If this variable is a list, and the list contains the element
289 `not-score', long file names will not be used for score files; if it
290 contains the element `not-save', long file names will not be used for
291 saving; and if it contains the element `not-kill', long file names
292 will not be used for kill files.")
293
294 (defvar gnus-article-save-directory (or (getenv "SAVEDIR") "~/News/")
295   "*Name of the directory articles will be saved in (default \"~/News\").
296 Initialized from the SAVEDIR environment variable.")
297
298 (defvar gnus-kill-files-directory (or (getenv "SAVEDIR") "~/News/")
299   "*Name of the directory where kill files will be stored (default \"~/News\").
300 Initialized from the SAVEDIR environment variable.")
301
302 (defvar gnus-default-article-saver 'gnus-summary-save-in-rmail
303   "*A function to save articles in your favorite format.
304 The function must be interactively callable (in other words, it must
305 be an Emacs command).
306
307 Gnus provides the following functions:
308
309 * gnus-summary-save-in-rmail (Rmail format)
310 * gnus-summary-save-in-mail (Unix mail format)
311 * gnus-summary-save-in-folder (MH folder)
312 * gnus-summary-save-in-file (article format).
313 * gnus-summary-save-in-vm (use VM's folder format).")
314
315 (defvar gnus-rmail-save-name (function gnus-plain-save-name)
316   "*A function generating a file name to save articles in Rmail format.
317 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
318
319 (defvar gnus-mail-save-name (function gnus-plain-save-name)
320   "*A function generating a file name to save articles in Unix mail format.
321 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
322
323 (defvar gnus-folder-save-name (function gnus-folder-save-name)
324   "*A function generating a file name to save articles in MH folder.
325 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
326
327 (defvar gnus-file-save-name (function gnus-numeric-save-name)
328   "*A function generating a file name to save articles in article format.
329 The function is called with NEWSGROUP, HEADERS, and optional
330 LAST-FILE.")
331
332 (defvar gnus-split-methods nil
333   "*Variable used to suggest where articles are to be saved.
334 The syntax of this variable is the same as `nnmail-split-methods'.  
335
336 For instance, if you would like to save articles related to Gnus in
337 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
338 you could set this variable to something like:
339
340  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
341    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))")
342
343 (defvar gnus-save-score nil
344   "*If non-nil, save group scoring info.")
345
346 (defvar gnus-use-adaptive-scoring nil
347   "*If non-nil, use some adaptive scoring scheme.")
348
349 (defvar gnus-use-cache nil
350   "*If non-nil, Gnus will cache (some) articles locally.")
351
352 (defvar gnus-use-scoring t
353   "*If non-nil, enable scoring.")
354
355 (defvar gnus-fetch-old-headers nil
356   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
357 If an unread article in the group refers to an older, already read (or
358 just marked as read) article, the old article will not normally be
359 displayed in the Summary buffer.  If this variable is non-nil, Gnus
360 will attempt to grab the headers to the old articles, and thereby
361 build complete threads.  If it has the value `some', only enough
362 headers to connect otherwise loose threads will be displayed.
363
364 The server has to support XOVER for any of this to work.")
365
366 ;see gnus-cus.el
367 ;(defvar gnus-visual t
368 ;  "*If non-nil, will do various highlighting.
369 ;If nil, no mouse highlights (or any other highlights) will be
370 ;performed.  This might speed up Gnus some when generating large group
371 ;and summary buffers.")
372
373 (defvar gnus-novice-user t
374   "*Non-nil means that you are a usenet novice.
375 If non-nil, verbose messages may be displayed and confirmations may be
376 required.")
377
378 (defvar gnus-expert-user nil
379   "*Non-nil means that you will never be asked for confirmation about anything.
380 And that means *anything*.")
381
382 (defvar gnus-verbose 7
383   "*Integer that says how verbose Gnus should be.
384 The higher the number, the more messages Gnus will flash to say what
385 it's doing.  At zero, Gnus will be totally mute; at five, Gnus will
386 display most important messages; and at ten, Gnus will keep on
387 jabbering all the time.")
388
389 (defvar gnus-keep-same-level nil
390   "*Non-nil means that the next newsgroup after the current will be on the same level.
391 When you type, for instance, `n' after reading the last article in the
392 current newsgroup, you will go to the next newsgroup. If this variable
393 is nil, the next newsgroup will be the next from the group
394 buffer. 
395 If this variable is non-nil, Gnus will either put you in the
396 next newsgroup with the same level, or, if no such newsgroup is
397 available, the next newsgroup with the lowest possible level higher
398 than the current level.
399 If this variable is `best', Gnus will make the next newsgroup the one
400 with the best level.")
401
402 (defvar gnus-summary-make-false-root 'adopt
403   "*nil means that Gnus won't gather loose threads.
404 If the root of a thread has expired or been read in a previous
405 session, the information necessary to build a complete thread has been
406 lost. Instead of having many small sub-threads from this original thread
407 scattered all over the summary buffer, Gnus can gather them. 
408
409 If non-nil, Gnus will try to gather all loose sub-threads from an
410 original thread into one large thread.
411
412 If this variable is non-nil, it should be one of `none', `adopt',
413 `dummy' or `empty'.
414
415 If this variable is `none', Gnus will not make a false root, but just
416 present the sub-threads after another.
417 If this variable is `dummy', Gnus will create a dummy root that will
418 have all the sub-threads as children.
419 If this variable is `adopt', Gnus will make one of the \"children\"
420 the parent and mark all the step-children as such.
421 If this variable is `empty', the \"children\" are printed with empty
422 subject fields.  (Or rather, they will be printed with a string
423 given by the `gnus-summary-same-subject' variable.)")
424
425 (defvar gnus-summary-gather-subject-limit nil
426   "*Maximum length of subject comparisons when gathering loose threads.
427 Use nil to compare full subjects.  Setting this variable to a low
428 number will help gather threads that have been corrupted by
429 newsreaders chopping off subject lines, but it might also mean that
430 unrelated articles that have subject that happen to begin with the
431 same few characters will be incorrectly gathered.
432
433 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
434 comparing subjects.")
435
436 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
437 (defvar gnus-summary-same-subject ""
438   "*String indicating that the current article has the same subject as the previous.
439 This variable will only be used if the value of
440 `gnus-summary-make-false-root' is `empty'.")
441
442 (defvar gnus-summary-goto-unread t
443   "*If non-nil, marking commands will go to the next unread article.")
444
445 (defvar gnus-group-goto-unread t
446   "*If non-nil, movement commands will go to the next unread and subscribed group.")
447
448 (defvar gnus-check-new-newsgroups t
449   "*Non-nil means that Gnus will add new newsgroups at startup.
450 If this variable is `ask-server', Gnus will ask the server for new
451 groups since the last time it checked. This means that the killed list
452 is no longer necessary, so you could set `gnus-save-killed-list' to
453 nil. 
454
455 A variant is to have this variable be a list of select methods. Gnus
456 will then use the `ask-server' method on all these select methods to
457 query for new groups from all those servers.
458
459 Eg.
460   (setq gnus-check-new-newsgroups 
461         '((nntp \"some.server\") (nntp \"other.server\")))
462
463 If this variable is nil, then you have to tell Gnus explicitly to
464 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
465
466 (defvar gnus-check-bogus-newsgroups nil
467   "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
468 If this variable is nil, then you have to tell Gnus explicitly to
469 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
470
471 (defvar gnus-read-active-file t
472   "*Non-nil means that Gnus will read the entire active file at startup.
473 If this variable is nil, Gnus will only know about the groups in your
474 `.newsrc' file.
475
476 If this variable is `some', Gnus will try to only read the relevant
477 parts of the active file from the server.  Not all servers support
478 this, and it might be quite slow with other servers, but this should
479 generally be faster than both the t and nil value.
480
481 If you set this variable to nil or `some', you probably still want to
482 be told about new newsgroups that arrive.  To do that, set
483 `gnus-check-new-newsgroups' to `ask-server'.  This may not work
484 properly with all servers.")
485
486 (defvar gnus-level-subscribed 5
487   "*Groups with levels less than or equal to this variable are subscribed.")
488
489 (defvar gnus-level-unsubscribed 7
490   "*Groups with levels less than or equal to this variable are unsubscribed.
491 Groups with levels less than `gnus-level-subscribed', which should be
492 less than this variable, are subscribed.")
493
494 (defvar gnus-level-zombie 8
495   "*Groups with this level are zombie groups.")
496
497 (defvar gnus-level-killed 9
498   "*Groups with this level are killed.")
499
500 (defvar gnus-level-default-subscribed 3
501   "*New subscribed groups will be subscribed at this level.")
502
503 (defvar gnus-level-default-unsubscribed 6
504   "*New unsubscribed groups will be unsubscribed at this level.")
505
506 (defvar gnus-activate-foreign-newsgroups 4
507   "*If nil, Gnus will not check foreign newsgroups at startup.
508 If it is non-nil, it should be a number between one and nine. Foreign
509 newsgroups that have a level lower or equal to this number will be
510 activated on startup. For instance, if you want to active all
511 subscribed newsgroups, but not the rest, you'd set this variable to 
512 `gnus-level-subscribed'.
513
514 If you subscribe to lots of newsgroups from different servers, startup
515 might take a while. By setting this variable to nil, you'll save time,
516 but you won't be told how many unread articles there are in the
517 groups.")
518
519 (defvar gnus-save-newsrc-file t
520   "*Non-nil means that Gnus will save the `.newsrc' file.
521 Gnus always saves its own startup file, which is called
522 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
523 be readily understood by other newsreaders.  If you don't plan on
524 using other newsreaders, set this variable to nil to save some time on
525 exit.")
526
527 (defvar gnus-save-killed-list t
528   "*If non-nil, save the list of killed groups to the startup file.
529 This will save both time (when starting and quitting) and space (both
530 memory and disk), but it will also mean that Gnus has no record of
531 which groups are new and which are old, so the automatic new
532 newsgroups subscription methods become meaningless. You should always
533 set `gnus-check-new-newsgroups' to `ask-server' or nil if you set this
534 variable to nil.")
535
536 (defvar gnus-interactive-catchup t
537   "*If non-nil, require your confirmation when catching up a group.")
538
539 (defvar gnus-interactive-post t
540   "*If non-nil, group name will be asked for when posting.")
541
542 (defvar gnus-interactive-exit t
543   "*If non-nil, require your confirmation when exiting Gnus.")
544
545 (defvar gnus-kill-killed t
546   "*If non-nil, Gnus will apply kill files to already killed articles.
547 If it is nil, Gnus will never apply kill files to articles that have
548 already been through the scoring process, which might very well save lots
549 of time.")
550
551 (defvar gnus-extract-address-components 'gnus-extract-address-components
552   "*Function for extracting address components from a From header.
553 Two pre-defined function exist: `gnus-extract-address-components',
554 which is the default, quite fast, and too simplistic solution, and
555 `mail-extract-address-components', which works much better, but is
556 slower.")
557
558 (defvar gnus-summary-default-score 0
559   "*Default article score level.
560 If this variable is nil, scoring will be disabled.")
561
562 (defvar gnus-summary-zcore-fuzz 0
563   "*Fuzziness factor for the zcore in the summary buffer.
564 Articles with scores closer than this to `gnus-summary-default-score'
565 will not be marked.")
566
567 (defvar gnus-simplify-subject-fuzzy-regexp nil
568   "*Regular expression that will be removed from subject strings if
569 fuzzy subject simplification is selected.")
570
571 (defvar gnus-group-default-list-level gnus-level-subscribed
572   "*Default listing level. 
573 Ignored if `gnus-group-use-permanent-levels' is non-nil.")
574
575 (defvar gnus-group-use-permanent-levels nil
576   "*If non-nil, once you set a level, Gnus will use this level.")
577
578 (defvar gnus-show-mime nil
579   "*If non-nil, do mime processing of articles.
580 The articles will simply be fed to the function given by
581 `gnus-show-mime-method'.")
582
583 (defvar gnus-strict-mime t
584   "*If nil, decode MIME header even if there is not Mime-Version field.")
585  
586 (defvar gnus-show-mime-method (function metamail-buffer)
587   "*Function to process a MIME message.
588 The function is called from the article buffer.")
589
590 (defvar gnus-show-threads t
591   "*If non-nil, display threads in summary mode.")
592
593 (defvar gnus-thread-hide-subtree nil
594   "*If non-nil, hide all threads initially.
595 If threads are hidden, you have to run the command
596 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
597 to expose hidden threads.")
598
599 (defvar gnus-thread-hide-killed t
600   "*If non-nil, hide killed threads automatically.")
601
602 (defvar gnus-thread-ignore-subject nil
603   "*If non-nil, ignore subjects and do all threading based on the Reference header.
604 If nil, which is the default, articles that have different subjects
605 from their parents will start separate threads.")
606
607 (defvar gnus-thread-indent-level 4
608   "*Number that says how much each sub-thread should be indented.")
609
610 (defvar gnus-ignored-newsgroups 
611   (purecopy (mapconcat 'identity
612                        '("^to\\."       ; not "real" groups
613                          "^[0-9. \t]+ " ; all digits in name
614                          "[][\"#'()]"   ; bogus characters
615                          )
616                        "\\|"))
617   "*A regexp to match uninteresting newsgroups in the active file.
618 Any lines in the active file matching this regular expression are
619 removed from the newsgroup list before anything else is done to it,
620 thus making them effectively non-existent.")
621
622 (defvar gnus-ignored-headers
623   "^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:"
624   "*All headers that match this regexp will be hidden.
625 If `gnus-visible-headers' is non-nil, this variable will be ignored.")
626
627 (defvar gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:"
628   "*All headers that do not match this regexp will be hidden.
629 If this variable is non-nil, `gnus-ignored-headers' will be ignored.")
630
631 (defvar gnus-sorted-header-list
632   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:" 
633     "^Cc:" "^Date:" "^Organization:")
634   "*This variable is a list of regular expressions.
635 If it is non-nil, headers that match the regular expressions will
636 be placed first in the article buffer in the sequence specified by
637 this list.")
638
639 (defvar gnus-show-all-headers nil
640   "*If non-nil, don't hide any headers.")
641
642 (defvar gnus-save-all-headers t
643   "*If non-nil, don't remove any headers before saving.")
644
645 (defvar gnus-inhibit-startup-message nil
646   "*If non-nil, the startup message will not be displayed.")
647
648 (defvar gnus-signature-separator "^-- *$"
649   "Regexp matching signature separator.")
650
651 (defvar gnus-auto-extend-newsgroup t
652   "*If non-nil, extend newsgroup forward and backward when requested.")
653
654 (defvar gnus-auto-select-first t
655   "*If non-nil, select the first unread article when entering a group.
656 If you want to prevent automatic selection of the first unread article
657 in some newsgroups, set the variable to nil in
658 `gnus-select-group-hook'.") 
659
660 (defvar gnus-auto-select-next t
661   "*If non-nil, offer to go to the next group from the end of the previous.
662 If the value is t and the next newsgroup is empty, Gnus will exit
663 summary mode and go back to group mode.  If the value is neither nil
664 nor t, Gnus will select the following unread newsgroup.  In
665 particular, if the value is the symbol `quietly', the next unread
666 newsgroup will be selected without any confirmations.")
667
668 (defvar gnus-auto-select-same nil
669   "*If non-nil, select the next article with the same subject.")
670
671 (defvar gnus-summary-check-current nil
672   "*If non-nil, consider the current article when moving.
673 The \"unread\" movement commands will stay on the same line if the
674 current article is unread.")
675
676 (defvar gnus-auto-center-summary t
677   "*If non-nil, always center the current summary buffer.")
678
679 (defvar gnus-break-pages t
680   "*If non-nil, do page breaking on articles.
681 The page delimiter is specified by the `gnus-page-delimiter'
682 variable.")
683
684 (defvar gnus-page-delimiter "^\^L"
685   "*Regexp describing what to use as article page delimiters.
686 The default value is \"^\^L\", which is a form linefeed at the
687 beginning of a line.")
688
689 (defvar gnus-use-full-window t
690   "*If non-nil, use the entire Emacs screen.")
691
692 (defvar gnus-window-configuration nil
693   "Obsolete variable.  See `gnus-buffer-configuration'.")
694
695 (defvar gnus-buffer-configuration
696   '((group ([group 1.0 point] 
697             (if gnus-carpal [group-carpal 4])))
698     (summary ([summary 1.0 point]
699               (if gnus-carpal [summary-carpal 4])))
700     (article ([summary 0.25 point] 
701               (if gnus-carpal [summary-carpal 4]) 
702               [article 1.0]))
703     (server ([server 1.0 point]
704              (if gnus-carpal [server-carpal 2])))
705     (browse ([browse 1.0 point]
706              (if gnus-carpal [browse-carpal 2])))
707     (group-mail ([mail 1.0 point]))
708     (summary-mail ([mail 1.0 point]))
709     (summary-reply ([article 0.5]
710                     [mail 1.0 point]))
711     (info ([nil 1.0 point]))
712     (summary-faq ([summary 0.25]
713                   [faq 1.0 point]))
714     (edit-group ([group 0.5]
715                  [edit-group 1.0 point]))
716     (edit-server ([server 0.5]
717                   [edit-server 1.0 point]))
718     (edit-score ([summary 0.25]
719                  [edit-score 1.0 point]))
720     (post ([post 1.0 point]))
721     (reply ([article 0.5]
722             [mail 1.0 point]))
723     (mail-forward ([mail 1.0 point]))
724     (post-forward ([post 1.0 point]))
725     (reply-yank ([mail 1.0 point]))
726     (followup ([article 0.5]
727                [post 1.0 point]))
728     (followup-yank ([post 1.0 point])))
729   "Window configuration for all possible Gnus buffers.
730 This variable is a list of lists.  Each of these lists has a NAME and
731 a RULE.  The NAMEs are commonsense names like `group', which names a
732 rule used when displaying the group buffer; `summary', which names a
733 rule for what happens when you enter a group and do not display an
734 article buffer; and so on.  See the value of this variable for a
735 complete list of NAMEs.
736
737 Each RULE is a list of vectors.  The first element in this vector is
738 the name of the buffer to be displayed; the second element is the
739 percentage of the screen this buffer is to occupy (a number in the
740 0.0-0.99 range); the optional third element is `point', which should
741 be present to denote which buffer point is to go to after making this
742 buffer configuration.")
743
744 (defvar gnus-window-to-buffer
745   '((group . gnus-group-buffer)
746     (summary . gnus-summary-buffer)
747     (article . gnus-article-buffer)
748     (server . gnus-server-buffer)
749     (browse . "*Gnus Browse Server*")
750     (edit-group . gnus-group-edit-buffer)
751     (edit-server . gnus-server-edit-buffer)
752     (group-carpal . gnus-carpal-group-buffer)
753     (summary-carpal . gnus-carpal-summary-buffer)
754     (server-carpal . gnus-carpal-server-buffer)
755     (browse-carpal . gnus-carpal-browse-buffer)
756     (edit-score . gnus-score-edit-buffer)
757     (mail . gnus-mail-buffer)
758     (post . gnus-post-news-buffer)
759     (faq . gnus-faq-buffer))
760   "Mapping from short symbols to buffer names or buffer variables.")
761
762 (defvar gnus-carpal nil
763   "*If non-nil, display clickable icons.")
764
765 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
766   "*Function called with a group name when new group is detected.
767 A few pre-made functions are supplied: `gnus-subscribe-randomly'
768 inserts new groups at the beginning of the list of groups;
769 `gnus-subscribe-alphabetically' inserts new groups in strict
770 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
771 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
772 for your decision.")
773
774 ;; Suggested by a bug report by Hallvard B Furuseth.
775 ;; <h.b.furuseth@usit.uio.no>. 
776 (defvar gnus-subscribe-options-newsgroup-method
777   (function gnus-subscribe-alphabetically)
778   "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
779 If, for instance, you want to subscribe to all newsgroups in the
780 \"no\" and \"alt\" hierarchies, you'd put the following in your
781 .newsrc file:
782
783 options -n no.all alt.all
784
785 Gnus will the subscribe all new newsgroups in these hierarchies with
786 the subscription method in this variable.")
787
788 (defvar gnus-subscribe-hierarchical-interactive nil
789   "*If non-nil, Gnus will offer to subscribe hierarchically.
790 When a new hierarchy appears, Gnus will ask the user:
791
792 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
793
794 If the user pressed `d', Gnus will descend the hierarchy, `y' will
795 subscribe to all newsgroups in the hierarchy and `s' will skip this
796 hierarchy in its entirety.")
797
798 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
799   "*Function used for sorting the group buffer.
800 This function will be called with group info entries as the arguments
801 for the groups to be sorted.  Pre-made functions include
802 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread' and
803 `gnus-group-sort-by-level'")
804
805 ;; Mark variables suggested by Thomas Michanek
806 ;; <Thomas.Michanek@telelogic.se>. 
807 (defvar gnus-unread-mark ? 
808   "*Mark used for unread articles.")
809 (defvar gnus-ticked-mark ?!
810   "*Mark used for ticked articles.")
811 (defvar gnus-dormant-mark ??
812   "*Mark used for dormant articles.")
813 (defvar gnus-del-mark ?r
814   "*Mark used for del'd articles.")
815 (defvar gnus-read-mark ?R
816   "*Mark used for read articles.")
817 (defvar gnus-expirable-mark ?E
818   "*Mark used for expirable articles.")
819 (defvar gnus-killed-mark ?K
820   "*Mark used for killed articles.")
821 (defvar gnus-kill-file-mark ?X
822   "*Mark used for articles killed by kill files.")
823 (defvar gnus-low-score-mark ?Y
824   "*Mark used for articles with a low score.")
825 (defvar gnus-catchup-mark ?C
826   "*Mark used for articles that are caught up.")
827 (defvar gnus-replied-mark ?A
828   "*Mark used for articles that have been replied to.")
829 (defvar gnus-process-mark ?# 
830   "*Process mark.")
831 (defvar gnus-ancient-mark ?O
832   "*Mark used for ancient articles.")
833 (defvar gnus-canceled-mark ?G
834   "*Mark used for canceled articles.")
835 (defvar gnus-score-over-mark ?+
836   "*Score mark used for articles with high scores.")
837 (defvar gnus-score-below-mark ?-
838   "*Score mark used for articles with low scores.")
839 (defvar gnus-empty-thread-mark ? 
840   "*There is no thread under the article.")
841 (defvar gnus-not-empty-thread-mark ?=
842   "*There is a thread under the article.")
843 (defvar gnus-dummy-mark ?Z
844   "*This is a dummy article.")
845
846 (defvar gnus-view-pseudo-asynchronously nil
847   "*If non-nil, Gnus will view pseudo-articles asynchronously.")
848
849 (defvar gnus-view-pseudos nil
850   "*If `automatic', pseudo-articles will be viewed automatically.
851 If `not-confirm', pseudos will be viewed automatically, and the user
852 will not be asked to confirm the command.")
853
854 (defvar gnus-view-pseudos-separately t
855   "*If non-nil, one pseudo-article will be created for each file to be viewed.
856 If nil, all files that use the same viewing command will be given as a
857 list of parameters to that command.")
858
859 (defvar gnus-group-line-format "%M%S%p%5y: %(%g%)\n"
860   "*Format of group lines.
861 It works along the same lines as a normal formatting string,
862 with some simple extensions.
863
864 %M    Only marked articles (character, \"*\" or \" \")
865 %S    Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
866 %L    Level of subscribedness (integer)
867 %N    Number of unread articles (integer)
868 %I    Number of dormant articles (integer)
869 %i    Number of ticked and dormant (integer)
870 %T    Number of ticked articles (integer)
871 %R    Number of read articles (integer)
872 %t    Total number of articles (integer)
873 %y    Number of unread, unticked articles (integer)
874 %G    Group name (string)
875 %g    Qualified group name (string)
876 %D    Group description (string)
877 %s    Select method (string)
878 %o    Moderated group (char, \"m\")
879 %p    Process mark (char)
880 %O    Moderated group (string, \"(m)\" or \"\")
881 %n    Select from where (string)
882 %z    A string that look like `<%s:%n>' if a foreign select method is used
883 %u    User defined specifier. The next character in the format string should
884       be a letter.  Gnus will call the function gnus-user-format-function-X,
885       where X is the letter following %u. The function will be passed the
886       current header as argument. The function should return a string, which
887       will be inserted into the buffer just like information from any other
888       group specifier.
889
890 Text between %( and %) will be highlighted with `gnus-mouse-face' when
891 the mouse point move inside the area.  There can only be one such area.
892
893 Note that this format specification is not always respected. For
894 reasons of efficiency, when listing killed groups, this specification
895 is ignored altogether. If the spec is changed considerably, your
896 output may end up looking strange when listing both alive and killed
897 groups.
898
899 If you use %o or %O, reading the active file will be slower and quite
900 a bit of extra memory will be used. %D will also worsen performance.
901 Also note that if you change the format specification to include any
902 of these specs, you must probably re-start Gnus to see them go into
903 effect.") 
904
905 (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
906   "*The format specification of the lines in the summary buffer.
907
908 It works along the same lines as a normal formatting string,
909 with some simple extensions.
910
911 %N   Article number, left padded with spaces (string)
912 %S   Subject (string)
913 %s   Subject if it is at the root of a thread, and \"\" otherwise (string)
914 %n   Name of the poster (string)
915 %a   Extracted name of the poster (string)
916 %A   Extracted address of the poster (string)
917 %F   Contents of the From: header (string)
918 %x   Contents of the Xref: header (string)
919 %D   Date of the article (string)
920 %d   Date of the article (string) in DD-MMM format
921 %M   Message-id of the article (string)
922 %r   References of the article (string)
923 %c   Number of characters in the article (integer)
924 %L   Number of lines in the article (integer)
925 %I   Indentation based on thread level (a string of spaces)
926 %T   A string with two possible values: 80 spaces if the article
927      is on thread level two or larger and 0 spaces on level one
928 %R   \"R\" if this article has been replied to, \" \" otherwise (character)
929 %U   Status of this article (character, \"D\", \"K\", \"-\" or \" \")
930 %[   Opening bracket (character, \"[\" or \"<\")
931 %]   Closing bracket (character, \"]\" or \">\")
932 %>   Spaces of length thread-level (string)
933 %<   Spaces of length (- 20 thread-level) (string)
934 %i   Article score (number)
935 %z   Article zcore (character)
936 %t   Number of articles under the current thread (number).
937 %e   Whether the thread is empty or not (character).
938 %u   User defined specifier. The next character in the format string should
939      be a letter.  Gnus will call the function gnus-user-format-function-X,
940      where X is the letter following %u. The function will be passed the
941      current header as argument. The function should return a string, which
942      will be inserted into the summary just like information from any other
943      summary specifier.
944
945 Text between %( and %) will be highlighted with `gnus-mouse-face'
946 when the mouse point is placed inside the area.  There can only be one
947 such area.
948
949 The %U (status), %R (replied) and %z (zcore) specs have to be handled
950 with care. For reasons of efficiency, Gnus will compute what column
951 these characters will end up in, and \"hard-code\" that. This means that
952 it is illegal to have these specs after a variable-length spec. Well,
953 you might not be arrested, but your summary buffer will look strange,
954 which is bad enough.
955
956 The smart choice is to have these specs as for to the left as
957 possible. 
958
959 This restriction may disappear in later versions of Gnus.")
960
961 (defvar gnus-summary-dummy-line-format "*  :                          : %S\n"
962   "*The format specification for the dummy roots in the summary buffer.
963 It works along the same lines as a normal formatting string,
964 with some simple extensions.
965
966 %S  The subject")
967
968 (defvar gnus-summary-mode-line-format "Gnus  %G/%A %Z"
969   "*The format specification for the summary mode line.")
970
971 (defvar gnus-article-mode-line-format "Gnus  %G/%A %S"
972   "*The format specification for the article mode line.")
973
974 (defvar gnus-group-mode-line-format "Gnus  List of groups   {%M:%S}  "
975   "*The format specification for the group mode line.")
976
977 (defvar gnus-valid-select-methods
978   '(("nntp" post address prompt-address)
979     ("nnspool" post)
980     ("nnvirtual" none virtual prompt-address) 
981     ("nnmbox" mail respool) 
982     ("nnml" mail respool)
983     ("nnmh" mail respool) 
984     ("nndir" none prompt-address address)
985     ("nneething" none prompt-address)
986     ("nndigest" none) 
987     ("nndoc" none prompt-address) 
988     ("nnbabyl" mail respool) 
989     ("nnkiboze" post virtual) 
990     ;;("nnsoup" post)
991     ("nnfolder" mail respool))
992   "An alist of valid select methods.
993 The first element of each list lists should be a string with the name
994 of the select method. The other elements may be be the category of
995 this method (ie. `post', `mail', `none' or whatever) or other
996 properties that this method has (like being respoolable).
997 If you implement a new select method, all you should have to change is
998 this variable. I think.")
999
1000 (defvar gnus-updated-mode-lines '(group article summary)
1001   "*List of buffers that should update their mode lines.
1002 The list may contain the symbols `group', `article' and `summary'. If
1003 the corresponding symbol is present, Gnus will keep that mode line
1004 updated with information that may be pertinent. 
1005 If this variable is nil, screen refresh may be quicker.")
1006
1007 ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
1008 (defvar gnus-mode-non-string-length 21
1009   "*Max length of mode-line non-string contents.
1010 If this is nil, Gnus will take space as is needed, leaving the rest
1011 of the modeline intact.")
1012
1013 ;see gnus-cus.el
1014 ;(defvar gnus-mouse-face 'highlight
1015 ;  "*Face used for mouse highlighting in Gnus.
1016 ;No mouse highlights will be done if `gnus-visual' is nil.")
1017
1018 (defvar gnus-summary-mark-below nil
1019   "*Mark all articles with a score below this variable as read.
1020 This variable is local to each summary buffer and usually set by the
1021 score file.")  
1022
1023 (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number)
1024   "*List of functions used for sorting threads in the summary buffer.
1025 By default, threads are sorted by article number.
1026
1027 Each function takes two threads and return non-nil if the first thread
1028 should be sorted before the other.  If you use more than one function,
1029 the primary sort function should be the last.
1030
1031 Ready-mady functions include `gnus-thread-sort-by-number',
1032 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
1033 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
1034 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').")
1035
1036 (defvar gnus-thread-score-function '+
1037   "*Function used for calculating the total score of a thread.
1038
1039 The function is called with the scores of the article and each
1040 subthread and should then return the score of the thread.
1041
1042 Some functions you can use are `+', `max', or `min'.")
1043
1044 (defvar gnus-options-subscribe nil
1045   "*All new groups matching this regexp will be subscribed unconditionally.
1046 Note that this variable deals only with new newsgroups.  This variable
1047 does not affect old newsgroups.")
1048
1049 (defvar gnus-options-not-subscribe nil
1050   "*All new groups matching this regexp will be ignored.
1051 Note that this variable deals only with new newsgroups.  This variable
1052 does not affect old (already subscribed) newsgroups.")
1053
1054 (defvar gnus-auto-expirable-newsgroups nil
1055   "*Groups in which to automatically mark read articles as expirable.
1056 If non-nil, this should be a regexp that should match all groups in
1057 which to perform auto-expiry.  This only makes sense for mail groups.")
1058
1059 (defvar gnus-hidden-properties '(invisible t intangible t)
1060   "Property list to use for hiding text.")
1061
1062 (defvar gnus-modtime-botch nil
1063   "*Non-nil means .newsrc should be deleted prior to save.  Its use is
1064 due to the bogus appearance that .newsrc was modified on disc.")
1065
1066 ;; Hooks.
1067
1068 (defvar gnus-group-mode-hook nil
1069   "*A hook for Gnus group mode.")
1070
1071 (defvar gnus-summary-mode-hook nil
1072   "*A hook for Gnus summary mode.
1073 This hook is run before any variables are set in the summary buffer.")
1074
1075 (defvar gnus-article-mode-hook nil
1076   "*A hook for Gnus article mode.")
1077
1078 (defun gnus-summary-prepare-exit-hook nil
1079   "*A hook called when preparing to exit from the summary buffer.
1080 It calls `gnus-summary-expire-articles' by default.")
1081 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles)
1082
1083 (defun gnus-summary-exit-hook nil
1084   "*A hook called on exit from the summary buffer.")
1085
1086 (defvar gnus-open-server-hook nil
1087   "*A hook called just before opening connection to the news server.")
1088
1089 (defvar gnus-startup-hook nil
1090   "*A hook called at startup.
1091 This hook is called after Gnus is connected to the NNTP server.")
1092
1093 (defvar gnus-get-new-news-hook nil
1094   "*A hook run just before Gnus checks for new news.")
1095
1096 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
1097   "*A function that is called to generate the group buffer.
1098 The function is called with three arguments: The first is a number;
1099 all group with a level less or equal to that number should be listed,
1100 if the second is non-nil, empty groups should also be displayed. If
1101 the third is non-nil, it is a number. No groups with a level lower
1102 than this number should be displayed.
1103
1104 The only current function implemented is `gnus-group-prepare-flat'.")
1105
1106 (defvar gnus-group-prepare-hook nil
1107   "*A hook called after the group buffer has been generated.
1108 If you want to modify the group buffer, you can use this hook.")
1109
1110 (defvar gnus-summary-prepare-hook nil
1111   "*A hook called after the summary buffer has been generated.
1112 If you want to modify the summary buffer, you can use this hook.")
1113
1114 (defvar gnus-article-prepare-hook nil
1115   "*A hook called after an article has been prepared in the article buffer.
1116 If you want to run a special decoding program like nkf, use this hook.")
1117
1118 ;(defvar gnus-article-display-hook nil
1119 ;  "*A hook called after the article is displayed in the article buffer.
1120 ;The hook is designed to change the contents of the article
1121 ;buffer. Typical functions that this hook may contain are
1122 ;`gnus-article-hide-headers' (hide selected headers),
1123 ;`gnus-article-maybe-highlight' (perform fancy article highlighting), 
1124 ;`gnus-article-hide-signature' (hide signature) and
1125 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
1126 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
1127 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
1128 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
1129
1130 (defvar gnus-article-x-face-command
1131   "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
1132   "String or function to be executed to display an X-Face header.
1133 If it is a string, the command will be executed in a sub-shell
1134 asynchronously. The compressed face will be piped to this command.") 
1135
1136 (defvar gnus-article-x-face-too-ugly nil
1137   "Regexp matching posters whose face shouldn't be shown automatically.")
1138
1139 (defvar gnus-select-group-hook nil
1140   "*A hook called when a newsgroup is selected.
1141
1142 If you'd like to simplify subjects like the
1143 `gnus-summary-next-same-subject' command does, you can use the
1144 following hook:
1145
1146  (setq gnus-select-group-hook
1147       (list
1148         (lambda ()
1149           (mapcar (lambda (header)
1150                      (header-set-subject
1151                       header
1152                       (gnus-simplify-subject
1153                        (header-subject header) 're-only)))
1154                   gnus-newsgroup-headers))))")
1155
1156 (defvar gnus-select-article-hook
1157   '(gnus-summary-show-thread)
1158   "*A hook called when an article is selected.
1159 The default hook shows conversation thread subtrees of the selected
1160 article automatically using `gnus-summary-show-thread'.")
1161
1162 (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
1163   "*A hook called to apply kill files to a group.
1164 This hook is intended to apply a kill file to the selected newsgroup.
1165 The function `gnus-apply-kill-file' is called by default.
1166
1167 Since a general kill file is too heavy to use only for a few
1168 newsgroups, I recommend you to use a lighter hook function. For
1169 example, if you'd like to apply a kill file to articles which contains
1170 a string `rmgroup' in subject in newsgroup `control', you can use the
1171 following hook:
1172
1173  (setq gnus-apply-kill-hook
1174       (list
1175         (lambda ()
1176           (cond ((string-match \"control\" gnus-newsgroup-name)
1177                  (gnus-kill \"Subject\" \"rmgroup\")
1178                  (gnus-expunge \"X\"))))))")
1179
1180 (defvar gnus-visual-mark-article-hook 
1181   (list 'gnus-highlight-selected-summary)
1182   "*Hook run after selecting an article in the summary buffer.
1183 It is meant to be used for highlighting the article in some way.  It
1184 is not run if `gnus-visual' is nil.")
1185
1186 (defvar gnus-prepare-article-hook (list 'gnus-inews-insert-signature)
1187   "*A hook called after preparing body, but before preparing header headers.
1188 The default hook (`gnus-inews-insert-signature') inserts a signature
1189 file specified by the variable `gnus-signature-file'.")
1190
1191 (defvar gnus-exit-group-hook nil
1192   "*A hook called when exiting (not quitting) summary mode.")
1193
1194 (defvar gnus-suspend-gnus-hook nil
1195   "*A hook called when suspending (not exiting) Gnus.")
1196
1197 (defvar gnus-exit-gnus-hook nil
1198   "*A hook called when exiting Gnus.")
1199
1200 (defvar gnus-save-newsrc-hook nil
1201   "*A hook called when saving the newsrc file.")
1202
1203 (defvar gnus-summary-update-hook 
1204   (list 'gnus-summary-highlight-line)
1205   "*A hook called when a summary line is changed.
1206 The hook will not be called if `gnus-visual' is nil.
1207
1208 The default function `gnus-summary-highlight-line' will
1209 highlight the line according to the `gnus-summary-highlight'
1210 variable.")
1211
1212 (defvar gnus-mark-article-hook (list 'gnus-summary-mark-unread-as-read)
1213   "*A hook called when an article is selected for the first time.
1214 The hook is intended to mark an article as read (or unread)
1215 automatically when it is selected.")
1216
1217 ;; Remove any hilit infestation.
1218 (add-hook 'gnus-startup-hook
1219           (lambda ()
1220             (remove-hook 'gnus-summary-prepare-hook
1221                          'hilit-rehighlight-buffer-quietly)
1222             (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks)
1223             (setq gnus-mark-article-hook '(gnus-summary-mark-unread-as-read))
1224             (remove-hook 'gnus-article-prepare-hook
1225                          'hilit-rehighlight-buffer-quietly)))
1226
1227
1228 \f
1229 ;; Internal variables
1230
1231 ;; Avoid highlighting in kill files.
1232 (defvar gnus-summary-inhibit-highlight nil)
1233 (defvar gnus-newsgroup-selected-overlay nil)
1234
1235 (defvar gnus-article-mode-map nil)
1236 (defvar gnus-dribble-buffer nil)
1237 (defvar gnus-headers-retrieved-by nil)
1238 (defvar gnus-article-reply nil)
1239 (defvar gnus-override-method nil)
1240 (defvar gnus-article-check-size nil)
1241
1242 (defvar gnus-current-score-file nil)
1243 (defvar gnus-internal-global-score-files nil)
1244 (defvar gnus-score-file-list nil)
1245
1246
1247 (defvar gnus-current-move-group nil)
1248
1249 (defvar gnus-newsgroup-dependencies nil)
1250 (defvar gnus-newsgroup-threads nil)
1251 (defvar gnus-newsgroup-async nil)
1252 (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*")
1253
1254 (defvar gnus-newsgroup-adaptive nil)
1255
1256 (defvar gnus-summary-display-table nil)
1257
1258 (defconst gnus-group-line-format-alist
1259   (list (list ?M 'marked ?c)
1260         (list ?S 'subscribed ?c)
1261         (list ?L 'level ?d)
1262         (list ?N 'number ?s)
1263         (list ?I 'number-of-dormant ?d)
1264         (list ?T 'number-of-ticked ?d)
1265         (list ?R 'number-of-read ?s)
1266         (list ?t 'number-total ?d)
1267         (list ?y 'number-of-unread-unticked ?s)
1268         (list ?i 'number-of-ticked-and-dormant ?d)
1269         (list ?g 'group ?s)
1270         (list ?G 'qualified-group ?s)
1271         (list ?D 'newsgroup-description ?s)
1272         (list ?o 'moderated ?c)
1273         (list ?O 'moderated-string ?s)
1274         (list ?p 'process-marked ?c)
1275         (list ?s 'news-server ?s)
1276         (list ?n 'news-method ?s)
1277         (list ?z 'news-method-string ?s)
1278         (list ?u 'user-defined ?s)))
1279
1280 (defconst gnus-summary-line-format-alist 
1281   (list (list ?N 'number ?d)
1282         (list ?S 'subject ?s)
1283         (list ?s 'subject-or-nil ?s)
1284         (list ?n 'name ?s)
1285         (list ?A '(car (cdr (funcall gnus-extract-address-components from)))
1286               ?s)
1287         (list ?a '(or (car (funcall gnus-extract-address-components from)) 
1288                       from) ?s)
1289         (list ?F 'from ?s)
1290         (list ?x (macroexpand '(header-xref header)) ?s)
1291         (list ?D (macroexpand '(header-date header)) ?s)
1292         (list ?d '(gnus-dd-mmm (header-date header)) ?s)
1293         (list ?M (macroexpand '(header-id header)) ?s)
1294         (list ?r (macroexpand '(header-references header)) ?s)
1295         (list ?c '(or (header-chars header) 0) ?d)
1296         (list ?L 'lines ?d)
1297         (list ?I 'indentation ?s)
1298         (list ?T '(if (= level 0) "" (make-string (frame-width) ? )) ?s)
1299         (list ?R 'replied ?c)
1300         (list ?\[ 'opening-bracket ?c)
1301         (list ?\] 'closing-bracket ?c)
1302         (list ?\> '(make-string level ? ) ?s)
1303         (list ?\< '(make-string (max 0 (- 20 level)) ? ) ?s)
1304         (list ?i 'score ?d)
1305         (list ?z 'score-char ?c)
1306         (list ?U 'unread ?c)
1307         (list ?t '(gnus-summary-number-of-articles-in-thread 
1308                    (and (boundp 'thread) (car thread)))
1309               ?d)
1310         (list ?e '(gnus-summary-number-of-articles-in-thread 
1311                    (and (boundp 'thread) (car thread)) t)
1312               ?c)
1313         (list ?u 'user-defined ?s))
1314   "An alist of format specifications that can appear in summary lines,
1315 and what variables they correspond with, along with the type of the
1316 variable (string, integer, character, etc).")
1317
1318 (defconst gnus-summary-dummy-line-format-alist
1319   (list (list ?S 'subject ?s)
1320         (list ?N 'number ?d)
1321         (list ?u 'user-defined ?s)))
1322
1323 (defconst gnus-summary-mode-line-format-alist 
1324   (list (list ?G 'group-name ?s)
1325         (list ?g '(gnus-short-group-name group-name) ?s)
1326         (list ?A 'article-number ?d)
1327         (list ?Z 'unread-and-unselected ?s)
1328         (list ?V 'gnus-version ?s)
1329         (list ?U 'unread ?d)
1330         (list ?S 'subject ?s)
1331         (list ?e 'unselected ?d)
1332         (list ?u 'user-defined ?s)
1333         (list ?s '(gnus-current-score-file-nondirectory) ?s)))
1334
1335 (defconst gnus-group-mode-line-format-alist 
1336   (list (list ?S 'news-server ?s)
1337         (list ?M 'news-method ?s)
1338         (list ?u 'user-defined ?s)))
1339
1340 (defvar gnus-have-read-active-file nil)
1341
1342 (defconst gnus-maintainer
1343   "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)"
1344   "The mail address of the Gnus maintainers.")
1345
1346 (defconst gnus-version "(ding) Gnus v0.99.22"
1347   "Version number for this version of Gnus.")
1348
1349 (defvar gnus-info-nodes
1350   '((gnus-group-mode            "(gnus)The Group Buffer")
1351     (gnus-summary-mode          "(gnus)The Summary Buffer")
1352     (gnus-article-mode          "(gnus)The Article Buffer"))
1353   "Assoc list of major modes and related Info nodes.")
1354
1355 (defvar gnus-documentation-group-file "~/dgnus/lisp/doc.txt"
1356   "The location of the Gnus documentation group.")
1357
1358 (defvar gnus-group-buffer "*Group*")
1359 (defvar gnus-summary-buffer "*Summary*")
1360 (defvar gnus-article-buffer "*Article*")
1361 (defvar gnus-server-buffer "*Server*")
1362
1363 (defvar gnus-work-buffer " *gnus work*")
1364
1365 (defvar gnus-buffer-list nil
1366   "Gnus buffers that should be killed on exit.")
1367
1368 (defvar gnus-server-alist nil
1369   "List of available servers.")
1370
1371 (defvar gnus-variable-list
1372   '(gnus-newsrc-options gnus-newsrc-options-n
1373     gnus-newsrc-last-checked-date 
1374     gnus-newsrc-alist gnus-server-alist
1375     gnus-killed-list gnus-zombie-list)
1376   "Gnus variables saved in the quick startup file.")
1377
1378 (defvar gnus-overload-functions
1379   '((news-inews gnus-inews-news "rnewspost"))
1380   "Functions overloaded by gnus.
1381 It is a list of `(original overload &optional file)'.")
1382
1383 (defvar gnus-newsrc-options nil
1384   "Options line in the .newsrc file.")
1385
1386 (defvar gnus-newsrc-options-n nil
1387   "List of regexps representing groups to be subscribed/ignored unconditionally.") 
1388
1389 (defvar gnus-newsrc-last-checked-date nil
1390   "Date Gnus last asked server for new newsgroups.")
1391
1392 (defvar gnus-newsrc-alist nil
1393   "Assoc list of read articles.
1394 gnus-newsrc-hashtb should be kept so that both hold the same information.")
1395
1396 (defvar gnus-newsrc-hashtb nil
1397   "Hashtable of gnus-newsrc-alist.")
1398
1399 (defvar gnus-killed-list nil
1400   "List of killed newsgroups.")
1401
1402 (defvar gnus-killed-hashtb nil
1403   "Hash table equivalent of gnus-killed-list.")
1404
1405 (defvar gnus-zombie-list nil
1406   "List of almost dead newsgroups.")
1407
1408 (defvar gnus-description-hashtb nil
1409   "Descriptions of newsgroups.")
1410
1411 (defvar gnus-list-of-killed-groups nil
1412   "List of newsgroups that have recently been killed by the user.")
1413
1414 (defvar gnus-active-hashtb nil
1415   "Hashtable of active articles.")
1416
1417 (defvar gnus-moderated-list nil
1418   "List of moderated newsgroups.")
1419
1420 (defvar gnus-group-marked nil)
1421
1422 (defvar gnus-current-startup-file nil
1423   "Startup file for the current host.")
1424
1425 (defvar gnus-last-search-regexp nil
1426   "Default regexp for article search command.")
1427
1428 (defvar gnus-last-shell-command nil
1429   "Default shell command on article.")
1430
1431 (defvar gnus-current-select-method nil
1432   "The current method for selecting a newsgroup.")
1433
1434 (defvar gnus-group-list-mode nil)
1435
1436 (defvar gnus-article-internal-prepare-hook nil)
1437
1438 (defvar gnus-newsgroup-name nil)
1439 (defvar gnus-newsgroup-begin nil)
1440 (defvar gnus-newsgroup-end nil)
1441 (defvar gnus-newsgroup-last-rmail nil)
1442 (defvar gnus-newsgroup-last-mail nil)
1443 (defvar gnus-newsgroup-last-folder nil)
1444 (defvar gnus-newsgroup-last-file nil)
1445 (defvar gnus-newsgroup-auto-expire nil)
1446 (defvar gnus-newsgroup-active nil)
1447
1448 (defvar gnus-newsgroup-unreads nil
1449   "List of unread articles in the current newsgroup.")
1450
1451 (defvar gnus-newsgroup-unselected nil
1452   "List of unselected unread articles in the current newsgroup.")
1453
1454 (defvar gnus-newsgroup-reads nil
1455   "Alist of read articles and article marks in the current newsgroup.")
1456
1457 (defvar gnus-newsgroup-marked nil
1458   "List of ticked articles in the current newsgroup (a subset of unread art).")
1459
1460 (defvar gnus-newsgroup-killed nil
1461   "List of ranges of articles that have been through the scoring process.")
1462
1463 (defvar gnus-newsgroup-kill-headers nil)
1464
1465 (defvar gnus-newsgroup-replied nil
1466   "List of articles that have been replied to in the current newsgroup.")
1467
1468 (defvar gnus-newsgroup-expirable nil
1469   "List of articles in the current newsgroup that can be expired.")
1470
1471 (defvar gnus-newsgroup-processable nil
1472   "List of articles in the current newsgroup that can be processed.")
1473
1474 (defvar gnus-newsgroup-bookmarks nil
1475   "List of articles in the current newsgroup that have bookmarks.")
1476
1477 (defvar gnus-newsgroup-dormant nil
1478   "List of dormant articles in the current newsgroup.")
1479
1480 (defvar gnus-newsgroup-scored nil
1481   "List of scored articles in the current newsgroup.")
1482
1483 (defvar gnus-newsgroup-headers nil
1484   "List of article headers in the current newsgroup.")
1485 (defvar gnus-newsgroup-headers-hashtb-by-number nil)
1486
1487 (defvar gnus-newsgroup-ancient nil
1488   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1489
1490 (defvar gnus-current-article nil)
1491 (defvar gnus-article-current nil)
1492 (defvar gnus-current-headers nil)
1493 (defvar gnus-have-all-headers nil)
1494 (defvar gnus-last-article nil)
1495 (defvar gnus-newsgroup-history nil)
1496 (defvar gnus-current-kill-article nil)
1497
1498 ;; Save window configuration.
1499 (defvar gnus-prev-winconf nil)
1500
1501 ;; Format specs
1502 (defvar gnus-summary-line-format-spec nil)
1503 (defvar gnus-summary-dummy-line-format-spec nil)
1504 (defvar gnus-group-line-format-spec nil)
1505 (defvar gnus-summary-mode-line-format-spec nil)
1506 (defvar gnus-article-mode-line-format-spec nil)
1507 (defvar gnus-group-mode-line-format-spec nil)
1508 (defvar gnus-summary-mark-positions nil)
1509 (defvar gnus-group-mark-positions nil)
1510
1511 (defvar gnus-summary-expunge-below nil)
1512 (defvar gnus-reffed-article-number nil)
1513
1514 (defvar rmail-default-file (expand-file-name "~/XMBOX"))
1515 (defvar rmail-default-rmail-file (expand-file-name "~/XNEWS"))
1516
1517 (defvar gnus-cache-removeable-articles nil)
1518
1519 (defconst gnus-summary-local-variables 
1520   '(gnus-newsgroup-name 
1521     gnus-newsgroup-begin gnus-newsgroup-end 
1522     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail 
1523     gnus-newsgroup-last-folder gnus-newsgroup-last-file 
1524     gnus-newsgroup-auto-expire gnus-newsgroup-unreads 
1525     gnus-newsgroup-unselected gnus-newsgroup-marked
1526     gnus-newsgroup-reads
1527     gnus-newsgroup-replied gnus-newsgroup-expirable
1528     gnus-newsgroup-processable gnus-newsgroup-killed
1529     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1530     gnus-newsgroup-headers gnus-newsgroup-headers-hashtb-by-number
1531     gnus-current-article gnus-current-headers gnus-have-all-headers
1532     gnus-last-article gnus-article-internal-prepare-hook
1533     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1534     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1535     gnus-newsgroup-threads gnus-newsgroup-async
1536     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below 
1537     gnus-summary-mark-below gnus-newsgroup-active gnus-scores-exclude-files
1538     gnus-newsgroup-history gnus-newsgroup-ancient
1539     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1540     gnus-cache-removeable-articles)
1541   "Variables that are buffer-local to the summary buffers.")
1542
1543 (defconst gnus-bug-message
1544   "Sending a bug report to the Gnus Towers.
1545 ========================================
1546
1547 The buffer below is a mail buffer.  When you press `C-c C-c', it will
1548 be sent to the Gnus Bug Exterminators. 
1549
1550 At the bottom of the buffer you'll see lots of variable settings.
1551 Please do not delete those.  They will tell the Bug People what your
1552 environment is, so that it will be easier to locate the bugs.
1553
1554 If you have found a bug that makes Emacs go \"beep\", set
1555 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET') 
1556 and include the backtrace in your bug report.
1557
1558 Please describe the bug in annoying, painstaking detail.
1559
1560 Thank you for your help in stamping out bugs.
1561 ")
1562
1563 ;;; End of variables.
1564
1565 ;; Define some autoload functions Gnus might use.
1566 (eval-and-compile
1567
1568   ;; Various 
1569   (autoload 'metamail-buffer "metamail")
1570   (autoload 'Info-goto-node "info")
1571   (autoload 'hexl-hex-string-to-integer "hexl")
1572   (autoload 'pp "pp")
1573   (autoload 'pp-to-string "pp")
1574   (autoload 'pp-eval-expression "pp")
1575   (autoload 'mail-extract-address-components "mail-extr")
1576
1577   (autoload 'nnmail-split-fancy "nnmail")
1578   (autoload 'nnvirtual-catchup-group "nnvirtual")
1579
1580   ;; timezone
1581   (autoload 'timezone-make-date-arpa-standard "timezone")
1582   (autoload 'timezone-fix-time "timezone")
1583   (autoload 'timezone-make-sortable-date "timezone")
1584   (autoload 'timezone-make-time-string "timezone")
1585
1586   ;; rmail & friends
1587   (autoload 'mail-position-on-field "sendmail")
1588   (autoload 'mail-setup "sendmail")
1589   (autoload 'rmail-output "rmailout")
1590   (autoload 'news-mail-other-window "rnewspost")
1591   (autoload 'news-reply-yank-original "rnewspost")
1592   (autoload 'news-caesar-buffer-body "rnewspost")
1593   (autoload 'rmail-insert-rmail-file-header "rmail")
1594   (autoload 'rmail-count-new-messages "rmail")
1595   (autoload 'rmail-show-message "rmail")
1596
1597   ;; gnus-soup
1598   ;;(autoload 'gnus-group-brew-soup "gnus-soup" nil t)
1599   ;;(autoload 'gnus-brew-soup "gnus-soup" nil t)
1600   ;;(autoload 'gnus-soup-add-article "gnus-soup" nil t)
1601   ;;(autoload 'gnus-soup-send-replies "gnus-soup" nil t)
1602   ;;(autoload 'gnus-soup-save-areas "gnus-soup" nil t)
1603   ;;(autoload 'gnus-soup-pack-packet "gnus-soup" nil t)
1604   ;;(autoload 'nnsoup-pack-replies "nnsoup" nil t)
1605
1606   ;; gnus-mh
1607   (autoload 'gnus-mail-reply-using-mhe "gnus-mh")
1608   (autoload 'gnus-mail-forward-using-mhe "gnus-mh")
1609   (autoload 'gnus-mail-other-window-using-mhe "gnus-mh")
1610   (autoload 'gnus-summary-save-in-folder "gnus-mh")
1611   (autoload 'gnus-summary-save-article-folder "gnus-mh")
1612   (autoload 'gnus-Folder-save-name "gnus-mh")
1613   (autoload 'gnus-folder-save-name "gnus-mh")
1614
1615   ;; gnus-vis misc
1616   (autoload 'gnus-group-make-menu-bar "gnus-vis")
1617   (autoload 'gnus-summary-make-menu-bar "gnus-vis")
1618   (autoload 'gnus-server-make-menu-bar "gnus-vis")
1619   (autoload 'gnus-article-make-menu-bar "gnus-vis")
1620   (autoload 'gnus-browse-make-menu-bar "gnus-vis")
1621   (autoload 'gnus-highlight-selected-summary "gnus-vis")
1622   (autoload 'gnus-summary-highlight-line "gnus-vis")
1623   (autoload 'gnus-carpal-setup-buffer "gnus-vis")
1624
1625   ;; gnus-vis article
1626   (autoload 'gnus-article-push-button "gnus-vis" nil t)
1627   (autoload 'gnus-article-press-button "gnus-vis" nil t)
1628   (autoload 'gnus-article-highlight "gnus-vis" nil t)
1629   (autoload 'gnus-article-highlight-some "gnus-vis" nil t)
1630   (autoload 'gnus-article-hide "gnus-vis" nil t)
1631   (autoload 'gnus-article-hide-signature "gnus-vis" nil t)
1632   (autoload 'gnus-article-highlight-headers "gnus-vis" nil t)
1633   (autoload 'gnus-article-highlight-signature "gnus-vis" nil t)
1634   (autoload 'gnus-article-add-buttons "gnus-vis" nil t)
1635   (autoload 'gnus-article-next-button "gnus-vis" nil t)
1636   (autoload 'gnus-article-add-button "gnus-vis")
1637
1638   ;; gnus-cite
1639   (autoload 'gnus-article-highlight-citation "gnus-cite" nil t)
1640   (autoload 'gnus-article-hide-citation-maybe "gnus-cite" nil t)
1641   (autoload 'gnus-article-hide-citation "gnus-cite" nil t)
1642
1643   ;; gnus-kill
1644   (autoload 'gnus-kill "gnus-kill")
1645   (autoload 'gnus-apply-kill-file-internal "gnus-kill")
1646   (autoload 'gnus-kill-file-edit-file "gnus-kill")
1647   (autoload 'gnus-kill-file-raise-followups-to-author "gnus-kill")
1648   (autoload 'gnus-execute "gnus-kill")
1649   (autoload 'gnus-expunge "gnus-kill")
1650
1651   ;; gnus-cache
1652   (autoload 'gnus-cache-possibly-enter-article "gnus-cache")
1653   (autoload 'gnus-cache-save-buffers "gnus-cache")
1654   (autoload 'gnus-cache-possibly-remove-articles "gnus-cache")
1655   (autoload 'gnus-cache-request-article "gnus-cache")
1656   (autoload 'gnus-cache-retrieve-headers "gnus-cache")
1657   (autoload 'gnus-cache-possibly-alter-active "gnus-cache")
1658   (autoload 'gnus-jog-cache "gnus-cache" nil t)
1659   (autoload 'gnus-cache-enter-remove-article "gnus-cache")
1660
1661   ;; gnus-score
1662   (autoload 'gnus-summary-increase-score "gnus-score" nil t)
1663   (autoload 'gnus-summary-lower-score "gnus-score" nil t)
1664   (autoload 'gnus-summary-score-map "gnus-score" nil nil 'keymap)
1665   (autoload 'gnus-score-save "gnus-score")
1666   (autoload 'gnus-score-headers "gnus-score")
1667   (autoload 'gnus-current-score-file-nondirectory "gnus-score")
1668   (autoload 'gnus-score-adaptive "gnus-score")
1669   (autoload 'gnus-score-remove-lines-adaptive "gnus-score")
1670   (autoload 'gnus-score-find-trace "gnus-score")
1671
1672   ;; gnus-edit
1673   (autoload 'gnus-score-customize "gnus-edit" nil t)
1674
1675   ;; gnus-uu
1676   (autoload 'gnus-uu-extract-map "gnus-uu" nil nil 'keymap)
1677   (autoload 'gnus-uu-mark-map "gnus-uu" nil nil 'keymap)
1678   (autoload 'gnus-uu-digest-mail-forward "gnus-uu" nil t)
1679   (autoload 'gnus-uu-digest-post-forward "gnus-uu" nil t)
1680   (autoload 'gnus-uu-mark-series "gnus-uu" nil t)
1681   (autoload 'gnus-uu-mark-region "gnus-uu" nil t)
1682   (autoload 'gnus-uu-mark-by-regexp "gnus-uu" nil t)
1683   (autoload 'gnus-uu-mark-all "gnus-uu" nil t)
1684   (autoload 'gnus-uu-mark-sparse "gnus-uu" nil t)
1685   (autoload 'gnus-uu-mark-thread "gnus-uu" nil t)
1686   (autoload 'gnus-uu-decode-uu "gnus-uu" nil t)
1687   (autoload 'gnus-uu-decode-uu-and-save "gnus-uu" nil t)
1688   (autoload 'gnus-uu-decode-unshar "gnus-uu" nil t)
1689   (autoload 'gnus-uu-decode-unshar-and-save "gnus-uu" nil t)
1690   (autoload 'gnus-uu-decode-save "gnus-uu" nil t)
1691   (autoload 'gnus-uu-decode-binhex "gnus-uu" nil t)
1692   (autoload 'gnus-uu-decode-uu-view "gnus-uu" nil t)
1693   (autoload 'gnus-uu-decode-uu-and-save-view "gnus-uu" nil t)
1694   (autoload 'gnus-uu-decode-unshar-view "gnus-uu" nil t)
1695   (autoload 'gnus-uu-decode-unshar-and-save-view "gnus-uu" nil t)
1696   (autoload 'gnus-uu-decode-save-view "gnus-uu" nil t)
1697   (autoload 'gnus-uu-decode-binhex-view "gnus-uu" nil t)
1698
1699   ;; gnus-msg
1700   (autoload 'gnus-summary-send-map "gnus-msg" nil nil 'keymap)
1701   (autoload 'gnus-group-post-news "gnus-msg" nil t)
1702   (autoload 'gnus-group-mail "gnus-msg" nil t)
1703   (autoload 'gnus-summary-post-news "gnus-msg" nil t)
1704   (autoload 'gnus-summary-followup "gnus-msg" nil t)
1705   (autoload 'gnus-summary-followup-with-original "gnus-msg" nil t)
1706   (autoload 'gnus-summary-followup-and-reply "gnus-msg" nil t)
1707   (autoload 'gnus-summary-followup-and-reply-with-original "gnus-msg" nil t)
1708   (autoload 'gnus-summary-cancel-article "gnus-msg" nil t)
1709   (autoload 'gnus-summary-supersede-article "gnus-msg" nil t)
1710   (autoload 'gnus-post-news "gnus-msg" nil t)
1711   (autoload 'gnus-inews-news "gnus-msg" nil t)
1712   (autoload 'gnus-cancel-news "gnus-msg" nil t)
1713   (autoload 'gnus-summary-reply "gnus-msg" nil t)
1714   (autoload 'gnus-summary-reply-with-original "gnus-msg" nil t)
1715   (autoload 'gnus-summary-mail-forward "gnus-msg" nil t)
1716   (autoload 'gnus-summary-mail-other-window "gnus-msg" nil t)
1717   (autoload 'gnus-mail-reply-using-mail "gnus-msg")
1718   (autoload 'gnus-mail-yank-original "gnus-msg")
1719   (autoload 'gnus-mail-send-and-exit "gnus-msg")
1720   (autoload 'gnus-mail-forward-using-mail "gnus-msg")
1721   (autoload 'gnus-mail-other-window-using-mail "gnus-msg")
1722   (autoload 'gnus-article-mail-with-original "gnus-msg")
1723   (autoload 'gnus-article-mail "gnus-msg")
1724   (autoload 'gnus-bug "gnus-msg" nil t)
1725
1726   ;; gnus-vm
1727   (autoload 'gnus-summary-save-in-vm "gnus-vm" nil t)
1728   (autoload 'gnus-summary-save-article-vm "gnus-vm" nil t)
1729   (autoload 'gnus-mail-forward-using-vm "gnus-vm")
1730   (autoload 'gnus-mail-reply-using-vm "gnus-vm")
1731   (autoload 'gnus-mail-other-window-using-vm "gnus-vm" nil t)
1732   (autoload 'gnus-yank-article "gnus-vm" nil t)
1733
1734   )
1735
1736 \f
1737
1738 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1739 ;; If you want the cursor to go somewhere else, set these two
1740 ;; functions in some startup hook to whatever you want.
1741 (defalias 'gnus-summary-position-cursor 'gnus-goto-colon)
1742 (defalias 'gnus-group-position-cursor 'gnus-goto-colon)
1743
1744 ;;; Various macros and substs.
1745
1746 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
1747   "Pop to BUFFER, evaluate FORMS, and then returns to original window."
1748   (` (let ((GnusStartBufferWindow (selected-window)))
1749        (unwind-protect
1750            (progn
1751              (pop-to-buffer (, buffer))
1752              (,@ forms))
1753          (select-window GnusStartBufferWindow)))))
1754
1755 (defmacro gnus-gethash (string hashtable)
1756   "Get hash value of STRING in HASHTABLE."
1757   ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable))))
1758   ;;(` (abbrev-expansion (, string) (, hashtable)))
1759   (` (symbol-value (intern-soft (, string) (, hashtable)))))
1760
1761 (defmacro gnus-sethash (string value hashtable)
1762   "Set hash value. Arguments are STRING, VALUE, and HASHTABLE."
1763   ;; We cannot use define-abbrev since it only accepts string as value.
1764   ;; (set (intern string hashtable) value))
1765   (` (set (intern (, string) (, hashtable)) (, value))))
1766
1767 (defsubst gnus-buffer-substring (beg end)
1768   (buffer-substring (match-beginning beg) (match-end end)))
1769
1770 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1771 ;;   function `substring' might cut on a middle of multi-octet
1772 ;;   character.
1773 (defun gnus-truncate-string (str width)
1774   (substring str 0 width))
1775
1776 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>. A safe way
1777 ;; to limit the length of a string. This function is necessary since
1778 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
1779 (defsubst gnus-limit-string (str width)
1780   (if (> (length str) width)
1781       (substring str 0 width)
1782     str))
1783
1784 (defsubst gnus-simplify-subject-re (subject)
1785   "Remove \"Re:\" from subject lines."
1786   (let ((case-fold-search t))
1787     (if (string-match "^re: *" subject)
1788         (substring subject (match-end 0))
1789       subject)))
1790
1791 (defsubst gnus-goto-char (point)
1792   (and point (goto-char point)))
1793
1794 (defmacro gnus-buffer-exists-p (buffer)
1795   (` (and (, buffer)
1796           (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name)
1797                    (, buffer)))))
1798
1799 (defmacro gnus-kill-buffer (buffer)
1800   (` (if (gnus-buffer-exists-p (, buffer))
1801          (kill-buffer (, buffer)))))
1802
1803 (defsubst gnus-point-at-bol ()
1804   "Return point at the beginning of line."
1805   (let ((p (point)))
1806     (beginning-of-line)
1807     (prog1
1808         (point)
1809       (goto-char p))))
1810
1811 (defsubst gnus-point-at-eol ()
1812   "Return point at the beginning of line."
1813   (let ((p (point)))
1814     (end-of-line)
1815     (prog1
1816         (point)
1817       (goto-char p))))
1818
1819 ;; Delete the current line (and the next N lines.);
1820 (defmacro gnus-delete-line (&optional n)
1821   (` (delete-region (progn (beginning-of-line) (point))
1822                     (progn (forward-line (, (or n 1))) (point)))))
1823
1824 ;;; Load the compatability functions. 
1825
1826 (require 'gnus-cus)
1827 (require 'gnus-ems)
1828
1829 \f
1830 ;;;
1831 ;;; Gnus Utility Functions
1832 ;;;
1833
1834 (defun gnus-extract-address-components (from)
1835   (let (name address)
1836     ;; First find the address - the thing with the @ in it.  This may
1837     ;; not be accurate in mail addresses, but does the trick most of
1838     ;; the time in news messages.
1839     (if (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
1840         (setq address (substring from (match-beginning 0) (match-end 0))))
1841     ;; Then we check whether the "name <address>" format is used.
1842     (and address
1843          (string-match (concat "<" (regexp-quote address) ">") from)
1844          (and (setq name (substring from 0 (1- (match-beginning 0))))
1845               ;; Strip any quotes from the name.
1846               (string-match "\".*\"" name)
1847               (setq name (substring name 1 (1- (match-end 0))))))
1848     ;; If not, then "address (name)" is used.
1849     (or name
1850         (and (string-match "(.+)" from)
1851              (setq name (substring from (1+ (match-beginning 0)) 
1852                                    (1- (match-end 0)))))
1853         (and (string-match "()" from)
1854              (setq name address))
1855         ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
1856         ;; XOVER might not support folded From headers.
1857         (and (string-match "(.*" from)
1858              (setq name (substring from (1+ (match-beginning 0)) 
1859                                    (match-end 0)))))
1860     ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1861     (list (or name from) (or address from))))
1862
1863 (defun gnus-fetch-field (field)
1864   "Return the value of the header FIELD of current article."
1865   (save-excursion
1866     (save-restriction
1867       (let ((case-fold-search t))
1868         (gnus-narrow-to-headers)
1869         (mail-fetch-field field)))))
1870
1871 (defun gnus-goto-colon ()
1872   (beginning-of-line)
1873   (search-forward ":" (gnus-point-at-eol) t))
1874
1875 (defun gnus-narrow-to-headers ()
1876   (widen)
1877   (save-excursion
1878     (narrow-to-region
1879      (goto-char (point-min))
1880      (if (search-forward "\n\n" nil t)
1881          (1- (point))
1882        (point-max)))))
1883
1884 (defvar gnus-old-specs nil)
1885
1886 (defun gnus-update-format-specifications ()
1887   (gnus-make-thread-indent-array)
1888
1889   (let ((formats '(summary summary-dummy group 
1890                            summary-mode group-mode article-mode))
1891         old-format new-format)
1892     (while formats
1893       (setq new-format (symbol-value
1894                         (intern (format "gnus-%s-line-format" (car formats)))))
1895       (or (and (setq old-format (cdr (assq (car formats) gnus-old-specs)))
1896                (equal old-format new-format))
1897           (set (intern (format "gnus-%s-line-format-spec" (car formats)))
1898                (gnus-parse-format
1899                 new-format
1900                 (symbol-value 
1901                  (intern (format "gnus-%s-line-format-alist"
1902                                  (if (eq (car formats) 'article-mode)
1903                                      'summary-mode (car formats))))))))
1904       (setq gnus-old-specs (cons (cons (car formats) new-format)
1905                                  (delq (car formats) gnus-old-specs)))
1906       (setq formats (cdr formats))))
1907       
1908   (gnus-update-group-mark-positions)
1909   (gnus-update-summary-mark-positions)
1910
1911   (if (and (string-match "%D" gnus-group-line-format)
1912            (not gnus-description-hashtb)
1913            gnus-read-active-file)
1914       (gnus-read-all-descriptions-files)))
1915
1916 (defun gnus-update-summary-mark-positions ()
1917   (save-excursion
1918     (let ((gnus-replied-mark 129)
1919           (gnus-score-below-mark 130)
1920           (gnus-score-over-mark 130)
1921           (thread nil)
1922           pos)
1923       (gnus-set-work-buffer)
1924       (gnus-summary-insert-line 
1925        nil [0 "" "" "" "" "" 0 0 ""]  0 nil 128 t nil "" nil 1)
1926       (goto-char (point-min))
1927       (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
1928                                          (- (point) 2)))))
1929       (goto-char (point-min))
1930       (setq pos (cons (cons 'replied (and (search-forward "\201" nil t)
1931                                           (- (point) 2))) pos))
1932       (goto-char (point-min))
1933       (setq pos (cons (cons 'score (and (search-forward "\202" nil t)
1934                                         (- (point) 2))) pos))
1935       (setq gnus-summary-mark-positions pos))))
1936
1937 (defun gnus-update-group-mark-positions ()
1938   (save-excursion
1939     (let ((gnus-process-mark 128)
1940           (gnus-group-marked '("dummy.group")))
1941       (gnus-sethash "dummy.group" '(0 . 0) gnus-active-hashtb)
1942       (gnus-set-work-buffer)
1943       (gnus-group-insert-group-line nil "dummy.group" 0 nil 0 nil)
1944       (goto-char (point-min))
1945       (setq gnus-group-mark-positions
1946             (list (cons 'process (and (search-forward "\200" nil t)
1947                                       (- (point) 2))))))))
1948
1949 (defun gnus-mouse-face-function (form)
1950   (` (let ((string (, form)))
1951        (put-text-property 0 (length string) 'mouse-face gnus-mouse-face string)
1952        string)))
1953
1954 (defun gnus-max-width-function (el max-width)
1955   (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width)))
1956   (` (let* ((val (eval (, el)))
1957             (valstr (if (numberp val)
1958                         (int-to-string val) val)))
1959        (if (> (length valstr) (, max-width))
1960            (substring valstr 0 (, max-width))
1961          valstr))))
1962
1963 (defun gnus-parse-format (format spec-alist)
1964   ;; This function parses the FORMAT string with the help of the
1965   ;; SPEC-ALIST and returns a list that can be eval'ed to return the
1966   ;; string.  If the FORMAT string contains the specifiers %( and %)
1967   ;; the text between them will have the mouse-face text property.
1968   (if (string-match "\\`\\(.*\\)%(\\(.*\\)%)\\(.*\n?\\)\\'" format)
1969       (if (and gnus-visual gnus-mouse-face)
1970           (let ((pre (substring format (match-beginning 1) (match-end 1)))
1971                 (button (substring format (match-beginning 2) (match-end 2)))
1972                 (post (substring format (match-beginning 3) (match-end 3))))
1973             (list 'concat
1974                   (gnus-parse-simple-format pre spec-alist)
1975                   (gnus-mouse-face-function 
1976                    (gnus-parse-simple-format button spec-alist))
1977                   (gnus-parse-simple-format post spec-alist)))
1978         (gnus-parse-simple-format
1979          (concat (substring format (match-beginning 1) (match-end 1))
1980                  (substring format (match-beginning 2) (match-end 2))
1981                  (substring format (match-beginning 3) (match-end 3)))
1982          spec-alist))
1983     (gnus-parse-simple-format format spec-alist)))
1984
1985 (defun gnus-parse-simple-format (format spec-alist)
1986   ;; This function parses the FORMAT string with the help of the
1987   ;; SPEC-ALIST and returns a list that can be eval'ed to return the
1988   ;; string. The list will consist of the symbol `format', a format
1989   ;; specification string, and a list of forms depending on the
1990   ;; SPEC-ALIST.
1991   (let ((max-width 0)
1992         spec flist fstring newspec elem beg)
1993     (save-excursion
1994       (gnus-set-work-buffer)
1995       (insert format)
1996       (goto-char (point-min))
1997       (while (re-search-forward "%[-0-9]*\\(,[0-9]*\\)*\\(.\\)\\(.\\)?" nil t)
1998         (setq spec (string-to-char (buffer-substring (match-beginning 2)
1999                                                      (match-end 2))))
2000         ;; First check if there are any specs that look anything like
2001         ;; "%12,12A", ie. with a "max width specification". These have
2002         ;; to be treated specially.
2003         (if (setq beg (match-beginning 1))
2004             (setq max-width 
2005                   (string-to-int 
2006                    (buffer-substring (1+ (match-beginning 1)) (match-end 1))))
2007           (setq max-width 0)
2008           (setq beg (match-beginning 2)))
2009         ;; Find the specification from `spec-alist'.
2010         (if (not (setq elem (cdr (assq spec spec-alist))))
2011             (setq elem '("*" ?s)))
2012         ;; Treat user defined format specifiers specially
2013         (and (eq (car elem) 'user-defined)
2014              (setq elem
2015                    (list 
2016                     (list (intern (concat "gnus-user-format-function-"
2017                                           (buffer-substring
2018                                            (match-beginning 3)
2019                                            (match-end 3))))
2020                           'header)
2021                     ?s))
2022              (delete-region (match-beginning 3) (match-end 3)))
2023         (if (not (zerop max-width))
2024             (let ((el (car elem)))
2025               (cond ((= (car (cdr elem)) ?c) 
2026                      (setq el (list 'char-to-string el)))
2027                     ((= (car (cdr elem)) ?d)
2028                      (numberp el) (setq el (list 'int-to-string el))))
2029               (setq flist (cons (gnus-max-width-function el max-width)
2030                                 flist))
2031               (setq newspec ?s))
2032           (setq flist (cons (car elem) flist))
2033           (setq newspec (car (cdr elem))))
2034         ;; Remove the old specification (and possibly a ",12" string).
2035         (delete-region beg (match-end 2))
2036         ;; Insert the new specification.
2037         (goto-char beg)
2038         (insert newspec))
2039       (setq fstring (buffer-substring 1 (point-max))))
2040     (cons 'format (cons fstring (nreverse flist)))))
2041
2042 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
2043 (defun gnus-read-init-file ()
2044   (and gnus-init-file
2045        (or (and (file-exists-p gnus-init-file) 
2046                 ;; Don't try to load a directory.
2047                 (not (file-directory-p gnus-init-file)))
2048            (file-exists-p (concat gnus-init-file ".el"))
2049            (file-exists-p (concat gnus-init-file ".elc")))
2050        (load gnus-init-file nil t)))
2051
2052 (defun gnus-set-work-buffer ()
2053   (if (get-buffer gnus-work-buffer)
2054       (progn
2055         (set-buffer gnus-work-buffer)
2056         (erase-buffer))
2057     (set-buffer (get-buffer-create gnus-work-buffer))
2058     (kill-all-local-variables)
2059     (buffer-disable-undo (current-buffer))
2060     (gnus-add-current-to-buffer-list)))
2061
2062 ;; Article file names when saving.
2063
2064 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2065   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2066 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
2067 Otherwise, it is like ~/News/news/group/num."
2068   (let ((default
2069           (expand-file-name
2070            (concat (if (gnus-use-long-file-name 'not-save)
2071                        (gnus-capitalize-newsgroup newsgroup)
2072                      (gnus-newsgroup-directory-form newsgroup))
2073                    "/" (int-to-string (header-number headers)))
2074            (or gnus-article-save-directory "~/News"))))
2075     (if (and last-file
2076              (string-equal (file-name-directory default)
2077                            (file-name-directory last-file))
2078              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2079         default
2080       (or last-file default))))
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 non-nil, it is
2085 ~/News/news.group/num.  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                        newsgroup
2090                      (gnus-newsgroup-directory-form newsgroup))
2091                    "/" (int-to-string (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-Plain-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.  Otherwise, it is like ~/News/news/group/news."
2104   (or last-file
2105       (expand-file-name
2106        (if (gnus-use-long-file-name 'not-save)
2107            (gnus-capitalize-newsgroup newsgroup)
2108          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2109        (or gnus-article-save-directory "~/News"))))
2110
2111 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2112   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2113 If variable `gnus-use-long-file-name' is non-nil, it is
2114 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
2115   (or last-file
2116       (expand-file-name
2117        (if (gnus-use-long-file-name 'not-save)
2118            newsgroup
2119          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2120        (or gnus-article-save-directory "~/News"))))
2121
2122 ;; For subscribing new newsgroup
2123
2124 (defun gnus-subscribe-hierarchical-interactive (groups)
2125   (let ((groups (sort groups 'string<))
2126         prefixes prefix start ans group starts)
2127     (while groups
2128       (setq prefixes (list "^"))
2129       (while (and groups prefixes)
2130         (while (not (string-match (car prefixes) (car groups)))
2131           (setq prefixes (cdr prefixes)))
2132         (setq prefix (car prefixes))
2133         (setq start (1- (length prefix)))
2134         (if (and (string-match "[^\\.]\\." (car groups) start)
2135                  (cdr groups)
2136                  (setq prefix 
2137                        (concat "^" (substring (car groups) 0 (match-end 0))))
2138                  (string-match prefix (car (cdr groups))))
2139             (progn
2140               (setq prefixes (cons prefix prefixes))
2141               (message "Descend hierarchy %s? ([y]nsq): " 
2142                        (substring prefix 1 (1- (length prefix))))
2143               (setq ans (read-char))
2144               (cond ((= ans ?n)
2145                      (while (and groups 
2146                                  (string-match prefix 
2147                                                (setq group (car groups))))
2148                        (setq gnus-killed-list 
2149                              (cons group gnus-killed-list))
2150                        (gnus-sethash group group gnus-killed-hashtb)
2151                        (setq groups (cdr groups)))
2152                      (setq starts (cdr starts)))
2153                     ((= ans ?s)
2154                      (while (and groups 
2155                                  (string-match prefix 
2156                                                (setq group (car groups))))
2157                        (gnus-sethash group group gnus-killed-hashtb)
2158                        (gnus-subscribe-alphabetically (car groups))
2159                        (setq groups (cdr groups)))
2160                      (setq starts (cdr starts)))
2161                     ((= ans ?q)
2162                      (while groups
2163                        (setq group (car groups))
2164                        (setq gnus-killed-list (cons group gnus-killed-list))
2165                        (gnus-sethash group group gnus-killed-hashtb)
2166                        (setq groups (cdr groups))))
2167                     (t nil)))
2168           (message "Subscribe %s? ([n]yq)" (car groups))
2169           (setq ans (read-char))
2170           (setq group (car groups))
2171           (cond ((= ans ?y)
2172                  (gnus-subscribe-alphabetically (car groups))
2173                  (gnus-sethash group group gnus-killed-hashtb))
2174                 ((= ans ?q)
2175                  (while groups
2176                    (setq group (car groups))
2177                    (setq gnus-killed-list (cons group gnus-killed-list))
2178                    (gnus-sethash group group gnus-killed-hashtb)
2179                    (setq groups (cdr groups))))
2180                 (t 
2181                  (setq gnus-killed-list (cons group gnus-killed-list))
2182                  (gnus-sethash group group gnus-killed-hashtb)))
2183           (setq groups (cdr groups)))))))
2184
2185 (defun gnus-subscribe-randomly (newsgroup)
2186   "Subscribe new NEWSGROUP by making it the first newsgroup."
2187   (gnus-subscribe-newsgroup newsgroup))
2188
2189 (defun gnus-subscribe-alphabetically (newgroup)
2190   "Subscribe new NEWSGROUP and insert it in alphabetical order."
2191   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2192   (let ((groups (cdr gnus-newsrc-alist))
2193         before)
2194     (while (and (not before) groups)
2195       (if (string< newgroup (car (car groups)))
2196           (setq before (car (car groups)))
2197         (setq groups (cdr groups))))
2198     (gnus-subscribe-newsgroup newgroup before)))
2199
2200 (defun gnus-subscribe-hierarchically (newgroup)
2201   "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
2202   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2203   (save-excursion
2204     (set-buffer (find-file-noselect gnus-current-startup-file))
2205     (let ((groupkey newgroup)
2206           before)
2207       (while (and (not before) groupkey)
2208         (goto-char (point-min))
2209         (let ((groupkey-re
2210                (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
2211           (while (and (re-search-forward groupkey-re nil t)
2212                       (progn
2213                         (setq before (buffer-substring
2214                                       (match-beginning 1) (match-end 1)))
2215                         (string< before newgroup)))))
2216         ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
2217         (setq groupkey
2218               (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
2219                   (substring groupkey (match-beginning 1) (match-end 1)))))
2220       (gnus-subscribe-newsgroup newgroup before))))
2221
2222 (defun gnus-subscribe-interactively (newsgroup)
2223   "Subscribe new NEWSGROUP interactively.
2224 It is inserted in hierarchical newsgroup order if subscribed. If not,
2225 it is killed."
2226   (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup))
2227       (gnus-subscribe-hierarchically newsgroup)
2228     (setq gnus-killed-list (cons newsgroup gnus-killed-list))))
2229
2230 (defun gnus-subscribe-zombies (newsgroup)
2231   "Make new NEWSGROUP a zombie group."
2232   (setq gnus-zombie-list (cons newsgroup gnus-zombie-list)))
2233
2234 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
2235   "Subscribe new NEWSGROUP.
2236 If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made
2237 the first newsgroup."
2238   ;; We subscribe the group by changing its level to `subscribed'.
2239   (gnus-group-change-level 
2240    newsgroup gnus-level-default-subscribed
2241    gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb))
2242   (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))
2243
2244 ;; For directories
2245
2246 (defun gnus-newsgroup-directory-form (newsgroup)
2247   "Make hierarchical directory name from NEWSGROUP name."
2248   (let ((newsgroup (gnus-newsgroup-saveable-name newsgroup))
2249         (len (length newsgroup))
2250         idx)
2251     ;; If this is a foreign group, we don't want to translate the
2252     ;; entire name.  
2253     (if (setq idx (string-match ":" newsgroup))
2254         (aset newsgroup idx ?/)
2255       (setq idx 0))
2256     ;; Replace all occurrences of `.' with `/'.
2257     (while (< idx len)
2258       (if (= (aref newsgroup idx) ?.)
2259           (aset newsgroup idx ?/))
2260       (setq idx (1+ idx)))
2261     newsgroup))
2262
2263 (defun gnus-newsgroup-saveable-name (group)
2264   ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
2265   ;; with dots.
2266   (gnus-replace-chars-in-string group ?/ ?.))
2267
2268 (defun gnus-make-directory (dir)
2269   "Make DIRECTORY recursively."
2270   ;; Why don't we use `(make-directory dir 'parents)'? That's just one
2271   ;; of the many mysteries of the universe.
2272  (let* ((dir (expand-file-name dir default-directory))
2273          dirs err)
2274     (if (string-match "/$" dir)
2275         (setq dir (substring dir 0 (match-beginning 0))))
2276     ;; First go down the path until we find a directory that exists.
2277     (while (not (file-exists-p dir))
2278       (setq dirs (cons dir dirs))
2279       (string-match "/[^/]+$" dir)
2280       (setq dir (substring dir 0 (match-beginning 0))))
2281     ;; Then create all the subdirs.
2282     (while (and dirs (not err))
2283       (condition-case ()
2284           (make-directory (car dirs))
2285         (error (setq err t)))
2286       (setq dirs (cdr dirs)))
2287     ;; We return whether we were successful or not. 
2288     (not dirs)))
2289
2290 (defun gnus-capitalize-newsgroup (newsgroup)
2291   "Capitalize NEWSGROUP name."
2292   (and (not (zerop (length newsgroup)))
2293        (concat (char-to-string (upcase (aref newsgroup 0)))
2294                (substring newsgroup 1))))
2295
2296 ;; Var
2297
2298 (defun gnus-simplify-subject (subject &optional re-only)
2299   "Remove `Re:' and words in parentheses.
2300 If optional argument RE-ONLY is non-nil, strip `Re:' only."
2301   (let ((case-fold-search t))           ;Ignore case.
2302     ;; Remove `Re:' and `Re^N:'.
2303     (if (string-match "^re:[ \t]*" subject)
2304         (setq subject (substring subject (match-end 0))))
2305     ;; Remove words in parentheses from end.
2306     (or re-only
2307         (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
2308           (setq subject (substring subject 0 (match-beginning 0)))))
2309     ;; Return subject string.
2310     subject))
2311
2312 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
2313 ;; all whitespace.
2314 (defun gnus-simplify-subject-fuzzy (subject)
2315   (let ((case-fold-search t))
2316     (save-excursion
2317       (gnus-set-work-buffer)
2318       (insert subject)
2319       (inline (gnus-simplify-buffer-fuzzy))
2320       (buffer-string))))
2321
2322 (defun gnus-simplify-buffer-fuzzy ()
2323   (goto-char (point-min))
2324   ;; Fix by Stainless Steel Rat <ratinox@ccs.neu.edu>.
2325   (while (re-search-forward "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*"
2326                             nil t)
2327     (replace-match "" t t))
2328   (goto-char (point-min))
2329   (while (re-search-forward "[ \t\n]*([^()]*)[ \t\n]*$" nil t)
2330     (replace-match "" t t))
2331   (goto-char (point-min))
2332   (while (re-search-forward "[ \t]+" nil t)
2333     (replace-match " " t t))
2334   (goto-char (point-min))
2335   (while (re-search-forward "[ \t]+$" nil t)
2336     (replace-match "" t t))
2337   (goto-char (point-min))
2338   (while (re-search-forward "^[ \t]+" nil t)
2339     (replace-match "" t t))
2340   (if gnus-simplify-subject-fuzzy-regexp
2341       (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t)
2342         (replace-match "" t t))))
2343
2344 ;; Add the current buffer to the list of buffers to be killed on exit. 
2345 (defun gnus-add-current-to-buffer-list ()
2346   (or (memq (current-buffer) gnus-buffer-list)
2347       (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list))))
2348
2349 (defun gnus-string> (s1 s2)
2350   (not (or (string< s1 s2)
2351            (string= s1 s2))))
2352
2353 ;; Functions accessing headers.
2354 ;; Functions are more convenient than macros in some cases.
2355
2356 (defun gnus-header-number (header)
2357   (header-number header))
2358
2359 (defun gnus-header-subject (header)
2360   (header-subject header))
2361
2362 (defun gnus-header-from (header)
2363   (header-from header))
2364
2365 (defun gnus-header-xref (header)
2366   (header-xref header))
2367
2368 (defun gnus-header-lines (header)
2369   (header-lines header))
2370
2371 (defun gnus-header-date (header)
2372   (header-date header))
2373
2374 (defun gnus-header-id (header)
2375   (header-id header))
2376
2377 (defun gnus-header-references (header)
2378   (header-references header))
2379
2380 ;;; General various misc type functions.
2381
2382 (defun gnus-clear-system ()
2383   "Clear all variables and buffers."
2384   ;; Clear Gnus variables.
2385   (let ((variables gnus-variable-list))
2386     (while variables
2387       (set (car variables) nil)
2388       (setq variables (cdr variables))))
2389   ;; Clear other internal variables.
2390   (setq gnus-list-of-killed-groups nil
2391         gnus-have-read-active-file nil
2392         gnus-newsrc-alist nil
2393         gnus-newsrc-hashtb nil
2394         gnus-killed-list nil
2395         gnus-zombie-list nil
2396         gnus-killed-hashtb nil
2397         gnus-active-hashtb nil
2398         gnus-moderated-list nil
2399         gnus-description-hashtb nil
2400         gnus-newsgroup-headers nil
2401         gnus-newsgroup-headers-hashtb-by-number nil
2402         gnus-newsgroup-name nil
2403         gnus-server-alist nil
2404         gnus-current-select-method nil)
2405   ;; Reset any score variables.
2406   (and (boundp 'gnus-score-cache)
2407        (set 'gnus-score-cache nil))
2408   (and (boundp 'gnus-internal-global-score-files)
2409        (set 'gnus-internal-global-score-files nil))
2410   ;; Kill the startup file.
2411   (and gnus-current-startup-file
2412        (get-file-buffer gnus-current-startup-file)
2413        (kill-buffer (get-file-buffer gnus-current-startup-file)))
2414   ;; Save any cache buffers.
2415   (and gnus-use-cache (gnus-cache-save-buffers))
2416   ;; Clear the dribble buffer.
2417   (gnus-dribble-clear)
2418   ;; Kill global KILL file buffer.
2419   (if (get-file-buffer (gnus-newsgroup-kill-file nil))
2420       (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
2421   (gnus-kill-buffer nntp-server-buffer)
2422   ;; Kill Gnus buffers.
2423   (while gnus-buffer-list
2424     (gnus-kill-buffer (car gnus-buffer-list))
2425     (setq gnus-buffer-list (cdr gnus-buffer-list))))
2426
2427 (defun gnus-windows-old-to-new (setting)
2428   (if (symbolp setting)
2429       (setq setting 
2430             (cond ((eq setting 'SelectArticle)
2431                    'article)
2432                   ((eq setting 'SelectSubject)
2433                    'summary)
2434                   ((eq setting 'SelectNewsgroup)
2435                    'group)
2436                   (t setting))))
2437   (if (or (listp setting)
2438           (not (and gnus-window-configuration
2439                     (memq setting '(group summary article)))))
2440       setting
2441     (let* ((setting (if (eq setting 'group) 
2442                         (if (assq 'newsgroup gnus-window-configuration)
2443                             'newsgroup
2444                           'newsgroups) setting))
2445            (elem (car (cdr (assq setting gnus-window-configuration))))
2446            (total (apply '+ elem))
2447            (types '(group summary article))
2448            (pbuf (if (eq setting 'newsgroups) 'group 'summary))
2449            (i 0)
2450            perc
2451            out)
2452       (while (< i 3)
2453         (or (zerop (nth i elem))
2454             (progn
2455               (setq perc  (/ (* 1.0 (nth 0 elem)) total))
2456               (setq out (cons (if (eq pbuf (nth i types))
2457                                   (vector (nth i types) perc 'point)
2458                                 (vector (nth i types) perc))
2459                               out))))
2460         (setq i (1+ i)))
2461       (list (nreverse out)))))
2462            
2463 (defun gnus-add-configuration (conf)
2464   (setq gnus-buffer-configuration 
2465         (cons conf (delq (assq (car conf) gnus-buffer-configuration)
2466                          gnus-buffer-configuration))))
2467
2468 (defun gnus-configure-windows (setting &optional force)
2469   (setq setting (gnus-windows-old-to-new setting))
2470   (let ((r (if (symbolp setting)
2471                (cdr (assq setting gnus-buffer-configuration))
2472              setting))
2473         (in-buf (current-buffer))
2474         rule val w height hor ohor heights sub jump-buffer
2475         rel total to-buf all-visible)
2476     (or r (error "No such setting: %s" setting))
2477
2478     (if (and (not force) (setq all-visible (gnus-all-windows-visible-p r)))
2479         ;; All the windows mentioned are already visibe, so we just
2480         ;; put point in the assigned buffer, and do not touch the
2481         ;; winconf. 
2482         (select-window (get-buffer-window all-visible))
2483
2484       ;; Either remove all windows or just remove all Gnus windows.
2485       (if gnus-use-full-window
2486           (delete-other-windows)
2487         (gnus-remove-some-windows)
2488         (switch-to-buffer nntp-server-buffer))
2489
2490       (while r
2491         (setq hor (car r)
2492               ohor nil)
2493
2494         ;; We have to do the (possible) horizontal splitting before the
2495         ;; vertical. 
2496         (if (and (listp (car hor)) 
2497                  (eq (car (car hor)) 'horizontal))
2498             (progn
2499               (split-window 
2500                nil
2501                (if (integerp (nth 1 (car hor)))
2502                    (nth 1 (car hor))
2503                  (- (frame-width) (floor (* (frame-width) (nth 1 (car hor))))))
2504                t)
2505               (setq hor (cdr hor))))
2506
2507         ;; Go through the rules and eval the elements that are to be
2508         ;; evaled.  
2509         (while hor
2510           (if (setq val (if (vectorp (car hor)) (car hor) (eval (car hor))))
2511               (progn
2512                 ;; Expand short buffer name.
2513                 (setq w (aref val 0))
2514                 (and (setq w (cdr (assq w gnus-window-to-buffer)))
2515                      (progn
2516                        (setq val (apply 'vector (mapcar 'identity val)))
2517                        (aset val 0 w)))
2518                 (setq ohor (cons val ohor))))
2519           (setq hor (cdr hor)))
2520         (setq rule (cons (nreverse ohor) rule))
2521         (setq r (cdr r)))
2522       (setq rule (nreverse rule))
2523
2524       ;; We tally the window sizes.
2525       (setq total (window-height))
2526       (while rule
2527         (setq hor (car rule))
2528         (if (and (listp (car hor)) (eq (car (car hor)) 'horizontal))
2529             (setq hor (cdr hor)))
2530         (setq sub 0)
2531         (while hor
2532           (setq rel (aref (car hor) 1)
2533                 heights (cons
2534                          (cond ((and (floatp rel) (= 1.0 rel))
2535                                 'x)
2536                                ((integerp rel)
2537                                 rel)
2538                                (t
2539                                 (max (floor (* total rel)) 4)))
2540                          heights)
2541                 sub (+ sub (if (numberp (car heights)) (car heights) 0))
2542                 hor (cdr hor)))
2543         (setq heights (nreverse heights)
2544               hor (car rule))
2545
2546         ;; We then go through these heighs and create windows for them.
2547         (while heights
2548           (setq height (car heights)
2549                 heights (cdr heights))
2550           (and (eq height 'x)
2551                (setq height (- total sub)))
2552           (and heights
2553                (split-window nil height))
2554           (setq to-buf (aref (car hor) 0))
2555           (switch-to-buffer 
2556            (cond ((not to-buf)
2557                   in-buf)
2558                  ((symbolp to-buf)
2559                   (symbol-value (aref (car hor) 0)))
2560                  (t
2561                   (aref (car hor) 0))))
2562           (and (> (length (car hor)) 2)
2563                (eq (aref (car hor) 2) 'point)
2564                (setq jump-buffer (current-buffer)))
2565           (other-window 1)
2566           (setq hor (cdr hor)))
2567       
2568         (setq rule (cdr rule)))
2569
2570       ;; Finally, we pop to the buffer that's supposed to have point. 
2571       (or jump-buffer (error "Missing `point' in spec for %s" setting))
2572
2573       (select-window (get-buffer-window jump-buffer))
2574       (set-buffer jump-buffer))))
2575
2576 (defun gnus-all-windows-visible-p (rule)
2577   (let (invisible hor jump-buffer val buffer)
2578     ;; Go through the rules and eval the elements that are to be
2579     ;; evaled.  
2580     (while (and rule (not invisible))
2581       (setq hor (car rule)
2582             rule (cdr rule))
2583       (while (and hor (not invisible))
2584         (if (setq val (if (vectorp (car hor)) 
2585                           (car hor)
2586                         (if (not (eq (car (car hor)) 'horizontal))
2587                             (eval (car hor)))))
2588             (progn
2589               ;; Expand short buffer name.
2590               (setq buffer (or (cdr (assq (aref val 0) gnus-window-to-buffer))
2591                                (aref val 0)))
2592               (setq buffer (if (symbolp buffer) (symbol-value buffer)
2593                              buffer))
2594               (and (> (length val) 2) (eq 'point (aref val 2))
2595                    (setq jump-buffer buffer))
2596               (setq invisible (not (and buffer (get-buffer-window buffer))))))
2597         (setq hor (cdr hor))))
2598     (and (not invisible) jump-buffer)))
2599
2600 (defun gnus-window-top-edge (&optional window)
2601   (nth 1 (window-edges window)))
2602
2603 (defun gnus-remove-some-windows ()
2604   (let ((buffers gnus-window-to-buffer)
2605         buf bufs lowest-buf lowest)
2606     (save-excursion
2607       ;; Remove windows on all known Gnus buffers.
2608       (while buffers
2609         (setq buf (cdr (car buffers)))
2610         (if (symbolp buf)
2611             (setq buf (and (boundp buf) (symbol-value buf))))
2612         (and buf 
2613              (get-buffer-window buf)
2614              (progn
2615                (setq bufs (cons buf bufs))
2616                (pop-to-buffer buf)
2617                (if (or (not lowest)
2618                        (< (gnus-window-top-edge) lowest))
2619                    (progn
2620                      (setq lowest (gnus-window-top-edge))
2621                      (setq lowest-buf buf)))))
2622         (setq buffers (cdr buffers)))
2623       ;; Remove windows on *all* summary buffers.
2624       (let (wins)
2625         (walk-windows
2626          (lambda (win)
2627            (let ((buf (window-buffer win)))
2628              (if (string-match  "^\\*Summary" (buffer-name buf))
2629              (progn
2630                (setq bufs (cons buf bufs))
2631                (pop-to-buffer buf)
2632                (if (or (not lowest)
2633                        (< (gnus-window-top-edge) lowest))
2634                    (progn
2635                      (setq lowest-buf buf)
2636                      (setq lowest (gnus-window-top-edge))))))))))
2637       (and lowest-buf 
2638            (progn
2639              (pop-to-buffer lowest-buf)
2640              (switch-to-buffer nntp-server-buffer)))
2641       (while bufs
2642         (and (not (eq (car bufs) lowest-buf))
2643              (delete-windows-on (car bufs)))
2644         (setq bufs (cdr bufs))))))
2645                           
2646 (defun gnus-version ()
2647   "Version numbers of this version of Gnus."
2648   (interactive)
2649   (let ((methods gnus-valid-select-methods)
2650         (mess gnus-version)
2651         meth)
2652     ;; Go through all the legal select methods and add their version
2653     ;; numbers to the total version string. Only the backends that are
2654     ;; currently in use will have their message numbers taken into
2655     ;; consideration. 
2656     (while methods
2657       (setq meth (intern (concat (car (car methods)) "-version")))
2658       (and (boundp meth)
2659            (stringp (symbol-value meth))
2660            (setq mess (concat mess "; " (symbol-value meth))))
2661       (setq methods (cdr methods)))
2662     (gnus-message 2 mess)))
2663
2664 (defun gnus-info-find-node ()
2665   "Find Info documentation of Gnus."
2666   (interactive)
2667   ;; Enlarge info window if needed.
2668   (let ((mode major-mode))
2669     (gnus-configure-windows 'info)
2670     (Info-goto-node (car (cdr (assq mode gnus-info-nodes))))))
2671
2672 (defun gnus-overload-functions (&optional overloads)
2673   "Overload functions specified by optional argument OVERLOADS.
2674 If nothing is specified, use the variable gnus-overload-functions."
2675   (let ((defs nil)
2676         (overloads (or overloads gnus-overload-functions)))
2677     (while overloads
2678       (setq defs (car overloads))
2679       (setq overloads (cdr overloads))
2680       ;; Load file before overloading function if necessary.  Make
2681       ;; sure we cannot use `require' always.
2682       (and (not (fboundp (car defs)))
2683            (car (cdr (cdr defs)))
2684            (load (car (cdr (cdr defs))) nil 'nomessage))
2685       (fset (car defs) (car (cdr defs))))))
2686
2687 (defun gnus-replace-chars-in-string (string from to)
2688   "Replace characters in STRING from FROM to TO."
2689   (let ((string (substring string 0))   ;Copy string.
2690         (len (length string))
2691         (idx 0))
2692     ;; Replace all occurrences of FROM with TO.
2693     (while (< idx len)
2694       (if (= (aref string idx) from)
2695           (aset string idx to))
2696       (setq idx (1+ idx)))
2697     string))
2698
2699 (defun gnus-days-between (date1 date2)
2700   ;; Return the number of days between date1 and date2.
2701   (- (gnus-day-number date1) (gnus-day-number date2)))
2702
2703 (defun gnus-day-number (date)
2704   (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
2705                      (timezone-parse-date date))))
2706     (timezone-absolute-from-gregorian 
2707      (nth 1 dat) (nth 2 dat) (car dat))))
2708
2709 ;; Returns a floating point number that says how many seconds have
2710 ;; lapsed between Jan 1 12:00:00 1970 and DATE.
2711 (defun gnus-seconds-since-epoch (date)
2712   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2713                         (timezone-parse-date date)))
2714          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
2715                         (timezone-parse-time
2716                          (aref (timezone-parse-date date) 3))))
2717          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
2718                         (timezone-parse-date "Jan 1 12:00:00 1970")))
2719          (tday (- (timezone-absolute-from-gregorian 
2720                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
2721                   (timezone-absolute-from-gregorian 
2722                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
2723     (+ (nth 2 ttime)
2724        (* (nth 1 ttime) 60)
2725        (* 1.0 (nth 0 ttime) 60 60)
2726        (* 1.0 tday 60 60 24))))
2727
2728 (defun gnus-file-newer-than (file date)
2729   (let ((fdate (nth 5 (file-attributes file))))
2730     (or (> (car fdate) (car date))
2731         (and (= (car fdate) (car date))
2732              (> (nth 1 fdate) (nth 1 date))))))
2733
2734 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
2735 ;; the echo area.
2736 (defun gnus-y-or-n-p (prompt)
2737   (prog1
2738       (y-or-n-p prompt)
2739     (message "")))
2740
2741 (defun gnus-yes-or-no-p (prompt)
2742   (prog1
2743       (yes-or-no-p prompt)
2744     (message "")))
2745
2746 ;; Check whether to use long file names.
2747 (defun gnus-use-long-file-name (symbol)
2748   ;; The variable has to be set...
2749   (and gnus-use-long-file-name
2750        ;; If it isn't a list, then we return t.
2751        (or (not (listp gnus-use-long-file-name))
2752            ;; If it is a list, and the list contains `symbol', we
2753            ;; return nil.  
2754            (not (memq symbol gnus-use-long-file-name)))))
2755
2756 ;; I suspect there's a better way, but I haven't taken the time to do
2757 ;; it yet. -erik selberg@cs.washington.edu
2758 (defun gnus-dd-mmm (messy-date)
2759   "Return a string like DD-MMM from a big messy string"
2760   (let ((datevec (timezone-parse-date messy-date)))
2761     (format "%2s-%s"
2762             (or (aref datevec 2) "??")
2763             (capitalize
2764              (or (car 
2765                   (nth (1- (string-to-number (aref datevec 1)))
2766                        timezone-months-assoc))
2767                  "???")))))
2768
2769 ;; Make a hash table (default and minimum size is 255).
2770 ;; Optional argument HASHSIZE specifies the table size.
2771 (defun gnus-make-hashtable (&optional hashsize)
2772   (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 255) 255) 0))
2773
2774 ;; Make a number that is suitable for hashing; bigger than MIN and one
2775 ;; less than 2^x.
2776 (defun gnus-create-hash-size (min)
2777   (let ((i 1))
2778     (while (< i min)
2779       (setq i (* 2 i)))
2780     (1- i)))
2781
2782 ;; Show message if message has a lower level than `gnus-verbose'. 
2783 ;; Guide-line for numbers:
2784 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
2785 ;; for things that take a long time, 7 - not very important messages
2786 ;; on stuff, 9 - messages inside loops.
2787 (defun gnus-message (level &rest args)
2788   (if (<= level gnus-verbose)
2789       (apply 'message args)
2790     ;; We have to do this format thingie here even if the result isn't
2791     ;; shown - the return value has to be the same as the return value
2792     ;; from `message'.
2793     (apply 'format args)))
2794
2795 ;; Generate a unique new group name.
2796 (defun gnus-generate-new-group-name (leaf)
2797   (let ((name leaf)
2798         (num 0))
2799     (while (gnus-gethash name gnus-newsrc-hashtb)
2800       (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
2801     name))
2802
2803 ;;; List and range functions
2804
2805 (defun gnus-last-element (list)
2806   "Return last element of LIST."
2807   (while (cdr list)
2808     (setq list (cdr list)))
2809   (car list))
2810
2811 (defun gnus-copy-sequence (list)
2812   "Do a complete, total copy of a list."
2813   (if (and (consp list) (not (consp (cdr list))))
2814       (cons (car list) (cdr list))
2815     (mapcar (lambda (elem) (if (consp elem) 
2816                                (if (consp (cdr elem))
2817                                    (gnus-copy-sequence elem)
2818                                  (cons (car elem) (cdr elem)))
2819                              elem))
2820             list)))
2821
2822 (defun gnus-set-difference (list1 list2)
2823   "Return a list of elements of LIST1 that do not appear in LIST2."
2824   (let ((list1 (copy-sequence list1)))
2825     (while list2
2826       (setq list1 (delq (car list2) list1))
2827       (setq list2 (cdr list2)))
2828     list1))
2829
2830 (defun gnus-sorted-complement (list1 list2)
2831   "Return a list of elements of LIST1 that do not appear in LIST2.
2832 Both lists have to be sorted over <."
2833   (let (out)
2834     (if (or (null list1) (null list2))
2835         (or list1 list2)
2836       (while (and list1 list2)
2837         (cond ((= (car list1) (car list2))
2838                (setq list1 (cdr list1)
2839                      list2 (cdr list2)))
2840               ((< (car list1) (car list2))
2841                (setq out (cons (car list1) out))
2842                (setq list1 (cdr list1)))
2843               (t
2844                (setq out (cons (car list2) out))
2845                (setq list2 (cdr list2)))))
2846       (nconc (nreverse out) (or list1 list2)))))
2847
2848 (defun gnus-intersection (list1 list2)      
2849   (let ((result nil))
2850     (while list2
2851       (if (memq (car list2) list1)
2852           (setq result (cons (car list2) result)))
2853       (setq list2 (cdr list2)))
2854     result))
2855
2856 (defun gnus-sorted-intersection (list1 list2)
2857   ;; LIST1 and LIST2 have to be sorted over <.
2858   (let (out)
2859     (while (and list1 list2)
2860       (cond ((= (car list1) (car list2))
2861              (setq out (cons (car list1) out)
2862                    list1 (cdr list1)
2863                    list2 (cdr list2)))
2864             ((< (car list1) (car list2))
2865              (setq list1 (cdr list1)))
2866             (t
2867              (setq list2 (cdr list2)))))
2868     (nreverse out)))
2869
2870 (defun gnus-set-sorted-intersection (list1 list2)
2871   ;; LIST1 and LIST2 have to be sorted over <.
2872   ;; This function modifies LIST1.
2873   (let* ((top (cons nil list1))
2874          (prev top))
2875   (while (and list1 list2)
2876     (cond ((= (car list1) (car list2))
2877            (setq prev list1
2878                  list1 (cdr list1)
2879                  list2 (cdr list2)))
2880           ((< (car list1) (car list2))
2881            (setcdr prev (cdr list1))
2882            (setq list1 (cdr list1)))
2883           (t
2884            (setq list2 (cdr list2)))))
2885   (setcdr prev nil)
2886   (cdr top)))
2887
2888 (defun gnus-compress-sequence (numbers &optional always-list)
2889   "Convert list of numbers to a list of ranges or a single range.
2890 If ALWAYS-LIST is non-nil, this function will always release a list of
2891 ranges."
2892   (let* ((first (car numbers))
2893          (last (car numbers))
2894          result)
2895     (if (null numbers)
2896         nil
2897       (if (not (listp (cdr numbers)))
2898           numbers
2899         (while numbers
2900           (cond ((= last (car numbers)) nil) ;Omit duplicated number
2901                 ((= (1+ last) (car numbers)) ;Still in sequence
2902                  (setq last (car numbers)))
2903                 (t                      ;End of one sequence
2904                  (setq result 
2905                        (cons (if (= first last) first
2906                                (cons first last)) result))
2907                  (setq first (car numbers))
2908                  (setq last  (car numbers))))
2909           (setq numbers (cdr numbers)))
2910         (if (and (not always-list) (null result))
2911             (if (= first last) (list first) (cons first last))
2912           (nreverse (cons (if (= first last) first (cons first last))
2913                           result)))))))
2914
2915 (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
2916 (defun gnus-uncompress-range (ranges)
2917   "Expand a list of ranges into a list of numbers.
2918 RANGES is either a single range on the form `(num . num)' or a list of
2919 these ranges."
2920   (let (first last result)
2921     (cond 
2922      ((null ranges)
2923       nil)
2924      ((not (listp (cdr ranges)))
2925       (setq first (car ranges))
2926       (setq last (cdr ranges))
2927       (while (<= first last)
2928         (setq result (cons first result))
2929         (setq first (1+ first)))
2930       (nreverse result))
2931      (t
2932       (while ranges
2933         (if (atom (car ranges))
2934             (if (numberp (car ranges))
2935                 (setq result (cons (car ranges) result)))
2936           (setq first (car (car ranges)))
2937           (setq last  (cdr (car ranges)))
2938           (while (<= first last)
2939             (setq result (cons first result))
2940             (setq first (1+ first))))
2941         (setq ranges (cdr ranges)))
2942       (nreverse result)))))
2943
2944 (defun gnus-add-to-range (ranges list)
2945   "Return a list of ranges that has all articles from both RANGES and LIST.
2946 Note: LIST has to be sorted over `<'."
2947   (if (not ranges)
2948       (gnus-compress-sequence list t)
2949     (setq list (copy-sequence list))
2950     (or (listp (cdr ranges))
2951         (setq ranges (list ranges)))
2952     (let ((out ranges)
2953           ilist lowest highest temp)
2954       (while (and ranges list)
2955         (setq ilist list)
2956         (setq lowest (or (and (atom (car ranges)) (car ranges))
2957                          (car (car ranges))))
2958         (while (and list (cdr list) (< (car (cdr list)) lowest))
2959           (setq list (cdr list)))
2960         (if (< (car ilist) lowest)
2961             (progn
2962               (setq temp list)
2963               (setq list (cdr list))
2964               (setcdr temp nil)
2965               (setq out (nconc (gnus-compress-sequence ilist t) out))))
2966         (setq highest (or (and (atom (car ranges)) (car ranges))
2967                           (cdr (car ranges))))
2968         (while (and list (<= (car list) highest))
2969           (setq list (cdr list)))
2970         (setq ranges (cdr ranges)))
2971       (if list
2972           (setq out (nconc (gnus-compress-sequence list t) out)))
2973       (setq out (sort out (lambda (r1 r2) 
2974                             (< (or (and (atom r1) r1) (car r1))
2975                                (or (and (atom r2) r2) (car r2))))))
2976       (setq ranges out)
2977       (while ranges
2978         (if (atom (car ranges))
2979             (if (cdr ranges)
2980                 (if (atom (car (cdr ranges)))
2981                     (if (= (1+ (car ranges)) (car (cdr ranges)))
2982                         (progn
2983                           (setcar ranges (cons (car ranges) 
2984                                                (car (cdr ranges))))
2985                           (setcdr ranges (cdr (cdr ranges)))))
2986                   (if (= (1+ (car ranges)) (car (car (cdr ranges))))
2987                       (progn
2988                         (setcar (car (cdr ranges)) (car ranges))
2989                         (setcar ranges (car (cdr ranges)))
2990                         (setcdr ranges (cdr (cdr ranges)))))))
2991           (if (cdr ranges)
2992               (if (atom (car (cdr ranges)))
2993                   (if (= (1+ (cdr (car ranges))) (car (cdr ranges)))
2994                       (progn
2995                         (setcdr (car ranges) (car (cdr ranges)))
2996                         (setcdr ranges (cdr (cdr ranges)))))
2997                 (if (= (1+ (cdr (car ranges))) (car (car (cdr ranges))))
2998                     (progn
2999                       (setcdr (car ranges) (cdr (car (cdr ranges))))
3000                       (setcdr ranges (cdr (cdr ranges))))))))
3001         (setq ranges (cdr ranges)))
3002       out)))
3003
3004 (defun gnus-remove-from-range (ranges list)
3005   "Return a list of ranges that has all articles from LIST removed from RANGES.
3006 Note: LIST has to be sorted over `<'."
3007   ;; !!! This function shouldn't look like this, but I've got a headache.
3008   (gnus-compress-sequence 
3009    (gnus-sorted-complement
3010     (gnus-uncompress-range ranges) list)))
3011
3012 (defun gnus-member-of-range (number ranges)
3013   (if (not (listp (cdr ranges)))
3014       (and (>= number (car ranges)) 
3015            (<= number (cdr ranges)))
3016     (let ((not-stop t))
3017       (while (and ranges 
3018                   (if (numberp (car ranges))
3019                       (>= number (car ranges))
3020                     (>= number (car (car ranges))))
3021                   not-stop)
3022         (if (if (numberp (car ranges))
3023                 (= number (car ranges))
3024               (and (>= number (car (car ranges)))
3025                    (<= number (cdr (car ranges)))))
3026             (setq not-stop nil))
3027         (setq ranges (cdr ranges)))
3028       (not not-stop))))
3029
3030 \f
3031 ;;;
3032 ;;; Gnus group mode
3033 ;;;
3034
3035 (defvar gnus-group-mode-map nil)
3036 (defvar gnus-group-group-map nil)
3037 (defvar gnus-group-mark-map nil)
3038 (defvar gnus-group-list-map nil)
3039 (defvar gnus-group-sub-map nil)
3040 (put 'gnus-group-mode 'mode-class 'special)
3041
3042 (if gnus-group-mode-map
3043     nil
3044   (setq gnus-group-mode-map (make-keymap))
3045   (suppress-keymap gnus-group-mode-map)
3046   (define-key gnus-group-mode-map " " 'gnus-group-read-group)
3047   (define-key gnus-group-mode-map "=" 'gnus-group-select-group)
3048   (define-key gnus-group-mode-map "\r" 'gnus-group-select-group)
3049   (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group)
3050   (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group)
3051   (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group)
3052   (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group)
3053   (define-key gnus-group-mode-map "N" 'gnus-group-next-group)
3054   (define-key gnus-group-mode-map "P" 'gnus-group-prev-group)
3055   (define-key gnus-group-mode-map "\M-n" 'gnus-group-next-unread-group-same-level)
3056   (define-key gnus-group-mode-map "\M-p" 'gnus-group-prev-unread-group-same-level)
3057   (define-key gnus-group-mode-map "," 'gnus-group-best-unread-group)
3058   (define-key gnus-group-mode-map "." 'gnus-group-first-unread-group)
3059   (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group)
3060   (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group)
3061   (define-key gnus-group-mode-map "c" 'gnus-group-catchup-current)
3062   (define-key gnus-group-mode-map "C" 'gnus-group-catchup-current-all)
3063   (define-key gnus-group-mode-map "l" 'gnus-group-list-groups)
3064   (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups)
3065   (define-key gnus-group-mode-map "m" 'gnus-group-mail)
3066   (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news)
3067   (define-key gnus-group-mode-map "\M-g" 'gnus-group-get-new-news-this-group)
3068   (define-key gnus-group-mode-map "R" 'gnus-group-restart)
3069   (define-key gnus-group-mode-map "r" 'gnus-group-read-init-file)
3070   (define-key gnus-group-mode-map "B" 'gnus-group-browse-foreign-server)
3071   (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups)
3072   (define-key gnus-group-mode-map "F" 'gnus-find-new-newsgroups)
3073   (define-key gnus-group-mode-map "\C-c\C-d" 'gnus-group-describe-group)
3074   (define-key gnus-group-mode-map "\M-d" 'gnus-group-describe-all-groups)
3075   (define-key gnus-group-mode-map "\C-c\C-a" 'gnus-group-apropos)
3076   (define-key gnus-group-mode-map "\C-c\M-C-a" 'gnus-group-description-apropos)
3077   (define-key gnus-group-mode-map "a" 'gnus-group-post-news)
3078   (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill)
3079   (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill)
3080   (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group)
3081   (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group)
3082   (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region)
3083   (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups)
3084   (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-group-list-killed)
3085   (define-key gnus-group-mode-map "\C-c\C-x" 'gnus-group-expire-articles)
3086   (define-key gnus-group-mode-map "\C-c\M-\C-x" 'gnus-group-expire-all-groups)
3087   (define-key gnus-group-mode-map "V" 'gnus-version)
3088   (define-key gnus-group-mode-map "s" 'gnus-group-save-newsrc)
3089   (define-key gnus-group-mode-map "z" 'gnus-group-suspend)
3090   (define-key gnus-group-mode-map "Z" 'gnus-group-clear-dribble)
3091   (define-key gnus-group-mode-map "q" 'gnus-group-exit)
3092   (define-key gnus-group-mode-map "Q" 'gnus-group-quit)
3093   (define-key gnus-group-mode-map "\M-f" 'gnus-group-fetch-faq)
3094   (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly)
3095   (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node)
3096   (define-key gnus-group-mode-map "\M-e" 'gnus-group-edit-group-method)
3097   (define-key gnus-group-mode-map "^" 'gnus-group-enter-server-mode)
3098   (define-key gnus-group-mode-map gnus-mouse-2 'gnus-mouse-pick-group)
3099   (define-key gnus-group-mode-map "<" 'beginning-of-buffer)
3100   (define-key gnus-group-mode-map ">" 'end-of-buffer)
3101   (define-key gnus-group-mode-map "\C-c\C-b" 'gnus-bug)
3102   (define-key gnus-group-mode-map "\C-c\C-s" 'gnus-group-sort-groups)
3103
3104   (define-key gnus-group-mode-map "#" 'gnus-group-mark-group)
3105   (define-key gnus-group-mode-map "\M-#" 'gnus-group-unmark-group)
3106   (define-prefix-command 'gnus-group-mark-map)
3107   (define-key gnus-group-mode-map "M" 'gnus-group-mark-map)
3108   (define-key gnus-group-mark-map "m" 'gnus-group-mark-group)
3109   (define-key gnus-group-mark-map "u" 'gnus-group-unmark-group)
3110   (define-key gnus-group-mark-map "w" 'gnus-group-mark-region)
3111
3112   (define-prefix-command 'gnus-group-group-map)
3113   (define-key gnus-group-mode-map "G" 'gnus-group-group-map)
3114   (define-key gnus-group-group-map "d" 'gnus-group-make-directory-group)
3115   (define-key gnus-group-group-map "h" 'gnus-group-make-help-group)
3116   (define-key gnus-group-group-map "a" 'gnus-group-make-archive-group)
3117   (define-key gnus-group-group-map "k" 'gnus-group-make-kiboze-group)
3118   (define-key gnus-group-group-map "m" 'gnus-group-make-group)
3119   (define-key gnus-group-group-map "E" 'gnus-group-edit-group)
3120   (define-key gnus-group-group-map "e" 'gnus-group-edit-group-method)
3121   (define-key gnus-group-group-map "p" 'gnus-group-edit-group-parameters)
3122   (define-key gnus-group-group-map "v" 'gnus-group-add-to-virtual)
3123   (define-key gnus-group-group-map "V" 'gnus-group-make-empty-virtual)
3124   (define-key gnus-group-group-map "D" 'gnus-group-enter-directory)
3125   (define-key gnus-group-group-map "f" 'gnus-group-make-doc-group)
3126   ;;(define-key gnus-group-group-map "sb" 'gnus-group-brew-soup)
3127   ;;(define-key gnus-group-group-map "sw" 'gnus-soup-save-areas)
3128   ;;(define-key gnus-group-group-map "ss" 'gnus-soup-send-replies)
3129   ;;(define-key gnus-group-group-map "sp" 'gnus-soup-pack-packet)
3130   ;;(define-key gnus-group-group-map "sr" 'nnsoup-pack-replies)
3131
3132   (define-prefix-command 'gnus-group-list-map)
3133   (define-key gnus-group-mode-map "A" 'gnus-group-list-map)
3134   (define-key gnus-group-list-map "k" 'gnus-group-list-killed)
3135   (define-key gnus-group-list-map "z" 'gnus-group-list-zombies)
3136   (define-key gnus-group-list-map "s" 'gnus-group-list-groups)
3137   (define-key gnus-group-list-map "u" 'gnus-group-list-all-groups)
3138   (define-key gnus-group-list-map "a" 'gnus-group-apropos)
3139   (define-key gnus-group-list-map "d" 'gnus-group-description-apropos)
3140   (define-key gnus-group-list-map "m" 'gnus-group-list-matching)
3141   (define-key gnus-group-list-map "M" 'gnus-group-list-all-matching)
3142
3143   (define-prefix-command 'gnus-group-sub-map)
3144   (define-key gnus-group-mode-map "S" 'gnus-group-sub-map)
3145   (define-key gnus-group-sub-map "l" 'gnus-group-set-current-level)
3146   (define-key gnus-group-sub-map "t" 'gnus-group-unsubscribe-current-group)
3147   (define-key gnus-group-sub-map "s" 'gnus-group-unsubscribe-group)
3148   (define-key gnus-group-sub-map "k" 'gnus-group-kill-group)
3149   (define-key gnus-group-sub-map "y" 'gnus-group-yank-group)
3150   (define-key gnus-group-sub-map "w" 'gnus-group-kill-region)
3151   (define-key gnus-group-sub-map "z" 'gnus-group-kill-all-zombies))
3152
3153 (defun gnus-group-mode ()
3154   "Major mode for reading news.
3155
3156 All normal editing commands are switched off.
3157 \\<gnus-group-mode-map>
3158 The group buffer lists (some of) the groups available.  For instance,
3159 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
3160 lists all zombie groups. 
3161
3162 Groups that are displayed can be entered with `\\[gnus-group-read-group]'.  To subscribe 
3163 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'. 
3164
3165 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). 
3166
3167 The following commands are available:
3168
3169 \\{gnus-group-mode-map}"
3170   (interactive)
3171   (if gnus-visual (gnus-group-make-menu-bar))
3172   (kill-all-local-variables)
3173   (setq mode-line-modified "-- ")
3174   (make-local-variable 'mode-line-format)
3175   (setq mode-line-format (copy-sequence mode-line-format))
3176   (and (equal (nth 3 mode-line-format) "   ")
3177        (setcar (nthcdr 3 mode-line-format) ""))
3178   (setq major-mode 'gnus-group-mode)
3179   (setq mode-name "Group")
3180   (gnus-group-set-mode-line)
3181   (setq mode-line-process nil)
3182   (use-local-map gnus-group-mode-map)
3183   (buffer-disable-undo (current-buffer))
3184   (setq truncate-lines t)
3185   (setq buffer-read-only t)
3186   (run-hooks 'gnus-group-mode-hook))
3187
3188 (defun gnus-mouse-pick-group (e)
3189   (interactive "e")
3190   (mouse-set-point e)
3191   (gnus-group-read-group nil))
3192
3193 ;; Look at LEVEL and find out what the level is really supposed to be.
3194 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
3195 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
3196 (defun gnus-group-default-level (&optional level number-or-nil)
3197   (cond  
3198    (gnus-group-use-permanent-levels
3199     (setq gnus-group-default-list-level 
3200           (or level gnus-group-default-list-level))
3201     (or gnus-group-default-list-level gnus-level-subscribed))
3202    (number-or-nil
3203     level)
3204    (t
3205     (or level gnus-group-default-list-level gnus-level-subscribed))))
3206   
3207
3208 ;;;###autoload
3209 (defun gnus-no-server (&optional arg)
3210   "Read network news.
3211 If ARG is a positive number, Gnus will use that as the
3212 startup level. If ARG is nil, Gnus will be started at level 2. 
3213 If ARG is non-nil and not a positive number, Gnus will
3214 prompt the user for the name of an NNTP server to use.
3215 As opposed to `gnus', this command will not connect to the local server."
3216   (interactive "P")
3217   (setq gnus-group-use-permanent-levels t)
3218   (gnus (or arg (1- gnus-level-default-subscribed)) t))
3219
3220 ;;;###autoload
3221 (defun gnus (&optional arg dont-connect)
3222   "Read network news.
3223 If ARG is non-nil and a positive number, Gnus will use that as the
3224 startup level. If ARG is non-nil and not a positive number, Gnus will
3225 prompt the user for the name of an NNTP server to use."
3226   (interactive "P")
3227   (if (get-buffer gnus-group-buffer)
3228       (progn
3229         (switch-to-buffer gnus-group-buffer)
3230         (gnus-group-get-new-news))
3231
3232     (gnus-clear-system)
3233
3234     (gnus-group-setup-buffer)
3235     (let ((buffer-read-only nil))
3236       (erase-buffer)
3237       (if (not gnus-inhibit-startup-message)
3238           (progn
3239             (gnus-group-startup-message)
3240             (sit-for 0))))
3241     
3242     (nnheader-init-server-buffer)
3243     (gnus-read-init-file)
3244
3245     (let ((level (and arg (numberp arg) (> arg 0) arg))
3246           did-connect)
3247       (unwind-protect
3248           (progn
3249             (or dont-connect 
3250                 (setq did-connect
3251                       (gnus-start-news-server (and arg (not level))))))
3252         (if (and (not dont-connect) 
3253                  (not did-connect))
3254             (gnus-group-quit)
3255           (run-hooks 'gnus-startup-hook)
3256           ;; NNTP server is successfully open. 
3257
3258           ;; Find the current startup file name.
3259           (setq gnus-current-startup-file 
3260                 (gnus-make-newsrc-file gnus-startup-file))
3261
3262           ;; Read the dribble file.
3263           (and gnus-use-dribble-file (gnus-dribble-read-file))
3264
3265           (gnus-summary-make-display-table)
3266           (gnus-setup-news nil level)
3267           (gnus-group-list-groups level)
3268           (gnus-configure-windows 'group))))))
3269
3270 (defun gnus-unload ()
3271   "Unload all Gnus features."
3272   (interactive)
3273   (or (boundp 'load-history)
3274       (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
3275   (let ((history load-history)
3276         feature)
3277     (while history
3278       (and (string-match "^gnus" (car (car history)))
3279            (setq feature (cdr (assq 'provide (car history))))
3280            (unload-feature feature 'force))
3281       (setq history (cdr history)))))
3282
3283 (defun gnus-group-startup-message (&optional x y)
3284   "Insert startup message in current buffer."
3285   ;; Insert the message.
3286   (erase-buffer)
3287   (insert
3288    (format "
3289           _    ___ _             _      
3290           _ ___ __ ___  __    _ ___     
3291           __   _     ___    __  ___     
3292               _           ___     _     
3293              _  _ __             _      
3294              ___   __            _      
3295                    __           _       
3296                     _      _   _        
3297                    _      _    _        
3298                       _  _    _         
3299                   __  ___               
3300                  _   _ _     _          
3301                 _   _                   
3302               _    _                    
3303              _    _                     
3304             _                         
3305           __                             
3306
3307
3308       Gnus * A newsreader for Emacsen
3309     A Praxis release * larsi@ifi.uio.no
3310
3311            gnus-version))
3312   ;; And then hack it.
3313   ;; 18 is the longest line.
3314   (indent-rigidly (point-min) (point-max) 
3315                   (/ (max (- (window-width) (or x 46)) 0) 2))
3316   (goto-char (point-min))
3317   (let* ((pheight (count-lines (point-min) (point-max)))
3318          (wheight (window-height))
3319          (rest (- wheight  pheight)))
3320     (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
3321     
3322     
3323
3324   ;; Fontify some.
3325   (goto-char (point-min))
3326   (search-forward "Praxis")
3327   (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3328   (goto-char (point-min)))
3329
3330 (defun gnus-group-startup-message-old (&optional x y)
3331   "Insert startup message in current buffer."
3332   ;; Insert the message.
3333   (erase-buffer)
3334   (insert
3335    (format "
3336      %s
3337            A newsreader 
3338       for GNU Emacs
3339
3340         Based on GNUS 
3341              written by 
3342      Masanobu UMEDA
3343
3344        A Praxis Release
3345       larsi@ifi.uio.no
3346
3347            gnus-version))
3348   ;; And then hack it.
3349   ;; 18 is the longest line.
3350   (indent-rigidly (point-min) (point-max) 
3351                   (/ (max (- (window-width) (or x 28)) 0) 2))
3352   (goto-char (point-min))
3353   ;; +4 is fuzzy factor.
3354   (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2))
3355
3356   ;; Fontify some.
3357   (goto-char (point-min))
3358   (search-forward "Praxis")
3359   (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3360   (goto-char (point-min)))
3361
3362 (defun gnus-group-setup-buffer ()
3363   (or (get-buffer gnus-group-buffer)
3364       (progn
3365         (switch-to-buffer gnus-group-buffer)
3366         (gnus-add-current-to-buffer-list)
3367         (gnus-group-mode)
3368         (and gnus-carpal (gnus-carpal-setup-buffer 'group)))))
3369
3370 (defun gnus-group-list-groups (&optional level unread)
3371   "List newsgroups with level LEVEL or lower that have unread articles.
3372 Default is all subscribed groups.
3373 If argument UNREAD is non-nil, groups with no unread articles are also
3374 listed." 
3375   (interactive (list (if current-prefix-arg
3376                          (prefix-numeric-value current-prefix-arg)
3377                        (or
3378                         (gnus-group-default-level nil t)
3379                         gnus-group-default-list-level
3380                         gnus-level-subscribed))))
3381   (or level
3382       (setq level (car gnus-group-list-mode)
3383             unread (cdr gnus-group-list-mode)))
3384   (setq level (gnus-group-default-level level))
3385   (gnus-group-setup-buffer)     ;May call from out of group buffer
3386   (let ((case-fold-search nil)
3387         (group (gnus-group-group-name)))
3388     (funcall gnus-group-prepare-function level unread nil)
3389     (if (zerop (buffer-size))
3390         (gnus-message 5 gnus-no-groups-message)
3391       (goto-char (point-min))
3392       (if (not group)
3393           ;; Go to the first group with unread articles.
3394           (gnus-group-search-forward nil nil nil t)
3395         ;; Find the right group to put point on. If the current group
3396         ;; has disapeared in the new listing, try to find the next
3397         ;; one. If no next one can be found, just leave point at the
3398         ;; first newsgroup in the buffer.
3399         (if (not (gnus-goto-char
3400                   (text-property-any (point-min) (point-max) 
3401                                      'gnus-group (intern group))))
3402             (let ((newsrc (nthcdr 3 (gnus-gethash group gnus-newsrc-hashtb))))
3403               (while (and newsrc
3404                           (not (gnus-goto-char 
3405                                 (text-property-any 
3406                                  (point-min) (point-max) 'gnus-group 
3407                                  (intern (car (car newsrc)))))))
3408                 (setq newsrc (cdr newsrc)))
3409               (or newsrc (progn (goto-char (point-max))
3410                                 (forward-line -1))))))
3411       ;; Adjust cursor point.
3412       (gnus-group-position-cursor))))
3413
3414 (defun gnus-group-prepare-flat (level &optional all lowest regexp) 
3415   "List all newsgroups with unread articles of level LEVEL or lower.
3416 If ALL is non-nil, list groups that have no unread articles.
3417 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
3418 If REGEXP, only list groups matching REGEXP."
3419   (set-buffer gnus-group-buffer)
3420   (let ((buffer-read-only nil)
3421         (newsrc (cdr gnus-newsrc-alist))
3422         (lowest (or lowest 1))
3423         info clevel unread group)
3424     (erase-buffer)
3425     (if (< lowest gnus-level-zombie)
3426         ;; List living groups.
3427         (while newsrc
3428           (setq info (car newsrc)
3429                 group (car info)
3430                 newsrc (cdr newsrc)
3431                 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
3432           (and unread ; This group might be bogus
3433                (or (not regexp)
3434                    (string-match regexp group))
3435                (<= (setq clevel (car (cdr info))) level) 
3436                (>= clevel lowest)
3437                (or all            ; We list all groups?
3438                    (eq unread t)  ; We list unactivated groups
3439                    (> unread 0)   ; We list groups with unread articles
3440                    (cdr (assq 'tick (nth 3 info)))) ; And groups with tickeds
3441                (gnus-group-insert-group-line 
3442                 nil group (car (cdr info)) (nth 3 info) unread (nth 4 info)))))
3443
3444     ;; List dead groups.
3445     (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
3446          (gnus-group-prepare-flat-list-dead 
3447           (setq gnus-zombie-list (sort gnus-zombie-list 'string<)) 
3448           gnus-level-zombie ?Z
3449           regexp))
3450     (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
3451          (gnus-group-prepare-flat-list-dead 
3452           (setq gnus-killed-list (sort gnus-killed-list 'string<)) 
3453           gnus-level-killed ?K regexp))
3454
3455     (gnus-group-set-mode-line)
3456     (setq gnus-group-list-mode (cons level all))
3457     (run-hooks 'gnus-group-prepare-hook)))
3458
3459 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
3460   ;; List zombies and killed lists somehwat faster, which was
3461   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>. It does
3462   ;; this by ignoring the group format specification altogether.
3463   (let (group beg)
3464     (while groups
3465       (setq group (car groups)
3466             groups (cdr groups))
3467       (if (or (not regexp)
3468               (string-match regexp group))
3469           (progn
3470             (setq beg (point))
3471             (insert (format " %c     *: %s\n" mark group))
3472             (add-text-properties 
3473              beg (1+ beg) 
3474              (list 'gnus-group (intern group)
3475                    'gnus-unread t
3476                    'gnus-level level)))))))
3477
3478 (defun gnus-group-real-name (group)
3479   "Find the real name of a foreign newsgroup."
3480   (if (string-match ":[^:]+$" group)
3481       (substring group (1+ (match-beginning 0)))
3482     group))
3483
3484 (defun gnus-group-prefixed-name (group method)
3485   "Return the whole name from GROUP and METHOD."
3486   (and (stringp method) (setq method (gnus-server-to-method method)))
3487   (concat (format "%s" (car method))
3488           (if (and 
3489                (assoc (format "%s" (car method)) (gnus-methods-using 'address))
3490                (not (string= (nth 1 method) "")))
3491               (concat "+" (nth 1 method)))
3492           ":" group))
3493
3494 (defun gnus-group-real-prefix (group)
3495   "Return the prefix of the current group name."
3496   (if (string-match "^[^:]+:" group)
3497       (substring group 0 (match-end 0))
3498     ""))
3499
3500 (defun gnus-group-method-name (group)
3501   "Return the method used for selecting GROUP."
3502   (let ((prefix (gnus-group-real-prefix group)))
3503     (if (equal prefix "")
3504         gnus-select-method
3505       (if (string-match "^[^\\+]+\\+" prefix)
3506           (list (intern (substring prefix 0 (1- (match-end 0))))
3507                 (substring prefix (match-end 0) (1- (length prefix))))
3508         (list (intern (substring prefix 0 (1- (length prefix)))) "")))))
3509
3510 (defun gnus-group-foreign-p (group)
3511   "Return nil if GROUP is native, non-nil if it is foreign."
3512   (string-match ":" group))
3513
3514 (defun gnus-group-set-info (info &optional method-only-group part)
3515   (let* ((entry (gnus-gethash
3516                  (or method-only-group (car info)) gnus-newsrc-hashtb))
3517          (part-info info)
3518          (info (if method-only-group (nth 2 entry) info)))
3519     (if (not method-only-group)
3520         ()
3521       (or entry
3522           (error "Trying to change non-existent group %s" method-only-group))
3523       ;; We have recevied parts of the actual group info - either the
3524       ;; select method or the group parameters.  We first check
3525       ;; whether we have to extend the info, and if so, do that.
3526       (let ((len (length info))
3527             (total (if (eq part 'method) 5 6)))
3528         (and (< len total)
3529              (setcdr (nthcdr (1- len) info)
3530                      (make-list (- total len) nil)))
3531         ;; Then we enter the new info.
3532         (setcar (nthcdr (1- total) info) part-info)))
3533     ;; We uncompress some lists of marked articles.
3534     (let (marked)
3535       (if (not (setq marked (nth 3 info)))
3536           ()
3537         (while marked
3538           (or (eq 'score (car (car marked)))
3539               (eq 'bookmark (car (car marked)))
3540               (eq 'killed (car (car marked)))
3541               (setcdr (car marked) 
3542                       (gnus-uncompress-range (cdr (car marked)))))
3543           (setq marked (cdr marked)))))
3544     (if entry
3545         ()
3546       ;; This is a new group, so we just create it.
3547       (save-excursion
3548         (set-buffer gnus-group-buffer)
3549         (if (nth 4 info)
3550             ;; It's a foreign group...
3551             (gnus-group-make-group 
3552              (gnus-group-real-name (car info))
3553              (prin1-to-string (car (nth 4 info)))
3554              (nth 1 (nth 4 info)))
3555           ;; It's a native group.
3556           (gnus-group-make-group
3557            (car info)
3558            (prin1-to-string (car gnus-select-method))
3559            (nth 1 gnus-select-method)))
3560         (gnus-message 6 "Note: New group created")
3561         (setq entry 
3562               (gnus-gethash (gnus-group-prefixed-name 
3563                              (gnus-group-real-name (car info))
3564                              (or (nth 4 info) gnus-select-method))
3565                             gnus-newsrc-hashtb))))
3566     ;; Whether it was a new group or not, we now have the entry, so we
3567     ;; can do the update.
3568     (if entry
3569         (progn
3570           (setcar (nthcdr 2 entry) info)
3571           (if (and (not (eq (car entry) t)) 
3572                    (gnus-gethash (car info) gnus-active-hashtb))
3573               (let ((marked (nth 3 info)))
3574                 (setcar entry 
3575                         (max 0 (- (length (gnus-list-of-unread-articles 
3576                                            (car info)))
3577                                   (length (cdr (assq 'tick marked)))
3578                                   (length (cdr (assq 'dormant marked)))))))))
3579       (error "No such group: %s" (car info)))))
3580
3581 (defun gnus-group-set-method-info (group select-method)
3582   (gnus-group-set-info select-method group 'method))
3583
3584 (defun gnus-group-set-params-info (group params)
3585   (gnus-group-set-info params group 'params))
3586
3587 (defun gnus-group-update-group-line ()
3588   "This function updates the current line in the newsgroup buffer and
3589 moves the point to the colon."
3590   (let* ((buffer-read-only nil)
3591          (group (gnus-group-group-name))
3592          (entry (and group (gnus-gethash group gnus-newsrc-hashtb))))
3593     (if entry
3594         (gnus-dribble-enter 
3595          (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3596                  ")")))
3597     (beginning-of-line)
3598     (delete-region (point) (progn (forward-line 1) (point)))
3599     (gnus-group-insert-group-line-info group)
3600     (forward-line -1)
3601     (gnus-group-position-cursor)))
3602
3603 (defun gnus-group-insert-group-line-info (group)
3604   (let ((entry (gnus-gethash group gnus-newsrc-hashtb)) 
3605         active info)
3606     (if entry
3607         (progn
3608           (setq info (nth 2 entry))
3609           (gnus-group-insert-group-line 
3610            nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
3611       (setq active (gnus-gethash group gnus-active-hashtb))
3612       (gnus-group-insert-group-line 
3613        nil group 
3614        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
3615        nil (if active (- (1+ (cdr active)) (car active)) 0) nil))))
3616
3617 (defun gnus-group-insert-group-line (gformat group level marked number method)
3618   (let* ((gformat (or gformat gnus-group-line-format-spec))
3619          (active (gnus-gethash group gnus-active-hashtb))
3620          (number-total (if active (1+ (- (cdr active) (car active))) 0))
3621          (number-of-dormant (length (cdr (assq 'dormant marked))))
3622          (number-of-ticked (length (cdr (assq 'tick marked))))
3623          (number-of-ticked-and-dormant
3624           (+ number-of-ticked number-of-dormant))
3625          (number-of-unread-unticked 
3626           (if (numberp number) (int-to-string (max 0 number))
3627             "*"))
3628          (number-of-read
3629           (if (numberp number)
3630               (max 0 (- number-total number))
3631             "*"))
3632          (subscribed (cond ((<= level gnus-level-subscribed) ? )
3633                            ((<= level gnus-level-unsubscribed) ?U)
3634                            ((= level gnus-level-zombie) ?Z)
3635                            (t ?K)))
3636          (qualified-group (gnus-group-real-name group))
3637          (newsgroup-description 
3638           (if gnus-description-hashtb
3639               (or (gnus-gethash group gnus-description-hashtb) "")
3640             ""))
3641          (moderated (if (member group gnus-moderated-list) ?m ? ))
3642          (moderated-string (if (eq moderated ?m) "(m)" ""))
3643          (method (gnus-server-get-method group method))
3644          (news-server (or (car (cdr method)) ""))
3645          (news-method (or (car method) ""))
3646          (news-method-string 
3647           (if method (format "(%s:%s)" (car method) (car (cdr method))) ""))
3648          (marked (if (and 
3649                       (numberp number) 
3650                       (zerop number)
3651                       (> number-of-ticked 0))
3652                      ?* ? ))
3653          (number (if (eq number t) "*" (+ number number-of-dormant 
3654                                           number-of-ticked)))
3655          (process-marked (if (member qualified-group gnus-group-marked)
3656                              gnus-process-mark ? ))
3657          (buffer-read-only nil)
3658          header ; passed as parameter to user-funcs.
3659          b)
3660     (beginning-of-line)
3661     (setq b (point))
3662     ;; Insert the text.
3663     (insert (eval gformat))
3664
3665     (add-text-properties 
3666      b (1+ b) (list 'gnus-group (intern group)
3667                     'gnus-unread (if (numberp number)
3668                                      (string-to-int number-of-unread-unticked)
3669                                    t)
3670                     'gnus-marked marked
3671                     'gnus-level level))))
3672
3673 (defun gnus-group-update-group (group &optional visible-only)
3674   "Update newsgroup info of GROUP.
3675 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't already."
3676   (save-excursion
3677     (set-buffer gnus-group-buffer)
3678     (let ((buffer-read-only nil)
3679           visible)
3680       (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
3681         (if entry
3682             (gnus-dribble-enter 
3683              (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
3684                      ")"))))
3685       ;; Buffer may be narrowed.
3686       (save-restriction
3687         (widen)
3688         ;; Search a line to modify.  If the buffer is large, the search
3689         ;; takes long time.  In most cases, current point is on the line
3690         ;; we are looking for.  So, first of all, check current line. 
3691         (if (or (progn
3692                   (beginning-of-line)
3693                   (eq (get-text-property (point) 'gnus-group)
3694                       (intern group)))
3695                 (progn
3696                   (gnus-goto-char 
3697                    (text-property-any 
3698                     (point-min) (point-max) 'gnus-group (intern group)))))
3699             ;; GROUP is listed in current buffer. So, delete old line.
3700             (progn
3701               (setq visible t)
3702               (beginning-of-line)
3703               (delete-region (point) (progn (forward-line 1) (point))))
3704           ;; No such line in the buffer, find out where it's supposed to
3705           ;; go, and insert it there (or at the end of the buffer).
3706           ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
3707           (or visible-only
3708               (let ((entry 
3709                      (cdr (cdr (gnus-gethash group gnus-newsrc-hashtb)))))
3710                 (while (and entry
3711                             (car entry)
3712                             (not
3713                              (gnus-goto-char
3714                               (text-property-any
3715                                (point-min) (point-max) 
3716                                'gnus-group (intern (car (car entry)))))))
3717                   (setq entry (cdr entry)))
3718                 (or entry (goto-char (point-max)))))))
3719       (if (or visible (not visible-only))
3720           (gnus-group-insert-group-line-info group))
3721       (gnus-group-set-mode-line))))
3722
3723 (defun gnus-group-set-mode-line ()
3724   (if (memq 'group gnus-updated-mode-lines)
3725       (let* ((gformat (or gnus-group-mode-line-format-spec
3726                           (setq gnus-group-mode-line-format-spec
3727                                 (gnus-parse-format 
3728                                  gnus-group-mode-line-format 
3729                                  gnus-group-mode-line-format-alist))))
3730              (news-server (car (cdr gnus-select-method)))
3731              (news-method (car gnus-select-method))
3732              (max-len 60)
3733              (mode-string (eval gformat)))
3734         (setq mode-string (eval gformat))
3735         (if (> (length mode-string) max-len) 
3736             (setq mode-string (substring mode-string 0 (- max-len 4))))
3737         (setq mode-line-buffer-identification mode-string)
3738         (set-buffer-modified-p t))))
3739
3740 (defun gnus-group-group-name ()
3741   "Get the name of the newsgroup on the current line."
3742   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
3743     (and group (symbol-name group))))
3744
3745 (defun gnus-group-group-level ()
3746   "Get the level of the newsgroup on the current line."
3747   (get-text-property (gnus-point-at-bol) 'gnus-level))
3748
3749 (defun gnus-group-group-unread ()
3750   "Get the number of unread articles of the newsgroup on the current line."
3751   (get-text-property (gnus-point-at-bol) 'gnus-unread))
3752
3753 (defun gnus-group-search-forward (&optional backward all level first-too)
3754   "Find the next newsgroup with unread articles.
3755 If BACKWARD is non-nil, find the previous newsgroup instead.
3756 If ALL is non-nil, just find any newsgroup.
3757 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
3758 group exists.
3759 If FIRST-TOO, the current line is also eligible as a target."
3760   (let ((way (if backward -1 1))
3761         (low gnus-level-killed)
3762         (beg (point))
3763         pos found lev)
3764     (if (and backward (progn (beginning-of-line)) (bobp))
3765         nil
3766       (or first-too (forward-line way))
3767       (while (and 
3768               (not (eobp))
3769               (not (setq 
3770                     found 
3771                     (and (or all
3772                              (and
3773                               (let ((unread 
3774                                      (get-text-property (point) 'gnus-unread)))
3775                                 (or (eq unread t) (and unread (> unread 0))))
3776                               (setq lev (get-text-property (point)
3777                                                            'gnus-level))
3778                               (<= lev gnus-level-subscribed)))
3779                          (or (not level)
3780                              (and (setq lev (get-text-property (point)
3781                                                                'gnus-level))
3782                                   (or (= lev level)
3783                                       (and (< lev low)
3784                                            (< level lev)
3785                                            (progn
3786                                              (setq low lev)
3787                                              (setq pos (point))
3788                                              nil))))))))
3789               (zerop (forward-line way)))))
3790     (if found 
3791         (progn (gnus-group-position-cursor) t)
3792       (goto-char (or pos beg))
3793       (and pos t))))
3794
3795 ;;; Gnus group mode commands
3796
3797 ;; Group marking.
3798
3799 (defun gnus-group-mark-group (n &optional unmark no-advance)
3800   "Mark the current group."
3801   (interactive "p")
3802   (let ((buffer-read-only nil)
3803         group)
3804     (while 
3805         (and (> n 0) 
3806              (setq group (gnus-group-group-name))
3807              (progn
3808                (beginning-of-line)
3809                (forward-char 
3810                 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
3811                (delete-char 1)
3812                (if unmark
3813                    (progn
3814                      (insert " ")
3815                      (setq gnus-group-marked (delete group gnus-group-marked)))
3816                  (insert "#")
3817                  (setq gnus-group-marked
3818                        (cons group (delete group gnus-group-marked))))
3819                t)
3820              (or no-advance (zerop (gnus-group-next-group 1))))
3821       (setq n (1- n)))
3822     (gnus-summary-position-cursor)
3823     n))
3824
3825 (defun gnus-group-unmark-group (n)
3826   "Remove the mark from the current group."
3827   (interactive "p")
3828   (gnus-group-mark-group n 'unmark))
3829
3830 (defun gnus-group-mark-region (unmark beg end)
3831   "Mark all groups between point and mark.
3832 If UNMARK, remove the mark instead."
3833   (interactive "P\nr")
3834   (let ((num (count-lines beg end)))
3835     (save-excursion
3836       (goto-char beg)
3837       (- num (gnus-group-mark-group num unmark)))))
3838
3839 (defun gnus-group-remove-mark (group)
3840   (and (gnus-group-goto-group group)
3841        (save-excursion
3842          (gnus-group-mark-group 1 'unmark t))))
3843
3844 ;; Return a list of groups to work on.  Take into consideration N (the
3845 ;; prefix) and the list of marked groups.
3846 (defun gnus-group-process-prefix (n)
3847   (cond (n
3848          (setq n (prefix-numeric-value n))
3849          ;; There is a prefix, so we return a list of the N next
3850          ;; groups. 
3851          (let ((way (if (< n 0) -1 1))
3852                (n (abs n))
3853                group groups)
3854            (save-excursion
3855              (while (and (> n 0)
3856                          (setq group (gnus-group-group-name)))
3857                (setq groups (cons group groups))
3858                (setq n (1- n))
3859                (forward-line way)))
3860            (nreverse groups)))
3861         (gnus-group-marked
3862          ;; No prefix, but a list of marked articles.
3863          (reverse gnus-group-marked))
3864         (t
3865          ;; Neither marked articles or a prefix, so we return the
3866          ;; current group.
3867          (let ((group (gnus-group-group-name)))
3868            (and group (list group))))))
3869
3870 ;; Selecting groups.
3871
3872 (defun gnus-group-read-group (&optional all no-article group)
3873   "Read news in this newsgroup.
3874 If the prefix argument ALL is non-nil, already read articles become
3875 readable. If the optional argument NO-ARTICLE is non-nil, no article
3876 will be auto-selected upon group entry."
3877   (interactive "P")
3878   (let ((group (or group (gnus-group-group-name)))
3879         number active marked entry)
3880     (or group (error "No group on current line"))
3881     (setq marked 
3882           (nth 3 (nth 2 (setq entry (gnus-gethash group gnus-newsrc-hashtb)))))
3883     ;; This group might be a dead group. In that case we have to get
3884     ;; the number of unread articles from `gnus-active-hashtb'.
3885     (if entry
3886         (setq number (car entry))
3887       (if (setq active (gnus-gethash group gnus-active-hashtb))
3888           (setq number (- (1+ (cdr active)) (car active)))))
3889     (gnus-summary-read-group 
3890      group (or all (and (numberp number) 
3891                         (zerop (+ number (length (cdr (assq 'tick marked)))
3892                                   (length (cdr (assq 'dormant marked)))))))
3893      no-article)))
3894
3895 (defun gnus-group-select-group (&optional all)
3896   "Select this newsgroup.
3897 No article is selected automatically.
3898 If argument ALL is non-nil, already read articles become readable."
3899   (interactive "P")
3900   (gnus-group-read-group all t))
3901
3902 (defun gnus-group-select-group-all ()
3903   "Select the current group and display all articles in it."
3904   (interactive)
3905   (gnus-group-select-group 'all))
3906
3907 ;; Enter a group that is not in the group buffer. Non-nil is returned
3908 ;; if selection was successful.
3909 (defun gnus-group-read-ephemeral-group 
3910   (group method &optional activate quit-config)
3911   (let ((group (if (gnus-group-foreign-p group) group
3912                  (gnus-group-prefixed-name group method))))
3913     (gnus-sethash 
3914      group
3915      (list t nil (list group gnus-level-default-subscribed nil nil 
3916                        (append method
3917                                (list
3918                                 (list 'quit-config 
3919                                       (if quit-config quit-config
3920                                         (cons (current-buffer) 'summary)))))))
3921      gnus-newsrc-hashtb)
3922     (set-buffer gnus-group-buffer)
3923     (or (gnus-check-server method)
3924         (error "Unable to contact server: %s" (gnus-status-message method)))
3925     (if activate (or (gnus-request-group group)
3926                      (error "Couldn't request group")))
3927     (condition-case ()
3928         (gnus-group-read-group t t group)
3929       (error nil)
3930       (quit nil))
3931     (not (equal major-mode 'gnus-group-mode))))
3932   
3933 (defun gnus-group-jump-to-group (group)
3934   "Jump to newsgroup GROUP."
3935   (interactive 
3936    (list (completing-read 
3937           "Group: " gnus-active-hashtb nil 
3938           (memq gnus-select-method gnus-have-read-active-file))))
3939
3940   (if (equal group "")
3941       (error "Empty group name"))
3942
3943   (let ((b (text-property-any 
3944             (point-min) (point-max) 'gnus-group (intern group))))
3945     (if b
3946         ;; Either go to the line in the group buffer...
3947         (goto-char b)
3948       ;; ... or insert the line.
3949       (or
3950        (gnus-gethash group gnus-active-hashtb)
3951        (gnus-activate-group group)
3952        (error "%s error: %s" group (gnus-status-message group)))
3953
3954       (gnus-group-update-group group)
3955       (goto-char (text-property-any 
3956                   (point-min) (point-max) 'gnus-group (intern group)))))
3957   ;; Adjust cursor point.
3958   (gnus-group-position-cursor))
3959
3960 (defun gnus-group-goto-group (group)
3961   "Goto to newsgroup GROUP."
3962   (let ((b (text-property-any (point-min) (point-max) 
3963                               'gnus-group (intern group))))
3964     (and b (goto-char b))))
3965
3966 (defun gnus-group-next-group (n)
3967   "Go to next N'th newsgroup.
3968 If N is negative, search backward instead.
3969 Returns the difference between N and the number of skips actually
3970 done."
3971   (interactive "p")
3972   (gnus-group-next-unread-group n t))
3973
3974 (defun gnus-group-next-unread-group (n &optional all level)
3975   "Go to next N'th unread newsgroup.
3976 If N is negative, search backward instead.
3977 If ALL is non-nil, choose any newsgroup, unread or not.
3978 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
3979 such group can be found, the next group with a level higher than
3980 LEVEL.
3981 Returns the difference between N and the number of skips actually
3982 made."
3983   (interactive "p")
3984   (let ((backward (< n 0))
3985         (n (abs n)))
3986     (while (and (> n 0)
3987                 (gnus-group-search-forward 
3988                  backward (or (not gnus-group-goto-unread) all) level))
3989       (setq n (1- n)))
3990     (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
3991                                (if level " on this level or higher" "")))
3992     n))
3993
3994 (defun gnus-group-prev-group (n)
3995   "Go to previous N'th newsgroup.
3996 Returns the difference between N and the number of skips actually
3997 done."
3998   (interactive "p")
3999   (gnus-group-next-unread-group (- n) t))
4000
4001 (defun gnus-group-prev-unread-group (n)
4002   "Go to previous N'th unread newsgroup.
4003 Returns the difference between N and the number of skips actually
4004 done."  
4005   (interactive "p")
4006   (gnus-group-next-unread-group (- n)))
4007
4008 (defun gnus-group-next-unread-group-same-level (n)
4009   "Go to next N'th unread newsgroup on the same level.
4010 If N is negative, search backward instead.
4011 Returns the difference between N and the number of skips actually
4012 done."
4013   (interactive "p")
4014   (gnus-group-next-unread-group n t (gnus-group-group-level))
4015   (gnus-group-position-cursor))
4016
4017 (defun gnus-group-prev-unread-group-same-level (n)
4018   "Go to next N'th unread newsgroup on the same level.
4019 Returns the difference between N and the number of skips actually
4020 done."
4021   (interactive "p")
4022   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
4023   (gnus-group-position-cursor))
4024
4025 (defun gnus-group-best-unread-group (&optional exclude-group)
4026   "Go to the group with the highest level.
4027 If EXCLUDE-GROUP, do not go to that group."
4028   (interactive)
4029   (goto-char (point-min))
4030   (let ((best 100000)
4031         unread best-point)
4032     (while (setq unread (get-text-property (point) 'gnus-unread))
4033       (if (and (numberp unread) (> unread 0))
4034           (progn
4035             (if (and (< (get-text-property (point) 'gnus-level) best)
4036                      (or (not exclude-group)
4037                          (not (equal exclude-group (gnus-group-group-name)))))
4038                 (progn 
4039                   (setq best (get-text-property (point) 'gnus-level))
4040                   (setq best-point (point))))))
4041       (forward-line 1))
4042     (if best-point (goto-char best-point))
4043     (gnus-summary-position-cursor)
4044     (and best-point (gnus-group-group-name))))
4045
4046 (defun gnus-group-first-unread-group ()
4047   "Go to the first group with unread articles."
4048   (interactive)
4049   (prog1
4050       (let ((opoint (point))
4051             unread)
4052         (goto-char (point-min))
4053         (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
4054                 (not (zerop unread)) ; Has unread articles.
4055                 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
4056             (point) ; Success.
4057           (goto-char opoint)
4058           nil)) ; Not success.
4059     (gnus-group-position-cursor)))
4060
4061 (defun gnus-group-enter-server-mode ()
4062   "Jump to the server buffer."
4063   (interactive)
4064   (gnus-server-setup-buffer)
4065   (gnus-configure-windows 'server)
4066   (gnus-server-prepare))
4067
4068 (defun gnus-group-make-group (name method &optional address)
4069   "Add a new newsgroup.
4070 The user will be prompted for a NAME, for a select METHOD, and an
4071 ADDRESS."
4072   (interactive
4073    (cons 
4074     (read-string "Group name: ")
4075     (let ((method
4076            (completing-read 
4077             "Method: " (append gnus-valid-select-methods gnus-server-alist)
4078             nil t)))
4079       (if (assoc method gnus-valid-select-methods)
4080           (list method
4081                 (if (memq 'prompt-address
4082                           (assoc method gnus-valid-select-methods))
4083                     (read-string "Address: ")
4084                   ""))
4085         (list method nil)))))
4086   
4087   (let* ((meth (if address (list (intern method) address) method))
4088          (nname (gnus-group-prefixed-name name meth))
4089          info)
4090     (and (gnus-gethash nname gnus-newsrc-hashtb)
4091          (error "Group %s already exists" nname))
4092     (gnus-group-change-level 
4093      (setq info (list t nname gnus-level-default-subscribed nil nil meth))
4094      gnus-level-default-subscribed gnus-level-killed 
4095      (and (gnus-group-group-name)
4096           (gnus-gethash (gnus-group-group-name)
4097                         gnus-newsrc-hashtb))
4098      t)
4099     (gnus-sethash nname (cons 1 0) gnus-active-hashtb)
4100     (gnus-dribble-enter 
4101      (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")"))
4102     (gnus-group-insert-group-line-info nname)
4103
4104     (if (assoc method gnus-valid-select-methods)
4105         (require (intern method)))
4106     (and (gnus-check-backend-function 'request-create-group nname)
4107          (gnus-request-create-group nname))))
4108
4109 (defun gnus-group-edit-group (group &optional part)
4110   "Edit the group on the current line."
4111   (interactive (list (gnus-group-group-name)))
4112   (let ((done-func '(lambda () 
4113                       "Exit editing mode and update the information."
4114                       (interactive)
4115                       (gnus-group-edit-group-done 'part 'group)))
4116         (part (or part 'info))
4117         (winconf (current-window-configuration))
4118         info)
4119     (or group (error "No group on current line"))
4120     (or (setq info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4121         (error "Killed group; can't be edited"))
4122     (set-buffer (get-buffer-create gnus-group-edit-buffer))
4123     (gnus-configure-windows 'edit-group)
4124     (gnus-add-current-to-buffer-list)
4125     (emacs-lisp-mode)
4126     ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4127     (use-local-map (copy-keymap emacs-lisp-mode-map))
4128     (local-set-key "\C-c\C-c" done-func)
4129     (make-local-variable 'gnus-prev-winconf)
4130     (setq gnus-prev-winconf winconf)
4131     ;; We modify the func to let it know what part it is editing.
4132     (setcar (cdr (nth 4 done-func)) (list 'quote part))
4133     (setcar (cdr (cdr (nth 4 done-func))) group)
4134     (erase-buffer)
4135     (insert
4136      (cond 
4137       ((eq part 'method)
4138        ";; Type `C-c C-c' after editing the select method.\n\n")
4139       ((eq part 'params)
4140        ";; Type `C-c C-c' after editing the group parameters.\n\n")
4141       ((eq part 'info)
4142        ";; Type `C-c C-c' after editing the group info.\n\n")))
4143     (let ((cinfo (gnus-copy-sequence info))
4144           marked)
4145       (if (not (setq marked (nth 3 cinfo)))
4146           ()
4147         (while marked
4148           (or (eq 'score (car (car marked)))
4149               (eq 'bookmark (car (car marked)))
4150               (eq 'killed (car (car marked)))
4151               (not (numberp (car (cdr (car marked)))))
4152               (setcdr (car marked) 
4153                       (gnus-compress-sequence (sort (cdr (car marked)) '<) t)))
4154           (setq marked (cdr marked))))
4155       (insert 
4156        (pp-to-string
4157         (cond ((eq part 'method)
4158                (or (nth 4 info) "native"))
4159               ((eq part 'params)
4160                (nth 5 info))
4161               (t
4162                cinfo)))
4163        "\n"))))
4164
4165 (defun gnus-group-edit-group-method (group)
4166   "Edit the select method of GROUP."
4167   (interactive (list (gnus-group-group-name)))
4168   (gnus-group-edit-group group 'method))
4169
4170 (defun gnus-group-edit-group-parameters (group)
4171   "Edit the group parameters of GROUP."
4172   (interactive (list (gnus-group-group-name)))
4173   (gnus-group-edit-group group 'params))
4174
4175 (defun gnus-group-edit-group-done (part group)
4176   "Get info from buffer, update variables and jump to the group buffer."
4177   (set-buffer (get-buffer-create gnus-group-edit-buffer))
4178   (goto-char (point-min))
4179   (let ((form (read (current-buffer)))
4180         (winconf gnus-prev-winconf))
4181     (if (eq part 'info) 
4182         (gnus-group-set-info form)
4183       (gnus-group-set-info form group part))
4184     (kill-buffer (current-buffer))
4185     (and winconf (set-window-configuration winconf))
4186     (set-buffer gnus-group-buffer)
4187     (gnus-group-update-group (gnus-group-group-name))
4188     (gnus-group-position-cursor)))
4189
4190 (defun gnus-group-make-help-group ()
4191   "Create the Gnus documentation group."
4192   (interactive)
4193   (let ((path load-path)
4194         name)
4195     (and (gnus-gethash (setq name (gnus-group-prefixed-name
4196                                    "gnus-help" '(nndoc "gnus-help")))
4197                        gnus-newsrc-hashtb)
4198          (error "Documentation group already exists"))
4199     (while (and path
4200                 (not (file-exists-p (concat (file-name-as-directory (car path))
4201                                             "doc.txt"))))
4202       (setq path (cdr path)))
4203     (or path (error "Couldn't find doc group"))
4204     (gnus-group-make-group 
4205      (gnus-group-real-name name)
4206      (list 'nndoc name
4207            (list 'nndoc-address (concat (file-name-as-directory (car path)) "doc.txt"))
4208            (list 'nndoc-article-type 'mbox))))
4209   (gnus-group-position-cursor))
4210
4211 (defun gnus-group-make-doc-group (file type)
4212   "Create a group that uses a single file as the source."
4213   (interactive 
4214    (list (read-file-name "File name: ") 
4215          (let ((err "")
4216                found char)
4217            (while (not found)
4218              (message "%sFile type (mbox, babyl, digest) [mbd]: " err)
4219              (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
4220                                ((= char ?b) 'babyl)
4221                                ((= char ?d) 'digest)
4222                                (t (setq err (format "%c unknown. " char))
4223                                   nil))))
4224            found)))
4225   (let* ((file (expand-file-name file))
4226          (name (gnus-generate-new-group-name
4227                 (gnus-group-prefixed-name
4228                  (file-name-nondirectory file) '(nndoc "")))))
4229     (gnus-group-make-group 
4230      (gnus-group-real-name name)
4231      (list 'nndoc name
4232            (list 'nndoc-address file)
4233            (list 'nndoc-article-type type)))))
4234
4235 (defun gnus-group-make-archive-group (&optional all)
4236   "Create the (ding) Gnus archive group of the most recent articles.
4237 Given a prefix, create a full group."
4238   (interactive)
4239   (let ((group (gnus-group-prefixed-name 
4240                 (if all "ding.archives" "ding.recent") '(nndir ""))))
4241     (and (gnus-gethash group gnus-newsrc-hashtb)
4242          (error "Archive group already exists"))
4243     (gnus-group-make-group
4244      (gnus-group-real-name group)
4245      "nndir" 
4246      (if all gnus-group-archive-directory 
4247        gnus-group-recent-archive-directory)))
4248   (gnus-group-position-cursor))
4249
4250 (defun gnus-group-make-directory-group (dir)
4251   "Create an nndir group.
4252 The user will be prompted for a directory. The contents of this
4253 directory will be used as a newsgroup. The directory should contain
4254 mail messages or news articles in files that have numeric names."
4255   (interactive
4256    (list (read-file-name "Create group from directory: ")))
4257   (or (file-exists-p dir) (error "No such directory"))
4258   (or (file-directory-p dir) (error "Not a directory"))
4259   (gnus-group-make-group dir "nndir" dir)
4260   (gnus-group-position-cursor))
4261
4262 (defun gnus-group-make-kiboze-group (group address scores)
4263   "Create an nnkiboze group.
4264 The user will be prompted for a name, a regexp to match groups, and
4265 score file entries for articles to include in the group."
4266   (interactive
4267    (list
4268     (read-string "nnkiboze group name: ")
4269     (read-string "Source groups (regexp): ")
4270     (let ((headers (mapcar (lambda (group) (list group))
4271                            '("subject" "from" "number" "date" "message-id"
4272                              "references" "chars" "lines" "xref")))
4273           scores header regexp regexps)
4274       (while (not (equal "" (setq header (completing-read 
4275                                           "Match on header: " headers nil t))))
4276         (setq regexps nil)
4277         (while (not (equal "" (setq regexp (read-string 
4278                                             (format "Match on %s (string): "
4279                                                     header)))))
4280           (setq regexps (cons (list regexp nil nil 'r) regexps)))
4281         (setq scores (cons (cons header regexps) scores)))
4282       scores)))
4283   (gnus-group-make-group group "nnkiboze" address)
4284   (save-excursion
4285     (gnus-set-work-buffer)
4286     (let (emacs-lisp-mode-hook)
4287       (pp scores (current-buffer)))
4288     (write-region (point-min) (point-max) 
4289                   (concat (or gnus-kill-files-directory "~/News")
4290                           "nnkiboze:" group "." gnus-score-file-suffix)))
4291   (gnus-group-position-cursor))
4292
4293 (defun gnus-group-add-to-virtual (n vgroup)
4294   "Add the current group to a virtual group."
4295   (interactive
4296    (list current-prefix-arg
4297          (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
4298                           "nnvirtual:")))
4299   (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
4300       (error "%s is not an nnvirtual group" vgroup))
4301   (let* ((groups (gnus-group-process-prefix n))
4302          (method (nth 4 (nth 2 (gnus-gethash vgroup gnus-newsrc-hashtb)))))
4303     (setcar (cdr method)
4304             (concat 
4305              (nth 1 method) "\\|"
4306              (mapconcat 
4307               (lambda (s) 
4308                 (gnus-group-remove-mark s)
4309                 (concat "\\(^" (regexp-quote s) "$\\)"))
4310               groups "\\|"))))
4311   (gnus-group-position-cursor))
4312
4313 (defun gnus-group-make-empty-virtual (group)
4314   "Create a new, fresh, empty virtual group."
4315   (interactive "sCreate new, empty virtual group: ")
4316   (let* ((method (list 'nnvirtual "^$"))
4317          (pgroup (gnus-group-prefixed-name group method)))
4318     ;; Check whether it exists already.
4319     (and (gnus-gethash pgroup gnus-newsrc-hashtb)
4320          (error "Group %s already exists." pgroup))
4321     ;; Subscribe the new group after the group on the current line.
4322     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
4323     (gnus-group-update-group pgroup)
4324     (forward-line -1)
4325     (gnus-group-position-cursor)))
4326
4327 (defun gnus-group-enter-directory (dir)
4328   "Enter an ephemeral nneething group."
4329   (interactive "DDirectory to read: ")
4330   (let* ((method (list 'nneething dir))
4331          (leaf (gnus-group-prefixed-name
4332                 (file-name-nondirectory (directory-file-name dir))
4333                 method))
4334          (name (gnus-generate-new-group-name leaf)))
4335     (let ((nneething-read-only t))
4336       (or (gnus-group-read-ephemeral-group 
4337            name method t
4338            (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
4339                                       'summary 'group)))
4340           (error "Couldn't enter %s" dir)))))
4341
4342 ;; Group sorting commands
4343 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
4344
4345 (defun gnus-group-sort-groups ()
4346   "Sort the group buffer using `gnus-group-sort-function'."
4347   (interactive)
4348   (setq gnus-newsrc-alist 
4349         (sort (cdr gnus-newsrc-alist) gnus-group-sort-function))
4350   (gnus-make-hashtable-from-newsrc-alist)
4351   (gnus-group-list-groups))
4352
4353 (defun gnus-group-sort-by-alphabet (info1 info2)
4354   (string< (car info1) (car info2)))
4355
4356 (defun gnus-group-sort-by-unread (info1 info2)
4357   (let ((n1 (car (gnus-gethash (car info1) gnus-newsrc-hashtb)))
4358         (n2 (car (gnus-gethash (car info2) gnus-newsrc-hashtb))))
4359     (< (or (and (numberp n1) n1) 0)
4360        (or (and (numberp n2) n2) 0))))
4361
4362 (defun gnus-group-sort-by-level (info1 info2)
4363   (< (nth 1 info1) (nth 1 info2)))
4364
4365 ;; Group catching up.
4366
4367 (defun gnus-group-catchup-current (&optional n all)
4368   "Mark all articles not marked as unread in current newsgroup as read.
4369 If prefix argument N is numeric, the ARG next newsgroups will be
4370 caught up. If ALL is non-nil, marked articles will also be marked as
4371 read. Cross references (Xref: header) of articles are ignored.
4372 The difference between N and actual number of newsgroups that were
4373 caught up is returned."
4374   (interactive "P")
4375   (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
4376                gnus-expert-user
4377                (gnus-y-or-n-p
4378                 (if all
4379                     "Do you really want to mark all articles as read? "
4380                   "Mark all unread articles as read? "))))
4381       n
4382     (let ((groups (gnus-group-process-prefix n))
4383           (ret 0))
4384       (while groups
4385         ;; Virtual groups have to be given special treatment. 
4386         (let ((method (gnus-find-method-for-group (car groups))))
4387           (if (eq 'nnvirtual (car method))
4388               (nnvirtual-catchup-group
4389                (gnus-group-real-name (car groups)) (nth 1 method) all)))
4390         (gnus-group-remove-mark (car groups))
4391         (if (prog1
4392                 (gnus-group-goto-group (car groups))
4393               (gnus-group-catchup (car groups) all))
4394             (gnus-group-update-group-line)
4395           (setq ret (1+ ret)))
4396         (setq groups (cdr groups)))
4397       (gnus-group-next-unread-group 1)
4398       ret)))
4399
4400 (defun gnus-group-catchup-current-all (&optional n)
4401   "Mark all articles in current newsgroup as read.
4402 Cross references (Xref: header) of articles are ignored."
4403   (interactive "P")
4404   (gnus-group-catchup-current n 'all))
4405
4406 (defun gnus-group-catchup (group &optional all)
4407   "Mark all articles in GROUP as read.
4408 If ALL is non-nil, all articles are marked as read.
4409 The return value is the number of articles that were marked as read,
4410 or nil if no action could be taken."
4411   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4412          (num (car entry))
4413          (marked (nth 3 (nth 2 entry))))
4414     (if (not (numberp (car entry)))
4415         (gnus-message 1 "Can't catch up; non-active group")
4416       ;; Do the updating only if the newsgroup isn't killed.
4417       (if (not entry)
4418           ()
4419         (gnus-update-read-articles 
4420          group (and (not all) (append (cdr (assq 'tick marked))
4421                                       (cdr (assq 'dormant marked))))
4422          nil (and (not all) (cdr (assq 'tick marked))))
4423         (and all 
4424              (setq marked (nth 3 (nth 2 entry)))
4425              (setcar (nthcdr 3 (nth 2 entry)) 
4426                      (delq (assq 'dormant marked) 
4427                            (nth 3 (nth 2 entry)))))))
4428     num))
4429
4430 (defun gnus-group-expire-articles (&optional n)
4431   "Expire all expirable articles in the current newsgroup."
4432   (interactive "P")
4433   (let ((groups (gnus-group-process-prefix n))
4434         group)
4435     (or groups (error "No groups to expire"))
4436     (while groups
4437       (setq group (car groups)
4438             groups (cdr groups))
4439       (gnus-group-remove-mark group)
4440       (if (not (gnus-check-backend-function 'request-expire-articles group))
4441           ()
4442         (let* ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
4443                (expirable (if (memq 'total-expire (nth 5 info))
4444                               (cons nil (gnus-list-of-read-articles group))
4445                             (assq 'expire (nth 3 info)))))
4446           (and expirable 
4447                (setcdr expirable
4448                        (gnus-request-expire-articles 
4449                         (cdr expirable) group))))))))
4450
4451 (defun gnus-group-expire-all-groups ()
4452   "Expire all expirable articles in all newsgroups."
4453   (interactive)
4454   (save-excursion
4455     (gnus-message 5 "Expiring...")
4456     (let ((gnus-group-marked (mapcar (lambda (info) (car info))
4457                                      (cdr gnus-newsrc-alist))))
4458       (gnus-group-expire-articles nil)))
4459   (gnus-group-position-cursor)
4460   (gnus-message 5 "Expiring...done"))
4461
4462 (defun gnus-group-set-current-level (n level)
4463   "Set the level of the next N groups to LEVEL."
4464   (interactive "P\nnLevel: ")
4465   (or (and (>= level 1) (<= level gnus-level-killed))
4466       (error "Illegal level: %d" level))
4467   (let ((groups (gnus-group-process-prefix n))
4468         group)
4469     (while groups
4470       (setq group (car groups)
4471             groups (cdr groups))
4472       (gnus-group-remove-mark group)
4473       (gnus-message 6 "Changed level of %s from %d to %d" 
4474                     group (gnus-group-group-level) level)
4475       (gnus-group-change-level group level
4476                                (gnus-group-group-level))
4477       (gnus-group-update-group-line)))
4478   (gnus-group-position-cursor))
4479
4480 (defun gnus-group-unsubscribe-current-group (&optional n)
4481   "Toggle subscription of the current group.
4482 If given numerical prefix, toggle the N next groups."
4483   (interactive "P")
4484   (let ((groups (gnus-group-process-prefix n))
4485         group)
4486     (while groups
4487       (setq group (car groups)
4488             groups (cdr groups))
4489       (gnus-group-remove-mark group)
4490       (gnus-group-unsubscribe-group
4491        group (if (<= (gnus-group-group-level) gnus-level-subscribed)
4492                  gnus-level-default-unsubscribed
4493                gnus-level-default-subscribed))
4494       (gnus-group-update-group-line))
4495     (gnus-group-next-group 1)))
4496
4497 (defun gnus-group-unsubscribe-group (group &optional level)
4498   "Toggle subscribe from/to unsubscribe GROUP.
4499 New newsgroup is added to .newsrc automatically."
4500   (interactive
4501    (list (completing-read
4502           "Group: " gnus-active-hashtb nil 
4503           (memq gnus-select-method gnus-have-read-active-file))))
4504   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
4505     (cond (newsrc
4506            ;; Toggle subscription flag.
4507            (gnus-group-change-level 
4508             newsrc (if level level (if (<= (nth 1 (nth 2 newsrc)) 
4509                                            gnus-level-subscribed) 
4510                                        (1+ gnus-level-subscribed)
4511                                      gnus-level-default-subscribed)))
4512            (gnus-group-update-group group))
4513           ((and (stringp group)
4514                 (or (not (memq gnus-select-method gnus-have-read-active-file))
4515                     (gnus-gethash group gnus-active-hashtb)))
4516            ;; Add new newsgroup.
4517            (gnus-group-change-level 
4518             group 
4519             (if level level gnus-level-default-subscribed) 
4520             (or (and (member group gnus-zombie-list) 
4521                      gnus-level-zombie) 
4522                 gnus-level-killed)
4523             (and (gnus-group-group-name)
4524                  (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
4525            (gnus-group-update-group group))
4526           (t (error "No such newsgroup: %s" group)))
4527     (gnus-group-position-cursor)))
4528
4529 (defun gnus-group-transpose-groups (n)
4530   "Move the current newsgroup up N places.
4531 If given a negative prefix, move down instead. The difference between
4532 N and the number of steps taken is returned." 
4533   (interactive "p")
4534   (or (gnus-group-group-name)
4535       (error "No group on current line"))
4536   (gnus-group-kill-group 1)
4537   (prog1
4538       (forward-line (- n))
4539     (gnus-group-yank-group)
4540     (gnus-group-position-cursor)))
4541
4542 (defun gnus-group-kill-all-zombies ()
4543   "Kill all zombie newsgroups."
4544   (interactive)
4545   (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
4546   (setq gnus-zombie-list nil)
4547   (gnus-group-list-groups))
4548
4549 (defun gnus-group-kill-region (begin end)
4550   "Kill newsgroups in current region (excluding current point).
4551 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
4552   (interactive "r")
4553   (let ((lines
4554          ;; Count lines.
4555          (save-excursion
4556            (count-lines
4557             (progn
4558               (goto-char begin)
4559               (beginning-of-line)
4560               (point))
4561             (progn
4562               (goto-char end)
4563               (beginning-of-line)
4564               (point))))))
4565     (goto-char begin)
4566     (beginning-of-line)                 ;Important when LINES < 1
4567     (gnus-group-kill-group lines)))
4568
4569 (defun gnus-group-kill-group (&optional n)
4570   "The the next N groups.
4571 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
4572 However, only groups that were alive can be yanked; already killed 
4573 groups or zombie groups can't be yanked.
4574 The return value is the name of the (last) group that was killed."
4575   (interactive "P")
4576   (let ((buffer-read-only nil)
4577         (groups (gnus-group-process-prefix n))
4578         group entry level)
4579     (while groups
4580       (setq group (car groups)
4581             groups (cdr groups))
4582       (gnus-group-remove-mark group)
4583       (setq level (gnus-group-group-level))
4584       (gnus-delete-line)
4585       (if (setq entry (gnus-gethash group gnus-newsrc-hashtb))
4586           (setq gnus-list-of-killed-groups 
4587                 (cons (cons (car entry) (nth 2 entry)) 
4588                       gnus-list-of-killed-groups)))
4589       (gnus-group-change-level 
4590        (if entry entry group) gnus-level-killed (if entry nil level)))
4591     (gnus-group-position-cursor)
4592     group))
4593
4594 (defun gnus-group-yank-group (&optional arg)
4595   "Yank the last newsgroups killed with \\[gnus-group-kill-group],
4596 inserting it before the current newsgroup.  The numeric ARG specifies
4597 how many newsgroups are to be yanked.  The name of the (last)
4598 newsgroup yanked is returned."
4599   (interactive "p")
4600   (if (not arg) (setq arg 1))
4601   (let (info group prev)
4602     (while (>= (setq arg (1- arg)) 0)
4603       (if (not (setq info (car gnus-list-of-killed-groups)))
4604           (error "No more newsgroups to yank"))
4605       (setq group (nth 2 info))
4606       ;; Find which newsgroup to insert this one before - search
4607       ;; backward until something suitable is found. If there are no
4608       ;; other newsgroups in this buffer, just make this newsgroup the
4609       ;; first newsgroup.
4610       (setq prev (gnus-group-group-name))
4611       (gnus-group-change-level 
4612        info (nth 2 info) gnus-level-killed 
4613        (and prev (gnus-gethash prev gnus-newsrc-hashtb))
4614        t)
4615       (gnus-group-insert-group-line-info (nth 1 info))
4616       (setq gnus-list-of-killed-groups 
4617             (cdr gnus-list-of-killed-groups)))
4618     (forward-line -1)
4619     (gnus-group-position-cursor)
4620     group))
4621       
4622 (defun gnus-group-list-all-groups (&optional arg)
4623   "List all newsgroups with level ARG or lower.
4624 Default is gnus-level-unsubscribed, which lists all subscribed and most
4625 unsubscribed groups."
4626   (interactive "P")
4627   (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
4628
4629 (defun gnus-group-list-killed ()
4630   "List all killed newsgroups in the group buffer."
4631   (interactive)
4632   (if (not gnus-killed-list)
4633       (gnus-message 6 "No killed groups")
4634     (let (gnus-group-list-mode)
4635       (funcall gnus-group-prepare-function 
4636                gnus-level-killed t gnus-level-killed))
4637     (goto-char (point-min)))
4638   (gnus-group-position-cursor))
4639
4640 (defun gnus-group-list-zombies ()
4641   "List all zombie newsgroups in the group buffer."
4642   (interactive)
4643   (if (not gnus-zombie-list)
4644       (gnus-message 6 "No zombie groups")
4645     (let (gnus-group-list-mode)
4646       (funcall gnus-group-prepare-function
4647                gnus-level-zombie t gnus-level-zombie))
4648     (goto-char (point-min)))
4649   (gnus-group-position-cursor))
4650
4651 (defun gnus-group-get-new-news (&optional arg)
4652   "Get newly arrived articles.
4653 If ARG is non-nil, it should be a number between one and nine to
4654 specify which levels you are interested in re-scanning."
4655   (interactive "P")
4656   (run-hooks 'gnus-get-new-news-hook)
4657   (setq arg (gnus-group-default-level arg t))
4658   (if (and gnus-read-active-file (not arg))
4659       (progn
4660         (gnus-read-active-file)
4661         (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed))))
4662     (let ((gnus-read-active-file (not arg))
4663           (gnus-have-read-active-file 
4664            (and (not arg) gnus-have-read-active-file)))
4665       (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed)))))
4666   (gnus-group-list-groups))
4667
4668 (defun gnus-group-get-new-news-this-group (&optional n)
4669   "Check for newly arrived news in the current group (and the N-1 next groups).
4670 The difference between N and the number of newsgroup checked is returned.
4671 If N is negative, this group and the N-1 previous groups will be checked."
4672   (interactive "P")
4673   (let* ((groups (gnus-group-process-prefix n))
4674          (ret (if (numberp n) (- n (length groups)) 0))
4675          group)
4676     (while groups
4677       (setq group (car groups)
4678             groups (cdr groups))
4679       (gnus-group-remove-mark group)
4680       (or (gnus-get-new-news-in-group group)
4681           (progn 
4682             (ding) 
4683             (message "%s error: %s" group (gnus-status-message group))
4684             (sit-for 2))))
4685     (gnus-group-next-unread-group 1 t)
4686     (gnus-summary-position-cursor)
4687     ret))
4688
4689 (defun gnus-get-new-news-in-group (group)
4690   (and group 
4691        (gnus-activate-group group)
4692        (progn
4693          (gnus-get-unread-articles-in-group 
4694           (nth 2 (gnus-gethash group gnus-newsrc-hashtb))
4695           (gnus-gethash group gnus-active-hashtb))
4696          (gnus-group-update-group-line)
4697          t)))
4698
4699 (defun gnus-group-fetch-faq (group)
4700   "Fetch the FAQ for the current group."
4701   (interactive (list (gnus-group-real-name (gnus-group-group-name))))
4702   (or group (error "No group name given"))
4703   (let ((file (concat gnus-group-faq-directory (gnus-group-real-name group))))
4704     (if (not (file-exists-p file))
4705         (error "No such file: %s" file)
4706       (find-file file))))
4707   
4708 (defun gnus-group-describe-group (force &optional group)
4709   "Display a description of the current newsgroup."
4710   (interactive (list current-prefix-arg (gnus-group-group-name)))
4711   (and force (setq gnus-description-hashtb nil))
4712   (let ((method (gnus-find-method-for-group group))
4713         desc)
4714     (or group (error "No group name given"))
4715     (and (or (and gnus-description-hashtb
4716                   ;; We check whether this group's method has been
4717                   ;; queried for a description file.  
4718                   (gnus-gethash 
4719                    (gnus-group-prefixed-name "" method) 
4720                    gnus-description-hashtb))
4721              (setq desc (gnus-group-get-description group))
4722              (gnus-read-descriptions-file method))
4723          (message
4724           (or desc (gnus-gethash group gnus-description-hashtb)
4725               "No description available")))))
4726
4727 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4728 (defun gnus-group-describe-all-groups (&optional force)
4729   "Pop up a buffer with descriptions of all newsgroups."
4730   (interactive "P")
4731   (and force (setq gnus-description-hashtb nil))
4732   (if (not (or gnus-description-hashtb
4733                (gnus-read-all-descriptions-files)))
4734       (error "Couldn't request descriptions file"))
4735   (let ((buffer-read-only nil)
4736         b)
4737     (erase-buffer)
4738     (mapatoms
4739      (lambda (group)
4740        (setq b (point))
4741        (insert (format "      *: %-20s %s\n" (symbol-name group)
4742                        (symbol-value group)))
4743        (add-text-properties 
4744         b (1+ b) (list 'gnus-group group
4745                        'gnus-unread t 'gnus-marked nil
4746                        'gnus-level (1+ gnus-level-subscribed))))
4747      gnus-description-hashtb)
4748     (goto-char (point-min))
4749     (gnus-group-position-cursor)))
4750
4751 ;; Suggested by by Daniel Quinlan <quinlan@best.com>.
4752 (defun gnus-group-apropos (regexp &optional search-description)
4753   "List all newsgroups that have names that match a regexp."
4754   (interactive "sGnus apropos (regexp): ")
4755   (let ((prev "")
4756         (obuf (current-buffer))
4757         groups des)
4758     ;; Go through all newsgroups that are known to Gnus.
4759     (mapatoms 
4760      (lambda (group)
4761        (and (symbol-name group)
4762             (string-match regexp (symbol-name group))
4763             (setq groups (cons (symbol-name group) groups))))
4764      gnus-active-hashtb)
4765     ;; Go through all descriptions that are known to Gnus. 
4766     (if search-description
4767         (mapatoms 
4768          (lambda (group)
4769            (and (string-match regexp (symbol-value group))
4770                 (gnus-gethash (symbol-name group) gnus-active-hashtb)
4771                 (setq groups (cons (symbol-name group) groups))))
4772          gnus-description-hashtb))
4773     (if (not groups)
4774         (gnus-message 3 "No groups matched \"%s\"." regexp)
4775       ;; Print out all the groups.
4776       (save-excursion
4777         (pop-to-buffer "*Gnus Help*")
4778         (buffer-disable-undo (current-buffer))
4779         (erase-buffer)
4780         (setq groups (sort groups 'string<))
4781         (while groups
4782           ;; Groups may be entered twice into the list of groups.
4783           (if (not (string= (car groups) prev))
4784               (progn
4785                 (insert (setq prev (car groups)) "\n")
4786                 (if (and gnus-description-hashtb
4787                          (setq des (gnus-gethash (car groups) 
4788                                                  gnus-description-hashtb)))
4789                     (insert "  " des "\n"))))
4790           (setq groups (cdr groups)))
4791         (goto-char (point-min))))
4792     (pop-to-buffer obuf)))
4793
4794 (defun gnus-group-description-apropos (regexp)
4795   "List all newsgroups that have names or descriptions that match a regexp."
4796   (interactive "sGnus description apropos (regexp): ")
4797   (if (not (or gnus-description-hashtb
4798                (gnus-read-all-descriptions-files)))
4799       (error "Couldn't request descriptions file"))
4800   (gnus-group-apropos regexp t))
4801
4802 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
4803 (defun gnus-group-list-matching (level regexp &optional all lowest) 
4804   "List all groups with unread articles that match REGEXP.
4805 If the prefix LEVEL is non-nil, it should be a number that says which
4806 level to cut off listing groups. 
4807 If ALL, also list groups with no unread articles.
4808 If LOWEST, don't list groups with level lower than LOWEST."
4809   (interactive "P\nsList newsgroups matching: ")
4810   (gnus-group-prepare-flat (or level gnus-level-subscribed)
4811                            all (or lowest 1) regexp)
4812   (goto-char (point-min))
4813   (gnus-group-position-cursor))
4814
4815 (defun gnus-group-list-all-matching (level regexp &optional lowest) 
4816   "List all groups that match REGEXP.
4817 If the prefix LEVEL is non-nil, it should be a number that says which
4818 level to cut off listing groups. 
4819 If LOWEST, don't list groups with level lower than LOWEST."
4820   (interactive "P\nsList newsgroups matching: ")
4821   (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
4822
4823 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
4824 (defun gnus-group-save-newsrc ()
4825   "Save the Gnus startup files."
4826   (interactive)
4827   (gnus-save-newsrc-file))
4828
4829 (defun gnus-group-restart (&optional arg)
4830   "Force Gnus to read the .newsrc file."
4831   (interactive "P")
4832   (gnus-save-newsrc-file)
4833   (gnus-setup-news 'force)
4834   (gnus-group-list-groups arg))
4835
4836 (defun gnus-group-read-init-file ()
4837   "Read the Gnus elisp init file."
4838   (interactive)
4839   (gnus-read-init-file))
4840
4841 (defun gnus-group-check-bogus-groups (&optional silent)
4842   "Check bogus newsgroups.
4843 If given a prefix, don't ask for confirmation before removing a bogus
4844 group."
4845   (interactive "P")
4846   (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
4847   (gnus-group-list-groups))
4848
4849 (defun gnus-group-edit-global-kill (&optional article group)
4850   "Edit the global kill file.
4851 If GROUP, edit that local kill file instead."
4852   (interactive "P")
4853   (setq gnus-current-kill-article article)
4854   (gnus-kill-file-edit-file group)
4855   (gnus-message 6
4856    (substitute-command-keys
4857     "Editing a global kill file (Type \\[gnus-kill-file-exit] to exit)")))
4858
4859 (defun gnus-group-edit-local-kill (article group)
4860   "Edit a local kill file."
4861   (interactive (list nil (gnus-group-group-name)))
4862   (gnus-group-edit-global-kill article group))
4863
4864 (defun gnus-group-force-update ()
4865   "Update `.newsrc' file."
4866   (interactive)
4867   (gnus-save-newsrc-file))
4868
4869 (defun gnus-group-suspend ()
4870   "Suspend the current Gnus session.
4871 In fact, cleanup buffers except for group mode buffer.
4872 The hook gnus-suspend-gnus-hook is called before actually suspending."
4873   (interactive)
4874   (run-hooks 'gnus-suspend-gnus-hook)
4875   ;; Kill Gnus buffers except for group mode buffer.
4876   (let ((group-buf (get-buffer gnus-group-buffer)))
4877     ;; Do this on a separate list in case the user does a ^G before we finish
4878     (let ((gnus-buffer-list
4879            (delq group-buf (delq gnus-dribble-buffer
4880                                  (append gnus-buffer-list nil)))))
4881       (while gnus-buffer-list
4882         (gnus-kill-buffer (car gnus-buffer-list))
4883         (setq gnus-buffer-list (cdr gnus-buffer-list))))
4884     (if group-buf
4885         (progn
4886           (setq gnus-buffer-list (list group-buf))
4887           (bury-buffer group-buf)
4888           (delete-windows-on group-buf t)))))
4889
4890 (defun gnus-group-clear-dribble ()
4891   "Clear all information from the dribble buffer."
4892   (interactive)
4893   (gnus-dribble-clear))
4894
4895 (defun gnus-group-exit ()
4896   "Quit reading news after updating .newsrc.eld and .newsrc.
4897 The hook `gnus-exit-gnus-hook' is called before actually exiting."
4898   (interactive)
4899   (if (or noninteractive                ;For gnus-batch-kill
4900           (zerop (buffer-size))         ;No news is good news.
4901           (not (gnus-server-opened gnus-select-method)) ;NNTP connection closed
4902           (not gnus-interactive-exit)   ;Without confirmation
4903           gnus-expert-user
4904           (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
4905       (progn
4906         (run-hooks 'gnus-exit-gnus-hook)
4907         ;; Offer to save data from non-quitted summary buffers.
4908         (gnus-offer-save-summaries)
4909         ;; Save the newsrc file(s).
4910         (gnus-save-newsrc-file)
4911         ;; Kill-em-all.
4912         (gnus-close-backends)
4913         ;; Reset everything.
4914         (gnus-clear-system))))
4915
4916 (defun gnus-close-backends ()
4917   ;; Send a close request to all backends that support such a request. 
4918   (let ((methods gnus-valid-select-methods)
4919         func)
4920     (while methods
4921       (if (fboundp (setq func (intern (concat (car (car methods))
4922                                               "-request-close"))))
4923           (funcall func))
4924       (setq methods (cdr methods)))))
4925
4926 (defun gnus-group-quit ()
4927   "Quit reading news without updating .newsrc.eld or .newsrc.
4928 The hook `gnus-exit-gnus-hook' is called before actually exiting."
4929   (interactive)
4930   (if (or noninteractive                ;For gnus-batch-kill
4931           (zerop (buffer-size))
4932           (not (gnus-server-opened gnus-select-method))
4933           gnus-expert-user
4934           (not gnus-current-startup-file)
4935           (gnus-yes-or-no-p
4936            (format "Quit reading news without saving %s? "
4937                    (file-name-nondirectory gnus-current-startup-file))))
4938       (progn
4939         (run-hooks 'gnus-exit-gnus-hook)
4940         (if gnus-use-full-window
4941             (delete-other-windows)
4942           (gnus-remove-some-windows))
4943         (gnus-dribble-save)
4944         (gnus-close-backends)
4945         (gnus-clear-system))))
4946
4947 (defun gnus-offer-save-summaries ()
4948   (save-excursion
4949     (let ((buflist (buffer-list)) 
4950           buffers bufname)
4951       (while buflist
4952         (and (setq bufname (buffer-name (car buflist)))
4953              (string-match "Summary" bufname)
4954              (save-excursion
4955                (set-buffer bufname)
4956                ;; We check that this is, indeed, a summary buffer.
4957                (eq major-mode 'gnus-summary-mode))
4958              (setq buffers (cons bufname buffers)))
4959         (setq buflist (cdr buflist)))
4960       (and buffers
4961            (map-y-or-n-p 
4962             "Update summary buffer %s? "
4963             (lambda (buf)
4964               (set-buffer buf)
4965               (gnus-summary-exit))
4966             buffers)))))
4967
4968 (defun gnus-group-describe-briefly ()
4969   "Give a one line description of the group mode commands."
4970   (interactive)
4971   (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")))
4972
4973 (defun gnus-group-browse-foreign-server (method)
4974   "Browse a foreign news server.
4975 If called interactively, this function will ask for a select method
4976  (nntp, nnspool, etc.) and a server address (eg. nntp.some.where). 
4977 If not, METHOD should be a list where the first element is the method
4978 and the second element is the address."
4979   (interactive
4980    (list (let ((how (completing-read 
4981                      "Which backend: "
4982                      (append gnus-valid-select-methods gnus-server-alist)
4983                      nil t "nntp")))
4984            ;; We either got a backend name or a virtual server name.
4985            ;; If the first, we also need an address.
4986            (if (assoc how gnus-valid-select-methods)
4987                (list (intern how)
4988                      ;; Suggested by mapjph@bath.ac.uk.
4989                      (completing-read 
4990                       "Address: " 
4991                       (mapcar (lambda (server) (list server))
4992                               gnus-secondary-servers)))
4993              ;; We got a server name, so we find the method.
4994              (gnus-server-to-method how)))))
4995   (gnus-browse-foreign-server method))
4996
4997 \f
4998 ;;;
4999 ;;; Browse Server Mode
5000 ;;;
5001
5002 (defvar gnus-browse-mode-hook nil)
5003 (defvar gnus-browse-mode-map nil)
5004 (put 'gnus-browse-mode 'mode-class 'special)
5005
5006 (if gnus-browse-mode-map
5007     nil
5008   (setq gnus-browse-mode-map (make-keymap))
5009   (suppress-keymap gnus-browse-mode-map)
5010   (define-key gnus-browse-mode-map " " 'gnus-browse-read-group)
5011   (define-key gnus-browse-mode-map "=" 'gnus-browse-select-group)
5012   (define-key gnus-browse-mode-map "n" 'gnus-browse-next-group)
5013   (define-key gnus-browse-mode-map "p" 'gnus-browse-prev-group)
5014   (define-key gnus-browse-mode-map "\177" 'gnus-browse-prev-group)
5015   (define-key gnus-browse-mode-map "N" 'gnus-browse-next-group)
5016   (define-key gnus-browse-mode-map "P" 'gnus-browse-prev-group)
5017   (define-key gnus-browse-mode-map "\M-n" 'gnus-browse-next-group)
5018   (define-key gnus-browse-mode-map "\M-p" 'gnus-browse-prev-group)
5019   (define-key gnus-browse-mode-map "\r" 'gnus-browse-select-group)
5020   (define-key gnus-browse-mode-map "u" 'gnus-browse-unsubscribe-current-group)
5021   (define-key gnus-browse-mode-map "l" 'gnus-browse-exit)
5022   (define-key gnus-browse-mode-map "L" 'gnus-browse-exit)
5023   (define-key gnus-browse-mode-map "q" 'gnus-browse-exit)
5024   (define-key gnus-browse-mode-map "Q" 'gnus-browse-exit)
5025   (define-key gnus-browse-mode-map "\C-c\C-c" 'gnus-browse-exit)
5026   (define-key gnus-browse-mode-map "?" 'gnus-browse-describe-briefly)
5027   (define-key gnus-browse-mode-map "\C-c\C-i" 'gnus-info-find-node)
5028   )
5029
5030 (defvar gnus-browse-current-method nil)
5031 (defvar gnus-browse-return-buffer nil)
5032
5033 (defvar gnus-browse-buffer "*Gnus Browse Server*")
5034
5035 (defun gnus-browse-foreign-server (method &optional return-buffer)
5036   (setq gnus-browse-current-method method)
5037   (setq gnus-browse-return-buffer return-buffer)
5038   (let ((gnus-select-method method)
5039         groups group)
5040     (gnus-message 5 "Connecting to %s..." (nth 1 method))
5041     (or (gnus-check-server method)
5042         (error "Unable to contact server: %s" (gnus-status-message method)))
5043     (or (gnus-request-list method)
5044         (error "Couldn't request list: %s" (gnus-status-message method)))
5045     (get-buffer-create gnus-browse-buffer)
5046     (gnus-add-current-to-buffer-list)
5047     (and gnus-carpal (gnus-carpal-setup-buffer 'browse))
5048     (gnus-configure-windows 'browse)
5049     (buffer-disable-undo (current-buffer))
5050     (let ((buffer-read-only nil))
5051       (erase-buffer))
5052     (gnus-browse-mode)
5053     (setq mode-line-buffer-identification
5054           (format
5055            "Gnus  Browse Server {%s:%s}" (car method) (car (cdr method))))
5056     (save-excursion
5057       (set-buffer nntp-server-buffer)
5058       (let ((cur (current-buffer)))
5059         (goto-char (point-min))
5060         (or (string= gnus-ignored-newsgroups "")
5061             (delete-matching-lines gnus-ignored-newsgroups))
5062         (while (re-search-forward 
5063                 "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
5064           (goto-char (match-end 1))
5065           (setq groups (cons (cons (buffer-substring (match-beginning 1)
5066                                                      (match-end 1))
5067                                    (max 0 (- (1+ (read cur)) (read cur))))
5068                              groups)))))
5069     (setq groups (sort groups 
5070                        (lambda (l1 l2)
5071                          (string< (car l1) (car l2)))))
5072     (let ((buffer-read-only nil))
5073       (while groups
5074         (setq group (car groups))
5075         (insert 
5076          (format "K%7d: %s\n" (cdr group) (car group)))
5077         (setq groups (cdr groups))))
5078     (switch-to-buffer (current-buffer))
5079     (goto-char (point-min))
5080     (gnus-group-position-cursor)))
5081
5082 (defun gnus-browse-mode ()
5083   "Major mode for browsing a foreign server.
5084
5085 All normal editing commands are switched off.
5086
5087 \\<gnus-browse-mode-map>
5088 The only things you can do in this buffer is
5089
5090 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
5091 The group will be inserted into the group buffer upon exit from this
5092 buffer.  
5093
5094 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
5095
5096 3) `\\[gnus-browse-exit]' to return to the group buffer."
5097   (interactive)
5098   (kill-all-local-variables)
5099   (if gnus-visual (gnus-browse-make-menu-bar))
5100   (setq mode-line-modified "-- ")
5101   (make-local-variable 'mode-line-format)
5102   (setq mode-line-format (copy-sequence mode-line-format))
5103   (and (equal (nth 3 mode-line-format) "   ")
5104        (setcar (nthcdr 3 mode-line-format) ""))
5105   (setq major-mode 'gnus-browse-mode)
5106   (setq mode-name "Browse Server")
5107   (setq mode-line-process nil)
5108   (use-local-map gnus-browse-mode-map)
5109   (buffer-disable-undo (current-buffer))
5110   (setq truncate-lines t)
5111   (setq buffer-read-only t)
5112   (run-hooks 'gnus-browse-mode-hook))
5113
5114 (defun gnus-browse-read-group (&optional no-article)
5115   "Enter the group at the current line."
5116   (interactive)
5117   (let ((group (gnus-browse-group-name)))
5118     (or (gnus-group-read-ephemeral-group 
5119          group gnus-browse-current-method nil
5120          (cons (current-buffer) 'browse))
5121         (error "Couldn't enter %s" group))))
5122
5123 (defun gnus-browse-select-group ()
5124   "Select the current group."
5125   (interactive)
5126   (gnus-browse-read-group 'no))
5127
5128 (defun gnus-browse-next-group (n)
5129   "Go to the next group."
5130   (interactive "p")
5131   (prog1
5132       (forward-line n)
5133     (gnus-group-position-cursor)))
5134
5135 (defun gnus-browse-prev-group (n)
5136   "Go to the next group."
5137   (interactive "p")
5138   (gnus-browse-next-group (- n)))
5139
5140 (defun gnus-browse-unsubscribe-current-group (arg)
5141   "(Un)subscribe to the next ARG groups."
5142   (interactive "p")
5143   (and (eobp)
5144        (error "No group at current line."))
5145   (let ((ward (if (< arg 0) -1 1))
5146         (arg (abs arg)))
5147     (while (and (> arg 0)
5148                 (not (eobp))
5149                 (gnus-browse-unsubscribe-group)
5150                 (zerop (gnus-browse-next-group ward)))
5151       (setq arg (1- arg)))
5152     (gnus-group-position-cursor)
5153     (if (/= 0 arg) (gnus-message 7 "No more newsgroups"))
5154     arg))
5155
5156 (defun gnus-browse-group-name ()
5157   (save-excursion
5158     (beginning-of-line)
5159     (if (not (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t))
5160         ()
5161       (gnus-group-prefixed-name 
5162        (buffer-substring (match-beginning 1) (match-end 1))
5163        gnus-browse-current-method))))
5164   
5165 (defun gnus-browse-unsubscribe-group ()
5166   (let ((sub nil)
5167         (buffer-read-only nil)
5168         group)
5169     (save-excursion
5170       (beginning-of-line)
5171       (if (= (following-char) ?K) (setq sub t))
5172       (setq group (gnus-browse-group-name))
5173       (beginning-of-line)
5174       (delete-char 1)
5175       (if sub
5176           (progn
5177             (gnus-group-change-level 
5178              (list t group gnus-level-default-subscribed
5179                    nil nil gnus-browse-current-method) 
5180              gnus-level-default-subscribed gnus-level-killed
5181              (and (car (nth 1 gnus-newsrc-alist))
5182                   (gnus-gethash (car (nth 1 gnus-newsrc-alist))
5183                                 gnus-newsrc-hashtb))
5184              t)
5185             (insert ? ))
5186         (gnus-group-change-level 
5187          group gnus-level-killed gnus-level-default-subscribed)
5188         (insert ?K)))
5189     t))
5190
5191 (defun gnus-browse-exit ()
5192   "Quit browsing and return to the group buffer."
5193   (interactive)
5194   (if (eq major-mode 'gnus-browse-mode)
5195       (kill-buffer (current-buffer)))
5196   (if gnus-browse-return-buffer
5197       (gnus-configure-windows 'server 'force)
5198     (gnus-configure-windows 'group 'force)
5199     (gnus-group-list-groups nil)))
5200
5201 (defun gnus-browse-describe-briefly ()
5202   "Give a one line description of the group mode commands."
5203   (interactive)
5204   (gnus-message 6
5205    (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")))
5206       
5207 \f
5208 ;;;
5209 ;;; Gnus summary mode
5210 ;;;
5211
5212 (defvar gnus-summary-mode-map nil)
5213 (defvar gnus-summary-mark-map nil)
5214 (defvar gnus-summary-mscore-map nil)
5215 (defvar gnus-summary-article-map nil)
5216 (defvar gnus-summary-thread-map nil)
5217 (defvar gnus-summary-goto-map nil)
5218 (defvar gnus-summary-exit-map nil)
5219 (defvar gnus-summary-interest-map nil)
5220 (defvar gnus-summary-sort-map nil)
5221 (defvar gnus-summary-backend-map nil)
5222 (defvar gnus-summary-save-map nil)
5223 (defvar gnus-summary-wash-map nil)
5224 (defvar gnus-summary-wash-hide-map nil)
5225 (defvar gnus-summary-wash-highlight-map nil)
5226 (defvar gnus-summary-wash-time-map nil)
5227 (defvar gnus-summary-help-map nil)
5228
5229 (put 'gnus-summary-mode 'mode-class 'special)
5230
5231 (if gnus-summary-mode-map
5232     nil
5233   (setq gnus-summary-mode-map (make-keymap))
5234   (suppress-keymap gnus-summary-mode-map)
5235
5236   ;; Non-orthogonal keys
5237
5238   (define-key gnus-summary-mode-map " " 'gnus-summary-next-page)
5239   (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page)
5240   (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up)
5241   (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article)
5242   (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article)
5243   (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article)
5244   (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article)
5245   (define-key gnus-summary-mode-map "\M-\C-n" 'gnus-summary-next-same-subject)
5246   (define-key gnus-summary-mode-map "\M-\C-p" 'gnus-summary-prev-same-subject)
5247   (define-key gnus-summary-mode-map "\M-n" 'gnus-summary-next-unread-subject)
5248   (define-key gnus-summary-mode-map "\M-p" 'gnus-summary-prev-unread-subject)
5249   (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article)
5250   (define-key gnus-summary-mode-map "," 'gnus-summary-best-unread-article)
5251   (define-key gnus-summary-mode-map "\M-s" 'gnus-summary-search-article-forward)
5252   (define-key gnus-summary-mode-map "\M-r" 'gnus-summary-search-article-backward)
5253   (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article)
5254   (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article)
5255   (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject)
5256   (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article)
5257   (define-key gnus-summary-mode-map "\M-^" 'gnus-summary-refer-article)
5258   (define-key gnus-summary-mode-map "u" 'gnus-summary-tick-article-forward)
5259   (define-key gnus-summary-mode-map "!" 'gnus-summary-tick-article-forward)
5260   (define-key gnus-summary-mode-map "U" 'gnus-summary-tick-article-backward)
5261   (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward)
5262   (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward)
5263   (define-key gnus-summary-mode-map "E" 'gnus-summary-mark-as-expirable)
5264   (define-key gnus-summary-mode-map "\M-u" 'gnus-summary-clear-mark-forward)
5265   (define-key gnus-summary-mode-map "\M-U" 'gnus-summary-clear-mark-backward)
5266   (define-key gnus-summary-mode-map "k" 'gnus-summary-kill-same-subject-and-select)
5267   (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject)
5268   (define-key gnus-summary-mode-map "\M-\C-k" 'gnus-summary-kill-thread)
5269   (define-key gnus-summary-mode-map "\M-\C-l" 'gnus-summary-lower-thread)
5270   (define-key gnus-summary-mode-map "e" 'gnus-summary-edit-article)
5271   (define-key gnus-summary-mode-map "#" 'gnus-summary-mark-as-processable)
5272   (define-key gnus-summary-mode-map "\M-#" 'gnus-summary-unmark-as-processable)
5273   (define-key gnus-summary-mode-map "\M-\C-t" 'gnus-summary-toggle-threads)
5274   (define-key gnus-summary-mode-map "\M-\C-s" 'gnus-summary-show-thread)
5275   (define-key gnus-summary-mode-map "\M-\C-h" 'gnus-summary-hide-thread)
5276   (define-key gnus-summary-mode-map "\M-\C-f" 'gnus-summary-next-thread)
5277   (define-key gnus-summary-mode-map "\M-\C-b" 'gnus-summary-prev-thread)
5278   (define-key gnus-summary-mode-map "\M-\C-u" 'gnus-summary-up-thread)
5279   (define-key gnus-summary-mode-map "\M-\C-d" 'gnus-summary-down-thread)
5280   (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command)
5281   (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit)
5282   (define-key gnus-summary-mode-map "\C-w" 'gnus-summary-mark-region-as-read)
5283   (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation)
5284   (define-key gnus-summary-mode-map "?" 'gnus-summary-mark-as-dormant)
5285   (define-key gnus-summary-mode-map "\C-c\M-\C-s" 'gnus-summary-show-all-expunged)
5286   (define-key gnus-summary-mode-map "\C-c\C-s\C-n" 'gnus-summary-sort-by-number)
5287   (define-key gnus-summary-mode-map "\C-c\C-s\C-a" 'gnus-summary-sort-by-author)
5288   (define-key gnus-summary-mode-map "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject)
5289   (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date)
5290   (define-key gnus-summary-mode-map "\C-c\C-s\C-i" 'gnus-summary-sort-by-score)
5291   (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window)
5292   (define-key gnus-summary-mode-map "\C-x\C-s" 'gnus-summary-reselect-current-group)
5293   (define-key gnus-summary-mode-map "\M-g" 'gnus-summary-rescan-group)
5294   (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking)
5295   (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message)
5296   (define-key gnus-summary-mode-map "\M-t" 'gnus-summary-toggle-mime)
5297   (define-key gnus-summary-mode-map "f" 'gnus-summary-followup)
5298   (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original)
5299   (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article)
5300   (define-key gnus-summary-mode-map "r" 'gnus-summary-reply)
5301   (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original)
5302   (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)
5303   (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article)
5304   (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-article-mail)
5305   (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output)
5306   (define-key gnus-summary-mode-map "\M-k" 'gnus-summary-edit-local-kill)
5307   (define-key gnus-summary-mode-map "\M-K" 'gnus-summary-edit-global-kill)
5308   (define-key gnus-summary-mode-map "V" 'gnus-version)
5309   (define-key gnus-summary-mode-map "\C-c\C-d" 'gnus-summary-describe-group)
5310   (define-key gnus-summary-mode-map "q" 'gnus-summary-exit)
5311   (define-key gnus-summary-mode-map "Q" 'gnus-summary-exit-no-update)
5312   (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node)
5313   (define-key gnus-summary-mode-map gnus-mouse-2 'gnus-mouse-pick-article)
5314   (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)
5315   (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news)
5316   (define-key gnus-summary-mode-map "x" 'gnus-summary-remove-lines-marked-as-read)
5317 ; (define-key gnus-summary-mode-map "X" 'gnus-summary-remove-lines-marked-with)
5318   (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article)
5319   (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header)
5320   (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article)
5321 ;  (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly)
5322   (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article)
5323   (define-key gnus-summary-mode-map "\C-c\C-v\C-v" 'gnus-uu-decode-uu-view)
5324   (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-enter-digest-group)
5325   (define-key gnus-summary-mode-map "v" 'gnus-summary-verbose-headers)
5326   (define-key gnus-summary-mode-map "\C-c\C-b" 'gnus-bug)
5327
5328
5329   ;; Sort of orthogonal keymap
5330   (define-prefix-command 'gnus-summary-mark-map)
5331   (define-key gnus-summary-mode-map "M" 'gnus-summary-mark-map)
5332   (define-key gnus-summary-mark-map "t" 'gnus-summary-tick-article-forward)
5333   (define-key gnus-summary-mark-map "!" 'gnus-summary-tick-article-forward)
5334   (define-key gnus-summary-mark-map "d" 'gnus-summary-mark-as-read-forward)
5335   (define-key gnus-summary-mark-map "r" 'gnus-summary-mark-as-read-forward)
5336   (define-key gnus-summary-mark-map "c" 'gnus-summary-clear-mark-forward)
5337   (define-key gnus-summary-mark-map " " 'gnus-summary-clear-mark-forward)
5338   (define-key gnus-summary-mark-map "e" 'gnus-summary-mark-as-expirable)
5339   (define-key gnus-summary-mark-map "x" 'gnus-summary-mark-as-expirable)
5340   (define-key gnus-summary-mark-map "?" 'gnus-summary-mark-as-dormant)
5341   (define-key gnus-summary-mark-map "b" 'gnus-summary-set-bookmark)
5342   (define-key gnus-summary-mark-map "B" 'gnus-summary-remove-bookmark)
5343   (define-key gnus-summary-mark-map "#" 'gnus-summary-mark-as-processable)
5344   (define-key gnus-summary-mark-map "\M-#" 'gnus-summary-unmark-as-processable)
5345   (define-key gnus-summary-mark-map "\M-r" 'gnus-summary-remove-lines-marked-as-read)
5346   (define-key gnus-summary-mark-map "\M-\C-r" 'gnus-summary-remove-lines-marked-with)
5347   (define-key gnus-summary-mark-map "D" 'gnus-summary-show-all-dormant)
5348   (define-key gnus-summary-mark-map "\M-D" 'gnus-summary-hide-all-dormant)
5349   (define-key gnus-summary-mark-map "S" 'gnus-summary-show-all-expunged)
5350   (define-key gnus-summary-mark-map "C" 'gnus-summary-catchup)
5351   (define-key gnus-summary-mark-map "H" 'gnus-summary-catchup-to-here)
5352   (define-key gnus-summary-mark-map "\C-c" 'gnus-summary-catchup-all)
5353   (define-key gnus-summary-mark-map "k" 'gnus-summary-kill-same-subject-and-select)
5354   (define-key gnus-summary-mark-map "K" 'gnus-summary-kill-same-subject)
5355
5356   (define-prefix-command 'gnus-summary-mscore-map)
5357   (define-key gnus-summary-mark-map "V" 'gnus-summary-mscore-map)
5358   (define-key gnus-summary-mscore-map "c" 'gnus-summary-clear-above)
5359   (define-key gnus-summary-mscore-map "u" 'gnus-summary-tick-above)
5360   (define-key gnus-summary-mscore-map "m" 'gnus-summary-mark-above)
5361   (define-key gnus-summary-mscore-map "k" 'gnus-summary-kill-below)
5362
5363   (define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map)
5364   
5365   (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
5366   
5367   (define-prefix-command 'gnus-summary-goto-map)
5368   (define-key gnus-summary-mode-map "G" 'gnus-summary-goto-map)
5369   (define-key gnus-summary-goto-map "n" 'gnus-summary-next-unread-article)
5370   (define-key gnus-summary-goto-map "p" 'gnus-summary-prev-unread-article)
5371   (define-key gnus-summary-goto-map "N" 'gnus-summary-next-article)
5372   (define-key gnus-summary-goto-map "P" 'gnus-summary-prev-article)
5373   (define-key gnus-summary-goto-map "\C-n" 'gnus-summary-next-same-subject)
5374   (define-key gnus-summary-goto-map "\C-p" 'gnus-summary-prev-same-subject)
5375   (define-key gnus-summary-goto-map "\M-n" 'gnus-summary-next-unread-subject)
5376   (define-key gnus-summary-goto-map "\M-p" 'gnus-summary-prev-unread-subject)
5377   (define-key gnus-summary-goto-map "f" 'gnus-summary-first-unread-article)
5378   (define-key gnus-summary-goto-map "b" 'gnus-summary-best-unread-article)
5379   (define-key gnus-summary-goto-map "g" 'gnus-summary-goto-subject)
5380   (define-key gnus-summary-goto-map "l" 'gnus-summary-goto-last-article)
5381   (define-key gnus-summary-goto-map "p" 'gnus-summary-pop-article)
5382
5383
5384   (define-prefix-command 'gnus-summary-thread-map)
5385   (define-key gnus-summary-mode-map "T" 'gnus-summary-thread-map)
5386   (define-key gnus-summary-thread-map "k" 'gnus-summary-kill-thread)
5387   (define-key gnus-summary-thread-map "l" 'gnus-summary-lower-thread)
5388   (define-key gnus-summary-thread-map "i" 'gnus-summary-raise-thread)
5389   (define-key gnus-summary-thread-map "T" 'gnus-summary-toggle-threads)
5390   (define-key gnus-summary-thread-map "s" 'gnus-summary-show-thread)
5391   (define-key gnus-summary-thread-map "S" 'gnus-summary-show-all-threads)
5392   (define-key gnus-summary-thread-map "h" 'gnus-summary-hide-thread)
5393   (define-key gnus-summary-thread-map "H" 'gnus-summary-hide-all-threads)
5394   (define-key gnus-summary-thread-map "n" 'gnus-summary-next-thread)
5395   (define-key gnus-summary-thread-map "p" 'gnus-summary-prev-thread)
5396   (define-key gnus-summary-thread-map "u" 'gnus-summary-up-thread)
5397   (define-key gnus-summary-thread-map "d" 'gnus-summary-down-thread)
5398   (define-key gnus-summary-thread-map "#" 'gnus-uu-mark-thread)
5399
5400   
5401   (define-prefix-command 'gnus-summary-exit-map)
5402   (define-key gnus-summary-mode-map "Z" 'gnus-summary-exit-map)
5403   (define-key gnus-summary-exit-map "c" 'gnus-summary-catchup-and-exit)
5404   (define-key gnus-summary-exit-map "C" 'gnus-summary-catchup-all-and-exit)
5405   (define-key gnus-summary-exit-map "E" 'gnus-summary-exit-no-update)
5406   (define-key gnus-summary-exit-map "Q" 'gnus-summary-exit)
5407   (define-key gnus-summary-exit-map "Z" 'gnus-summary-exit)
5408   (define-key gnus-summary-exit-map "n" 'gnus-summary-catchup-and-goto-next-group)
5409   (define-key gnus-summary-exit-map "R" 'gnus-summary-reselect-current-group)
5410   (define-key gnus-summary-exit-map "G" 'gnus-summary-rescan-group)
5411   (define-key gnus-summary-exit-map "N" 'gnus-summary-next-group)
5412   (define-key gnus-summary-exit-map "P" 'gnus-summary-prev-group)
5413
5414
5415   (define-prefix-command 'gnus-summary-article-map)
5416   (define-key gnus-summary-mode-map "A" 'gnus-summary-article-map)
5417   (define-key gnus-summary-article-map " " 'gnus-summary-next-page)
5418   (define-key gnus-summary-article-map "n" 'gnus-summary-next-page)
5419   (define-key gnus-summary-article-map "\177" 'gnus-summary-prev-page)
5420   (define-key gnus-summary-article-map "p" 'gnus-summary-prev-page)
5421   (define-key gnus-summary-article-map "\r" 'gnus-summary-scroll-up)
5422   (define-key gnus-summary-article-map "<" 'gnus-summary-beginning-of-article)
5423   (define-key gnus-summary-article-map ">" 'gnus-summary-end-of-article)
5424   (define-key gnus-summary-article-map "b" 'gnus-summary-beginning-of-article)
5425   (define-key gnus-summary-article-map "e" 'gnus-summary-end-of-article)
5426   (define-key gnus-summary-article-map "^" 'gnus-summary-refer-parent-article)
5427   (define-key gnus-summary-article-map "r" 'gnus-summary-refer-parent-article)
5428   (define-key gnus-summary-article-map "g" 'gnus-summary-show-article)
5429   (define-key gnus-summary-article-map "s" 'gnus-summary-isearch-article)
5430
5431
5432
5433   (define-prefix-command 'gnus-summary-wash-map)
5434   (define-key gnus-summary-mode-map "W" 'gnus-summary-wash-map)
5435
5436   (define-prefix-command 'gnus-summary-wash-hide-map)
5437   (define-key gnus-summary-wash-map "W" 'gnus-summary-wash-hide-map)
5438   (define-key gnus-summary-wash-hide-map "a" 'gnus-article-hide)
5439   (define-key gnus-summary-wash-hide-map "h" 'gnus-article-hide-headers)
5440   (define-key gnus-summary-wash-hide-map "s" 'gnus-article-hide-signature)
5441   (define-key gnus-summary-wash-hide-map "c" 'gnus-article-hide-citation)
5442   (define-key gnus-summary-wash-hide-map "\C-c" 'gnus-article-hide-citation-maybe)
5443
5444   (define-prefix-command 'gnus-summary-wash-highlight-map)
5445   (define-key gnus-summary-wash-map "H" 'gnus-summary-wash-highlight-map)
5446   (define-key gnus-summary-wash-highlight-map "a" 'gnus-article-highlight)
5447   (define-key gnus-summary-wash-highlight-map "h" 'gnus-article-highlight-headers)
5448   (define-key gnus-summary-wash-highlight-map "c" 'gnus-article-highlight-citation)
5449   (define-key gnus-summary-wash-highlight-map "s" 'gnus-article-highlight-signature)
5450
5451   (define-prefix-command 'gnus-summary-wash-time-map)
5452   (define-key gnus-summary-wash-map "T" 'gnus-summary-wash-time-map)
5453   (define-key gnus-summary-wash-time-map "z" 'gnus-article-date-ut)
5454   (define-key gnus-summary-wash-time-map "u" 'gnus-article-date-ut)
5455   (define-key gnus-summary-wash-time-map "l" 'gnus-article-date-local)
5456   (define-key gnus-summary-wash-time-map "e" 'gnus-article-date-lapsed)
5457
5458   (define-key gnus-summary-wash-map "b" 'gnus-article-add-buttons)
5459   (define-key gnus-summary-wash-map "o" 'gnus-article-treat-overstrike)
5460   (define-key gnus-summary-wash-map "w" 'gnus-article-word-wrap)
5461   (define-key gnus-summary-wash-map "c" 'gnus-article-remove-cr)
5462   (define-key gnus-summary-wash-map "q" 'gnus-article-de-quoted-unreadable)
5463   (define-key gnus-summary-wash-map "f" 'gnus-article-display-x-face)
5464   (define-key gnus-summary-wash-map "l" 'gnus-summary-stop-page-breaking)
5465   (define-key gnus-summary-wash-map "r" 'gnus-summary-caesar-message)
5466   (define-key gnus-summary-wash-map "t" 'gnus-summary-toggle-header)
5467   (define-key gnus-summary-wash-map "m" 'gnus-summary-toggle-mime)
5468
5469
5470   (define-prefix-command 'gnus-summary-help-map)
5471   (define-key gnus-summary-mode-map "H" 'gnus-summary-help-map)
5472   (define-key gnus-summary-help-map "v" 'gnus-version)
5473   (define-key gnus-summary-help-map "f" 'gnus-summary-fetch-faq)
5474   (define-key gnus-summary-help-map "d" 'gnus-summary-describe-group)
5475   (define-key gnus-summary-help-map "h" 'gnus-summary-describe-briefly)
5476   (define-key gnus-summary-help-map "i" 'gnus-info-find-node)
5477
5478
5479   (define-prefix-command 'gnus-summary-backend-map)
5480   (define-key gnus-summary-mode-map "B" 'gnus-summary-backend-map)
5481   (define-key gnus-summary-backend-map "e" 'gnus-summary-expire-articles)
5482   (define-key gnus-summary-backend-map "\M-\C-e" 
5483     'gnus-summary-expire-articles-now)
5484   (define-key gnus-summary-backend-map "\177" 'gnus-summary-delete-article)
5485   (define-key gnus-summary-backend-map "m" 'gnus-summary-move-article)
5486   (define-key gnus-summary-backend-map "r" 'gnus-summary-respool-article)
5487   (define-key gnus-summary-backend-map "w" 'gnus-summary-edit-article)
5488   (define-key gnus-summary-backend-map "c" 'gnus-summary-copy-article)
5489   (define-key gnus-summary-backend-map "q" 'gnus-summary-fancy-query)
5490   (define-key gnus-summary-backend-map "i" 'gnus-summary-import-article)
5491
5492
5493   (define-prefix-command 'gnus-summary-save-map)
5494   (define-key gnus-summary-mode-map "O" 'gnus-summary-save-map)
5495   (define-key gnus-summary-save-map "o" 'gnus-summary-save-article)
5496   (define-key gnus-summary-save-map "m" 'gnus-summary-save-article-mail)
5497   (define-key gnus-summary-save-map "r" 'gnus-summary-save-article-rmail)
5498   (define-key gnus-summary-save-map "f" 'gnus-summary-save-article-file)
5499   (define-key gnus-summary-save-map "h" 'gnus-summary-save-article-folder)
5500   (define-key gnus-summary-save-map "v" 'gnus-summary-save-article-vm)
5501   (define-key gnus-summary-save-map "p" 'gnus-summary-pipe-output)
5502 ;  (define-key gnus-summary-save-map "s" 'gnus-soup-add-article)
5503
5504   (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
5505
5506   (define-key gnus-summary-mode-map "\M-&" 'gnus-summary-universal-argument)
5507 ;  (define-key gnus-summary-various-map "\C-s" 'gnus-summary-search-article-forward)
5508 ;  (define-key gnus-summary-various-map "\C-r" 'gnus-summary-search-article-backward)
5509 ;  (define-key gnus-summary-various-map "r" 'gnus-summary-refer-article)
5510 ;  (define-key gnus-summary-various-map "&" 'gnus-summary-execute-command)
5511 ;  (define-key gnus-summary-various-map "T" 'gnus-summary-toggle-truncation)
5512 ;  (define-key gnus-summary-various-map "e" 'gnus-summary-expand-window)
5513   (define-key gnus-summary-article-map "D" 'gnus-summary-enter-digest-group)
5514 ;  (define-key gnus-summary-various-map "k" 'gnus-summary-edit-local-kill)
5515 ;  (define-key gnus-summary-various-map "K" 'gnus-summary-edit-global-kill)
5516
5517   (define-key gnus-summary-mode-map "V" 'gnus-summary-score-map)
5518
5519 ;  (define-prefix-command 'gnus-summary-sort-map)
5520 ;  (define-key gnus-summary-various-map "s" 'gnus-summary-sort-map)
5521 ;  (define-key gnus-summary-sort-map "n" 'gnus-summary-sort-by-number)
5522 ;  (define-key gnus-summary-sort-map "a" 'gnus-summary-sort-by-author)
5523 ;  (define-key gnus-summary-sort-map "s" 'gnus-summary-sort-by-subject)
5524 ;  (define-key gnus-summary-sort-map "d" 'gnus-summary-sort-by-date)
5525 ;  (define-key gnus-summary-sort-map "i" 'gnus-summary-sort-by-score)
5526
5527   (define-key gnus-summary-mode-map "I" 'gnus-summary-increase-score)
5528   (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-score)
5529   )
5530
5531
5532 \f
5533
5534 (defun gnus-summary-mode (&optional group)
5535   "Major mode for reading articles.
5536
5537 All normal editing commands are switched off.
5538 \\<gnus-summary-mode-map>
5539 Each line in this buffer represents one article.  To read an
5540 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
5541 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]', 
5542 respectively.
5543
5544 You can also post articles and send mail from this buffer.  To 
5545 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author 
5546 of an article, type `\\[gnus-summary-reply]'.
5547
5548 There are approx. one gazillion commands you can execute in this 
5549 buffer; read the info pages for more information (`\\[gnus-info-find-node]'). 
5550
5551 The following commands are available:
5552
5553 \\{gnus-summary-mode-map}"
5554   (interactive)
5555   (if gnus-visual (gnus-summary-make-menu-bar))
5556   (kill-all-local-variables)
5557   (let ((locals gnus-summary-local-variables))
5558     (while locals
5559       (if (consp (car locals))
5560           (progn
5561             (make-local-variable (car (car locals)))
5562             (set (car (car locals)) (eval (cdr (car locals)))))
5563         (make-local-variable (car locals))
5564         (set (car locals) nil))
5565       (setq locals (cdr locals))))
5566   (gnus-make-thread-indent-array)
5567   (setq mode-line-modified "-- ")
5568   (make-local-variable 'mode-line-format)
5569   (setq mode-line-format (copy-sequence mode-line-format))
5570   (and (equal (nth 3 mode-line-format) "   ")
5571        (setcar (nthcdr 3 mode-line-format) ""))
5572   (setq major-mode 'gnus-summary-mode)
5573   (setq mode-name "Summary")
5574   (make-local-variable 'minor-mode-alist)
5575   (use-local-map gnus-summary-mode-map)
5576   (buffer-disable-undo (current-buffer))
5577   (setq buffer-read-only t)             ;Disable modification
5578   (setq truncate-lines t)
5579   (setq selective-display t)
5580   (setq selective-display-ellipses t)   ;Display `...'
5581   (setq buffer-display-table gnus-summary-display-table)
5582   (setq gnus-newsgroup-name group)
5583   (run-hooks 'gnus-summary-mode-hook))
5584
5585 (defun gnus-summary-make-display-table ()
5586   ;; Change the display table.  Odd characters have a tendency to mess
5587   ;; up nicely formatted displays - we make all possible glyphs
5588   ;; display only a single character.
5589
5590   ;; We start from the standard display table, if any.
5591   (setq gnus-summary-display-table 
5592         (or (copy-sequence standard-display-table)
5593             (make-display-table)))
5594   ;; Nix out all the control chars...
5595   (let ((i 32))
5596     (while (>= (setq i (1- i)) 0)
5597       (aset gnus-summary-display-table i [??])))
5598   ;; ... but not newline and cr, of course. (cr is necessary for the
5599   ;; selective display).  
5600   (aset gnus-summary-display-table ?\n nil)
5601   (aset gnus-summary-display-table ?\r nil)
5602   ;; We nix out any glyphs over 126 that are not set already.  
5603   (let ((i 256))
5604     (while (>= (setq i (1- i)) 127)
5605       ;; Only modify if the entry is nil.
5606       (or (aref gnus-summary-display-table i) 
5607           (aset gnus-summary-display-table i [??])))))
5608
5609 (defun gnus-summary-clear-local-variables ()
5610   (let ((locals gnus-summary-local-variables))
5611     (while locals
5612       (if (consp (car locals))
5613           (and (vectorp (car (car locals)))
5614                (set (car (car locals)) nil))
5615         (and (vectorp (car locals))
5616              (set (car locals) nil)))
5617       (setq locals (cdr locals)))))
5618
5619 ;; Some summary mode macros.
5620
5621 ;; Return a header specified by a NUMBER.
5622 (defun gnus-get-header-by-number (number)
5623   (save-excursion
5624     (set-buffer gnus-summary-buffer)
5625     (or gnus-newsgroup-headers-hashtb-by-number
5626         (gnus-make-headers-hashtable-by-number))
5627     (gnus-gethash (int-to-string number)
5628                   gnus-newsgroup-headers-hashtb-by-number)))
5629
5630 ;; Fast version of the function above.
5631 (defmacro gnus-get-header-by-num (number)
5632   (` (gnus-gethash (int-to-string (, number)) 
5633                    gnus-newsgroup-headers-hashtb-by-number)))
5634
5635 (defmacro gnus-summary-search-forward (&optional unread subject backward)
5636   "Search for article forward.
5637 If UNREAD is non-nil, only unread articles are selected.
5638 If SUBJECT is non-nil, the article which has the same subject will be
5639 searched for. 
5640 If BACKWARD is non-nil, the search will be performed backwards instead."
5641   (` (gnus-summary-search-subject (, backward) (, unread) (, subject))))
5642
5643 (defmacro gnus-summary-search-backward (&optional unread subject)
5644   "Search for article backward.
5645 If 1st optional argument UNREAD is non-nil, only unread article is selected.
5646 If 2nd optional argument SUBJECT is non-nil, the article which has
5647 the same subject will be searched for."
5648   (` (gnus-summary-search-forward (, unread) (, subject) t)))
5649
5650 (defmacro gnus-summary-article-number (&optional number-or-nil)
5651   "The article number of the article on the current line.
5652 If there isn's an article number here, then we return the current
5653 article number."
5654   (if number-or-nil
5655       '(get-text-property (gnus-point-at-bol) 'gnus-number)
5656     '(or (get-text-property (gnus-point-at-bol) 'gnus-number) 
5657          gnus-current-article)))
5658
5659 (defmacro gnus-summary-thread-level ()
5660   "The thread level of the article on the current line."
5661   '(or (get-text-property (gnus-point-at-bol) 'gnus-level)
5662        0))
5663
5664 (defmacro gnus-summary-article-mark ()
5665   "The mark on the current line."
5666   '(get-text-property (gnus-point-at-bol) 'gnus-mark))
5667
5668 (defun gnus-summary-subject-string ()
5669   "Return current subject string or nil if nothing."
5670   (let ((article (gnus-summary-article-number))
5671         header)
5672     (and article 
5673          (setq header (gnus-get-header-by-num article))
5674          (vectorp header)
5675          (header-subject header))))
5676
5677 ;; Various summary mode internalish functions.
5678
5679 (defun gnus-mouse-pick-article (e)
5680   (interactive "e")
5681   (mouse-set-point e)
5682   (gnus-summary-next-page nil t))
5683
5684 (defun gnus-summary-setup-buffer (group)
5685   "Initialize summary buffer."
5686   (let ((buffer (concat "*Summary " group "*")))
5687     (if (get-buffer buffer)
5688         (progn
5689           (set-buffer buffer)
5690           (not gnus-newsgroup-begin))
5691       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
5692       (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
5693       (gnus-add-current-to-buffer-list)
5694       (gnus-summary-mode group)
5695       (and gnus-carpal (gnus-carpal-setup-buffer 'summary))
5696       (setq gnus-newsgroup-name group)
5697       t)))
5698
5699 (defun gnus-set-global-variables ()
5700   ;; Set the global equivalents of the summary buffer-local variables
5701   ;; to the latest values they had. These reflect the summary buffer
5702   ;; that was in action when the last article was fetched.
5703   (if (eq major-mode 'gnus-summary-mode) 
5704       (progn
5705         (setq gnus-summary-buffer (current-buffer))
5706         (let ((name gnus-newsgroup-name)
5707               (marked gnus-newsgroup-marked)
5708               (unread gnus-newsgroup-unreads)
5709               (headers gnus-current-headers)
5710               (score-file gnus-current-score-file))
5711           (save-excursion
5712             (set-buffer gnus-group-buffer)
5713             (setq gnus-newsgroup-name name)
5714             (setq gnus-newsgroup-marked marked)
5715             (setq gnus-newsgroup-unreads unread)
5716             (setq gnus-current-headers headers)
5717             (setq gnus-current-score-file score-file))))))
5718
5719 (defun gnus-summary-insert-dummy-line (sformat subject number)
5720   (if (not sformat) 
5721       (setq sformat gnus-summary-dummy-line-format-spec))
5722   (let (b)
5723     (beginning-of-line)
5724     (setq b (point))
5725     (insert (eval sformat))
5726     (add-text-properties
5727      b (1+ b)
5728      (list 'gnus-number number 
5729            'gnus-mark gnus-dummy-mark
5730            'gnus-level 0))))
5731
5732 (defvar gnus-thread-indent-array nil)
5733 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
5734 (defun gnus-make-thread-indent-array ()
5735   (let ((n 200))
5736     (if (and gnus-thread-indent-array
5737              (= gnus-thread-indent-level gnus-thread-indent-array-level))
5738         nil
5739       (setq gnus-thread-indent-array (make-vector 201 "")
5740             gnus-thread-indent-array-level gnus-thread-indent-level)
5741       (while (>= n 0)
5742         (aset gnus-thread-indent-array n
5743               (make-string (* n gnus-thread-indent-level) ? ))
5744         (setq n (1- n))))))
5745
5746 (defun gnus-summary-insert-line 
5747   (sformat header level current unread replied expirable subject-or-nil
5748            &optional dummy score)
5749   (or sformat (setq sformat gnus-summary-line-format-spec))
5750   (let* ((indentation (aref gnus-thread-indent-array level))
5751          (lines (header-lines header))
5752          (score (or score gnus-summary-default-score 0))
5753          (score-char
5754           (if (or (null gnus-summary-default-score)
5755                   (<= (abs (- score gnus-summary-default-score))
5756                       gnus-summary-zcore-fuzz)) ? 
5757             (if (< score gnus-summary-default-score)
5758                 gnus-score-below-mark gnus-score-over-mark)))
5759          (replied (if replied gnus-replied-mark ? ))
5760          (from (header-from header))
5761          (name (cond 
5762                 ((string-match "(.+)" from)
5763                  (substring from (1+ (match-beginning 0)) (1- (match-end 0))))
5764                 ((string-match "<[^>]+> *$" from)
5765                  (let ((beg (match-beginning 0)))
5766                    (or (and (string-match "^\"[^\"]*\"" from)
5767                             (substring from (1+ (match-beginning 0))
5768                                        (1- (match-end 0))))
5769                        (substring from 0 beg))))
5770                 (t from)))
5771          (subject (header-subject header))
5772          (number (header-number header))
5773          (opening-bracket (if dummy ?\< ?\[))
5774          (closing-bracket (if dummy ?\> ?\]))
5775          (buffer-read-only nil)
5776          (b (progn (beginning-of-line) (point))))
5777     (or (numberp lines) (setq lines 0))
5778     (insert (eval sformat))
5779     (add-text-properties
5780      b (1+ b) (list 'gnus-number number 
5781                     'gnus-mark (or unread gnus-unread-mark)
5782                     'gnus-level level))))
5783
5784 (defun gnus-summary-update-line (&optional dont-update)
5785   ;; Update summary line after change.
5786   (or (not gnus-summary-default-score)
5787       gnus-summary-inhibit-highlight
5788       (let ((gnus-summary-inhibit-highlight t)
5789             (article (gnus-summary-article-number)))
5790         (progn
5791           (or dont-update
5792               (if (and gnus-summary-mark-below
5793                        (< (gnus-summary-article-score)
5794                           gnus-summary-mark-below))
5795                   (and (not (memq article gnus-newsgroup-marked))
5796                        (not (memq article gnus-newsgroup-dormant))
5797                        (memq article gnus-newsgroup-unreads)
5798                        (gnus-summary-mark-article-as-read gnus-low-score-mark))
5799                 (and (eq (gnus-summary-article-mark) gnus-low-score-mark)
5800                      (gnus-summary-mark-article-as-unread gnus-unread-mark))))
5801           (and gnus-visual
5802                (run-hooks 'gnus-summary-update-hook))))))
5803
5804 (defun gnus-summary-update-lines (&optional beg end)
5805   ;; Mark article as read (or not) by taking into account scores.
5806   (let ((beg (or beg (point-min)))
5807         (end (or end (point-max))))
5808     (if (or (not gnus-summary-default-score)
5809             gnus-summary-inhibit-highlight)
5810         ()
5811       (let ((gnus-summary-inhibit-highlight t)
5812             article)
5813         (save-excursion
5814           (set-buffer gnus-summary-buffer)
5815           (goto-char beg)
5816           (beginning-of-line)
5817           (while (and (not (eobp)) (< (point) end))
5818             (if (and gnus-summary-mark-below
5819                      (< (or (cdr (assq 
5820                                   (setq article (get-text-property 
5821                                                  (point) 'gnus-number))
5822                                   gnus-newsgroup-scored))
5823                             gnus-summary-default-score 0)
5824                         gnus-summary-mark-below))
5825                 ;; We want to possibly mark it as read...
5826                 (and (not (memq article gnus-newsgroup-marked))
5827                      (not (memq article gnus-newsgroup-dormant))
5828                      (memq article gnus-newsgroup-unreads)
5829                      (gnus-summary-mark-article-as-read gnus-low-score-mark))
5830               ;; We want to possibly mark it as unread.
5831               (and (eq (get-text-property (point) 'gnus-mark)
5832                        gnus-low-score-mark)
5833                    (gnus-summary-mark-article-as-unread gnus-unread-mark)))
5834             ;; Do the visual highlights at the same time.
5835             (and gnus-visual (run-hooks 'gnus-summary-update-hook))
5836             (forward-line 1)))))))
5837
5838 (defvar gnus-tmp-gathered nil)
5839
5840 (defun gnus-summary-number-of-articles-in-thread (thread &optional char)
5841   ;; Sum up all elements (and sub-elements) in a list.
5842   (let* ((number
5843           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
5844           (if (and (consp thread) (cdr thread))
5845               (apply
5846                '+ 1 (mapcar
5847                      'gnus-summary-number-of-articles-in-thread 
5848                      (cdr thread)))
5849             1)))
5850     (if char 
5851         (if (> number 1) gnus-not-empty-thread-mark
5852           gnus-empty-thread-mark)
5853       number)))
5854
5855 (defun gnus-summary-read-group 
5856   (group &optional show-all no-article kill-buffer)
5857   "Start reading news in newsgroup GROUP.
5858 If SHOW-ALL is non-nil, already read articles are also listed.
5859 If NO-ARTICLE is non-nil, no article is selected initially."
5860   (gnus-message 5 "Retrieving newsgroup: %s..." group)
5861   (let* ((new-group (gnus-summary-setup-buffer group))
5862          (quit-config (nth 1 (assoc 'quit-config (gnus-find-method-for-group
5863                                                   group))))
5864          (did-select (and new-group (gnus-select-newsgroup group show-all))))
5865     (cond 
5866      ((not new-group)
5867       (gnus-set-global-variables)
5868       (gnus-kill-buffer kill-buffer)
5869       (gnus-configure-windows 'summary)
5870       (gnus-set-mode-line 'summary)
5871       (gnus-summary-position-cursor)
5872       (message "")
5873       t)
5874      ((null did-select) 
5875       (and (eq major-mode 'gnus-summary-mode)
5876            (not (equal (current-buffer) kill-buffer))
5877            (progn
5878              (kill-buffer (current-buffer))
5879              (if (not quit-config)
5880                  (progn
5881                    (set-buffer gnus-group-buffer)
5882                    (gnus-group-jump-to-group group)
5883                    (gnus-group-next-unread-group 1))
5884                (if (not (buffer-name (car quit-config)))
5885                    (gnus-configure-windows 'group 'force)
5886                  (set-buffer (car quit-config))
5887                  (and (eq major-mode 'gnus-summary-mode)
5888                       (gnus-set-global-variables))
5889                  (gnus-configure-windows (cdr quit-config))))))
5890       (message "Can't select group")
5891       nil)
5892      ((eq did-select 'quit)
5893       (and (eq major-mode 'gnus-summary-mode)
5894            (not (equal (current-buffer) kill-buffer))
5895            (kill-buffer (current-buffer)))
5896       (gnus-kill-buffer kill-buffer)
5897       (if (not quit-config)
5898           (progn
5899             (set-buffer gnus-group-buffer)
5900             (gnus-group-jump-to-group group)
5901             (gnus-group-next-unread-group 1)
5902             (gnus-configure-windows 'group 'force))
5903         (if (not (buffer-name (car quit-config)))
5904             (gnus-configure-windows 'group 'force)
5905           (set-buffer (car quit-config))
5906           (and (eq major-mode 'gnus-summary-mode)
5907                (gnus-set-global-variables))
5908           (gnus-configure-windows (cdr quit-config))))
5909       (signal 'quit nil))
5910      (t
5911       (gnus-set-global-variables)
5912       ;; Save the active value in effect when the group was entered.
5913       (setq gnus-newsgroup-active 
5914             (gnus-copy-sequence
5915              (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
5916       ;; You can change the subjects in this hook.
5917       (run-hooks 'gnus-select-group-hook)
5918       ;; Do score processing.
5919       (and gnus-use-scoring (gnus-possibly-score-headers))
5920       (gnus-update-format-specifications)
5921       ;; Generate the summary buffer.
5922       (gnus-summary-prepare)
5923       ;; Create the header hashtb.
5924       (gnus-make-headers-hashtable-by-number)
5925       (if (zerop (buffer-size))
5926           (cond (gnus-newsgroup-dormant
5927                  (gnus-summary-show-all-dormant))
5928                 ((and gnus-newsgroup-scored show-all)
5929                  (gnus-summary-show-all-expunged))))
5930       ;; Function `gnus-apply-kill-file' must be called in this hook.
5931       (run-hooks 'gnus-apply-kill-hook)
5932       (if (zerop (buffer-size))
5933           (progn
5934             ;; This newsgroup is empty.
5935             (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
5936             (gnus-message 6 "No unread news")
5937             (gnus-kill-buffer kill-buffer)
5938             nil)
5939         ;;(save-excursion
5940         ;;  (if kill-buffer
5941         ;;      (let ((gnus-summary-buffer kill-buffer))
5942         ;;      (gnus-configure-windows 'group))))
5943         ;; Hide conversation thread subtrees.  We cannot do this in
5944         ;; gnus-summary-prepare-hook since kill processing may not
5945         ;; work with hidden articles.
5946         (and gnus-show-threads
5947              gnus-thread-hide-subtree
5948              (gnus-summary-hide-all-threads))
5949         ;; Show first unread article if requested.
5950         (goto-char (point-min))
5951         (if (and (not no-article)
5952                  gnus-auto-select-first
5953                  (gnus-summary-first-unread-article))
5954             ()
5955           (gnus-configure-windows 'summary))
5956         (gnus-set-mode-line 'summary)
5957         (gnus-summary-position-cursor)
5958         ;; If in async mode, we send some info to the backend.
5959         (and gnus-newsgroup-async
5960              (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
5961              (gnus-request-asynchronous 
5962               gnus-newsgroup-name
5963               (if (and gnus-asynchronous-article-function
5964                        (fboundp gnus-asynchronous-article-function))
5965                   (funcall gnus-asynchronous-article-function
5966                            gnus-newsgroup-threads)
5967                 gnus-newsgroup-threads)))
5968         (gnus-kill-buffer kill-buffer)
5969         (if (not (get-buffer-window gnus-group-buffer))
5970             ()
5971           ;; gotta use windows, because recenter does wierd stuff if
5972           ;; the current buffer ain't the displayed window.
5973           (let ((owin (selected-window))) 
5974             (select-window (get-buffer-window gnus-group-buffer))
5975             (and (gnus-group-goto-group group)
5976                  (recenter))
5977             (select-window owin))))
5978       t))))
5979
5980 (defun gnus-summary-prepare ()
5981   ;; Generate the summary buffer.
5982   (let ((buffer-read-only nil))
5983     (erase-buffer)
5984     (gnus-summary-prepare-threads 
5985      (if gnus-show-threads
5986          (gnus-gather-threads 
5987           (gnus-sort-threads 
5988            (if (and gnus-summary-expunge-below
5989                     (not gnus-fetch-old-headers))
5990                (gnus-make-threads-and-expunge)
5991              (gnus-make-threads))))
5992        gnus-newsgroup-headers)
5993      'cull)
5994     (gnus-summary-update-lines)
5995     ;; Remove the final newline.
5996     ;;(goto-char (point-max))
5997     ;;(delete-char -1)
5998     ;; Call hooks for modifying summary buffer.
5999     ;; Suggested by sven@tde.LTH.Se (Sven Mattisson).
6000     (goto-char (point-min))
6001     (run-hooks 'gnus-summary-prepare-hook)))
6002
6003 (defun gnus-gather-threads (threads)
6004   "Gather threads that have lost their roots."
6005   (if (not gnus-summary-make-false-root)
6006       threads 
6007     (let ((hashtb (gnus-make-hashtable 1023))
6008           (prev threads)
6009           (result threads)
6010           subject hthread whole-subject)
6011       (while threads
6012         (setq whole-subject 
6013               (setq subject (header-subject (car (car threads)))))
6014         (if gnus-summary-gather-subject-limit
6015             (or (and (numberp gnus-summary-gather-subject-limit)
6016                      (> (length subject) gnus-summary-gather-subject-limit)
6017                      (setq subject
6018                            (substring subject 0 
6019                                       gnus-summary-gather-subject-limit)))
6020                 (and (eq 'fuzzy gnus-summary-gather-subject-limit)
6021                      (setq subject (gnus-simplify-subject-fuzzy subject))))
6022           (setq subject (gnus-simplify-subject-re subject)))
6023         (if (setq hthread 
6024                   (gnus-gethash subject hashtb))
6025             (progn
6026               (or (stringp (car (car hthread)))
6027                   (setcar hthread (list whole-subject (car hthread))))
6028               (setcdr (car hthread) (nconc (cdr (car hthread)) 
6029                                            (list (car threads))))
6030               (setcdr prev (cdr threads))
6031               (setq threads prev))
6032           (gnus-sethash subject threads hashtb))
6033         (setq prev threads)
6034         (setq threads (cdr threads)))
6035       result)))
6036
6037 (defun gnus-make-threads ()
6038   ;; This function takes the dependencies already made by 
6039   ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6040   ;; through the dependecies in the hash table and finds all the
6041   ;; roots. Roots do not refer back to any valid articles.
6042   (gnus-message 6 "Threading...")
6043   (let (roots new-roots)
6044     (and gnus-fetch-old-headers
6045          (eq gnus-headers-retrieved-by 'nov)
6046          (gnus-build-old-threads))
6047     (mapatoms
6048      (lambda (refs)
6049        (if (not (car (symbol-value refs)))
6050            (setq roots (append (cdr (symbol-value refs)) roots))
6051          ;; Ok, these refer back to valid articles, but if
6052          ;; `gnus-thread-ignore-subject' is nil, we have to check that
6053          ;; the root has the same subject as its children. The children
6054          ;; that do not are made into roots and removed from the list
6055          ;; of children. 
6056          (or gnus-thread-ignore-subject
6057              (let* ((prev (symbol-value refs))
6058                     (subject (gnus-simplify-subject-re 
6059                               (header-subject (car prev))))
6060                     (headers (cdr prev)))
6061                (while headers
6062                  (if (not (string= subject
6063                                    (gnus-simplify-subject-re 
6064                                     (header-subject (car headers)))))
6065                      (progn
6066                        (setq new-roots (cons (car headers) new-roots))
6067                        (setcdr prev (cdr headers)))
6068                    (setq prev headers))
6069                  (setq headers (cdr headers)))))))
6070      gnus-newsgroup-dependencies)
6071
6072     ;; We enter the new roots into the dependencies structure to
6073     ;; ensure that any possible later thread-regeneration will be
6074     ;; possible. 
6075     (let ((r new-roots))
6076       (while r
6077         (gnus-sethash (concat (header-id (car r)) ".boo")
6078                       (list nil (car r)) gnus-newsgroup-dependencies)
6079         (setq r (cdr r))))
6080
6081     (setq roots (nconc new-roots roots))
6082
6083     (prog1
6084         (mapcar 'gnus-trim-thread
6085                 (apply 'append
6086                        (mapcar 'gnus-cut-thread
6087                                (mapcar 'gnus-make-sub-thread roots))))
6088       (gnus-message 6 "Threading...done"))))
6089
6090   
6091 (defun gnus-make-threads-and-expunge ()
6092   ;; This function takes the dependencies already made by 
6093   ;; `gnus-get-newsgroup-headers' and builds the trees. First we go
6094   ;; through the dependecies in the hash table and finds all the
6095   ;; roots. Roots do not refer back to any valid articles.
6096   (gnus-message 6 "Threading...")
6097   (let ((default (or gnus-summary-default-score 0))
6098         (below gnus-summary-expunge-below)
6099         roots article new-roots)
6100     (and gnus-fetch-old-headers
6101          (eq gnus-headers-retrieved-by 'nov)
6102          (gnus-build-old-threads))
6103     (mapatoms
6104      (lambda (refs)
6105        (if (not (car (symbol-value refs)))
6106            ;; These articles do not refer back to any other articles -
6107            ;; they are roots.
6108            (let ((headers (cdr (symbol-value refs))))
6109              ;; We weed out the low-scored articles.
6110              (while headers
6111                (if (not (< (or (cdr (assq (header-number (car headers))
6112                                           gnus-newsgroup-scored)) default)
6113                            below))
6114                    ;; It is over.
6115                    (setq roots (cons (car headers) roots))
6116                  ;; It is below, so we mark it as read.
6117                  (setq gnus-newsgroup-unreads
6118                        (delq (header-number (car headers))
6119                              gnus-newsgroup-unreads))
6120                  (setq gnus-newsgroup-reads 
6121                        (cons (cons (header-number (car headers))
6122                                    gnus-low-score-mark) 
6123                              gnus-newsgroup-reads)))
6124                (setq headers (cdr headers))))
6125          ;; Ok, these refer back to valid articles, but if
6126          ;; `gnus-thread-ignore-subject' is nil, we have to check that
6127          ;; the root has the same subject as its children. The children
6128          ;; that do not are made into roots and removed from the list
6129          ;; of children. 
6130          (or gnus-thread-ignore-subject
6131              (let* ((prev (symbol-value refs))
6132                     (subject (gnus-simplify-subject-re 
6133                               (header-subject (car prev))))
6134                     (headers (cdr prev)))
6135                (while headers
6136                  (if (not (string= subject
6137                                    (gnus-simplify-subject-re 
6138                                     (header-subject (car headers)))))
6139                      (progn
6140                        (if (not (< (or (cdr (assq (header-number (car headers))
6141                                                   gnus-newsgroup-scored))
6142                                        default) below))
6143                            (setq new-roots (cons (car headers) new-roots))
6144                          (setq gnus-newsgroup-unreads
6145                                (delq (header-number (car headers))
6146                                      gnus-newsgroup-unreads))
6147                          (setq gnus-newsgroup-reads
6148                                (cons (cons (header-number (car headers)) 
6149                                            gnus-low-score-mark) 
6150                                      gnus-newsgroup-reads)))
6151                        (setcdr prev (cdr headers)))
6152                    (setq prev headers))
6153                  (setq headers (cdr headers)))))
6154          ;; If this article is expunged, some of the children might be
6155          ;; roots.  
6156          (if (< (or (cdr (assq (header-number (car (symbol-value refs)))
6157                                gnus-newsgroup-scored)) default)
6158                 below)
6159              (let* ((prev (symbol-value refs))
6160                     (headers (cdr prev)))
6161                (while headers
6162                  (setq article (header-number (car headers)))
6163                  (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6164                                  default) below))
6165                      (progn (setq new-roots (cons (car headers) new-roots))
6166                             (setq prev headers))
6167                    (setq gnus-newsgroup-unreads 
6168                          (delq article gnus-newsgroup-unreads))
6169                    (setq gnus-newsgroup-reads 
6170                          (cons (cons article gnus-low-score-mark) 
6171                                gnus-newsgroup-reads))
6172                    (setcdr prev (cdr headers)))
6173                  (setq headers (cdr headers))))
6174            ;; It was not expunged, but we look at expunged children.
6175            (let* ((prev (symbol-value refs))
6176                   (headers (cdr prev))
6177                   article)
6178              (while headers
6179                (setq article (header-number (car headers)))
6180                (if (not (< (or (cdr (assq article gnus-newsgroup-scored))
6181                                default) below))
6182                    (setq prev headers)
6183                  (setq gnus-newsgroup-unreads 
6184                        (delq article gnus-newsgroup-unreads))
6185                  (setq gnus-newsgroup-reads 
6186                        (cons (cons article gnus-low-score-mark)
6187                              gnus-newsgroup-reads))
6188                  (setcdr prev (cdr headers)))
6189                (setq headers (cdr headers)))))))
6190      gnus-newsgroup-dependencies)
6191
6192     ;; We enter the new roots into the dependencies structure to
6193     ;; ensure that any possible later thread-regeneration will be
6194     ;; possible. 
6195     (let ((r new-roots))
6196       (while r
6197         (gnus-sethash (concat (header-id (car r)) ".boo")
6198                       (list nil (car r)) gnus-newsgroup-dependencies)
6199         (setq r (cdr r))))
6200
6201     (setq roots (nconc new-roots roots))
6202
6203     (prog1
6204         (mapcar 'gnus-trim-thread
6205                 (apply 'append
6206                        (mapcar 'gnus-cut-thread
6207                                (mapcar 'gnus-make-sub-thread roots))))
6208       (gnus-message 6 "Threading...done"))))
6209
6210   
6211 (defun gnus-cut-thread (thread)
6212   ;; Remove leaf dormant or ancient articles from THREAD.
6213   (let ((head (car thread))
6214         (tail (apply 'append (mapcar 'gnus-cut-thread (cdr thread)))))
6215     (if (and (null tail)
6216              (let ((number (header-number head)))
6217                (or (memq number gnus-newsgroup-ancient)
6218                    (memq number gnus-newsgroup-dormant)
6219                    (and gnus-summary-expunge-below
6220                         (eq gnus-fetch-old-headers 'some)
6221                         (< (or (cdr (assq number gnus-newsgroup-scored))
6222                                gnus-summary-default-score 0)
6223                            gnus-summary-expunge-below)
6224                         (progn
6225                           (setq gnus-newsgroup-unreads
6226                                 (delq number gnus-newsgroup-unreads))
6227                           (setq gnus-newsgroup-reads
6228                                 (cons (cons number gnus-low-score-mark)
6229                                       gnus-newsgroup-reads))
6230                           t)))))
6231         nil
6232       (list (cons head tail)))))
6233
6234 (defun gnus-trim-thread (thread)
6235   ;; Remove root ancient articles with only one child from THREAD.
6236   (if (and (eq gnus-fetch-old-headers 'some)
6237            (memq (header-number (car thread)) gnus-newsgroup-ancient)
6238            (= (length thread) 2))
6239       (gnus-trim-thread (nth 1 thread))
6240     thread))
6241
6242 (defun gnus-make-sub-thread (root)
6243   ;; This function makes a sub-tree for a node in the tree.
6244   (let ((children (reverse (cdr (gnus-gethash (downcase (header-id root))
6245                                               gnus-newsgroup-dependencies)))))
6246     (cons root (mapcar 'gnus-make-sub-thread children))))
6247
6248 (defun gnus-build-old-threads ()
6249   ;; Look at all the articles that refer back to old articles, and
6250   ;; fetch the headers for the articles that aren't there. This will
6251   ;; build complete threads - if the roots haven't been expired by the
6252   ;; server, that is.
6253   (let (id heads)
6254     (mapatoms
6255      (lambda (refs)
6256        (if (not (car (symbol-value refs)))
6257            (progn
6258              (setq heads (cdr (symbol-value refs)))
6259              (while heads
6260                (if (not (memq (header-number (car heads))
6261                               gnus-newsgroup-dormant))
6262                    (progn
6263                      (setq id (symbol-name refs))
6264                      (while (and (setq id (gnus-build-get-header id))
6265                                  (not (car (gnus-gethash 
6266                                             id gnus-newsgroup-dependencies)))))
6267                      (setq heads nil))
6268                  (setq heads (cdr heads)))))))
6269      gnus-newsgroup-dependencies)))
6270
6271 (defun gnus-build-get-header (id)
6272   ;; Look through the buffer of NOV lines and find the header to
6273   ;; ID. Enter this line into the dependencies hash table, and return
6274   ;; the id of the parent article (if any).
6275   (let ((deps gnus-newsgroup-dependencies)
6276         found header)
6277     (prog1
6278         (save-excursion
6279           (set-buffer nntp-server-buffer)
6280           (goto-char (point-min))
6281           (while (and (not found) (search-forward id nil t))
6282             (beginning-of-line)
6283             (setq found (looking-at 
6284                          (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
6285                                  (regexp-quote id))))
6286             (or found (beginning-of-line 2)))
6287           (if found
6288               (let (ref)
6289                 (beginning-of-line)
6290                 (and
6291                  (setq header (gnus-nov-parse-line 
6292                                (read (current-buffer)) deps))
6293                  (setq ref (header-references header))
6294                  (string-match "\\(<[^>]+>\\) *$" ref)
6295                  (substring ref (match-beginning 1) (match-end 1))))))
6296       (and header
6297            (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers)
6298                  gnus-newsgroup-ancient (cons (header-number header)
6299                                               gnus-newsgroup-ancient))))))
6300
6301 ;; Re-build the thread containing ID.
6302 (defun gnus-rebuild-thread (id)
6303   (let ((dep gnus-newsgroup-dependencies)
6304         (buffer-read-only nil)
6305         parent headers refs thread art)
6306     (while (and id (setq headers
6307                          (car (setq art (gnus-gethash (downcase id) dep)))))
6308       (setq parent art)
6309       (setq id (and (setq refs (header-references headers))
6310                     (string-match "\\(<[^>]+>\\) *$" refs)
6311                     (substring refs (match-beginning 1) (match-end 1)))))
6312     (setq thread (gnus-make-sub-thread (car parent)))
6313     (gnus-rebuild-remove-articles thread)
6314     (let ((beg (point)))
6315       (gnus-summary-prepare-threads (list thread))
6316       (gnus-summary-update-lines beg (point)))))
6317
6318 ;; Delete all lines in the summary buffer that correspond to articles
6319 ;; in this thread.
6320 (defun gnus-rebuild-remove-articles (thread)
6321   (and (gnus-summary-goto-subject (header-number (car thread)))
6322        (gnus-delete-line))
6323   (mapcar (lambda (th) (gnus-rebuild-remove-articles th)) (cdr thread)))
6324
6325 (defun gnus-sort-threads (threads)
6326   ;; Sort threads as specified in `gnus-thread-sort-functions'.
6327   (let ((fun gnus-thread-sort-functions))
6328     (while fun
6329       (setq threads (sort threads (car fun))
6330             fun (cdr fun))))
6331   threads)
6332
6333 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
6334 (defmacro gnus-thread-header (thread)
6335   ;; Return header of first article in THREAD.
6336   ;; Note that THREAD must never, evr be anything else than a variable -
6337   ;; using some other form will lead to serious barfage.
6338   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
6339   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
6340   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ; 
6341         (vector thread) 2))
6342
6343 (defun gnus-thread-sort-by-number (h1 h2)
6344   "Sort threads by root article number."
6345   (< (header-number (gnus-thread-header h1))
6346      (header-number (gnus-thread-header h2))))
6347
6348 (defun gnus-thread-sort-by-author (h1 h2)
6349   "Sort threads by root author."
6350   (string-lessp
6351    (let ((extract (funcall 
6352                    gnus-extract-address-components
6353                    (header-from (gnus-thread-header h1)))))
6354      (or (car extract) (cdr extract)))
6355    (let ((extract (funcall
6356                    gnus-extract-address-components 
6357                    (header-from (gnus-thread-header h2)))))
6358      (or (car extract) (cdr extract)))))
6359
6360 (defun gnus-thread-sort-by-subject (h1 h2)
6361   "Sort threads by root subject."
6362   (string-lessp
6363    (downcase (gnus-simplify-subject 
6364               (header-subject (gnus-thread-header h1))))
6365    (downcase (gnus-simplify-subject 
6366               (header-subject (gnus-thread-header h2))))))
6367
6368 (defun gnus-thread-sort-by-date (h1 h2)
6369   "Sort threads by root article date."
6370   (string-lessp
6371    (gnus-sortable-date (header-date (gnus-thread-header h1)))
6372    (gnus-sortable-date (header-date (gnus-thread-header h2)))))
6373
6374 (defun gnus-thread-sort-by-score (h1 h2)
6375   "Sort threads by root article score.
6376 Unscored articles will be counted as having a score of zero."
6377   (> (or (cdr (assq (header-number (gnus-thread-header h1))
6378                     gnus-newsgroup-scored))
6379          gnus-summary-default-score 0)
6380      (or (cdr (assq (header-number (gnus-thread-header h2))
6381                     gnus-newsgroup-scored))
6382          gnus-summary-default-score 0)))
6383
6384 (defun gnus-thread-sort-by-total-score (h1 h2)
6385   "Sort threads by the sum of all scores in the thread.
6386 Unscored articles will be counted as having a score of zero."
6387   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
6388
6389 (defun gnus-thread-total-score (thread)
6390   ;;  This function find the total score of THREAD.
6391   (if (consp thread)
6392       (if (stringp (car thread))
6393           (apply gnus-thread-score-function 0
6394                  (mapcar 'gnus-thread-total-score-1 (cdr thread)))
6395         (gnus-thread-total-score-1 thread))
6396     (gnus-thread-total-score-1 (list thread))))
6397
6398 (defun gnus-thread-total-score-1 (root)
6399   ;; This function find the total score of the thread below ROOT.
6400   (setq root (car root))
6401   (apply gnus-thread-score-function
6402          (or (cdr (assq (header-number root) gnus-newsgroup-scored))
6403              gnus-summary-default-score 0)
6404          (mapcar 'gnus-thread-total-score
6405                  (cdr (gnus-gethash (downcase (header-id root))
6406                                     gnus-newsgroup-dependencies)))))
6407
6408 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
6409 (defvar gnus-tmp-prev-subject "")
6410
6411 (defun gnus-summary-prepare-threads (threads &optional cull)
6412   "Prepare summary buffer from THREADS and indentation LEVEL.  
6413 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'  
6414 or a straight list of headers."
6415   (message "Generating summary...")
6416   (let ((level 0)
6417         thread header number subject stack state gnus-tmp-gathered)
6418     (if (vectorp (car threads))
6419         ;; If this is a straight (sic) list of headers, then a
6420         ;; threaded summary display isn't required, so we just create
6421         ;; an unthreaded one.
6422         (gnus-summary-prepare-unthreaded threads cull)
6423
6424       ;; Do the threaded display.
6425
6426       (while (or threads stack)
6427         
6428         (if threads
6429             ;; If there are some threads, we do them before the
6430             ;; threads on the stack.
6431             (setq thread threads
6432                   header (car (car thread)))
6433           ;; There were no current threads, so we pop something off
6434           ;; the stack. 
6435           (setq state (car stack)
6436                 level (car state)
6437                 thread (cdr state)
6438                 stack (cdr stack)
6439                 header (car (car thread))))
6440
6441         (if (stringp header)
6442             (progn
6443               ;; The header is a dummy root.
6444               (cond 
6445                ((eq gnus-summary-make-false-root 'adopt)
6446                 ;; We let the first article adopt the rest.
6447                 (let ((th (car (cdr (car thread)))))
6448                   (while (cdr th)
6449                     (setq th (cdr th)))
6450                   (setcdr th (cdr (cdr (car thread))))
6451                   (setq gnus-tmp-gathered 
6452                         (nconc (mapcar
6453                                 (lambda (h) (header-number (car h)))
6454                                 (cdr (cdr (car thread))))
6455                                gnus-tmp-gathered))
6456                   (setcdr (cdr (car thread)) nil))
6457                 (setq level -1))
6458                ((eq gnus-summary-make-false-root 'empty)
6459                 ;; We print adopted articles with empty subject fields.
6460                 (setq gnus-tmp-gathered 
6461                       (nconc (mapcar
6462                               (lambda (h) (header-number (car h)))
6463                               (cdr (cdr (car thread))))
6464                              gnus-tmp-gathered))
6465                 (setq level -1))
6466                ((eq gnus-summary-make-false-root 'dummy)
6467                 ;; We output a dummy root.
6468                 (gnus-summary-insert-dummy-line 
6469                  nil header (header-number (car (car (cdr (car thread)))))))
6470                (t
6471                 ;; We do not make a root for the gathered
6472                 ;; sub-threads at all.  
6473                 (setq level -1))))
6474       
6475           (setq number (header-number header)
6476                 subject (header-subject header))
6477
6478           ;; Do the async thing.
6479           (and gnus-newsgroup-async
6480                (setq gnus-newsgroup-threads
6481                      (cons (cons number (header-lines header)) 
6482                            gnus-newsgroup-threads)))
6483
6484           ;; We may have to root out some bad articles...
6485           (and cull
6486                (= level 0)
6487                (cond ((and (memq (setq number (header-number header))
6488                                  gnus-newsgroup-dormant)
6489                            (null thread))
6490                       (setq header nil))
6491                      ((and gnus-summary-expunge-below
6492                            (< (or (cdr (assq number gnus-newsgroup-scored))
6493                                   gnus-summary-default-score 0)
6494                               gnus-summary-expunge-below))
6495                       (setq header nil)
6496                       (setq gnus-newsgroup-unreads 
6497                             (delq number gnus-newsgroup-unreads))
6498                       (setq gnus-newsgroup-reads
6499                             (cons (cons number gnus-low-score-mark)
6500                                   gnus-newsgroup-reads)))))
6501           
6502           (and
6503            header
6504            (progn
6505              (inline
6506                (gnus-summary-insert-line
6507                 nil header level nil 
6508                 (cond 
6509                  ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6510                  ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6511                  ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6512                  ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6513                  (t (or (cdr (assq number gnus-newsgroup-reads))
6514                         gnus-ancient-mark)))
6515                 (memq number gnus-newsgroup-replied)
6516                 (memq number gnus-newsgroup-expirable)
6517                 (if (and (eq gnus-summary-make-false-root 'empty)
6518                          (memq number gnus-tmp-gathered))
6519                     gnus-summary-same-subject
6520                   (if (or (zerop level)
6521                           (and gnus-thread-ignore-subject
6522                                (not (string= 
6523                                      (gnus-simplify-subject-re
6524                                       gnus-tmp-prev-subject)
6525                                      (gnus-simplify-subject-re
6526                                       subject)))))
6527                       subject
6528                     gnus-summary-same-subject))
6529                 (and (eq gnus-summary-make-false-root 'adopt)
6530                      (memq number gnus-tmp-gathered))
6531                 (cdr (assq number gnus-newsgroup-scored)))
6532
6533                (setq gnus-tmp-prev-subject subject)))))
6534
6535         (if (nth 1 thread) 
6536             (setq stack (cons (cons (max 0 level) (nthcdr 1 thread)) stack)))
6537         (setq level (1+ level))
6538         (setq threads (cdr (car thread))))))
6539   (message "Generating summary...done"))
6540
6541
6542
6543 (defun gnus-summary-prepare-unthreaded (headers &optional cull)
6544   (let (header number)
6545
6546     ;; Do the async thing, if that is required.
6547     (if gnus-newsgroup-async
6548         (setq gnus-newsgroup-threads
6549               (mapcar (lambda (h) (cons (header-number h) (header-lines h)))
6550                       headers)))
6551
6552     (while headers
6553       (setq header (car headers)
6554             headers (cdr headers)
6555             number (header-number header))
6556
6557       ;; We may have to root out some bad articles...
6558       (cond 
6559        ((and cull
6560              (memq (setq number (header-number header))
6561                    gnus-newsgroup-dormant)))
6562        ((and cull gnus-summary-expunge-below
6563              (< (or (cdr (assq number gnus-newsgroup-scored))
6564                     gnus-summary-default-score 0)
6565                 gnus-summary-expunge-below))
6566         (setq gnus-newsgroup-unreads 
6567               (delq number gnus-newsgroup-unreads))
6568         (setq gnus-newsgroup-reads
6569               (cons (cons number gnus-low-score-mark)
6570                     gnus-newsgroup-reads)))
6571        (t
6572         (gnus-summary-insert-line
6573          nil header 0 nil 
6574          (cond ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
6575                ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
6576                ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
6577                ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
6578                (t (or (cdr (assq number gnus-newsgroup-reads))
6579                       gnus-ancient-mark)))
6580          (memq number gnus-newsgroup-replied)
6581          (memq number gnus-newsgroup-expirable)
6582          (header-subject header) nil
6583          (cdr (assq number gnus-newsgroup-scored))))))))
6584
6585 (defun gnus-select-newsgroup (group &optional read-all)
6586   "Select newsgroup GROUP.
6587 If READ-ALL is non-nil, all articles in the group are selected."
6588   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
6589          (info (nth 2 entry))
6590          articles)
6591     (gnus-check-server
6592      (setq gnus-current-select-method (gnus-find-method-for-group group)))
6593
6594     (or (gnus-check-server gnus-current-select-method)
6595         (error "Couldn't open server"))
6596     
6597     (or (and (null entry)
6598              (gnus-activate-group group))
6599         (and (eq (car entry) t)
6600              (gnus-activate-group (car info)))
6601         (gnus-request-group group t)
6602         (progn
6603           (kill-buffer (current-buffer))
6604           (error "Couldn't request group %s: %s" 
6605                  group (gnus-status-message group))))
6606
6607     (setq gnus-newsgroup-name group)
6608     (setq gnus-newsgroup-unselected nil)
6609     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
6610
6611     (and gnus-asynchronous
6612          (gnus-check-backend-function 
6613           'request-asynchronous gnus-newsgroup-name)
6614          (setq gnus-newsgroup-async
6615                (gnus-request-asynchronous gnus-newsgroup-name)))
6616
6617     (setq articles (gnus-articles-to-read group read-all))
6618
6619     (cond 
6620      ((null articles) 
6621       (gnus-message 3 "Couldn't select newsgroup")
6622       'quit)
6623      ((eq articles 0) nil)
6624      (t
6625       ;; Init the dependencies hash table.
6626       (setq gnus-newsgroup-dependencies 
6627             (gnus-make-hashtable (length articles)))
6628       ;; Retrieve the headers and read them in.
6629       (gnus-message 5 "Fetching headers...")
6630       (setq gnus-newsgroup-headers 
6631             (if (eq 'nov (setq gnus-headers-retrieved-by
6632                                ;; This is a naughty hack. To get the
6633                                ;; retrieval of old headers to work, we
6634                                ;; set `nntp-nov-gap' to nil (locally),
6635                                ;; and then just retrieve the headers.
6636                                ;; Mucho magic.
6637                                (if gnus-fetch-old-headers
6638                                    (let (nntp-nov-gap)
6639                                      (gnus-retrieve-headers 
6640                                       (if (not (eq 1 (car articles)))
6641                                           (cons 1 articles)
6642                                         articles)
6643                                       gnus-newsgroup-name))
6644                                  (gnus-retrieve-headers 
6645                                   articles gnus-newsgroup-name))))
6646                 (progn
6647                   (gnus-get-newsgroup-headers-xover articles))
6648               ;; If we were to fetch old headers, but the backend didn't
6649               ;; support XOVER, then it is possible we fetched one article
6650               ;; that we shouldn't have. If that's the case, we remove it.
6651               (if (or (not gnus-fetch-old-headers)
6652                       (eq 1 (car articles)))
6653                   ()
6654                 (save-excursion
6655                   (set-buffer nntp-server-buffer)
6656                   (goto-char (point-min))
6657                   (and 
6658                    (looking-at "[0-9]+[ \t]+1[ \t]") ; This is not a NOV line.
6659                    (delete-region       ; So we delete this head.
6660                     (point) 
6661                     (search-forward "\n.\n" nil t)))))
6662               (gnus-get-newsgroup-headers)))
6663       (gnus-message 5 "Fetching headers...done")      
6664       ;; Remove canceled articles from the list of unread articles.
6665       (setq gnus-newsgroup-unreads
6666             (gnus-set-sorted-intersection 
6667              gnus-newsgroup-unreads
6668              (mapcar (lambda (headers) (header-number headers))
6669                      gnus-newsgroup-headers)))
6670       ;; Adjust and set lists of article marks.
6671       (and info
6672            (let (marked)
6673              (gnus-adjust-marked-articles info)
6674              (setq gnus-newsgroup-marked 
6675                    (copy-sequence
6676                     (cdr (assq 'tick (setq marked (nth 3 info))))))
6677              (setq gnus-newsgroup-replied 
6678                    (copy-sequence (cdr (assq 'reply marked))))
6679              (setq gnus-newsgroup-expirable
6680                    (copy-sequence (cdr (assq 'expire marked))))
6681              (setq gnus-newsgroup-killed
6682                    (copy-sequence (cdr (assq 'killed marked))))
6683              (setq gnus-newsgroup-bookmarks 
6684                    (copy-sequence (cdr (assq 'bookmark marked))))
6685              (setq gnus-newsgroup-dormant 
6686                    (copy-sequence (cdr (assq 'dormant marked))))
6687              (setq gnus-newsgroup-scored 
6688                    (copy-sequence (cdr (assq 'score marked))))
6689              (setq gnus-newsgroup-processable nil)))
6690       ;; Check whether auto-expire is to be done in this group.
6691       (setq gnus-newsgroup-auto-expire
6692             (or (and (stringp gnus-auto-expirable-newsgroups)
6693                      (string-match gnus-auto-expirable-newsgroups group))
6694                 (memq 'auto-expire (nth 5 info))))
6695       ;; First and last article in this newsgroup.
6696       (and gnus-newsgroup-headers
6697            (setq gnus-newsgroup-begin 
6698                  (header-number (car gnus-newsgroup-headers)))
6699            (setq gnus-newsgroup-end
6700                  (header-number (gnus-last-element gnus-newsgroup-headers))))
6701       (setq gnus-reffed-article-number -1)
6702       ;; GROUP is successfully selected.
6703       (or gnus-newsgroup-headers t)))))
6704
6705 (defun gnus-articles-to-read (group read-all)
6706   ;; Find out what articles the user wants to read.
6707   (let* ((articles
6708           ;; Select all articles if `read-all' is non-nil, or if all the
6709           ;; unread articles are dormant articles.
6710           (if (or (and read-all (not (numberp read-all)))
6711                   (= (length gnus-newsgroup-unreads) 
6712                      (length gnus-newsgroup-dormant)))
6713               (gnus-uncompress-range 
6714                (gnus-gethash group gnus-active-hashtb))
6715             gnus-newsgroup-unreads))
6716          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
6717          (scored (length scored-list))
6718          (number (length articles))
6719          (marked (+ (length gnus-newsgroup-marked)
6720                     (length gnus-newsgroup-dormant)))
6721          (select
6722           (cond 
6723            ((numberp read-all)
6724             read-all)
6725            (t
6726             (condition-case ()
6727                 (cond ((and (or (<= scored marked)
6728                                 (= scored number))
6729                             (numberp gnus-large-newsgroup)
6730                             (> number gnus-large-newsgroup))
6731                        (let ((input
6732                               (read-string
6733                                (format
6734                                 "How many articles from %s (default %d): "
6735                                 gnus-newsgroup-name number))))
6736                          (if (string-match "^[ \t]*$" input)
6737                              number input)))
6738                       ((and (> scored marked) (< scored number))
6739                        (let ((input
6740                               (read-string
6741                                (format 
6742                                 "%s %s (%d scored, %d total): "
6743                                 "How many articles from"
6744                                 group scored number))))
6745                          (if (string-match "^[ \t]*$" input)
6746                              number input)))
6747                       (t number))
6748               (quit nil))))))
6749     (setq select (if (stringp select) (string-to-number select) select))
6750     (if (or (null select) (zerop select))
6751         select
6752       (if (and (not (zerop scored)) (<= (abs select) scored))
6753           (progn
6754             (setq articles (sort scored-list '<))
6755             (setq number (length articles)))
6756         (setq articles (copy-sequence articles)))
6757
6758       (if (< (abs select) number)
6759           (if (< select 0) 
6760               ;; Select the N oldest articles.
6761               (setcdr (nthcdr (1- (abs select)) articles) nil)
6762             ;; Select the N most recent articles.
6763             (setq articles (nthcdr (- number select) articles))))
6764       (setq gnus-newsgroup-unselected
6765             (gnus-sorted-intersection
6766              gnus-newsgroup-unreads
6767              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
6768       articles)))
6769
6770 (defun gnus-killed-articles (killed articles)
6771   (let (out)
6772     (while articles
6773       (if (inline (gnus-member-of-range (car articles) killed))
6774           (setq out (cons (car articles) out)))
6775       (setq articles (cdr articles)))
6776     out))
6777
6778 (defun gnus-adjust-marked-articles (info &optional active)
6779   "Remove all marked articles that are no longer legal."
6780   (let ((marked-lists (nth 3 info))
6781         (active (or active (gnus-gethash (car info) gnus-active-hashtb)))
6782         m prev)
6783     ;; There are many types of marked articles.
6784     (while marked-lists
6785       (setq m (cdr (setq prev (car marked-lists))))
6786       (cond ((or (eq 'tick (car prev)) (eq 'dormant (car prev)))
6787              ;; Make sure that all ticked articles are a subset of the
6788              ;; unread/unselected articles.
6789              (while m
6790                (if (or (memq (car m) gnus-newsgroup-unreads)
6791                        (memq (car m) gnus-newsgroup-unselected))
6792                    (setq prev m)
6793                  (setcdr prev (cdr m)))
6794                (setq m (cdr m))))
6795             ((eq 'score (car prev))
6796              ;; Scored articles should be a subset of
6797              ;; unread/unselected articles. 
6798              (while m
6799                (if (or (memq (car (car m)) gnus-newsgroup-unreads)
6800                        (memq (car (car m)) gnus-newsgroup-unreads))
6801                    (setq prev m)
6802                  (setcdr prev (cdr m)))
6803                (setq m (cdr m))))
6804             ((eq 'bookmark (car prev))
6805              ;; Bookmarks should be a subset of active articles.
6806              (while m
6807                (if (< (car (car m)) (car active))
6808                    (setcdr prev (cdr m))
6809                  (setq prev m))
6810                (setq m (cdr m))))
6811             ((eq 'killed (car prev))
6812              ;; Articles that have been through the kill process are
6813              ;; to be a subset of active articles.
6814              (while (and m (< (or (and (numberp (car m)) (car m))
6815                                   (cdr (car m)))
6816                               (car active)))
6817                (setcdr prev (cdr m))
6818                (setq m (cdr m)))
6819              (if (and m (< (or (and (numberp (car m)) (car m))
6820                                (car (car m)))
6821                            (car active))) 
6822                  (setcar (if (numberp (car m)) m (car m)) (car active))))
6823             ((or (eq 'reply (car prev)) (eq 'expire (car prev)))
6824              ;; The replied and expirable articles have to be articles
6825              ;; that are active. 
6826              (while m
6827                (if (< (car m) (car active))
6828                    (setcdr prev (cdr m))
6829                  (setq prev m))
6830                (setq m (cdr m)))))
6831       (setq marked-lists (cdr marked-lists)))
6832     ;; Remove all lists that are empty.
6833     (setq marked-lists (nth 3 info))
6834     (if marked-lists
6835         (progn
6836           (while (= 1 (length (car marked-lists)))
6837             (setq marked-lists (cdr marked-lists)))
6838           (setq m (cdr (setq prev marked-lists)))
6839           (while m
6840             (if (= 1 (length (car m)))
6841                 (setcdr prev (cdr m))
6842               (setq prev m))
6843             (setq m (cdr m)))
6844           (setcar (nthcdr 3 info) marked-lists)))
6845     ;; Finally, if there are no marked lists at all left, and if there
6846     ;; are no elements after the lists in the info list, we just chop
6847     ;; the info list off before the marked lists.
6848     (and (null marked-lists) 
6849          (not (nthcdr 4 info))
6850          (setcdr (nthcdr 2 info) nil)))
6851   info)
6852
6853 (defun gnus-set-marked-articles 
6854   (info ticked replied expirable killed dormant bookmark score) 
6855   "Enter the various lists of marked articles into the newsgroup info list."
6856   (let (newmarked)
6857     (and ticked (setq newmarked (cons (cons 'tick ticked) nil)))
6858     (and replied (setq newmarked (cons (cons 'reply replied) newmarked)))
6859     (and expirable (setq newmarked (cons (cons 'expire expirable) 
6860                                          newmarked)))
6861     (and killed (setq newmarked (cons (cons 'killed killed) newmarked)))
6862     (and dormant (setq newmarked (cons (cons 'dormant dormant) newmarked)))
6863     (and bookmark (setq newmarked (cons (cons 'bookmark bookmark) 
6864                                         newmarked)))
6865     (and score (setq newmarked (cons (cons 'score score) newmarked)))
6866     (if (nthcdr 3 info)
6867         (progn
6868           (setcar (nthcdr 3 info) newmarked)
6869           (and (not newmarked)
6870                (not (nthcdr 4 info))
6871                (setcdr (nthcdr 2 info) nil)))
6872       (if newmarked
6873           (setcdr (nthcdr 2 info) (list newmarked))))))
6874
6875 (defun gnus-add-marked-articles (group type articles &optional info force)
6876   ;; Add ARTICLES of TYPE to the info of GROUP.
6877   ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't
6878   ;; add, but replace marked articles of TYPE with ARTICLES.
6879   (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
6880         marked m)
6881     (or (not info)
6882         (and (not (setq marked (nthcdr 3 info)))
6883              (setcdr (nthcdr 2 info) (list (list (cons type articles)))))
6884         (and (not (setq m (assq type (car marked))))
6885              (setcar marked (cons (cons type articles) (car marked))))
6886         (if force
6887             (setcdr m articles)
6888           (nconc m articles)))))
6889          
6890 (defun gnus-set-mode-line (where)
6891   "This function sets the mode line of the article or summary buffers.
6892 If WHERE is `summary', the summary mode line format will be used."
6893   (if (memq where gnus-updated-mode-lines)
6894       (let (mode-string)
6895         (save-excursion
6896           (set-buffer gnus-summary-buffer)
6897           (let* ((mformat (if (eq where 'article) 
6898                               gnus-article-mode-line-format-spec
6899                             gnus-summary-mode-line-format-spec))
6900                  (group-name gnus-newsgroup-name)
6901                  (article-number (or gnus-current-article 0))
6902                  (unread (- (length gnus-newsgroup-unreads)
6903                             (length gnus-newsgroup-dormant)))
6904                  (unread-and-unticked 
6905                   (- unread (length gnus-newsgroup-marked)))
6906                  (unselected (length gnus-newsgroup-unselected))
6907                  (unread-and-unselected
6908                   (cond ((and (zerop unread-and-unticked)
6909                               (zerop unselected)) "")
6910                         ((zerop unselected) 
6911                          (format "{%d more}" unread-and-unticked))
6912                         (t (format "{%d(+%d) more}"
6913                                    unread-and-unticked unselected))))
6914                  (subject
6915                   (if gnus-current-headers
6916                       (header-subject gnus-current-headers) ""))
6917                  (max-len (and gnus-mode-non-string-length
6918                                (- (frame-width) gnus-mode-non-string-length)))
6919                  header) ;; passed as argument to any user-format-funcs
6920             (setq mode-string (eval mformat))
6921             (or (numberp max-len)
6922                 (setq max-len (length mode-string)))
6923             (if (< max-len 4) (setq max-len 4))
6924             (if (> (length mode-string) max-len)
6925                 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
6926                 ;;  function `substring' might cut on a middle
6927                 ;;  of multi-octet character.
6928                 (setq mode-string 
6929                       (concat (gnus-truncate-string mode-string (- max-len 3))
6930                               "...")))
6931             (setq mode-string (format (format "%%-%ds" max-len)
6932                                       mode-string))))
6933         (setq mode-line-buffer-identification mode-string)
6934         (set-buffer-modified-p t))))
6935
6936 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6937   "Go through the HEADERS list and add all Xrefs to a hash table.
6938 The resulting hash table is returned, or nil if no Xrefs were found."
6939   (let* ((from-method (gnus-find-method-for-group from-newsgroup))
6940          (prefix (if (and 
6941                       (gnus-group-foreign-p from-newsgroup)
6942                       (not (memq 'virtual 
6943                                  (assoc (symbol-name (car from-method))
6944                                         gnus-valid-select-methods))))
6945                      (gnus-group-real-prefix from-newsgroup)))
6946          (xref-hashtb (make-vector 63 0))
6947          start group entry number xrefs header)
6948     (while headers
6949       (setq header (car headers))
6950       (if (and (setq xrefs (header-xref header))
6951                (not (memq (header-number header) unreads)))
6952           (progn
6953             (setq start 0)
6954             (while (string-match "\\([^ ]+\\):\\([0-9]+\\)" xrefs start)
6955               (setq start (match-end 0))
6956               (setq group (concat prefix (substring xrefs (match-beginning 1) 
6957                                                     (match-end 1))))
6958               (setq number 
6959                     (string-to-int (substring xrefs (match-beginning 2) 
6960                                               (match-end 2))))
6961               (if (setq entry (gnus-gethash group xref-hashtb))
6962                   (setcdr entry (cons number (cdr entry)))
6963                 (gnus-sethash group (cons number nil) xref-hashtb)))))
6964       (setq headers (cdr headers)))
6965     (if start xref-hashtb nil)))
6966
6967 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads expirable)
6968   "Look through all the headers and mark the Xrefs as read."
6969   (let ((virtual (memq 'virtual 
6970                        (assoc (symbol-name (car (gnus-find-method-for-group 
6971                                                  from-newsgroup)))
6972                               gnus-valid-select-methods)))
6973         name entry info xref-hashtb idlist method
6974         nth4)
6975     (save-excursion
6976       (set-buffer gnus-group-buffer)
6977       (if (setq xref-hashtb 
6978                 (gnus-create-xref-hashtb from-newsgroup headers unreads))
6979           (mapatoms 
6980            (lambda (group)
6981              (if (string= from-newsgroup (setq name (symbol-name group)))
6982                  ()
6983                (setq idlist (symbol-value group))
6984                ;; Dead groups are not updated.
6985                (if (and (prog1 
6986                             (setq entry (gnus-gethash name gnus-newsrc-hashtb)
6987                                   info (nth 2 entry))
6988                           (if (stringp (setq nth4 (nth 4 info)))
6989                               (setq nth4 (gnus-server-to-method nth4))))
6990                         ;; Only do the xrefs if the group has the same
6991                         ;; select method as the group we have just read.
6992                         (or (gnus-methods-equal-p 
6993                              nth4 (gnus-find-method-for-group from-newsgroup))
6994                             virtual
6995                             (equal nth4 
6996                                    (setq method (gnus-find-method-for-group 
6997                                                  from-newsgroup)))
6998                             (and (equal (car nth4) (car method))
6999                                  (equal (nth 1 nth4) (nth 1 method))))
7000                         gnus-use-cross-reference
7001                         (or (not (eq gnus-use-cross-reference t))
7002                             virtual
7003                             ;; Only do cross-references on subscribed
7004                             ;; groups, if that is what is wanted.  
7005                             (<= (nth 1 info) gnus-level-subscribed)))
7006                    (gnus-group-make-articles-read name idlist expirable))))
7007            xref-hashtb)))))
7008
7009 (defun gnus-group-make-articles-read (group articles expirable)
7010   (let* ((num 0)
7011          (entry (gnus-gethash group gnus-newsrc-hashtb))
7012          (info (nth 2 entry))
7013          (active (gnus-gethash group gnus-active-hashtb))
7014          exps expirable range)
7015     ;; First peel off all illegal article numbers.
7016     (if active
7017         (let ((ids articles)
7018               (ticked (cdr (assq 'tick (nth 3 info))))
7019               (dormant (cdr (assq 'dormant (nth 3 info))))
7020               id)
7021           (setq exps nil)
7022           (while ids
7023             (setq id (car ids))
7024             (if (or (> id (cdr active))
7025                     (< id (car active))
7026                     (memq id ticked)
7027                     (memq id dormant))
7028                 (setq articles (delq id articles)))
7029             (and (memq id expirable)
7030                  (setq exps (cons id exps)))
7031             (setq ids (cdr ids)))))
7032     ;; Update expirable articles.
7033     (gnus-add-marked-articles nil 'expirable exps info)
7034     (and active
7035          (null (nth 2 info))
7036          (> (car active) 1)
7037          (setcar (nthcdr 2 info) (cons 1 (1- (car active)))))
7038     (setcar (nthcdr 2 info)
7039             (setq range
7040                   (gnus-add-to-range 
7041                    (nth 2 info) 
7042                    (setq articles (sort articles '<)))))
7043     ;; Then we have to re-compute how many unread
7044     ;; articles there are in this group.
7045     (if active
7046         (progn
7047           (cond 
7048            ((not range)
7049             (setq num (- (1+ (cdr active)) (car active))))
7050            ((not (listp (cdr range)))
7051             (setq num (- (cdr active) (- (1+ (cdr range)) 
7052                                          (car range)))))
7053            (t
7054             (while range
7055               (if (numberp (car range))
7056                   (setq num (1+ num))
7057                 (setq num (+ num (- (1+ (cdr (car range)))
7058                                     (car (car range))))))
7059               (setq range (cdr range)))
7060             (setq num (- (cdr active) num))))
7061           ;; Update the number of unread articles.
7062           (setcar 
7063            entry 
7064            (max 0 (- num 
7065                      (length (cdr (assq 'tick (nth 3 info))))
7066                      (length 
7067                       (cdr (assq 'dormant (nth 3 info)))))))
7068           ;; Update the group buffer.
7069           (gnus-group-update-group group t)))))
7070
7071 (defun gnus-methods-equal-p (m1 m2)
7072   (let ((m1 (or m1 gnus-select-method))
7073         (m2 (or m2 gnus-select-method)))
7074     (or (equal m1 m2)
7075         (and (eq (car m1) (car m2))
7076              (or (not (memq 'address (assoc (symbol-name (car m1))
7077                                             gnus-valid-select-methods)))
7078                  (equal (nth 1 m1) (nth 1 m2)))))))
7079
7080 (defsubst gnus-header-value ()
7081   (buffer-substring (match-end 0) (gnus-point-at-eol)))
7082
7083 (defvar gnus-newsgroup-none-id 0)
7084
7085 (defun gnus-get-newsgroup-headers ()
7086   (setq gnus-article-internal-prepare-hook nil)
7087   (let ((cur nntp-server-buffer)
7088         (dependencies gnus-newsgroup-dependencies)
7089         headers id dep end ref)
7090     (save-excursion
7091       (set-buffer nntp-server-buffer)
7092       (goto-char (point-min))
7093       ;; Search to the beginning of the next header. Error messages
7094       ;; do not begin with 2 or 3.
7095       (while (re-search-forward "^[23][0-9]+ " nil t)
7096         (let ((header (make-vector 9 nil))
7097               (case-fold-search t)
7098               (p (point))
7099               in-reply-to)
7100           (setq id nil
7101                 ref nil)
7102           (header-set-number header (read cur))
7103           ;; This implementation of this function, with nine
7104           ;; search-forwards instead of the one re-search-forward and
7105           ;; a case (which basically was the old function) is actually
7106           ;; about twice as fast, even though it looks messier. You
7107           ;; can't have everything, I guess. Speed and elegance
7108           ;; doesn't always come hand in hand.
7109           (save-restriction
7110             (narrow-to-region (point) (or (save-excursion 
7111                                             (search-forward "\n.\n" nil t))
7112                                           (point)))
7113             (if (search-forward "\nfrom: " nil t)
7114                 (header-set-from header (gnus-header-value))
7115               (header-set-from header "(nobody)"))
7116             (goto-char p)
7117             (if (search-forward "\nsubject: " nil t)
7118                 (header-set-subject header (gnus-header-value))
7119               (header-set-subject header "(none)"))
7120             (goto-char p)
7121             (and (search-forward "\nxref: " nil t)
7122                  (header-set-xref header (gnus-header-value)))
7123             (goto-char p)
7124             (or (numberp (and (search-forward "\nlines: " nil t)
7125                               (header-set-lines header (read cur))))
7126                 (header-set-lines header 0))
7127             (goto-char p)
7128             (and (search-forward "\ndate: " nil t)
7129                  (header-set-date header (gnus-header-value)))
7130             (goto-char p)
7131             (if (search-forward "\nmessage-id: " nil t)
7132                 (header-set-id header (setq id (gnus-header-value)))
7133               ;; If there was no message-id, we just fake one to make
7134               ;; subsequent routines simpler.
7135               (header-set-id 
7136                header 
7137                (setq id (concat "none+" 
7138                                 (int-to-string 
7139                                  (setq gnus-newsgroup-none-id 
7140                                        (1+ gnus-newsgroup-none-id)))))))
7141             (goto-char p)
7142             (if (search-forward "\nreferences: " nil t)
7143                 (progn
7144                   (header-set-references header (gnus-header-value))
7145                   (setq end (match-end 0))
7146                   (save-excursion
7147                     (setq ref 
7148                           (downcase
7149                            (buffer-substring
7150                             (progn 
7151                               (end-of-line)
7152                               (search-backward ">" end t)
7153                               (1+ (point)))
7154                             (progn
7155                               (search-backward "<" end t)
7156                               (point)))))))
7157               ;; Get the references from the in-reply-to header if there
7158               ;; ware no references and the in-reply-to header looks
7159               ;; promising. 
7160               (if (and (search-forward "\nin-reply-to: " nil t)
7161                        (setq in-reply-to (gnus-header-value))
7162                        (string-match "<[^>]+>" in-reply-to))
7163                   (progn
7164                     (header-set-references 
7165                      header 
7166                      (setq ref (substring in-reply-to (match-beginning 0)
7167                                           (match-end 0))))
7168                     (setq ref (downcase ref)))
7169                 (setq ref "none")))
7170             ;; We do some threading while we read the headers. The
7171             ;; message-id and the last reference are both entered into
7172             ;; the same hash table. Some tippy-toeing around has to be
7173             ;; done in case an article has arrived before the article
7174             ;; which it refers to.
7175             (if (boundp (setq dep (intern (downcase id) dependencies)))
7176                 (if (car (symbol-value dep))
7177                     ;; An article with this Message-ID has already
7178                     ;; been seen, so we ignore this one, except we add
7179                     ;; any additional Xrefs (in case the two articles
7180                     ;; came from different servers.
7181                     (progn
7182                       (header-set-xref 
7183                        (car (symbol-value dep))
7184                        (concat (or (header-xref (car (symbol-value dep))) "")
7185                                (or (header-xref header) "")))
7186                       (setq header nil))
7187                   (setcar (symbol-value dep) header))
7188               (set dep (list header)))
7189             (if header
7190                 (progn
7191                   (if (boundp (setq dep (intern ref dependencies)))
7192                       (setcdr (symbol-value dep) 
7193                               (cons header (cdr (symbol-value dep))))
7194                     (set dep (list nil header)))
7195                   (setq headers (cons header headers))))
7196             (goto-char (point-max))))))
7197     (nreverse headers)))
7198
7199 ;; The following macros and functions were written by Felix Lee
7200 ;; <flee@cse.psu.edu>. 
7201
7202 (defmacro gnus-nov-read-integer ()
7203   '(prog1
7204        (if (= (following-char) ?\t)
7205            0
7206          (let ((num (condition-case nil (read buffer) (error nil))))
7207            (if (numberp num) num 0)))
7208      (or (eobp) (forward-char 1))))
7209
7210 (defmacro gnus-nov-skip-field ()
7211   '(search-forward "\t" eol 'move))
7212
7213 (defmacro gnus-nov-field ()
7214   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
7215
7216 ;; Goes through the xover lines and returns a list of vectors
7217 (defun gnus-get-newsgroup-headers-xover (sequence)
7218   "Parse the news overview data in the server buffer, and return a
7219 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
7220   ;; Get the Xref when the users reads the articles since most/some
7221   ;; NNTP servers do not include Xrefs when using XOVER.
7222   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
7223   (let ((cur nntp-server-buffer)
7224         (dependencies gnus-newsgroup-dependencies)
7225         number headers header)
7226     (save-excursion
7227       (set-buffer nntp-server-buffer)
7228       (goto-char (point-min))
7229       (while (and sequence (not (eobp)))
7230         (setq number (read cur))
7231         (while (and sequence (< (car sequence) number))
7232           (setq sequence (cdr sequence)))
7233         (and sequence 
7234              (eq number (car sequence))
7235              (progn
7236                (setq sequence (cdr sequence))
7237                (if (setq header 
7238                          (inline (gnus-nov-parse-line number dependencies)))
7239                    (setq headers (cons header headers)))))
7240         (forward-line 1))
7241       (setq headers (nreverse headers)))
7242     headers))
7243
7244 ;; This function has to be called with point after the article number
7245 ;; on the beginning of the line.
7246 (defun gnus-nov-parse-line (number dependencies)
7247   (let ((none 0)
7248         (eol (gnus-point-at-eol)) 
7249         (buffer (current-buffer))
7250         header ref id dep)
7251
7252     ;; overview: [num subject from date id refs chars lines misc]
7253     (narrow-to-region (point) eol)
7254     (forward-char)
7255
7256     (condition-case nil
7257         (setq header
7258               (vector 
7259                number                   ; number
7260                (gnus-nov-field)         ; subject
7261                (gnus-nov-field)         ; from
7262                (gnus-nov-field)         ; date
7263                (setq id (or (gnus-nov-field)
7264                             (concat "none+"
7265                                     (int-to-string 
7266                                      (setq none (1+ none)))))) ; id
7267                (progn
7268                  (save-excursion
7269                    (let ((beg (point)))
7270                      (search-forward "\t" eol)
7271                      (if (search-backward ">" beg t)
7272                          (setq ref 
7273                                (downcase 
7274                                 (buffer-substring 
7275                                  (1+ (point))
7276                                  (progn
7277                                    (search-backward "<" beg t)
7278                                    (point)))))
7279                        (setq ref nil))))
7280                  (gnus-nov-field))      ; refs
7281                (gnus-nov-read-integer)  ; chars
7282                (gnus-nov-read-integer)  ; lines
7283                (if (= (following-char) ?\n)
7284                    nil
7285                  (gnus-nov-field))      ; misc
7286                ))
7287       (error (progn 
7288                (ding)
7289                (message "Strange nov line.")
7290                (setq header nil)
7291                (goto-char eol))))
7292
7293     (widen)
7294
7295     ;; We build the thread tree.
7296     (and header
7297          (if (boundp (setq dep (intern (downcase id) dependencies)))
7298              (if (car (symbol-value dep))
7299                  ;; An article with this Message-ID has already been seen,
7300                  ;; so we ignore this one, except we add any additional
7301                  ;; Xrefs (in case the two articles came from different
7302                  ;; servers.
7303                  (progn
7304                    (header-set-xref 
7305                     (car (symbol-value dep))
7306                     (concat (or (header-xref (car (symbol-value dep))) "")
7307                             (or (header-xref header) "")))
7308                    (setq header nil))
7309                (setcar (symbol-value dep) header))
7310            (set dep (list header))))
7311     (if header
7312         (progn
7313           (if (boundp (setq dep (intern (or ref "none") 
7314                                         dependencies)))
7315               (setcdr (symbol-value dep) 
7316                       (cons header (cdr (symbol-value dep))))
7317             (set dep (list nil header)))))
7318     header))
7319
7320 (defun gnus-article-get-xrefs ()
7321   "Fill in the Xref value in `gnus-current-headers', if necessary.
7322 This is meant to be called in `gnus-article-internal-prepare-hook'."
7323   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
7324                                  gnus-current-headers)))
7325     (or (not gnus-use-cross-reference)
7326         (not headers)
7327         (and (header-xref headers)
7328              (not (string= (header-xref headers) "")))
7329         (let ((case-fold-search t)
7330               xref)
7331           (save-restriction
7332             (gnus-narrow-to-headers)
7333             (goto-char (point-min))
7334             (if (or (and (eq (downcase (following-char)) ?x)
7335                          (looking-at "Xref:"))
7336                     (search-forward "\nXref:" nil t))
7337                 (progn
7338                   (goto-char (1+ (match-end 0)))
7339                   (setq xref (buffer-substring (point) 
7340                                                (progn (end-of-line) (point))))
7341                   (header-set-xref headers xref))))))))
7342
7343 (defalias 'gnus-find-header-by-number 'gnus-get-header-by-number)
7344 (make-obsolete 'gnus-find-header-by-number 'gnus-get-header-by-number)
7345
7346 (defun gnus-make-headers-hashtable-by-number ()
7347   "Make hashtable for the variable gnus-newsgroup-headers by number."
7348   (save-excursion
7349     (set-buffer gnus-summary-buffer)
7350     (let ((headers gnus-newsgroup-headers)
7351           header)
7352       (setq gnus-newsgroup-headers-hashtb-by-number
7353             (gnus-make-hashtable (length headers)))
7354       (while headers
7355         (setq header (car headers))
7356         (gnus-sethash (int-to-string (header-number header))
7357                       header gnus-newsgroup-headers-hashtb-by-number)
7358         (setq headers (cdr headers))))))
7359
7360 (defun gnus-more-header-backward ()
7361   "Find new header backward."
7362   (let ((first (car (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7363         (artnum gnus-newsgroup-begin)
7364         (header nil))
7365     (while (and (not header)
7366                 (> artnum first))
7367       (setq artnum (1- artnum))
7368       (setq header (gnus-read-header artnum)))
7369     header))
7370
7371 (defun gnus-more-header-forward (&optional backward)
7372   "Find new header forward.
7373 If BACKWARD, find new header backward instead."
7374   (if backward
7375       (gnus-more-header-backward)
7376     (let ((last (cdr (gnus-gethash gnus-newsgroup-name gnus-active-hashtb)))
7377           (artnum gnus-newsgroup-end)
7378           (header nil))
7379       (while (and (not header)
7380                   (< artnum last))
7381         (setq artnum (1+ artnum))
7382         (setq header (gnus-read-header artnum)))
7383       header)))
7384
7385 (defun gnus-extend-newsgroup (header &optional backward)
7386   "Extend newsgroup selection with HEADER.
7387 Optional argument BACKWARD means extend toward backward."
7388   (if header
7389       (let ((artnum (header-number header)))
7390         (setq gnus-newsgroup-headers
7391               (if backward
7392                   (cons header gnus-newsgroup-headers)
7393                 (nconc gnus-newsgroup-headers (list header))))
7394         (setq gnus-newsgroup-unselected
7395               (delq artnum gnus-newsgroup-unselected))
7396         (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum))
7397         (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum)))))
7398
7399 (defun gnus-summary-work-articles (n)
7400   "Return a list of articles to be worked upon. The prefix argument,
7401 the list of process marked articles, and the current article will be
7402 taken into consideration."
7403   (let (articles)
7404     (if (and n (numberp n))
7405         (let ((backward (< n 0))
7406               (n (abs n)))
7407           (save-excursion
7408             (while (and (> n 0)
7409                         (setq articles (cons (gnus-summary-article-number) 
7410                                              articles))
7411                         (gnus-summary-search-forward nil nil backward))
7412               (setq n (1- n))))
7413           (sort articles (function <)))
7414       (or (reverse gnus-newsgroup-processable)
7415           (list (gnus-summary-article-number))))))
7416
7417 (defun gnus-summary-search-group (&optional backward use-level)
7418   "Search for next unread newsgroup.
7419 If optional argument BACKWARD is non-nil, search backward instead."
7420   (save-excursion
7421     (set-buffer gnus-group-buffer)
7422     (if (gnus-group-search-forward 
7423          backward nil (if use-level (gnus-group-group-level) nil))
7424         (gnus-group-group-name))))
7425
7426 (defun gnus-summary-best-group (&optional exclude-group)
7427   "Find the name of the best unread group.
7428 If EXCLUDE-GROUP, do not go to this group."
7429   (save-excursion
7430     (set-buffer gnus-group-buffer)
7431     (save-excursion
7432       (gnus-group-best-unread-group exclude-group))))
7433
7434 (defun gnus-subject-equal (s1 s2)
7435   (cond
7436    ((null gnus-summary-gather-subject-limit)
7437     (equal (gnus-simplify-subject-re s1)
7438            (gnus-simplify-subject-re s2)))
7439    ((eq gnus-summary-gather-subject-limit 'fuzzy)
7440     (equal (gnus-simplify-subject-fuzzy s1)
7441            (gnus-simplify-subject-fuzzy s2)))
7442    ((numberp gnus-summary-gather-subject-limit)
7443     (equal (gnus-limit-string s1 gnus-summary-gather-subject-limit)
7444            (gnus-limit-string s2 gnus-summary-gather-subject-limit)))
7445    (t
7446     (equal s1 s2))))
7447     
7448 (defun gnus-summary-search-subject (&optional backward unread subject)
7449   "Search for article forward.
7450 If BACKWARD is non-nil, search backward.
7451 If UNREAD is non-nil, only unread articles are selected.
7452 If SUBJECT is non-nil, the article which has the same subject will be
7453 searched for." 
7454   (let ((func (if backward 'previous-single-property-change
7455                 'next-single-property-change))
7456         (beg (point))
7457         (did t)
7458         pos psubject)
7459     (beginning-of-line)
7460     (and gnus-summary-check-current unread
7461          (eq (get-text-property (point) 'gnus-mark) gnus-unread-mark)
7462          (setq did nil))
7463     (if (not did)
7464         ()
7465       (forward-char (if backward (if (bobp) 0 -1) (if (eobp) 0 1)))
7466       (while
7467           (and 
7468            (setq pos (funcall func (point) 'gnus-number))
7469            (goto-char (if backward (1- pos) pos))
7470            (setq did
7471                  (not (and
7472                        (or (not unread)
7473                            (eq (get-text-property (point) 'gnus-mark)
7474                                gnus-unread-mark))
7475                        (or (not subject)
7476                            (and (setq psubject (inline (gnus-summary-subject-string)))
7477                                 (inline (gnus-subject-equal subject psubject)))))))
7478            (if backward (if (bobp) nil (forward-char -1) t)
7479              (if (eobp) nil (forward-char 1) t)))))
7480     (if did
7481         (progn (goto-char beg) nil)
7482       (prog1
7483           (get-text-property (point) 'gnus-number)
7484         (gnus-summary-position-cursor)))))
7485
7486 (defun gnus-summary-pseudo-article ()
7487   "The thread level of the article on the current line."
7488   (get-text-property (gnus-point-at-bol) 'gnus-pseudo))
7489
7490 (defalias 'gnus-summary-score 'gnus-summary-article-score)
7491 (make-obsolete 'gnus-summary-score 'gnus-summary-article-score)
7492 (defun gnus-summary-article-score ()
7493   "Return current article score."
7494   (or (cdr (assq (gnus-summary-article-number) gnus-newsgroup-scored))
7495       gnus-summary-default-score 0))
7496
7497 (defun gnus-summary-recenter ()
7498   "Center point in the summary window.
7499 If `gnus-auto-center-summary' is nil, or the article buffer isn't
7500 displayed, no centering will be performed." 
7501   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
7502   ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu.
7503   (let* ((top (cond ((< (window-height) 4) 0)
7504                     ((< (window-height) 7) 1)
7505                     (t 2)))
7506          (height (1- (window-height)))
7507          (bottom (save-excursion (goto-char (point-max))
7508                                  (forward-line (- height))
7509                                  (point)))
7510          (window (get-buffer-window (current-buffer))))
7511     (and 
7512      ;; The user has to want it,
7513      gnus-auto-center-summary 
7514      ;; the article buffer must be displayed,
7515      (get-buffer-window gnus-article-buffer)
7516      ;; Set the window start to either `bottom', which is the biggest
7517      ;; possible valid number, or the second line from the top,
7518      ;; whichever is the least.
7519      (set-window-start
7520       window (min bottom (save-excursion (forward-line (- top)) (point)))))))
7521
7522 ;; Function written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
7523 (defun gnus-short-group-name (group &optional levels)
7524   "Collapse GROUP name LEVELS."
7525   (let* ((name "") (foreign "") (depth -1) (skip 1)
7526          (levels (or levels
7527                      (progn
7528                        (while (string-match "\\." group skip)
7529                          (setq skip (match-end 0)
7530                                depth (+ depth 1)))
7531                        depth))))
7532     (if (string-match ":" group)
7533         (setq foreign (substring group 0 (match-end 0))
7534               group (substring group (match-end 0))))
7535     (while group
7536       (if (and (string-match "\\." group) (> levels 0))
7537           (setq name (concat name (substring group 0 1))
7538                 group (substring group (match-end 0))
7539                 levels (- levels 1)
7540                 name (concat name "."))
7541         (setq name (concat foreign name group)
7542               group nil)))
7543     name))
7544
7545 (defun gnus-summary-jump-to-group (newsgroup)
7546   "Move point to NEWSGROUP in group mode buffer."
7547   ;; Keep update point of group mode buffer if visible.
7548   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
7549       (save-window-excursion
7550         ;; Take care of tree window mode.
7551         (if (get-buffer-window gnus-group-buffer)
7552             (pop-to-buffer gnus-group-buffer))
7553         (gnus-group-jump-to-group newsgroup))
7554     (save-excursion
7555       ;; Take care of tree window mode.
7556       (if (get-buffer-window gnus-group-buffer)
7557           (pop-to-buffer gnus-group-buffer)
7558         (set-buffer gnus-group-buffer))
7559       (gnus-group-jump-to-group newsgroup))))
7560
7561 ;; This function returns a list of article numbers based on the
7562 ;; difference between the ranges of read articles in this group and
7563 ;; the range of active articles.
7564 (defun gnus-list-of-unread-articles (group)
7565   (let* ((read (nth 2 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
7566          (active (gnus-gethash group gnus-active-hashtb))
7567          (last (cdr active))
7568          first nlast unread)
7569     ;; If none are read, then all are unread. 
7570     (if (not read)
7571         (setq first (car active))
7572       ;; If the range of read articles is a single range, then the
7573       ;; first unread article is the article after the last read
7574       ;; article. Sounds logical, doesn't it?
7575       (if (not (listp (cdr read)))
7576           (setq first (1+ (cdr read)))
7577         ;; `read' is a list of ranges.
7578         (if (/= (setq nlast (or (and (numberp (car read)) (car read)) 
7579                                 (car (car read)))) 1)
7580             (setq first 1))
7581         (while read
7582           (if first 
7583               (while (< first nlast)
7584                 (setq unread (cons first unread))
7585                 (setq first (1+ first))))
7586           (setq first (1+ (if (atom (car read)) (car read) (cdr (car read)))))
7587           (setq nlast (if (atom (car (cdr read))) 
7588                           (car (cdr read))
7589                         (car (car (cdr read)))))
7590           (setq read (cdr read)))))
7591     ;; And add the last unread articles.
7592     (while (<= first last)
7593       (setq unread (cons first unread))
7594       (setq first (1+ first)))
7595     ;; Return the list of unread articles.
7596     (nreverse unread)))
7597
7598 (defun gnus-list-of-read-articles (group)
7599   (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
7600         (active (gnus-gethash group gnus-active-hashtb)))
7601     (and info active
7602          (gnus-sorted-complement 
7603           (gnus-uncompress-range active) 
7604           (gnus-list-of-unread-articles group)))))
7605
7606 ;; Various summary commands
7607
7608 (defun gnus-summary-universal-argument ()
7609   "Perform any operation on all articles marked with the process mark."
7610   (interactive)
7611   (gnus-set-global-variables)
7612   (let ((articles (reverse gnus-newsgroup-processable))
7613         func)
7614     (or articles (error "No articles marked"))
7615     (or (setq func (key-binding (read-key-sequence "C-c C-u")))
7616         (error "Undefined key"))
7617     (while articles
7618       (gnus-summary-goto-subject (car articles))
7619       (command-execute func)
7620       (gnus-summary-remove-process-mark (car articles))
7621       (setq articles (cdr articles)))))
7622
7623 (defun gnus-summary-toggle-truncation (&optional arg)
7624   "Toggle truncation of summary lines.
7625 With arg, turn line truncation on iff arg is positive."
7626   (interactive "P")
7627   (setq truncate-lines
7628         (if (null arg) (not truncate-lines)
7629           (> (prefix-numeric-value arg) 0)))
7630   (redraw-display))
7631
7632 (defun gnus-summary-reselect-current-group (&optional all)
7633   "Once exit and then reselect the current newsgroup.
7634 The prefix argument ALL means to select all articles."
7635   (interactive "P")
7636   (gnus-set-global-variables)
7637   (let ((current-subject (gnus-summary-article-number))
7638         (group gnus-newsgroup-name))
7639     (setq gnus-newsgroup-begin nil)
7640     (gnus-summary-exit t)
7641     ;; We have to adjust the point of group mode buffer because the
7642     ;; current point was moved to the next unread newsgroup by
7643     ;; exiting.
7644     (gnus-summary-jump-to-group group)
7645     (gnus-group-read-group all t)
7646     (gnus-summary-goto-subject current-subject)))
7647
7648 (defun gnus-summary-rescan-group (&optional all)
7649   "Exit the newsgroup, ask for new articles, and select the newsgroup."
7650   (interactive "P")
7651   (gnus-set-global-variables)
7652   ;; Fix by Ilja Weis <kult@uni-paderborn.de>.
7653   (let ((group gnus-newsgroup-name))
7654     (gnus-summary-exit)
7655     (gnus-summary-jump-to-group group)
7656     (save-excursion
7657       (set-buffer gnus-group-buffer)
7658       (gnus-group-get-new-news-this-group 1))
7659     (gnus-summary-jump-to-group group)
7660     (gnus-group-read-group all)))
7661
7662 (defun gnus-summary-update-info ()
7663   (let* ((group gnus-newsgroup-name))
7664     (if gnus-newsgroup-kill-headers
7665         (setq gnus-newsgroup-killed
7666               (gnus-compress-sequence
7667                (nconc
7668                 (gnus-set-sorted-intersection
7669                  (gnus-uncompress-range gnus-newsgroup-killed)
7670                  (setq gnus-newsgroup-unselected
7671                        (sort gnus-newsgroup-unselected '<)))
7672                 (setq gnus-newsgroup-unreads
7673                       (sort gnus-newsgroup-unreads '<))) t)))
7674     (or (listp (cdr gnus-newsgroup-killed))
7675         (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7676     (let ((headers gnus-newsgroup-headers))
7677       (gnus-close-group group)
7678       (run-hooks 'gnus-exit-group-hook)
7679       (gnus-update-read-articles 
7680        group gnus-newsgroup-unreads gnus-newsgroup-unselected 
7681        gnus-newsgroup-marked
7682        t gnus-newsgroup-replied gnus-newsgroup-expirable
7683        gnus-newsgroup-killed gnus-newsgroup-dormant
7684        gnus-newsgroup-bookmarks 
7685        (and gnus-save-score gnus-newsgroup-scored))
7686       (and gnus-use-cross-reference
7687            (gnus-mark-xrefs-as-read 
7688             group headers gnus-newsgroup-unreads gnus-newsgroup-expirable))
7689       ;; Do adaptive scoring, and possibly save score files.
7690       (and gnus-newsgroup-adaptive
7691            (gnus-score-adaptive))
7692       (and gnus-use-scoring 
7693            (fboundp 'gnus-score-save)
7694            (funcall 'gnus-score-save))
7695       ;; Do not switch windows but change the buffer to work.
7696       (set-buffer gnus-group-buffer)
7697       (or (assoc 'quit-config (gnus-find-method-for-group gnus-newsgroup-name))
7698           (gnus-group-update-group group)))))
7699   
7700 (defun gnus-summary-exit (&optional temporary)
7701   "Exit reading current newsgroup, and then return to group selection mode.
7702 gnus-exit-group-hook is called with no arguments if that value is non-nil."
7703   (interactive)
7704   (gnus-set-global-variables)
7705   (gnus-kill-save-kill-buffer)
7706   (let* ((group gnus-newsgroup-name)
7707          (quit-config (nth 1 (assoc 'quit-config (gnus-find-method-for-group
7708                                                   gnus-newsgroup-name))))
7709          (mode major-mode)
7710          (buf (current-buffer)))
7711     (run-hooks 'gnus-summary-prepare-exit-hook)
7712     (gnus-summary-update-info) ; Make all changes in this group permanent.
7713     (set-buffer buf)
7714     (and gnus-use-cache (gnus-cache-possibly-remove-articles))
7715     ;; Make sure where I was, and go to next newsgroup.
7716     (set-buffer gnus-group-buffer)
7717     (or quit-config
7718         (progn
7719           (gnus-group-jump-to-group group)
7720           (gnus-group-next-unread-group 1)))
7721     (if temporary
7722         nil                             ;Nothing to do.
7723       ;; We set all buffer-local variables to nil. It is unclear why
7724       ;; this is needed, but if we don't, buffer-local variables are
7725       ;; not garbage-collected, it seems. This would the lead to en
7726       ;; ever-growing Emacs.
7727       (set-buffer buf)
7728       (gnus-summary-clear-local-variables)
7729       ;; We clear the global counterparts of the buffer-local
7730       ;; variables as well, just to be on the safe side.
7731       (gnus-configure-windows 'group 'force)
7732       (gnus-summary-clear-local-variables)
7733       ;; Return to group mode buffer. 
7734       (if (eq mode 'gnus-summary-mode)
7735           (gnus-kill-buffer buf))
7736       (if (get-buffer gnus-article-buffer)
7737           (bury-buffer gnus-article-buffer))
7738       (setq gnus-current-select-method gnus-select-method)
7739       (pop-to-buffer gnus-group-buffer)
7740       (if (not quit-config)
7741           (progn
7742             (gnus-group-jump-to-group group)
7743             (gnus-group-next-unread-group 1))
7744         (if (not (buffer-name (car quit-config)))
7745             (gnus-configure-windows 'group 'force)
7746           (set-buffer (car quit-config))
7747           (and (eq major-mode 'gnus-summary-mode)
7748                (gnus-set-global-variables))
7749           (gnus-configure-windows (cdr quit-config))))
7750       (run-hooks 'gnus-summary-exit-hook))))
7751
7752 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7753 (defun gnus-summary-exit-no-update (&optional no-questions)
7754   "Quit reading current newsgroup without updating read article info."
7755   (interactive)
7756   (gnus-set-global-variables)
7757   (let* ((group gnus-newsgroup-name)
7758          (quit-config (nth 1 (assoc 'quit-config 
7759                                     (gnus-find-method-for-group group)))))
7760     (if (or no-questions
7761             gnus-expert-user
7762             (gnus-y-or-n-p "Do you really wanna quit reading this group? "))
7763         (progn
7764           (gnus-close-group group)
7765           (gnus-summary-clear-local-variables)
7766           (set-buffer gnus-group-buffer)
7767           (gnus-summary-clear-local-variables)
7768           ;; Return to group selection mode.
7769           (gnus-configure-windows 'group 'force)
7770           (if (get-buffer gnus-summary-buffer)
7771               (kill-buffer gnus-summary-buffer))
7772           (if (get-buffer gnus-article-buffer)
7773               (bury-buffer gnus-article-buffer))
7774           (if (equal (gnus-group-group-name) group)
7775               (gnus-group-next-unread-group 1))
7776           (if quit-config
7777               (progn
7778                 (if (not (buffer-name (car quit-config)))
7779                     (gnus-configure-windows 'group 'force)
7780                   (set-buffer (car quit-config))
7781                   (and (eq major-mode 'gnus-summary-mode)
7782                        (gnus-set-global-variables))
7783                   (gnus-configure-windows (cdr quit-config)))))))))
7784
7785 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7786 (defun gnus-summary-fetch-faq (group)
7787   "Fetch the FAQ for the current group."
7788   (interactive (list gnus-newsgroup-name))
7789   (let (gnus-faq-buffer)
7790     (and (setq gnus-faq-buffer (gnus-group-fetch-faq group))
7791          (gnus-configure-windows 'summary-faq))))
7792
7793 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7794 (defun gnus-summary-describe-group (&optional force)
7795   "Describe the current newsgroup."
7796   (interactive "P")
7797   (gnus-group-describe-group force gnus-newsgroup-name))
7798
7799 (defun gnus-summary-describe-briefly ()
7800   "Describe summary mode commands briefly."
7801   (interactive)
7802   (gnus-message 6
7803     (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")))
7804
7805 ;; Walking around group mode buffer from summary mode.
7806
7807 (defun gnus-summary-next-group (&optional no-article target-group backward)
7808   "Exit current newsgroup and then select next unread newsgroup.
7809 If prefix argument NO-ARTICLE is non-nil, no article is selected
7810 initially. If NEXT-GROUP, go to this group. If BACKWARD, go to
7811 previous group instead."
7812   (interactive "P")
7813   (gnus-set-global-variables)
7814   (let ((current-group gnus-newsgroup-name)
7815         (current-buffer (current-buffer))
7816         entered)
7817     ;; First we semi-exit this group to update Xrefs and all variables.
7818     ;; We can't do a real exit, because the window conf must remain
7819     ;; the same in case the user is prompted for info, and we don't
7820     ;; want the window conf to change before that...
7821     (gnus-summary-exit t)
7822     (while (not entered)
7823       ;; Then we find what group we are supposed to enter.
7824       (set-buffer gnus-group-buffer)
7825       (gnus-group-jump-to-group current-group)
7826       (setq target-group 
7827             (or target-group        
7828                 (if (eq gnus-keep-same-level 'best) 
7829                     (gnus-summary-best-group gnus-newsgroup-name)
7830                   (gnus-summary-search-group backward gnus-keep-same-level))))
7831       (if (not target-group)
7832           ;; There are no further groups, so we return to the group
7833           ;; buffer.
7834           (progn
7835             (gnus-message 5 "Returning to the group buffer")
7836             (setq entered t)
7837             (set-buffer current-buffer)
7838             (gnus-summary-exit))
7839         ;; We try to enter the target group.
7840         (gnus-group-jump-to-group target-group)
7841         (let ((unreads (gnus-group-group-unread)))
7842           (if (and (or (eq t unreads)
7843                        (and unreads (not (zerop unreads))))
7844                    (gnus-summary-read-group
7845                     target-group nil no-article current-buffer))
7846               (setq entered t)
7847             (setq current-group target-group
7848                   target-group nil)))))))
7849
7850 (defun gnus-summary-next-group-old (&optional no-article group backward)
7851   "Exit current newsgroup and then select next unread newsgroup.
7852 If prefix argument NO-ARTICLE is non-nil, no article is selected initially.
7853 If BACKWARD, go to previous group instead."
7854   (interactive "P")
7855   (gnus-set-global-variables)
7856   (let ((ingroup gnus-newsgroup-name)
7857         (sumbuf (current-buffer))
7858         num)
7859     (set-buffer gnus-group-buffer)
7860     (if (and group
7861              (or (and (numberp (setq num (car (gnus-gethash
7862                                                group gnus-newsrc-hashtb))))
7863                       (< num 1))
7864                  (null num)))
7865         (progn
7866           (gnus-group-jump-to-group group)
7867           (setq group nil))
7868       (gnus-group-jump-to-group ingroup))
7869     (gnus-summary-search-group backward)
7870     (let ((group (or group (gnus-summary-search-group backward))))
7871       (set-buffer sumbuf)
7872       (gnus-summary-exit t)             ;Update all information.
7873       (if (null group)
7874           (gnus-summary-exit-no-update t)
7875         (gnus-group-jump-to-group ingroup)
7876         (setq group (gnus-summary-search-group backward))
7877         (gnus-message 5 "Selecting %s..." group)
7878         (set-buffer gnus-group-buffer)
7879         ;; We are now in group mode buffer.
7880         ;; Make sure group mode buffer point is on GROUP.
7881         (gnus-group-jump-to-group group)
7882         (if (not (eq gnus-auto-select-next 'quietly))
7883             (progn
7884               (gnus-summary-read-group group nil no-article sumbuf)
7885               (and (string= gnus-newsgroup-name ingroup)
7886                    (bufferp sumbuf) (buffer-name sumbuf)
7887                    (progn
7888                      (set-buffer (setq gnus-summary-buffer sumbuf))
7889                      (gnus-summary-exit-no-update t))))
7890           (let ((prevgroup group))
7891             (gnus-group-jump-to-group ingroup)
7892             (setq group (gnus-summary-search-group backward))
7893             (gnus-summary-read-group group nil no-article sumbuf)
7894             (while (and (string= gnus-newsgroup-name ingroup)
7895                         (bufferp sumbuf) 
7896                         (buffer-name sumbuf)
7897                         (not (string= prevgroup (gnus-group-group-name))))
7898               (set-buffer gnus-group-buffer)
7899               (gnus-summary-read-group 
7900                (setq prevgroup (gnus-group-group-name)) 
7901                nil no-article sumbuf))
7902             (and (string= prevgroup (gnus-group-group-name))
7903                  ;; We have reached the final group in the group
7904                  ;; buffer.
7905                  (progn
7906                    (if (buffer-name sumbuf)
7907                        (progn
7908                          (set-buffer sumbuf)
7909                          (gnus-summary-exit)))))))))))
7910
7911 (defun gnus-summary-prev-group (&optional no-article)
7912   "Exit current newsgroup and then select previous unread newsgroup.
7913 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7914   (interactive "P")
7915   (gnus-summary-next-group no-article nil t))
7916
7917 ;; Walking around summary lines.
7918
7919 (defun gnus-summary-first-subject (&optional unread)
7920   "Go to the first unread subject.
7921 If UNREAD is non-nil, go to the first unread article.
7922 Returns nil if there are no unread articles."
7923   (interactive "P")
7924   (prog1
7925       (cond ((not unread)
7926              (goto-char (point-min)))
7927             ((gnus-goto-char 
7928               (text-property-any 
7929                (point-min) (point-max) 'gnus-mark gnus-unread-mark))
7930              t)
7931             (t 
7932              ;; There are no unread articles.
7933              (gnus-message 3 "No more unread articles")
7934              nil))
7935     (gnus-summary-position-cursor)))
7936
7937 (defun gnus-summary-next-subject (n &optional unread dont-display)
7938   "Go to next N'th summary line.
7939 If N is negative, go to the previous N'th subject line.
7940 If UNREAD is non-nil, only unread articles are selected.
7941 The difference between N and the actual number of steps taken is
7942 returned."
7943   (interactive "p")
7944   (let ((backward (< n 0))
7945         (n (abs n)))
7946     (while (and (> n 0)
7947                 (gnus-summary-search-forward unread nil backward))
7948       (setq n (1- n)))
7949     (if (/= 0 n) (gnus-message 7 "No more%s articles"
7950                                (if unread " unread" "")))
7951     (or dont-display
7952         (progn
7953           (gnus-summary-recenter)
7954           (gnus-summary-position-cursor)))
7955   n))
7956
7957 (defun gnus-summary-next-unread-subject (n)
7958   "Go to next N'th unread summary line."
7959   (interactive "p")
7960   (gnus-summary-next-subject n t))
7961
7962 (defun gnus-summary-prev-subject (n &optional unread)
7963   "Go to previous N'th summary line.
7964 If optional argument UNREAD is non-nil, only unread article is selected."
7965   (interactive "p")
7966   (gnus-summary-next-subject (- n) unread))
7967
7968 (defun gnus-summary-prev-unread-subject (n)
7969   "Go to previous N'th unread summary line."
7970   (interactive "p")
7971   (gnus-summary-next-subject (- n) t))
7972
7973 (defun gnus-summary-goto-subject (article)
7974   "Go the subject line of ARTICLE."
7975   (interactive
7976    (list
7977     (string-to-int
7978      (completing-read "Article number: "
7979                       (mapcar
7980                        (lambda (headers)
7981                          (list
7982                           (int-to-string (header-number headers))))
7983                        gnus-newsgroup-headers)
7984                       nil 'require-match))))
7985   (or article (error "No article number"))
7986   (let ((b (point)))
7987     (if (not (gnus-goto-char (text-property-any (point-min) (point-max)
7988                                                 'gnus-number article)))
7989         ()
7990       (gnus-summary-show-thread)
7991       ;; Skip dummy articles. 
7992       (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
7993           (forward-line 1))
7994       (prog1
7995           (if (not (eobp))
7996               article
7997             (goto-char b)
7998             nil)
7999         (gnus-summary-position-cursor)))))
8000
8001 ;; Walking around summary lines with displaying articles.
8002
8003 (defun gnus-summary-expand-window (&optional arg)
8004   "Make the summary buffer take up the entire Emacs frame.
8005 Given a prefix, will force an `article' buffer configuration."
8006   (interactive "P")
8007   (gnus-set-global-variables)
8008   (if arg
8009       (gnus-configure-windows 'article 'force)
8010     (gnus-configure-windows 'summary 'force)))
8011
8012 (defun gnus-summary-display-article (article &optional all-header)
8013   "Display ARTICLE in article buffer."
8014   (gnus-set-global-variables)
8015   (if (null article)
8016       nil
8017     (prog1
8018         (gnus-article-prepare article all-header)
8019       (gnus-summary-show-thread)
8020       (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
8021           (progn
8022             (forward-line 1)
8023             (gnus-summary-position-cursor)))
8024       (run-hooks 'gnus-select-article-hook)
8025       (gnus-summary-recenter)
8026       (gnus-summary-goto-subject article)
8027       ;; Successfully display article.
8028       (gnus-summary-update-line)
8029       (gnus-article-set-window-start 
8030        (cdr (assq article gnus-newsgroup-bookmarks)))
8031       t)))
8032
8033 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
8034   "Select the current article.
8035 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
8036 non-nil, the article will be re-fetched even if it already present in
8037 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
8038 be displayed."
8039   (and (not pseudo) (gnus-summary-pseudo-article)
8040        (error "This is a pseudo-article."))
8041   (let ((article (or article (gnus-summary-article-number)))
8042         (all-headers (not (not all-headers))) ;Must be T or NIL.
8043         did) 
8044     (prog1
8045         (save-excursion
8046           (set-buffer gnus-summary-buffer)
8047           (if (or (null gnus-current-article)
8048                   (null gnus-article-current)
8049                   (null (get-buffer gnus-article-buffer))
8050                   (not (eq article (cdr gnus-article-current)))
8051                   (not (equal (car gnus-article-current) gnus-newsgroup-name))
8052                   force)
8053               ;; The requested article is different from the current article.
8054               (progn
8055                 (gnus-summary-display-article article all-headers)
8056                 (setq did article))
8057             (if (or all-headers gnus-show-all-headers) 
8058                 (gnus-article-show-all-headers))
8059             nil))
8060       (if did 
8061           (gnus-article-set-window-start 
8062            (cdr (assq article gnus-newsgroup-bookmarks)))))))
8063
8064 (defun gnus-summary-set-current-mark (&optional current-mark)
8065   "Obsolete function."
8066   nil)
8067
8068 (defun gnus-summary-next-article (&optional unread subject backward)
8069   "Select the next article.
8070 If UNREAD, only unread articles are selected.
8071 If SUBJECT, only articles with SUBJECT are selected.
8072 If BACKWARD, the previous article is selected instead of the next."
8073   (interactive "P")
8074   (gnus-set-global-variables)
8075   (let (header)
8076     (cond
8077      ;; Is there such an article?
8078      ((or (gnus-summary-display-article 
8079            (gnus-summary-search-forward unread subject backward))
8080           (eq (gnus-summary-article-mark) gnus-canceled-mark))
8081       (gnus-summary-position-cursor))
8082      ;; If not, we try the first unread, if that is wanted.
8083      ((and subject
8084            gnus-auto-select-same
8085            (or (gnus-summary-first-unread-article)
8086                (eq (gnus-summary-article-mark) gnus-canceled-mark)))
8087       (gnus-summary-position-cursor)
8088       (gnus-message 6 "Wrapped"))
8089      ;; Try to get next/previous article not displayed in this group.
8090      ((and gnus-auto-extend-newsgroup
8091            (not unread) (not subject)
8092            (setq header (gnus-more-header-forward backward)))
8093       (gnus-extend-newsgroup header backward)
8094       (let ((buffer-read-only nil))
8095         (goto-char (if backward (point-min) (point-max)))
8096         (gnus-summary-prepare-threads (list header)))
8097       (gnus-summary-goto-article (if backward gnus-newsgroup-begin
8098                                    gnus-newsgroup-end)))
8099      ;; Go to next/previous group.
8100      (t
8101       (or (assoc 'quit-config (gnus-find-method-for-group gnus-newsgroup-name))
8102           (gnus-summary-jump-to-group gnus-newsgroup-name))
8103       (let ((cmd last-command-char)
8104             (group 
8105              (if (eq gnus-keep-same-level 'best) 
8106                  (gnus-summary-best-group gnus-newsgroup-name)
8107                (gnus-summary-search-group backward gnus-keep-same-level))))
8108         ;; For some reason, the group window gets selected. We change
8109         ;; it back.  
8110         (select-window (get-buffer-window (current-buffer)))
8111         ;; Keep just the event type of CMD.
8112         ;(and (listp cmd) (setq cmd (car cmd)))
8113         ;; Select next unread newsgroup automagically.
8114         (cond 
8115          ((not gnus-auto-select-next)
8116           (gnus-message 7 "No more%s articles" (if unread " unread" "")))
8117          ((eq gnus-auto-select-next 'quietly)
8118           ;; Select quietly.
8119           (if (assoc 'quit-config (gnus-find-method-for-group 
8120                                    gnus-newsgroup-name))
8121               (gnus-summary-exit)
8122             (gnus-message 7 "No more%s articles (%s)..."
8123                           (if unread " unread" "") 
8124                           (if group (concat "selecting " group)
8125                             "exiting"))
8126             (gnus-summary-next-group nil group backward)))
8127          (t
8128           (let ((keystrokes '(?\C-n ?\C-p))
8129                 key)
8130             (while (or (null key) (memq key keystrokes))
8131               (gnus-message 
8132                7 "No more%s articles%s" (if unread " unread" "")
8133                (if (and group (not (assoc 'quit-config
8134                                           (gnus-find-method-for-group 
8135                                            gnus-newsgroup-name))))
8136                    (format " (Type %s for %s [%s])"
8137                            (single-key-description cmd) group
8138                            (car (gnus-gethash group gnus-newsrc-hashtb)))
8139                  (format " (Type %s to exit %s)"
8140                          (single-key-description cmd)
8141                          gnus-newsgroup-name)))
8142               ;; Confirm auto selection.
8143               (let* ((event (read-char)))
8144                 (setq key (if (listp event) (car event) event))
8145                 (if (memq key keystrokes)
8146                     (let ((obuf (current-buffer)))
8147                       (switch-to-buffer gnus-group-buffer)
8148                       (and group
8149                            (gnus-group-jump-to-group group))
8150                       (condition-case ()
8151                           (execute-kbd-macro (char-to-string key))
8152                         (error (ding) nil))
8153                       (setq group (gnus-group-group-name))
8154                       (switch-to-buffer obuf)))))
8155             (if (equal key cmd)
8156                 (if (or (not group) (assoc 'quit-config
8157                                            (gnus-find-method-for-group
8158                                             gnus-newsgroup-name)))
8159                     (gnus-summary-exit)
8160                   (gnus-summary-next-group nil group backward))
8161               (setq unread-command-events (list key)))))))))))
8162
8163 (defun gnus-summary-next-unread-article ()
8164   "Select unread article after current one."
8165   (interactive)
8166   (gnus-summary-next-article t (and gnus-auto-select-same
8167                                     (gnus-summary-subject-string))))
8168
8169 (defun gnus-summary-prev-article (&optional unread subject)
8170   "Select the article after the current one.
8171 If UNREAD is non-nil, only unread articles are selected."
8172   (interactive "P")
8173   (gnus-summary-next-article unread subject t))
8174
8175 (defun gnus-summary-prev-unread-article ()
8176   "Select unred article before current one."
8177   (interactive)
8178   (gnus-summary-prev-article t (and gnus-auto-select-same
8179                                     (gnus-summary-subject-string))))
8180
8181 (defun gnus-summary-next-page (&optional lines circular)
8182   "Show next page of selected article.
8183 If end of article, select next article.
8184 Argument LINES specifies lines to be scrolled up.
8185 If CIRCULAR is non-nil, go to the start of the article instead of 
8186 instead of selecting the next article when reaching the end of the
8187 current article." 
8188   (interactive "P")
8189   (setq gnus-summary-buffer (current-buffer))
8190   (gnus-set-global-variables)
8191   (let ((article (gnus-summary-article-number))
8192         (endp nil))
8193     (gnus-configure-windows 'article)
8194     (if (or (null gnus-current-article)
8195             (null gnus-article-current)
8196             (/= article (cdr gnus-article-current))
8197             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8198         ;; Selected subject is different from current article's.
8199         (gnus-summary-display-article article)
8200       (gnus-eval-in-buffer-window
8201        gnus-article-buffer
8202        (setq endp (gnus-article-next-page lines)))
8203       (if endp
8204           (cond (circular
8205                  (gnus-summary-beginning-of-article))
8206                 (lines
8207                  (gnus-message 3 "End of message"))
8208                 ((null lines)
8209                  (gnus-summary-next-unread-article)))))
8210     (gnus-summary-recenter)
8211     (gnus-summary-position-cursor)))
8212
8213 (defun gnus-summary-prev-page (&optional lines)
8214   "Show previous page of selected article.
8215 Argument LINES specifies lines to be scrolled down."
8216   (interactive "P")
8217   (gnus-set-global-variables)
8218   (let ((article (gnus-summary-article-number)))
8219     (gnus-configure-windows 'article)
8220     (if (or (null gnus-current-article)
8221             (null gnus-article-current)
8222             (/= article (cdr gnus-article-current))
8223             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
8224         ;; Selected subject is different from current article's.
8225         (gnus-summary-display-article article)
8226       (gnus-summary-recenter)
8227       (gnus-eval-in-buffer-window gnus-article-buffer
8228         (gnus-article-prev-page lines))))
8229   (gnus-summary-position-cursor))
8230
8231 (defun gnus-summary-scroll-up (lines)
8232   "Scroll up (or down) one line current article.
8233 Argument LINES specifies lines to be scrolled up (or down if negative)."
8234   (interactive "p")
8235   (gnus-set-global-variables)
8236   (gnus-configure-windows 'article)
8237   (or (gnus-summary-select-article nil nil 'pseudo)
8238       (gnus-eval-in-buffer-window 
8239        gnus-article-buffer
8240        (cond ((> lines 0)
8241               (if (gnus-article-next-page lines)
8242                   (gnus-message 3 "End of message")))
8243              ((< lines 0)
8244               (gnus-article-prev-page (- lines))))))
8245   (gnus-summary-recenter)
8246   (gnus-summary-position-cursor))
8247
8248 (defun gnus-summary-next-same-subject ()
8249   "Select next article which has the same subject as current one."
8250   (interactive)
8251   (gnus-set-global-variables)
8252   (gnus-summary-next-article nil (gnus-summary-subject-string)))
8253
8254 (defun gnus-summary-prev-same-subject ()
8255   "Select previous article which has the same subject as current one."
8256   (interactive)
8257   (gnus-set-global-variables)
8258   (gnus-summary-prev-article nil (gnus-summary-subject-string)))
8259
8260 (defun gnus-summary-next-unread-same-subject ()
8261   "Select next unread article which has the same subject as current one."
8262   (interactive)
8263   (gnus-set-global-variables)
8264   (gnus-summary-next-article t (gnus-summary-subject-string)))
8265
8266 (defun gnus-summary-prev-unread-same-subject ()
8267   "Select previous unread article which has the same subject as current one."
8268   (interactive)
8269   (gnus-set-global-variables)
8270   (gnus-summary-prev-article t (gnus-summary-subject-string)))
8271
8272 (defun gnus-summary-first-unread-article ()
8273   "Select the first unread article. 
8274 Return nil if there are no unread articles."
8275   (interactive)
8276   (gnus-set-global-variables)
8277   (prog1
8278       (if (gnus-summary-first-subject t)
8279           (progn
8280             (gnus-summary-show-thread)
8281             (gnus-summary-first-subject t)
8282             (gnus-summary-display-article (gnus-summary-article-number))))
8283     (gnus-summary-position-cursor)))
8284
8285 (defun gnus-summary-best-unread-article ()
8286   "Select the unread article with the highest score."
8287   (interactive)
8288   (gnus-set-global-variables)
8289   (let ((scored gnus-newsgroup-scored)
8290         (best -1000000)
8291         article art)
8292     (while scored
8293       (or (> best (cdr (car scored)))
8294           (and (memq (setq art (car (car scored))) gnus-newsgroup-unreads)
8295                (not (memq art gnus-newsgroup-marked))
8296                (not (memq art gnus-newsgroup-dormant))
8297                (if (= best (cdr (car scored)))
8298                    (setq article (min art article))
8299                  (setq article art)
8300                  (setq best (cdr (car scored))))))
8301       (setq scored (cdr scored)))
8302     (cond
8303      ((or (not article) (null gnus-newsgroup-unreads))
8304       ;; We didn't find any scored articles, so we just jump to the
8305       ;; first article. 
8306       (gnus-summary-first-unread-article))
8307      ((> best gnus-summary-default-score)
8308       ;; We found one, and it's bigger than the default score, so we
8309       ;; select it.
8310       (gnus-summary-goto-article article))
8311      (t
8312       ;; We found an article, but it has a score lower than the
8313       ;; defaults, so we try to find an article with the default
8314       ;; score. 
8315       (goto-char (point-min))
8316       (while (and (or (not (= (gnus-summary-article-mark) gnus-unread-mark))
8317                       (and (assq (gnus-summary-article-number)
8318                                  gnus-newsgroup-scored)
8319                            (< (cdr (assq (gnus-summary-article-number)
8320                                          gnus-newsgroup-scored))
8321                               gnus-summary-default-score)))
8322                   (zerop (forward-line 1))
8323                   (not (eobp))))
8324       (if (= (gnus-summary-article-mark) gnus-unread-mark)
8325           ;; We jump to the article we have finally found.
8326           (gnus-summary-goto-article (gnus-summary-article-number))
8327         ;; Or there were no default-scored articles.
8328         (gnus-summary-goto-article article))))
8329     (gnus-summary-position-cursor)))
8330
8331 (defun gnus-summary-goto-article (article &optional all-headers)
8332   "Fetch ARTICLE and display it if it exists.
8333 If ALL-HEADERS is non-nil, no header lines are hidden."
8334   (interactive
8335    (list
8336     (string-to-int
8337      (completing-read 
8338       "Article number: "
8339       (mapcar (lambda (headers) (list (int-to-string (header-number headers))))
8340               gnus-newsgroup-headers) 
8341       nil 'require-match))))
8342   (prog1
8343       (and (gnus-summary-goto-subject article)
8344            (gnus-summary-display-article article all-headers))
8345     (gnus-summary-position-cursor)))
8346
8347 (defun gnus-summary-goto-last-article ()
8348   "Go to the previously read article."
8349   (interactive)
8350   (prog1
8351       (and gnus-last-article
8352            (gnus-summary-goto-article gnus-last-article))
8353     (gnus-summary-position-cursor)))
8354
8355 (defun gnus-summary-pop-article (number)
8356   "Pop one article off the history and go to the previous.
8357 NUMBER articles will be popped off."
8358   (interactive "p")
8359   (let (to)
8360     (setq gnus-newsgroup-history
8361           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8362     (if to
8363         (gnus-summary-goto-article (car to))
8364       (error "Article history empty")))
8365   (gnus-summary-position-cursor))
8366
8367 ;; Summary article oriented commands
8368
8369 (defun gnus-summary-refer-parent-article (n)
8370   "Refer parent article N times.
8371 The difference between N and the number of articles fetched is returned."
8372   (interactive "p")
8373   (gnus-set-global-variables)
8374   (while 
8375       (and 
8376        (> n 0)
8377        (let ((ref (header-references (gnus-get-header-by-num
8378                                       (gnus-summary-article-number)))))
8379          (if (and ref (not (equal ref ""))
8380                   (string-match "<[^<>]*>[ \t]*$" ref))
8381              (gnus-summary-refer-article 
8382               (substring ref (match-beginning 0) (match-end 0)))
8383            (gnus-message 1 "No references in article %d"
8384                          (gnus-summary-article-number))
8385            nil)))
8386     (setq n (1- n)))
8387   (gnus-summary-position-cursor)
8388   n)
8389     
8390 (defun gnus-summary-refer-article (message-id)
8391   "Refer article specified by MESSAGE-ID.
8392 NOTE: This command only works with newsgroups that use real or simulated NNTP."
8393   (interactive "sMessage-ID: ")
8394   (if (or (not (stringp message-id))
8395           (zerop (length message-id)))
8396       ()
8397     ;; Construct the correct Message-ID if necessary.
8398     ;; Suggested by tale@pawl.rpi.edu.
8399     (or (string-match "^<" message-id)
8400         (setq message-id (concat "<" message-id)))
8401     (or (string-match ">$" message-id)
8402         (setq message-id (concat message-id ">")))
8403     (let ((header (car (gnus-gethash (downcase message-id)
8404                                      gnus-newsgroup-dependencies))))
8405       (if header
8406           (or (gnus-summary-goto-article (header-number header))
8407               ;; The header has been read, but the article had been
8408               ;; expunged, so we insert it again.
8409               (progn
8410                 (gnus-summary-insert-line
8411                  nil header 0 nil gnus-read-mark nil nil
8412                  (header-subject header))
8413                 (forward-line -1)
8414                 (header-number header)))
8415         (let ((gnus-override-method gnus-refer-article-method)
8416               (gnus-ancient-mark gnus-read-mark)
8417               (tmp-point (window-start
8418                           (get-buffer-window gnus-article-buffer)))
8419               number tmp-buf)
8420           (and gnus-refer-article-method
8421                (gnus-check-server gnus-refer-article-method))
8422           ;; Save the old article buffer.
8423           (save-excursion
8424             (set-buffer gnus-article-buffer)
8425             (gnus-kill-buffer " *temp Article*")
8426             (setq tmp-buf (rename-buffer " *temp Article*")))
8427           (prog1
8428               (if (gnus-article-prepare 
8429                    message-id nil (gnus-read-header message-id))
8430                   (progn
8431                     (setq number (header-number gnus-current-headers))
8432                     (gnus-rebuild-thread message-id)
8433                     (gnus-summary-goto-subject number)
8434                     (if (null gnus-use-full-window)
8435                         (progn
8436                           (delete-windows-on tmp-buf)
8437                           (gnus-configure-windows 'article 'force)))
8438                     (gnus-summary-recenter)
8439                     (gnus-article-set-window-start 
8440                      (cdr (assq number gnus-newsgroup-bookmarks)))
8441                     message-id)
8442                 ;; We restore the old article buffer.
8443                 (save-excursion
8444                   (kill-buffer gnus-article-buffer)
8445                   (set-buffer tmp-buf)
8446                   (rename-buffer gnus-article-buffer)
8447                   (let ((buffer-read-only nil))
8448                     (and tmp-point
8449                          (set-window-start (get-buffer-window (current-buffer))
8450                                            tmp-point)))))))))))
8451
8452 (defun gnus-summary-enter-digest-group ()
8453   "Enter a digest group based on the current article."
8454   (interactive)
8455   (gnus-set-global-variables)
8456   (gnus-summary-select-article)
8457   ;; We do not want a narrowed article.
8458   (gnus-summary-stop-page-breaking)
8459   (let ((name (format "%s-%d" 
8460                       (gnus-group-prefixed-name 
8461                        gnus-newsgroup-name (list 'nndoc "")) 
8462                       gnus-current-article))
8463         (ogroup gnus-newsgroup-name)
8464         (buf (current-buffer)))
8465     (if (gnus-group-read-ephemeral-group 
8466          name (list 'nndoc name
8467                     (list 'nndoc-address (get-buffer gnus-article-buffer))
8468                     '(nndoc-article-type digest))
8469          t)
8470         (setcdr (nthcdr 4 (nth 2 (gnus-gethash name gnus-newsrc-hashtb)))
8471                 (list (list (cons 'to-group ogroup))))
8472       (switch-to-buffer buf)
8473       (gnus-set-global-variables)
8474       (gnus-configure-windows 'summary)
8475       (gnus-message 3 "Article not a digest?"))))
8476
8477 (defun gnus-summary-isearch-article ()
8478   "Do incremental search forward on current article."
8479   (interactive)
8480   (gnus-set-global-variables)
8481   (gnus-summary-select-article)
8482   (gnus-eval-in-buffer-window 
8483    gnus-article-buffer (isearch-forward)))
8484
8485 (defun gnus-summary-search-article-forward (regexp &optional backward)
8486   "Search for an article containing REGEXP forward.
8487 If BACKWARD, search backward instead."
8488   (interactive
8489    (list (read-string
8490           (format "Search article %s (regexp%s): "
8491                   (if current-prefix-arg "backward" "forward")
8492                   (if gnus-last-search-regexp
8493                       (concat ", default " gnus-last-search-regexp)
8494                     "")))
8495          current-prefix-arg))
8496   (gnus-set-global-variables)
8497   (if (string-equal regexp "")
8498       (setq regexp (or gnus-last-search-regexp ""))
8499     (setq gnus-last-search-regexp regexp))
8500   (if (gnus-summary-search-article regexp backward)
8501       (gnus-article-set-window-start 
8502        (cdr (assq (gnus-summary-article-number) gnus-newsgroup-bookmarks)))
8503     (error "Search failed: \"%s\"" regexp)))
8504
8505 (defun gnus-summary-search-article-backward (regexp)
8506   "Search for an article containing REGEXP backward."
8507   (interactive
8508    (list (read-string
8509           (format "Search article backward (regexp%s): "
8510                   (if gnus-last-search-regexp
8511                       (concat ", default " gnus-last-search-regexp)
8512                     "")))))
8513   (gnus-summary-search-article-forward regexp 'backward))
8514
8515 (defun gnus-summary-search-article (regexp &optional backward)
8516   "Search for an article containing REGEXP.
8517 Optional argument BACKWARD means do search for backward.
8518 gnus-select-article-hook is not called during the search."
8519   (let ((gnus-select-article-hook nil)  ;Disable hook.
8520         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8521         (re-search
8522          (if backward
8523              (function re-search-backward) (function re-search-forward)))
8524         (found nil)
8525         (last nil))
8526     ;; Hidden thread subtrees must be searched for ,too.
8527     (gnus-summary-show-all-threads)
8528     (if (eobp) (forward-line -1))
8529     ;; First of all, search current article.
8530     ;; We don't want to read article again from NNTP server nor reset
8531     ;; current point.
8532     (gnus-summary-select-article)
8533     (gnus-message 9 "Searching article: %d..." gnus-current-article)
8534     (setq last gnus-current-article)
8535     (gnus-eval-in-buffer-window gnus-article-buffer
8536       (save-restriction
8537         (widen)
8538         ;; Begin search from current point.
8539         (setq found (funcall re-search regexp nil t))))
8540     ;; Then search next articles.
8541     (while (and (not found)
8542                 (gnus-summary-display-article 
8543                  (gnus-summary-search-subject backward nil nil)))
8544       (gnus-message 9 "Searching article: %d..." gnus-current-article)
8545       (gnus-eval-in-buffer-window gnus-article-buffer
8546         (save-restriction
8547           (widen)
8548           (goto-char (if backward (point-max) (point-min)))
8549           (setq found (funcall re-search regexp nil t)))))
8550     (message "")
8551     ;; Adjust article pointer.
8552     (or (eq last gnus-current-article)
8553         (setq gnus-last-article last))
8554     ;; Return T if found such article.
8555     found))
8556
8557 (defun gnus-summary-execute-command (header regexp command &optional backward)
8558   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8559 If HEADER is an empty string (or nil), the match is done on the entire
8560 article. If BACKWARD (the prefix) is non-nil, search backward instead."
8561   (interactive
8562    (list (let ((completion-ignore-case t))
8563            (completing-read 
8564             "Header name: "
8565             (mapcar (lambda (string) (list string))
8566                     '("Number" "Subject" "From" "Lines" "Date"
8567                       "Message-ID" "Xref" "References"))
8568             nil 'require-match))
8569          (read-string "Regexp: ")
8570          (read-key-sequence "Command: ")
8571          current-prefix-arg))
8572   (gnus-set-global-variables)
8573   ;; Hidden thread subtrees must be searched as well.
8574   (gnus-summary-show-all-threads)
8575   ;; We don't want to change current point nor window configuration.
8576   (save-excursion
8577     (save-window-excursion
8578       (gnus-message 6 "Executing %s..." (key-description command))
8579       ;; We'd like to execute COMMAND interactively so as to give arguments.
8580       (gnus-execute header regexp
8581                     (` (lambda ()
8582                          (call-interactively '(, (key-binding command)))))
8583                     backward)
8584       (gnus-message 6 "Executing %s...done" (key-description command)))))
8585
8586 (defun gnus-summary-beginning-of-article ()
8587   "Scroll the article back to the beginning."
8588   (interactive)
8589   (gnus-set-global-variables)
8590   (gnus-summary-select-article)
8591   (gnus-configure-windows 'article)
8592   (gnus-eval-in-buffer-window
8593    gnus-article-buffer
8594    (widen)
8595    (goto-char (point-min))
8596    (and gnus-break-pages (gnus-narrow-to-page))))
8597
8598 (defun gnus-summary-end-of-article ()
8599   "Scroll to the end of the article."
8600   (interactive)
8601   (gnus-set-global-variables)
8602   (gnus-summary-select-article)
8603   (gnus-configure-windows 'article)
8604   (gnus-eval-in-buffer-window 
8605    gnus-article-buffer
8606    (widen)
8607    (goto-char (point-max))
8608    (recenter -3)
8609    (and gnus-break-pages (gnus-narrow-to-page))))
8610
8611 (defun gnus-summary-show-article ()
8612   "Force re-fetching of the current article."
8613   (interactive)
8614   (gnus-set-global-variables)
8615   (gnus-summary-select-article nil 'force)
8616   (gnus-configure-windows 'article)
8617   (gnus-summary-position-cursor))
8618
8619 (defun gnus-summary-verbose-headers (&optional arg)
8620   "Toggle permanent full header display.
8621 If ARG is a positive number, turn header display on.
8622 If ARG is a negative number, turn header display off."
8623   (interactive "P")
8624   (gnus-set-global-variables)
8625   (gnus-summary-toggle-header arg)
8626   (setq gnus-show-all-headers
8627         (cond ((or (not (numberp arg))
8628                    (zerop arg))
8629                (not gnus-show-all-headers))
8630               ((natnump arg)
8631                t))))
8632
8633 (defun gnus-summary-toggle-header (&optional arg)
8634   "Show the headers if they are hidden, or hide them if they are shown.
8635 If ARG is a positive number, show the entire header.
8636 If ARG is a negative number, hide the unwanted header lines."
8637   (interactive "P")
8638   (gnus-set-global-variables)
8639   (save-excursion
8640     (set-buffer gnus-article-buffer)
8641     (let ((buffer-read-only nil))
8642       (if (numberp arg) 
8643           (if (> arg 0) (remove-text-properties (point-min) (point-max) 
8644                                                 gnus-hidden-properties)
8645             (if (< arg 0) (run-hooks 'gnus-article-display-hook)))
8646         (if (text-property-any (point-min) (point-max) 'invisible t)
8647             (remove-text-properties 
8648              (point-min) (point-max) gnus-hidden-properties)
8649           ;; We hide the headers. This song and dance act below is
8650           ;; done because `gnus-have-all-headers' is buffer-local to
8651           ;; the summary buffer, and we only want to temporarily
8652           ;; change it in that buffer. Ugh.
8653           (let ((have gnus-have-all-headers))
8654             (save-excursion
8655               (set-buffer gnus-summary-buffer)
8656               (setq gnus-have-all-headers nil)
8657               (save-excursion
8658                 (set-buffer gnus-article-buffer)
8659                 (run-hooks 'gnus-article-display-hook))
8660               (setq gnus-have-all-headers have)))))
8661       (set-window-point (get-buffer-window (current-buffer)) (point-min)))))
8662
8663 (defun gnus-summary-show-all-headers ()
8664   "Make all header lines visible."
8665   (interactive)
8666   (gnus-set-global-variables)
8667   (gnus-article-show-all-headers))
8668
8669 (defun gnus-summary-toggle-mime (&optional arg)
8670   "Toggle MIME processing.
8671 If ARG is a positive number, turn MIME processing on."
8672   (interactive "P")
8673   (gnus-set-global-variables)
8674   (setq gnus-show-mime
8675         (if (null arg) (not gnus-show-mime)
8676           (> (prefix-numeric-value arg) 0)))
8677   (gnus-summary-select-article t 'force))
8678
8679 (defun gnus-summary-caesar-message (&optional arg)
8680   "Caesar rotate the current article by 13.
8681 The numerical prefix specifies how manu places to rotate each letter
8682 forward."
8683   (interactive "P")
8684   (gnus-set-global-variables)
8685   (gnus-summary-select-article)
8686   (let ((mail-header-separator ""))
8687     (gnus-eval-in-buffer-window 
8688      gnus-article-buffer
8689      (save-restriction
8690        (widen)
8691        (let ((start (window-start)))
8692          (news-caesar-buffer-body arg)
8693          (set-window-start (get-buffer-window (current-buffer)) start))))))
8694
8695 (defun gnus-summary-stop-page-breaking ()
8696   "Stop page breaking in the current article."
8697   (interactive)
8698   (gnus-set-global-variables)
8699   (gnus-summary-select-article)
8700   (gnus-eval-in-buffer-window gnus-article-buffer (widen)))
8701
8702 ;; Suggested by Brian Edmonds <bedmonds@prodigy.bc.ca>.
8703
8704 (defun gnus-summary-move-article (&optional n to-newsgroup select-method)
8705   "Move the current article to a different newsgroup.
8706 If N is a positive number, move the N next articles.
8707 If N is a negative number, move the N previous articles.
8708 If N is nil and any articles have been marked with the process mark,
8709 move those articles instead.
8710 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. 
8711 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8712 re-spool using this method.
8713 For this function to work, both the current newsgroup and the
8714 newsgroup that you want to move to have to support the `request-move'
8715 and `request-accept' functions. (Ie. mail newsgroups at present.)"
8716   (interactive "P")
8717   (gnus-set-global-variables)
8718   (or (gnus-check-backend-function 'request-move-article gnus-newsgroup-name)
8719       (error "The current newsgroup does not support article moving"))
8720   (let ((articles (gnus-summary-work-articles n))
8721         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8722         art-group to-method sel-met)
8723     (if (and (not to-newsgroup) (not select-method))
8724         (setq to-newsgroup
8725               (completing-read 
8726                (format "Where do you want to move %s? %s"
8727                        (if (> (length articles) 1)
8728                            (format "these %d articles" (length articles))
8729                          "this article")
8730                        (if gnus-current-move-group
8731                            (format "(%s default) " gnus-current-move-group)
8732                          ""))
8733                gnus-active-hashtb nil nil prefix)))
8734     (if to-newsgroup
8735         (progn
8736           (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8737               (setq to-newsgroup (or gnus-current-move-group "")))
8738           (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8739               (gnus-activate-group to-newsgroup)
8740               (error "No such group: %s" to-newsgroup))
8741           (setq gnus-current-move-group to-newsgroup)))
8742     (setq to-method (if select-method (list select-method "")
8743                       (gnus-find-method-for-group to-newsgroup)))
8744     (or (gnus-check-backend-function 'request-accept-article (car to-method))
8745         (error "%s does not support article copying" (car to-method)))
8746     (or (gnus-check-server to-method)
8747         (error "Can't open server %s" (car to-method)))
8748     (gnus-message 6 "Moving to %s: %s..." 
8749                   (or select-method to-newsgroup) articles)
8750     (while articles
8751       (if (setq art-group
8752                 (gnus-request-move-article 
8753                  (car articles)                   ; Article to move
8754                  gnus-newsgroup-name              ; From newsgrouo
8755                  (nth 1 (gnus-find-method-for-group 
8756                          gnus-newsgroup-name))    ; Server
8757                  (list 'gnus-request-accept-article 
8758                        (if select-method
8759                            (list 'quote select-method)
8760                          to-newsgroup)
8761                        (not (cdr articles)))     ; Accept form
8762                  (not (cdr articles))))          ; Only save nov last time
8763           (let* ((buffer-read-only nil)
8764                  (entry 
8765                   (or
8766                    (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8767                    (gnus-gethash 
8768                     (gnus-group-prefixed-name 
8769                      (car art-group) 
8770                      (if select-method (list select-method "")
8771                        (gnus-find-method-for-group to-newsgroup)))
8772                     gnus-newsrc-hashtb)))
8773                  (info (nth 2 entry))
8774                  (article (car articles)))
8775             (gnus-summary-goto-subject article)
8776             (beginning-of-line)
8777             (delete-region (point) (progn (forward-line 1) (point)))
8778             ;; Update the group that has been moved to.
8779             (if (not info)
8780                 ()                      ; This group does not exist yet.
8781               (if (not (memq article gnus-newsgroup-unreads))
8782                   (setcar (cdr (cdr info))
8783                           (gnus-add-to-range (nth 2 info) 
8784                                              (list (cdr art-group)))))
8785               ;; Copy any marks over to the new group.
8786               (let ((marks '((tick . gnus-newsgroup-marked)
8787                              (dormant . gnus-newsgroup-dormant)
8788                              (expire . gnus-newsgroup-expirable)
8789                              (bookmark . gnus-newsgroup-bookmarks)
8790                              (reply . gnus-newsgroup-replied)))
8791                     (to-article (cdr art-group)))
8792                 (while marks
8793                   (if (memq article (symbol-value (cdr (car marks))))
8794                       (gnus-add-marked-articles 
8795                        (car info) (car (car marks)) (list to-article) info))
8796                   (setq marks (cdr marks)))))
8797             ;; Update marks.
8798             (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8799             (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8800             (setq gnus-newsgroup-dormant
8801                   (delq article gnus-newsgroup-dormant))
8802             (setq gnus-newsgroup-reads
8803                   (cons (cons article gnus-canceled-mark)
8804                         gnus-newsgroup-reads)))
8805         (gnus-message 1 "Couldn't move article %s" (car articles)))
8806       (gnus-summary-remove-process-mark (car articles))
8807       (setq articles (cdr articles)))))
8808
8809 (defun gnus-summary-respool-article (&optional n respool-method)
8810   "Respool the current article.
8811 The article will be squeezed through the mail spooling process again,
8812 which means that it will be put in some mail newsgroup or other
8813 depending on `nnmail-split-methods'.
8814 If N is a positive number, respool the N next articles.
8815 If N is a negative number, respool the N previous articles.
8816 If N is nil and any articles have been marked with the process mark,
8817 respool those articles instead.
8818
8819 Respooling can be done both from mail groups and \"real\" newsgroups.
8820 In the former case, the articles in question will be moved from the
8821 current group into whatever groups they are destined to.  In the
8822 latter case, they will be copied into the relevant groups."
8823   (interactive "P")
8824   (gnus-set-global-variables)
8825   (let ((respool-methods (gnus-methods-using 'respool))
8826         (methname 
8827          (symbol-name (car (gnus-find-method-for-group gnus-newsgroup-name)))))
8828     (or respool-method
8829         (setq respool-method
8830               (completing-read
8831                "What method do you want to use when respooling? "
8832                respool-methods nil t methname)))
8833     (or (string= respool-method "")
8834         (if (assoc (symbol-name
8835                     (car (gnus-find-method-for-group gnus-newsgroup-name)))
8836                    respool-methods)
8837             (gnus-summary-move-article n nil (intern respool-method))
8838           (gnus-summary-copy-article n nil (intern respool-method))))))
8839
8840 ;; Suggested by gregj@unidata.com (Gregory J. Grubbs).
8841 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8842   "Move the current article to a different newsgroup.
8843 If N is a positive number, move the N next articles.
8844 If N is a negative number, move the N previous articles.
8845 If N is nil and any articles have been marked with the process mark,
8846 move those articles instead.
8847 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. 
8848 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
8849 re-spool using this method.
8850 For this function to work, the newsgroup that you want to move to have
8851 to support the `request-move' and `request-accept'
8852 functions. (Ie. mail newsgroups at present.)"
8853   (interactive "P")
8854   (gnus-set-global-variables)
8855   (let ((articles (gnus-summary-work-articles n))
8856         (copy-buf (get-buffer-create "*copy work*"))
8857         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
8858         art-group to-method)
8859     (buffer-disable-undo copy-buf)
8860     (if (and (not to-newsgroup) (not select-method))
8861         (setq to-newsgroup
8862               (completing-read 
8863                (format "Where do you want to copy %s? %s"
8864                        (if (> (length articles) 1)
8865                            (format "these %d articles" (length articles))
8866                          "this article")
8867                        (if gnus-current-move-group
8868                            (format "(%s default) " gnus-current-move-group)
8869                          ""))
8870                gnus-active-hashtb nil nil prefix)))
8871     (if to-newsgroup
8872         (progn
8873           (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
8874               (setq to-newsgroup (or gnus-current-move-group "")))
8875           (or (gnus-gethash to-newsgroup gnus-active-hashtb)
8876               (gnus-activate-group to-newsgroup)
8877               (error "No such group: %s" to-newsgroup))
8878           (setq gnus-current-move-group to-newsgroup)))
8879     (setq to-method (if select-method (list select-method "")
8880                       (gnus-find-method-for-group to-newsgroup)))
8881     (or (gnus-check-backend-function 'request-accept-article (car to-method))
8882         (error "%s does not support article copying" (car to-method)))
8883     (or (gnus-check-server to-method)
8884         (error "Can't open server %s" (car to-method)))
8885     (while articles
8886       (gnus-message 6 "Copying to %s: %s..." 
8887                     (or select-method to-newsgroup) articles)
8888       (if (setq art-group
8889                 (save-excursion
8890                   (set-buffer copy-buf)
8891                   (gnus-request-article-this-buffer
8892                    (car articles) gnus-newsgroup-name)
8893                   (gnus-request-accept-article
8894                    (if select-method (quote select-method) to-newsgroup)
8895                    (not (cdr articles)))))
8896           (let* ((entry 
8897                   (or
8898                    (gnus-gethash (car art-group) gnus-newsrc-hashtb)
8899                    (gnus-gethash 
8900                     (gnus-group-prefixed-name 
8901                      (car art-group) 
8902                      (if select-method (list select-method "")
8903                        (gnus-find-method-for-group to-newsgroup)))
8904                     gnus-newsrc-hashtb)))
8905                  (info (nth 2 entry))
8906                  (article (car articles)))
8907             ;; We copy the info over to the new group.
8908             (if (not info)
8909                 ()                      ; This group does not exist (yet).
8910               (if (not (memq article gnus-newsgroup-unreads))
8911                   (setcar (cdr (cdr info))
8912                           (gnus-add-to-range (nth 2 info) 
8913                                              (list (cdr art-group)))))
8914               ;; Copy any marks over to the new group.
8915               (let ((marks '((tick . gnus-newsgroup-marked)
8916                              (dormant . gnus-newsgroup-dormant)
8917                              (expire . gnus-newsgroup-expirable)
8918                              (bookmark . gnus-newsgroup-bookmarks)
8919                              (reply . gnus-newsgroup-replied)))
8920                     (to-article (cdr art-group)))
8921                 (while marks
8922                   (if (memq article (symbol-value (cdr (car marks))))
8923                       (gnus-add-marked-articles 
8924                        (car info) (car (car marks)) (list to-article) info))
8925                   (setq marks (cdr marks))))))
8926         (gnus-message 1 "Couldn't copy article %s" (car articles)))
8927       (gnus-summary-remove-process-mark (car articles))
8928       (setq articles (cdr articles)))
8929     (kill-buffer copy-buf)))
8930
8931 (defun gnus-summary-import-article (file)
8932   "Import a random file into a mail newsgroup."
8933   (interactive "fImport file: ")
8934   (let ((group gnus-newsgroup-name)
8935         atts)
8936     (or (gnus-check-backend-function 'request-accept-article group)
8937         (error "%s does not support article importing" group))
8938     (or (file-readable-p file)
8939         (not (file-regular-p file))
8940         (error "Can't read %s" file))
8941     (save-excursion
8942       (set-buffer (get-buffer-create " *import file*"))
8943       (buffer-disable-undo (current-buffer))
8944       (erase-buffer)
8945       (insert-file-contents file)
8946       (goto-char (point-min))
8947       (if (nnheader-article-p)
8948           ()
8949         (setq atts (file-attributes file))
8950         (insert "From: " (read-string "From: ") "\n"
8951                 "Subject: " (read-string "Subject: ") "\n"
8952                 "Date: " (current-time-string (nth 5 atts)) "\n"
8953                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8954       (gnus-request-accept-article group t)
8955       (kill-buffer (current-buffer)))))
8956
8957 (defun gnus-summary-expire-articles ()
8958   "Expire all articles that are marked as expirable in the current group."
8959   (interactive)
8960   (if (not (gnus-check-backend-function 
8961             'request-expire-articles gnus-newsgroup-name))
8962       ()
8963     (let* ((info (nth 2 (gnus-gethash gnus-newsgroup-name 
8964                                       gnus-newsrc-hashtb)))
8965            (total (memq 'total-expire (nth 5 info)))
8966            (expirable (if total
8967                           (gnus-list-of-read-articles gnus-newsgroup-name)
8968                         (setq gnus-newsgroup-expirable
8969                               (sort gnus-newsgroup-expirable '<))))
8970            es)
8971       (if (not expirable)
8972           ()
8973         (gnus-message 6 "Expiring articles...")
8974         ;; The list of articles that weren't expired is returned.
8975         (setq es (gnus-request-expire-articles expirable gnus-newsgroup-name))
8976         (or total (setq gnus-newsgroup-expirable es))
8977         ;; We go through the old list of expirable, and mark all
8978         ;; really expired articles as non-existant.
8979         (or (eq es expirable) ; If nothing was expired, we don't mark.
8980             (let ((gnus-use-cache nil))
8981               (while expirable
8982                 (or (memq (car expirable) es)
8983                     (gnus-summary-mark-article
8984                      (car expirable) gnus-canceled-mark))
8985                 (setq expirable (cdr expirable)))))
8986         (gnus-message 6 "Expiring articles...done")))))
8987
8988 (defun gnus-summary-expire-articles-now ()
8989   "Expunge all expirable articles in the current group.
8990 This means that *all* articles that are marked as expirable will be
8991 deleted forever, right now."
8992   (interactive)
8993   (or gnus-expert-user
8994       (gnus-y-or-n-p
8995        "Are you really, really, really sure you want to expunge? ")
8996       (error "Phew!"))
8997   (let ((nnmail-expiry-wait -1)
8998         (nnmail-expiry-wait-function nil))
8999     (gnus-summary-expire-articles)))
9000
9001 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9002 (defun gnus-summary-delete-article (&optional n)
9003   "Delete the N next (mail) articles.
9004 This command actually deletes articles. This is not a marking
9005 command. The article will disappear forever from you life, never to
9006 return. 
9007 If N is negative, delete backwards.
9008 If N is nil and articles have been marked with the process mark,
9009 delete these instead."
9010   (interactive "P")
9011   (or (gnus-check-backend-function 'request-expire-articles 
9012                                    gnus-newsgroup-name)
9013       (error "The current newsgroup does not support article deletion."))
9014   ;; Compute the list of articles to delete.
9015   (let ((articles (gnus-summary-work-articles n))
9016         not-deleted)
9017     (if (and gnus-novice-user
9018              (not (gnus-y-or-n-p 
9019                    (format "Do you really want to delete %s forever? "
9020                            (if (> (length articles) 1) "these articles"
9021                              "this article")))))
9022         ()
9023       ;; Delete the articles.
9024       (setq not-deleted (gnus-request-expire-articles 
9025                          articles gnus-newsgroup-name 'force))
9026       (while articles
9027         (gnus-summary-remove-process-mark (car articles))       
9028         ;; The backend might not have been able to delete the article
9029         ;; after all.  
9030         (or (memq (car articles) not-deleted)
9031             (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9032         (setq articles (cdr articles))))
9033     (gnus-summary-position-cursor)
9034     not-deleted))
9035
9036 (defun gnus-summary-edit-article ()
9037   "Enter into a buffer and edit the current article.
9038 This will have permanent effect only in mail groups."
9039   (interactive)
9040   (or (gnus-check-backend-function 
9041        'request-replace-article gnus-newsgroup-name)
9042       (error "The current newsgroup does not support article editing."))
9043   (gnus-summary-select-article t)
9044   (gnus-configure-windows 'article)
9045   (select-window (get-buffer-window gnus-article-buffer))
9046   (gnus-message 6 "C-c C-c to end edits")
9047   (setq buffer-read-only nil)
9048   (text-mode)
9049   (use-local-map (copy-keymap (current-local-map)))
9050   (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
9051   (buffer-enable-undo)
9052   (widen)
9053   (goto-char (point-min))
9054   (search-forward "\n\n" nil t))
9055
9056 (defun gnus-summary-edit-article-done ()
9057   "Make edits to the current article permanent."
9058   (interactive)
9059   (let ((buf (buffer-substring-no-properties (point-min) (point-max))))
9060     (erase-buffer)
9061     (insert buf)
9062     (if (not (gnus-request-replace-article 
9063               (cdr gnus-article-current) (car gnus-article-current) 
9064               (current-buffer)))
9065         (error "Couldn't replace article.")
9066       (gnus-article-mode)
9067       (use-local-map gnus-article-mode-map)
9068       (setq buffer-read-only t)
9069       (buffer-disable-undo (current-buffer))
9070       (gnus-configure-windows 'summary))
9071       (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook))))
9072
9073 (defun gnus-summary-edit-article-postpone ()
9074   "Postpone changes to the current article."
9075   (interactive)
9076   (gnus-article-mode)
9077   (use-local-map gnus-article-mode-map)
9078   (setq buffer-read-only t)
9079   (buffer-disable-undo (current-buffer))
9080   (gnus-configure-windows 'summary)
9081   (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook)))
9082
9083 (defun gnus-summary-fancy-query ()
9084   "Query where the fancy respool algorithm would put this article."
9085   (interactive)
9086   (gnus-summary-select-article)
9087   (save-excursion
9088     (set-buffer gnus-article-buffer)
9089     (save-restriction
9090       (goto-char (point-min))
9091       (search-forward "\n\n")
9092       (narrow-to-region (point-min) (point))
9093       (pp-eval-expression (list 'quote (nnmail-split-fancy))))))
9094
9095 ;; Summary score commands.
9096
9097 ;; Suggested by boubaker@cenatls.cena.dgac.fr.
9098
9099 (defun gnus-summary-raise-score (n)
9100   "Raise the score of the current article by N."
9101   (interactive "p")
9102   (gnus-summary-set-score (+ (gnus-summary-article-score) n)))
9103
9104 (defun gnus-summary-set-score (n)
9105   "Set the score of the current article to N."
9106   (interactive "p")
9107   ;; Skip dummy header line.
9108   (save-excursion
9109     (gnus-summary-show-thread)
9110     (if (eq (gnus-summary-article-mark) gnus-dummy-mark)
9111         (forward-line 1))
9112     (let ((buffer-read-only nil))
9113       ;; Set score.
9114       (gnus-summary-update-mark
9115        (if (= n (or gnus-summary-default-score 0)) ? 
9116          (if (< n (or gnus-summary-default-score 0)) 
9117              gnus-score-below-mark gnus-score-over-mark)) 'score))
9118     (let* ((article (gnus-summary-article-number))
9119            (score (assq article gnus-newsgroup-scored)))
9120       (if score (setcdr score n)
9121         (setq gnus-newsgroup-scored 
9122               (cons (cons article n) gnus-newsgroup-scored))))
9123     (gnus-summary-update-line)))
9124
9125 (defun gnus-summary-current-score ()
9126   "Return the score of the current article."
9127   (interactive)
9128   (message "%s" (gnus-summary-article-score)))
9129
9130 ;; Summary marking commands.
9131
9132 (defun gnus-summary-raise-same-subject-and-select (score)
9133   "Raise articles which has the same subject with SCORE and select the next."
9134   (interactive "p")
9135   (let ((subject (gnus-summary-subject-string)))
9136     (gnus-summary-raise-score score)
9137     (while (gnus-summary-search-subject nil nil subject)
9138       (gnus-summary-raise-score score))
9139     (gnus-summary-next-article t)))
9140
9141 (defun gnus-summary-raise-same-subject (score)
9142   "Raise articles which has the same subject with SCORE."
9143   (interactive "p")
9144   (let ((subject (gnus-summary-subject-string)))
9145     (gnus-summary-raise-score score)
9146     (while (gnus-summary-search-subject nil nil subject)
9147       (gnus-summary-raise-score score))
9148     (gnus-summary-next-subject 1 t)))
9149
9150 (defun gnus-score-default (level)
9151   (if level (prefix-numeric-value level) 
9152     gnus-score-interactive-default-score))
9153
9154 (defun gnus-summary-raise-thread (&optional score)
9155   "Raise the score of the articles in the current thread with SCORE."
9156   (interactive "P")
9157   (setq score (gnus-score-default score))
9158   (let (e)
9159     (save-excursion
9160       (let ((level (gnus-summary-thread-level)))
9161         (gnus-summary-raise-score score)
9162         (while (and (zerop (gnus-summary-next-subject 1 nil t))
9163                     (> (gnus-summary-thread-level) level))
9164           (gnus-summary-raise-score score))
9165         (setq e (point))))
9166     (let ((gnus-summary-check-current t))
9167       (or (zerop (gnus-summary-next-subject 1 t))
9168           (goto-char e))))
9169   (gnus-summary-recenter)
9170   (gnus-summary-position-cursor)
9171   (gnus-set-mode-line 'summary))
9172
9173 (defun gnus-summary-lower-same-subject-and-select (score)
9174   "Raise articles which has the same subject with SCORE and select the next."
9175   (interactive "p")
9176   (gnus-summary-raise-same-subject-and-select (- score)))
9177
9178 (defun gnus-summary-lower-same-subject (score)
9179   "Raise articles which has the same subject with SCORE."
9180   (interactive "p")
9181   (gnus-summary-raise-same-subject (- score)))
9182
9183 (defun gnus-summary-lower-thread (&optional score)
9184   "Lower score of articles in the current thread with SCORE."
9185   (interactive "P")
9186   (gnus-summary-raise-thread (- (1- (gnus-score-default score)))))
9187
9188 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9189   "Mark articles which has the same subject as read, and then select the next.
9190 If UNMARK is positive, remove any kind of mark.
9191 If UNMARK is negative, tick articles."
9192   (interactive "P")
9193   (if unmark
9194       (setq unmark (prefix-numeric-value unmark)))
9195   (let ((count
9196          (gnus-summary-mark-same-subject
9197           (gnus-summary-subject-string) unmark)))
9198     ;; Select next unread article. If auto-select-same mode, should
9199     ;; select the first unread article.
9200     (gnus-summary-next-article t (and gnus-auto-select-same
9201                                       (gnus-summary-subject-string)))
9202     (gnus-message 7 "%d article%s marked as %s"
9203                   count (if (= count 1) " is" "s are")
9204                   (if unmark "unread" "read"))))
9205
9206 (defun gnus-summary-kill-same-subject (&optional unmark)
9207   "Mark articles which has the same subject as read. 
9208 If UNMARK is positive, remove any kind of mark.
9209 If UNMARK is negative, tick articles."
9210   (interactive "P")
9211   (if unmark
9212       (setq unmark (prefix-numeric-value unmark)))
9213   (let ((count
9214          (gnus-summary-mark-same-subject
9215           (gnus-summary-subject-string) unmark)))
9216     ;; If marked as read, go to next unread subject.
9217     (if (null unmark)
9218         ;; Go to next unread subject.
9219         (gnus-summary-next-subject 1 t))
9220     (gnus-message 7 "%d articles are marked as %s"
9221                   count (if unmark "unread" "read"))))
9222
9223 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9224   "Mark articles with same SUBJECT as read, and return marked number.
9225 If optional argument UNMARK is positive, remove any kinds of marks.
9226 If optional argument UNMARK is negative, mark articles as unread instead."
9227   (let ((count 1))
9228     (save-excursion
9229       (cond 
9230        ((null unmark)                   ; Mark as read.
9231         (while (and 
9232                 (progn
9233                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9234                   (gnus-summary-show-thread) t)
9235                 (gnus-summary-search-forward nil subject))
9236           (setq count (1+ count))))
9237        ((> unmark 0)                    ; Tick.
9238         (while (and
9239                 (progn
9240                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9241                   (gnus-summary-show-thread) t)
9242                 (gnus-summary-search-forward nil subject))
9243           (setq count (1+ count))))
9244        (t                               ; Mark as unread.
9245         (while (and
9246                 (progn
9247                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9248                   (gnus-summary-show-thread) t)
9249                 (gnus-summary-search-forward nil subject))
9250           (setq count (1+ count)))))
9251       (gnus-set-mode-line 'summary)
9252       ;; Return the number of marked articles.
9253       count)))
9254
9255 (defun gnus-summary-mark-as-processable (n &optional unmark)
9256   "Set the process mark on the next N articles.
9257 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9258 the process mark instead.  The difference between N and the actual
9259 number of articles marked is returned."
9260   (interactive "p")
9261   (let ((backward (< n 0))
9262         (n (abs n)))
9263   (while (and 
9264           (> n 0)
9265           (if unmark
9266               (gnus-summary-remove-process-mark (gnus-summary-article-number))
9267             (gnus-summary-set-process-mark (gnus-summary-article-number)))
9268           (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9269     (setq n (1- n)))
9270   (if (/= 0 n) (gnus-message 7 "No more articles"))
9271   (gnus-summary-recenter)
9272   (gnus-summary-position-cursor)
9273   n))
9274
9275 (defun gnus-summary-unmark-as-processable (n)
9276   "Remove the process mark from the next N articles.
9277 If N is negative, mark backward instead.  The difference between N and
9278 the actual number of articles marked is returned."
9279   (interactive "p")
9280   (gnus-summary-mark-as-processable n t))
9281
9282 (defun gnus-summary-unmark-all-processable ()
9283   "Remove the process mark from all articles."
9284   (interactive)
9285   (save-excursion
9286     (while gnus-newsgroup-processable
9287       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9288   (gnus-summary-position-cursor))
9289
9290 (defun gnus-summary-mark-as-expirable (n)
9291   "Mark N articles forward as expirable.
9292 If N is negative, mark backward instead. The difference between N and
9293 the actual number of articles marked is returned."
9294   (interactive "p")
9295   (gnus-summary-mark-forward n gnus-expirable-mark))
9296
9297 (defun gnus-summary-mark-article-as-replied (article)
9298   "Mark ARTICLE replied and update the summary line."
9299   (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied))
9300   (let ((buffer-read-only nil))
9301     (if (gnus-summary-goto-subject article)
9302         (progn
9303           (gnus-summary-update-mark gnus-replied-mark 'replied)
9304           t))))
9305
9306 (defun gnus-summary-set-bookmark (article)
9307   "Set a bookmark in current article."
9308   (interactive (list (gnus-summary-article-number)))
9309   (if (or (not (get-buffer gnus-article-buffer))
9310           (not gnus-current-article)
9311           (not gnus-article-current)
9312           (not (equal gnus-newsgroup-name (car gnus-article-current))))
9313       (error "No current article selected"))
9314   ;; Remove old bookmark, if one exists.
9315   (let ((old (assq article gnus-newsgroup-bookmarks)))
9316     (if old (setq gnus-newsgroup-bookmarks 
9317                   (delq old gnus-newsgroup-bookmarks))))
9318   ;; Set the new bookmark, which is on the form 
9319   ;; (article-number . line-number-in-body).
9320   (setq gnus-newsgroup-bookmarks 
9321         (cons 
9322          (cons article 
9323                (save-excursion
9324                  (set-buffer gnus-article-buffer)
9325                  (count-lines
9326                   (min (point)
9327                        (save-excursion
9328                          (goto-char (point-min))
9329                          (search-forward "\n\n" nil t)
9330                          (point)))
9331                   (point))))
9332          gnus-newsgroup-bookmarks))
9333   (gnus-message 6 "A bookmark has been added to the current article."))
9334
9335 (defun gnus-summary-remove-bookmark (article)
9336   "Remove the bookmark from the current article."
9337   (interactive (list (gnus-summary-article-number)))
9338   ;; Remove old bookmark, if one exists.
9339   (let ((old (assq article gnus-newsgroup-bookmarks)))
9340     (if old 
9341         (progn
9342           (setq gnus-newsgroup-bookmarks 
9343                 (delq old gnus-newsgroup-bookmarks))
9344           (gnus-message 6 "Removed bookmark."))
9345       (gnus-message 6 "No bookmark in current article."))))
9346
9347 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9348 (defun gnus-summary-mark-as-dormant (n)
9349   "Mark N articles forward as dormant.
9350 If N is negative, mark backward instead.  The difference between N and
9351 the actual number of articles marked is returned."
9352   (interactive "p")
9353   (gnus-summary-mark-forward n gnus-dormant-mark))
9354
9355 (defun gnus-summary-set-process-mark (article)
9356   "Set the process mark on ARTICLE and update the summary line."
9357   (setq gnus-newsgroup-processable (cons article gnus-newsgroup-processable))
9358   (let ((buffer-read-only nil))
9359     (if (gnus-summary-goto-subject article)
9360         (progn
9361           (gnus-summary-show-thread)
9362           (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9363                (forward-line 1))
9364           (gnus-summary-update-mark gnus-process-mark 'replied)
9365           t))))
9366
9367 (defun gnus-summary-remove-process-mark (article)
9368   "Remove the process mark from ARTICLE and update the summary line."
9369   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9370   (let ((buffer-read-only nil))
9371     (if (gnus-summary-goto-subject article)
9372         (progn
9373           (gnus-summary-show-thread)
9374           (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9375                (forward-line 1))
9376           (gnus-summary-update-mark ?  'replied)
9377           (if (memq article gnus-newsgroup-replied) 
9378               (gnus-summary-update-mark gnus-replied-mark 'replied))
9379           t))))
9380
9381 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9382   "Mark N articles as read forwards.
9383 If N is negative, mark backwards instead.
9384 Mark with MARK. If MARK is ? , ?! or ??, articles will be
9385 marked as unread. 
9386 The difference between N and the actual number of articles marked is
9387 returned."
9388   (interactive "p")
9389   (gnus-set-global-variables)
9390   (let ((backward (< n 0))
9391         (gnus-summary-goto-unread
9392          (and gnus-summary-goto-unread
9393               (not (memq mark (list gnus-unread-mark
9394                                     gnus-ticked-mark gnus-dormant-mark)))))
9395         (n (abs n))
9396         (mark (or mark gnus-del-mark)))
9397   (while (and (> n 0)
9398               (gnus-summary-mark-article nil mark no-expire)
9399               (zerop (gnus-summary-next-subject 
9400                       (if backward -1 1) gnus-summary-goto-unread t)))
9401     (setq n (1- n)))
9402   (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9403   (gnus-summary-recenter)
9404   (gnus-summary-position-cursor)
9405   (gnus-set-mode-line 'summary)
9406   n))
9407
9408 (defun gnus-summary-mark-article-as-read (mark)
9409   "Mark the current article quickly as read with MARK."
9410   (let ((article (gnus-summary-article-number)))
9411     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9412     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9413     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9414     (setq gnus-newsgroup-reads
9415           (cons (cons article mark) gnus-newsgroup-reads))
9416     ;; Possibly remove from cache, if that is used. 
9417     (and gnus-use-cache (gnus-cache-enter-remove-article article))
9418     (and gnus-newsgroup-auto-expire 
9419          (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9420              (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9421              (= mark gnus-read-mark))
9422          (progn
9423            (setq mark gnus-expirable-mark)
9424            (setq gnus-newsgroup-expirable 
9425                  (cons article gnus-newsgroup-expirable))))
9426     (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9427       (forward-line 1))
9428     ;; Fix the mark.
9429     (gnus-summary-update-mark mark 'unread)
9430     t))
9431
9432 (defun gnus-summary-mark-article-as-unread (mark)
9433   "Mark the current article quickly as unread with MARK."
9434   (let ((article (gnus-summary-article-number)))
9435     (or (memq article gnus-newsgroup-unreads)
9436         (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9437     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9438     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9439     (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9440     (setq gnus-newsgroup-reads
9441           (delq (assq article gnus-newsgroup-reads)
9442                 gnus-newsgroup-reads))
9443     (if (= mark gnus-ticked-mark)
9444         (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9445     (if (= mark gnus-dormant-mark)
9446         (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))
9447
9448     ;; See whether the article is to be put in the cache.
9449     (and gnus-use-cache
9450          (vectorp (gnus-get-header-by-num article))
9451          (save-excursion
9452            (gnus-cache-possibly-enter-article 
9453             gnus-newsgroup-name article 
9454             (gnus-get-header-by-num article)
9455             (= mark gnus-ticked-mark)
9456             (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9457
9458     (while (eq (gnus-summary-article-mark) gnus-dummy-mark)
9459       (forward-line 1))
9460     ;; Fix the mark.
9461     (gnus-summary-update-mark mark 'unread)
9462     t))
9463
9464 (defun gnus-summary-mark-article (&optional article mark no-expire)
9465   "Mark ARTICLE with MARK.  MARK can be any character.
9466 Four MARK strings are reserved: `? ' (unread), `?!' (ticked), `??'
9467 (dormant) and `?E' (expirable).
9468 If MARK is nil, then the default character `?D' is used.
9469 If ARTICLE is nil, then the article on the current line will be
9470 marked." 
9471   (and (stringp mark)
9472        (setq mark (aref mark 0)))
9473   ;; If no mark is given, then we check auto-expiring.
9474   (and (not no-expire)
9475        gnus-newsgroup-auto-expire 
9476        (or (not mark)
9477            (and (numberp mark) 
9478                 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
9479                     (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
9480                     (= mark gnus-read-mark))))
9481        (setq mark gnus-expirable-mark))
9482   (let* ((mark (or mark gnus-del-mark))
9483          (article (or article (gnus-summary-article-number))))
9484     (or article (error "No article on current line"))
9485     (if (or (= mark gnus-unread-mark) 
9486             (= mark gnus-ticked-mark) 
9487             (= mark gnus-dormant-mark))
9488         (gnus-mark-article-as-unread article mark)
9489       (gnus-mark-article-as-read article mark))
9490
9491     ;; See whether the article is to be put in the cache.
9492     (and gnus-use-cache
9493          (not (= mark gnus-canceled-mark))
9494          (vectorp (gnus-get-header-by-num article))
9495          (save-excursion
9496            (gnus-cache-possibly-enter-article 
9497             gnus-newsgroup-name article 
9498             (gnus-get-header-by-num article)
9499             (= mark gnus-ticked-mark)
9500             (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9501
9502     (if (gnus-summary-goto-subject article)
9503         (let ((buffer-read-only nil))
9504           (gnus-summary-show-thread)
9505           (and (eq (gnus-summary-article-mark) gnus-dummy-mark)
9506                (forward-line 1))
9507           ;; Fix the mark.
9508           (gnus-summary-update-mark mark 'unread)
9509           t))))
9510
9511 (defun gnus-summary-update-mark (mark type)
9512   (beginning-of-line)
9513   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9514         (buffer-read-only nil)
9515         plist)
9516     (if (not forward)
9517         ()
9518       (forward-char forward)
9519       (setq plist (text-properties-at (point)))
9520       (delete-char 1)
9521       (insert mark)
9522       (and plist (add-text-properties (1- (point)) (point) plist))
9523       (and (eq type 'unread)
9524            (add-text-properties (1- (point)) (point) (list 'gnus-mark mark)))
9525       (gnus-summary-update-line (eq mark gnus-unread-mark)))))
9526   
9527 (defun gnus-mark-article-as-read (article &optional mark)
9528   "Enter ARTICLE in the pertinent lists and remove it from others."
9529   ;; Make the article expirable.
9530   (let ((mark (or mark gnus-del-mark)))
9531     (if (= mark gnus-expirable-mark)
9532         (setq gnus-newsgroup-expirable (cons article gnus-newsgroup-expirable))
9533       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9534     ;; Remove from unread and marked lists.
9535     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9536     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9537     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9538     (setq gnus-newsgroup-reads 
9539           (cons (cons article mark) gnus-newsgroup-reads))
9540     ;; Possibly remove from cache, if that is used. 
9541     (and gnus-use-cache (gnus-cache-enter-remove-article article))))
9542
9543 (defun gnus-mark-article-as-unread (article &optional mark)
9544   "Enter ARTICLE in the pertinent lists and remove it from others."
9545   (let ((mark (or mark gnus-ticked-mark)))
9546     ;; Add to unread list.
9547     (or (memq article gnus-newsgroup-unreads)
9548         (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads)))
9549     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9550     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9551     (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9552     (setq gnus-newsgroup-reads
9553           (delq (assq article gnus-newsgroup-reads)
9554                 gnus-newsgroup-reads))
9555     (if (= mark gnus-ticked-mark)
9556         (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked)))
9557     (if (= mark gnus-dormant-mark)
9558         (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant)))))
9559
9560 (defalias 'gnus-summary-mark-as-unread-forward 
9561   'gnus-summary-tick-article-forward)
9562 (make-obsolete 'gnus-summary-mark-as-unread-forward 
9563                'gnus-summary-tick-article-forward)
9564 (defun gnus-summary-tick-article-forward (n)
9565   "Tick N articles forwards.
9566 If N is negative, tick backwards instead.
9567 The difference between N and the number of articles ticked is returned."
9568   (interactive "p")
9569   (gnus-summary-mark-forward n gnus-ticked-mark))
9570
9571 (defalias 'gnus-summary-mark-as-unread-backward 
9572   'gnus-summary-tick-article-backward)
9573 (make-obsolete 'gnus-summary-mark-as-unread-backward 
9574                'gnus-summary-tick-article-backward)
9575 (defun gnus-summary-tick-article-backward (n)
9576   "Tick N articles backwards.
9577 The difference between N and the number of articles ticked is returned."
9578   (interactive "p")
9579   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9580
9581 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9582 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9583 (defun gnus-summary-tick-article (&optional article clear-mark)
9584   "Mark current article as unread.
9585 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9586 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9587   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9588                                        gnus-ticked-mark)))
9589
9590 (defun gnus-summary-mark-as-read-forward (n)
9591   "Mark N articles as read forwards.
9592 If N is negative, mark backwards instead.
9593 The difference between N and the actual number of articles marked is
9594 returned."
9595   (interactive "p")
9596   (gnus-summary-mark-forward n gnus-del-mark t))
9597
9598 (defun gnus-summary-mark-as-read-backward (n)
9599   "Mark the N articles as read backwards.
9600 The difference between N and the actual number of articles marked is
9601 returned."
9602   (interactive "p")
9603   (gnus-summary-mark-forward (- n) gnus-del-mark t))
9604
9605 (defun gnus-summary-mark-as-read (&optional article mark)
9606   "Mark current article as read.
9607 ARTICLE specifies the article to be marked as read.
9608 MARK specifies a string to be inserted at the beginning of the line."
9609   (gnus-summary-mark-article article mark))
9610
9611 (defun gnus-summary-clear-mark-forward (n)
9612   "Clear marks from N articles forward.
9613 If N is negative, clear backward instead.
9614 The difference between N and the number of marks cleared is returned."
9615   (interactive "p")
9616   (gnus-summary-mark-forward n gnus-unread-mark))
9617
9618 (defun gnus-summary-clear-mark-backward (n)
9619   "Clear marks from N articles backward.
9620 The difference between N and the number of marks cleared is returned."
9621   (interactive "p")
9622   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9623
9624 (defun gnus-summary-mark-unread-as-read ()
9625   "Intended to be used by `gnus-summary-mark-article-hook'."
9626   (or (memq gnus-current-article gnus-newsgroup-marked)
9627       (memq gnus-current-article gnus-newsgroup-dormant)
9628       (memq gnus-current-article gnus-newsgroup-expirable)
9629       (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9630
9631 (defun gnus-summary-mark-region-as-read (point mark all)
9632   "Mark all unread articles between point and mark as read.
9633 If given a prefix, mark all articles between point and mark as read,
9634 even ticked and dormant ones."
9635   (interactive "r\nP")
9636   (save-excursion
9637     (goto-char point)
9638     (beginning-of-line)
9639     (while (and 
9640             (< (point) mark)
9641             (progn
9642               (and
9643                (or all
9644                    (and
9645                     (not (memq (gnus-summary-article-number)
9646                                gnus-newsgroup-marked))
9647                     (not (memq (gnus-summary-article-number)
9648                                gnus-newsgroup-dormant))))
9649                (gnus-summary-mark-article
9650                 (gnus-summary-article-number) gnus-del-mark))
9651               t)
9652             (zerop (forward-line 1))))))
9653
9654 ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
9655 (defalias 'gnus-summary-delete-marked-as-read 
9656   'gnus-summary-remove-lines-marked-as-read)
9657 (make-obsolete 'gnus-summary-delete-marked-as-read 
9658                'gnus-summary-remove-lines-marked-as-read)
9659 (defun gnus-summary-remove-lines-marked-as-read ()
9660   "Remove lines that are marked as read."
9661   (interactive)
9662   (gnus-summary-remove-lines-marked-with 
9663    (concat (mapconcat
9664             (lambda (char) (char-to-string (symbol-value char)))
9665             '(gnus-del-mark gnus-read-mark gnus-ancient-mark
9666               gnus-killed-mark gnus-kill-file-mark
9667               gnus-low-score-mark gnus-expirable-mark
9668               gnus-canceled-mark gnus-catchup-mark)
9669             ""))))
9670
9671 (defalias 'gnus-summary-delete-marked-with 
9672   'gnus-summary-remove-lines-marked-with)
9673 (make-obsolete 'gnus-summary-delete-marked-with 
9674                'gnus-summary-remove-lines-marked-with)
9675 ;; Rewrite by Daniel Quinlan <quinlan@best.com>.
9676 (defun gnus-summary-remove-lines-marked-with (marks)
9677   "Remove lines that are marked with MARKS (e.g. \"DK\")."
9678   (interactive "sMarks: ")
9679   ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
9680   (gnus-set-global-variables)
9681   (let ((buffer-read-only nil)
9682         (marks (concat "^[" marks "]")))
9683     (goto-char (point-min))
9684     (if gnus-newsgroup-adaptive
9685         (gnus-score-remove-lines-adaptive marks)
9686       (while (re-search-forward marks nil t)
9687         (gnus-delete-line)))
9688     ;; If we use dummy roots, we have to do an additional sweep over
9689     ;; the buffer.
9690     (if (not (eq gnus-summary-make-false-root 'dummy))
9691         ()
9692       (goto-char (point-min))
9693       (setq marks (concat "^[" (char-to-string gnus-dummy-mark) "]"))
9694       (while (re-search-forward marks nil t)
9695         (if (gnus-subject-equal
9696              (gnus-summary-subject-string)
9697              (progn
9698                (forward-line 1)
9699                (gnus-summary-subject-string)))
9700             ()
9701           (forward-line -1)
9702           (gnus-delete-line)))))
9703   (or (zerop (buffer-size))
9704       (if (eobp)
9705           (gnus-summary-prev-subject 1)
9706         (gnus-summary-position-cursor))))
9707
9708 (defun gnus-summary-expunge-below (&optional score)
9709   "Remove articles with score less than SCORE."
9710   (interactive "P")
9711   (gnus-set-global-variables)
9712   (setq score (if score
9713                   (prefix-numeric-value score)
9714                 (or gnus-summary-default-score 0)))
9715   (save-excursion
9716     (set-buffer gnus-summary-buffer)
9717     (goto-char (point-min))
9718     (let ((buffer-read-only nil)
9719           beg)
9720       (while (not (eobp))
9721         (if (< (gnus-summary-article-score) score)
9722             (progn
9723               (setq beg (point))
9724               (forward-line 1)
9725               (delete-region beg (point)))
9726           (forward-line 1)))
9727       ;; Adjust point.
9728       (or (zerop (buffer-size))
9729           (if (eobp)
9730               (gnus-summary-prev-subject 1)
9731             (gnus-summary-position-cursor))))))
9732
9733 (defun gnus-summary-mark-below (score mark)
9734   "Mark articles with score less than SCORE with MARK."
9735   (interactive "P\ncMark: ")
9736   (gnus-set-global-variables)
9737   (setq score (if score
9738                   (prefix-numeric-value score)
9739                 (or gnus-summary-default-score 0)))
9740   (save-excursion
9741     (set-buffer gnus-summary-buffer)
9742     (goto-char (point-min))
9743     (while (not (eobp))
9744       (and (< (gnus-summary-article-score) score)
9745            (gnus-summary-mark-article nil mark))
9746       (forward-line 1))))
9747
9748 (defun gnus-summary-kill-below (&optional score)
9749   "Mark articles with score below SCORE as read."
9750   (interactive "P")
9751   (gnus-set-global-variables)
9752   (gnus-summary-mark-below score gnus-killed-mark))
9753
9754 (defun gnus-summary-clear-above (&optional score)
9755   "Clear all marks from articles with score above SCORE."
9756   (interactive "P")
9757   (gnus-set-global-variables)
9758   (gnus-summary-mark-above score gnus-unread-mark))
9759
9760 (defun gnus-summary-tick-above (&optional score)
9761   "Tick all articles with score above SCORE."
9762   (interactive "P")
9763   (gnus-set-global-variables)
9764   (gnus-summary-mark-above score gnus-ticked-mark))
9765
9766 (defun gnus-summary-mark-above (score mark)
9767   "Mark articles with score over SCORE with MARK."
9768   (interactive "P\ncMark: ")
9769   (gnus-set-global-variables)
9770   (setq score (if score
9771                   (prefix-numeric-value score)
9772                 (or gnus-summary-default-score 0)))
9773   (save-excursion
9774     (set-buffer gnus-summary-buffer)
9775     (goto-char (point-min))
9776     (while (not (eobp))
9777       (if (> (gnus-summary-article-score) score)
9778           (progn
9779             (gnus-summary-mark-article nil mark)
9780             (forward-line 1))
9781         (forward-line 1)))))
9782
9783 ;; Suggested by Daniel Quinlan <quinlan@best.com>.  
9784 (defun gnus-summary-show-all-expunged ()
9785   "Display all the hidden articles that were expunged for low scores."
9786   (interactive)
9787   (gnus-set-global-variables)
9788   (let ((buffer-read-only nil))
9789     (let ((scored gnus-newsgroup-scored)
9790           headers h)
9791       (while scored
9792         (or (gnus-summary-goto-subject (car (car scored)))
9793             (and (setq h (gnus-get-header-by-num (car (car scored))))
9794                  (< (cdr (car scored)) gnus-summary-expunge-below)
9795                  (setq headers (cons h headers))))
9796         (setq scored (cdr scored)))
9797       (or headers (error "No expunged articles hidden."))
9798       (goto-char (point-min))
9799       (save-excursion 
9800         (gnus-summary-update-lines 
9801          (point)
9802          (progn
9803            (gnus-summary-prepare-unthreaded (nreverse headers))
9804            (point)))))
9805     (goto-char (point-min))
9806     (gnus-summary-position-cursor)))
9807
9808 (defun gnus-summary-show-all-dormant ()
9809   "Display all the hidden articles that are marked as dormant."
9810   (interactive)
9811   (gnus-set-global-variables)
9812   (let ((buffer-read-only nil))
9813     (let ((dormant gnus-newsgroup-dormant)
9814           headers h)
9815       (while dormant
9816         (or (gnus-summary-goto-subject (car dormant))
9817             (and (setq h (gnus-get-header-by-num (car dormant)))
9818                  (setq headers (cons h headers))))
9819         (setq dormant (cdr dormant)))
9820       (or headers (error "No dormant articles hidden."))
9821       (goto-char (point-min))
9822       (save-excursion 
9823         (gnus-summary-update-lines 
9824          (point)
9825          (progn
9826            (gnus-summary-prepare-unthreaded (nreverse headers))
9827            (point)))))
9828     (goto-char (point-min))
9829     (gnus-summary-position-cursor)))
9830
9831 (defun gnus-summary-hide-all-dormant ()
9832   "Hide all dormant articles."
9833   (interactive)
9834   (gnus-set-global-variables)
9835   (gnus-summary-remove-lines-marked-with (char-to-string gnus-dormant-mark))
9836   (gnus-summary-position-cursor))
9837
9838 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
9839   "Mark all articles not marked as unread in this newsgroup as read.
9840 If prefix argument ALL is non-nil, all articles are marked as read.
9841 If QUIETLY is non-nil, no questions will be asked.
9842 If TO-HERE is non-nil, it should be a point in the buffer. All
9843 articles before this point will be marked as read.
9844 The number of articles marked as read is returned."
9845   (interactive "P")
9846   (gnus-set-global-variables)
9847   (prog1
9848       (if (or quietly
9849               (not gnus-interactive-catchup) ;Without confirmation?
9850               gnus-expert-user
9851               (gnus-y-or-n-p
9852                (if all
9853                    "Mark absolutely all articles as read? "
9854                  "Mark all unread articles as read? ")))
9855           (if (and not-mark 
9856                    (not gnus-newsgroup-adaptive)
9857                    (not gnus-newsgroup-auto-expire))
9858               (progn
9859                 (and all (setq gnus-newsgroup-marked nil
9860                                gnus-newsgroup-dormant nil))
9861                 (setq gnus-newsgroup-unreads 
9862                       (append gnus-newsgroup-marked gnus-newsgroup-dormant)))
9863             ;; We actually mark all articles as canceled, which we
9864             ;; have to do when using auto-expiry or adaptive scoring. 
9865             (let ((unreads (length gnus-newsgroup-unreads)))
9866               (gnus-summary-show-all-threads)
9867               (if (gnus-summary-first-subject (not all))
9868                   (while (and 
9869                           (if to-here (< (point) to-here) t)
9870                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9871                           (gnus-summary-search-subject nil (not all)))))
9872               (- unreads (length gnus-newsgroup-unreads))
9873               (or to-here
9874                   (setq gnus-newsgroup-unreads gnus-newsgroup-marked)))))
9875     (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
9876       (if (and (not to-here) (eq 'nnvirtual (car method)))
9877           (nnvirtual-catchup-group
9878            (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all)))
9879     (gnus-summary-position-cursor)))
9880
9881 (defun gnus-summary-catchup-to-here (&optional all)
9882   "Mark all unticked articles before the current one as read.
9883 If ALL is non-nil, also mark ticked and dormant articles as read."
9884   (interactive)
9885   (gnus-set-global-variables)
9886   (save-excursion
9887     (and (zerop (forward-line -1))
9888          (progn
9889            (end-of-line)
9890            (gnus-summary-catchup all t (point))
9891            (gnus-set-mode-line 'summary))))
9892   (gnus-summary-position-cursor))
9893
9894 (defun gnus-summary-catchup-all (&optional quietly)
9895   "Mark all articles in this newsgroup as read."
9896   (interactive)
9897   (gnus-set-global-variables)
9898   (gnus-summary-catchup t quietly))
9899
9900 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9901   "Mark all articles not marked as unread in this newsgroup as read, then exit.
9902 If prefix argument ALL is non-nil, all articles are marked as read."
9903   (interactive "P")
9904   (gnus-set-global-variables)
9905   (gnus-summary-catchup all quietly nil 'fast)
9906   ;; Select next newsgroup or exit.
9907   (if (eq gnus-auto-select-next 'quietly)
9908       (gnus-summary-next-group nil)
9909     (gnus-summary-exit)))
9910
9911 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9912   "Mark all articles in this newsgroup as read, and then exit."
9913   (interactive)
9914   (gnus-set-global-variables)
9915   (gnus-summary-catchup-and-exit t quietly))
9916
9917 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
9918 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9919   "Mark all articles in this group as read and select the next group.
9920 If given a prefix, mark all articles, unread as well as ticked, as
9921 read." 
9922   (interactive "P")
9923   (gnus-set-global-variables)
9924   (gnus-summary-catchup all)
9925   (gnus-summary-next-group))
9926
9927 ;; Thread-based commands.
9928
9929 (defun gnus-summary-toggle-threads (&optional arg)
9930   "Toggle showing conversation threads.
9931 If ARG is positive number, turn showing conversation threads on."
9932   (interactive "P")
9933   (gnus-set-global-variables)
9934   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9935     (setq gnus-show-threads
9936           (if (null arg) (not gnus-show-threads)
9937             (> (prefix-numeric-value arg) 0)))
9938     (gnus-summary-prepare)
9939     (gnus-summary-goto-subject current)
9940     (gnus-summary-position-cursor)))
9941
9942 (defun gnus-summary-show-all-threads ()
9943   "Show all threads."
9944   (interactive)
9945   (gnus-set-global-variables)
9946   (save-excursion
9947     (let ((buffer-read-only nil))
9948       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9949   (gnus-summary-position-cursor))
9950
9951 (defun gnus-summary-show-thread ()
9952   "Show thread subtrees.
9953 Returns nil if no thread was there to be shown."
9954   (interactive)
9955   (gnus-set-global-variables)
9956   (let ((buffer-read-only nil)
9957         (orig (point))
9958         ;; first goto end then to beg, to have point at beg after let
9959         (end (progn (end-of-line) (point)))
9960         (beg (progn (beginning-of-line) (point))))
9961     (prog1
9962         ;; Any hidden lines here?
9963         (search-forward "\r" end t)
9964       (subst-char-in-region beg end ?\^M ?\n t)
9965       (goto-char orig)
9966       (gnus-summary-position-cursor))))
9967
9968 (defun gnus-summary-hide-all-threads ()
9969   "Hide all thread subtrees."
9970   (interactive)
9971   (gnus-set-global-variables)
9972   (save-excursion
9973     (goto-char (point-min))
9974     (gnus-summary-hide-thread)
9975     (while (and (not (eobp)) (zerop (forward-line 1)))
9976       (gnus-summary-hide-thread)))
9977   (gnus-summary-position-cursor))
9978
9979 (defun gnus-summary-hide-thread ()
9980   "Hide thread subtrees.
9981 Returns nil if no threads were there to be hidden."
9982   (interactive)
9983   (gnus-set-global-variables)
9984   (let ((buffer-read-only nil)
9985         (start (point))
9986         (level (gnus-summary-thread-level))
9987         (end (point)))
9988     ;; Go forward until either the buffer ends or the subthread
9989     ;; ends. 
9990     (if (eobp)
9991         ()
9992       (while (and (zerop (forward-line 1))
9993                   (> (gnus-summary-thread-level) level))
9994         (setq end (point)))
9995       (prog1
9996           (save-excursion
9997             (goto-char end)
9998             (search-backward "\n" start t))
9999         (subst-char-in-region start end ?\n ?\^M t)
10000         (forward-line -1)))))
10001
10002 (defun gnus-summary-go-to-next-thread (&optional previous)
10003   "Go to the same level (or less) next thread.
10004 If PREVIOUS is non-nil, go to previous thread instead.
10005 Return the article number moved to, or nil if moving was impossible."
10006   (let ((level (gnus-summary-thread-level))
10007         (article (gnus-summary-article-number)))
10008     (if previous 
10009         (while (and (zerop (forward-line -1))
10010                     (> (gnus-summary-thread-level) level)))
10011       (while (and (save-excursion
10012                     (forward-line 1)
10013                     (not (eobp)))
10014                   (zerop (forward-line 1))
10015                   (> (gnus-summary-thread-level) level))))
10016     (gnus-summary-recenter)
10017     (gnus-summary-position-cursor)
10018     (let ((oart (gnus-summary-article-number)))
10019       (and (/= oart article) oart))))
10020
10021 (defun gnus-summary-next-thread (n)
10022   "Go to the same level next N'th thread.
10023 If N is negative, search backward instead.
10024 Returns the difference between N and the number of skips actually
10025 done."
10026   (interactive "p")
10027   (gnus-set-global-variables)
10028   (let ((backward (< n 0))
10029         (n (abs n)))
10030   (while (and (> n 0)
10031               (gnus-summary-go-to-next-thread backward))
10032     (setq n (1- n)))
10033   (gnus-summary-position-cursor)
10034   (if (/= 0 n) (gnus-message 7 "No more threads"))
10035   n))
10036
10037 (defun gnus-summary-prev-thread (n)
10038   "Go to the same level previous N'th thread.
10039 Returns the difference between N and the number of skips actually
10040 done."
10041   (interactive "p")
10042   (gnus-set-global-variables)
10043   (gnus-summary-next-thread (- n)))
10044
10045 (defun gnus-summary-go-down-thread (&optional same)
10046   "Go down one level in the current thread.
10047 If SAME is non-nil, also move to articles of the same level."
10048   (let ((level (gnus-summary-thread-level))
10049         (start (point)))
10050     (if (and (zerop (forward-line 1))
10051              (> (gnus-summary-thread-level) level))
10052         t
10053       (goto-char start)
10054       nil)))
10055
10056 (defun gnus-summary-go-up-thread ()
10057   "Go up one level in the current thread."
10058   (let ((level (gnus-summary-thread-level))
10059         (start (point)))
10060     (while (and (zerop (forward-line -1))
10061                 (>= (gnus-summary-thread-level) level)))
10062     (if (>= (gnus-summary-thread-level) level)
10063         (progn
10064           (goto-char start)
10065           nil)
10066       t)))
10067
10068 (defun gnus-summary-down-thread (n)
10069   "Go down thread N steps.
10070 If N is negative, go up instead.
10071 Returns the difference between N and how many steps down that were
10072 taken."
10073   (interactive "p")
10074   (gnus-set-global-variables)
10075   (let ((up (< n 0))
10076         (n (abs n)))
10077   (while (and (> n 0)
10078               (if up (gnus-summary-go-up-thread)
10079                 (gnus-summary-go-down-thread)))
10080     (setq n (1- n)))
10081   (gnus-summary-position-cursor)
10082   (if (/= 0 n) (gnus-message 7 "Can't go further"))
10083   n))
10084
10085 (defun gnus-summary-up-thread (n)
10086   "Go up thread N steps.
10087 If N is negative, go up instead.
10088 Returns the difference between N and how many steps down that were
10089 taken."
10090   (interactive "p")
10091   (gnus-set-global-variables)
10092   (gnus-summary-down-thread (- n)))
10093
10094 (defun gnus-summary-kill-thread (&optional unmark)
10095   "Mark articles under current thread as read.
10096 If the prefix argument is positive, remove any kinds of marks.
10097 If the prefix argument is negative, tick articles instead."
10098   (interactive "P")
10099   (gnus-set-global-variables)
10100   (if unmark
10101       (setq unmark (prefix-numeric-value unmark)))
10102   (let ((killing t)
10103         (level (gnus-summary-thread-level)))
10104     (save-excursion
10105       (while killing
10106         ;; Mark the article...
10107         (cond ((null unmark) (gnus-summary-mark-article-as-read
10108                                gnus-killed-mark))
10109               ((> unmark 0) (gnus-summary-mark-article-as-unread 
10110                              gnus-unread-mark))
10111               (t (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10112         ;; ...and go forward until either the buffer ends or the subtree
10113         ;; ends. 
10114         (if (not (and (zerop (forward-line 1))
10115                       (> (gnus-summary-thread-level) level)))
10116             (setq killing nil))))
10117     ;; Hide killed subtrees.
10118     (and (null unmark)
10119          gnus-thread-hide-killed
10120          (gnus-summary-hide-thread))
10121     ;; If marked as read, go to next unread subject.
10122     (if (null unmark)
10123         ;; Go to next unread subject.
10124         (gnus-summary-next-subject 1 t)))
10125   (gnus-set-mode-line 'summary))
10126
10127 ;; Summary sorting commands
10128
10129 (defun gnus-summary-sort-by-number (&optional reverse)
10130   "Sort summary buffer by article number.
10131 Argument REVERSE means reverse order."
10132   (interactive "P")
10133   (gnus-set-global-variables)
10134   (gnus-summary-sort 
10135    ;; `gnus-summary-article-number' is a macro, and `sort-subr' wants
10136    ;; a function, so we wrap it.
10137    (cons (lambda () (gnus-summary-article-number))
10138          'gnus-thread-sort-by-number) reverse))
10139
10140 (defun gnus-summary-sort-by-author (&optional reverse)
10141   "Sort summary buffer by author name alphabetically.
10142 If case-fold-search is non-nil, case of letters is ignored.
10143 Argument REVERSE means reverse order."
10144   (interactive "P")
10145   (gnus-set-global-variables)
10146   (gnus-summary-sort
10147    (cons
10148     (lambda ()
10149       (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10150              (extract (funcall
10151                        gnus-extract-address-components
10152                        (header-from header))))
10153         (concat (or (car extract) (cdr extract))
10154                 "\r" (header-subject header))))
10155     'gnus-thread-sort-by-author)
10156    reverse))
10157
10158 (defun gnus-summary-sort-by-subject (&optional reverse)
10159   "Sort summary buffer by subject alphabetically. `Re:'s are ignored.
10160 If case-fold-search is non-nil, case of letters is ignored.
10161 Argument REVERSE means reverse order."
10162   (interactive "P")
10163   (gnus-set-global-variables)
10164   (gnus-summary-sort
10165    (cons
10166     (lambda ()
10167       (let* ((header (gnus-get-header-by-num (gnus-summary-article-number)))
10168              (extract (funcall
10169                        gnus-extract-address-components
10170                        (header-from header))))
10171         (concat 
10172          (downcase (gnus-simplify-subject (gnus-summary-subject-string)))
10173          "\r" (or (car extract) (cdr extract)))))
10174     'gnus-thread-sort-by-subject)
10175    reverse))
10176
10177 (defun gnus-summary-sort-by-date (&optional reverse)
10178   "Sort summary buffer by date.
10179 Argument REVERSE means reverse order."
10180   (interactive "P")
10181   (gnus-set-global-variables)
10182   (gnus-summary-sort
10183    (cons
10184     (lambda ()
10185       (gnus-sortable-date
10186        (header-date 
10187         (gnus-get-header-by-num (gnus-summary-article-number)))))
10188     'gnus-thread-sort-by-date)
10189    reverse))
10190
10191 (defun gnus-summary-sort-by-score (&optional reverse)
10192   "Sort summary buffer by score.
10193 Argument REVERSE means reverse order."
10194   (interactive "P")
10195   (gnus-set-global-variables)
10196   (gnus-summary-sort 
10197    (cons (lambda () (gnus-summary-article-score))
10198          'gnus-thread-sort-by-score)
10199    (not reverse)))
10200
10201 (defvar gnus-summary-already-sorted nil)
10202 (defun gnus-summary-sort (predicate reverse)
10203   ;; Sort summary buffer by PREDICATE.  REVERSE means reverse order. 
10204   (if gnus-summary-already-sorted
10205       ()
10206     (let (buffer-read-only)
10207       (if (not gnus-show-threads)
10208           ;; We do untreaded sorting...
10209           (progn
10210             (goto-char (point-min))
10211             (sort-subr reverse 'forward-line 'end-of-line (car predicate)))
10212         ;; ... or we do threaded sorting.
10213         (let ((gnus-thread-sort-functions (list (cdr predicate)))
10214               (gnus-summary-prepare-hook nil)
10215               (gnus-summary-already-sorted nil))
10216           ;; We do that by simply regenerating the threads.
10217           (gnus-summary-prepare)
10218           (and gnus-show-threads
10219                gnus-thread-hide-subtree
10220                (gnus-summary-hide-all-threads))
10221           ;; If in async mode, we send some info to the backend.
10222           (and gnus-newsgroup-async
10223                (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads))
10224                (gnus-request-asynchronous 
10225                 gnus-newsgroup-name
10226                 (if (and gnus-asynchronous-article-function
10227                          (fboundp gnus-asynchronous-article-function))
10228                     (funcall gnus-asynchronous-article-function
10229                              gnus-newsgroup-threads)))))))))
10230
10231   
10232 (defun gnus-sortable-date (date)
10233   "Make sortable string by string-lessp from DATE.
10234 Timezone package is used."
10235   (let* ((date (timezone-fix-time date nil nil)) ;[Y M D H M S]
10236          (year (aref date 0))
10237          (month (aref date 1))
10238          (day (aref date 2)))
10239     (timezone-make-sortable-date 
10240      year month day 
10241      (timezone-make-time-string
10242       (aref date 3) (aref date 4) (aref date 5)))))
10243
10244
10245 ;; Summary saving commands.
10246
10247 (defun gnus-summary-save-article (&optional n)
10248   "Save the current article using the default saver function.
10249 If N is a positive number, save the N next articles.
10250 If N is a negative number, save the N previous articles.
10251 If N is nil and any articles have been marked with the process mark,
10252 save those articles instead.
10253 The variable `gnus-default-article-saver' specifies the saver function."
10254   (interactive "P")
10255   (gnus-set-global-variables)
10256   (let ((articles (gnus-summary-work-articles n)))
10257     (while articles
10258       (let ((header (gnus-get-header-by-num (car articles))))
10259         (if (vectorp header)
10260             (progn
10261               (save-window-excursion
10262                 (gnus-summary-select-article t nil nil (car articles)))
10263               (or gnus-save-all-headers
10264                   (gnus-article-hide-headers t))
10265               ;; Remove any X-Gnus lines.
10266               (save-excursion
10267                 (save-restriction
10268                   (set-buffer gnus-article-buffer)
10269                   (let ((buffer-read-only nil))
10270                     (goto-char (point-min))
10271                     (narrow-to-region (point) (or (search-forward "\n\n" nil t)
10272                                                   (point-max)))
10273                     (while (re-search-forward "^X-Gnus" nil t)
10274                       (beginning-of-line)
10275                       (delete-region (point)
10276                                      (progn (forward-line 1) (point))))
10277                     (widen))))
10278               (save-window-excursion
10279                 (if gnus-default-article-saver
10280                     (funcall gnus-default-article-saver)
10281                   (error "No default saver is defined."))))
10282           (if (assq 'name header)
10283               (gnus-copy-file (cdr (assq 'name header)))
10284             (gnus-message 1 "Article %d is unsaveable" (car articles)))))
10285       (gnus-summary-remove-process-mark (car articles))
10286       (setq articles (cdr articles)))
10287     (gnus-summary-position-cursor)
10288     n))
10289
10290 (defun gnus-summary-pipe-output (&optional arg)
10291   "Pipe the current article to a subprocess.
10292 If N is a positive number, pipe the N next articles.
10293 If N is a negative number, pipe the N previous articles.
10294 If N is nil and any articles have been marked with the process mark,
10295 pipe those articles instead."
10296   (interactive "P")
10297   (gnus-set-global-variables)
10298   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10299     (gnus-summary-save-article arg)))
10300
10301 (defun gnus-summary-save-article-mail (&optional arg)
10302   "Append the current article to an mail file.
10303 If N is a positive number, save the N next articles.
10304 If N is a negative number, save the N previous articles.
10305 If N is nil and any articles have been marked with the process mark,
10306 save those articles instead."
10307   (interactive "P")
10308   (gnus-set-global-variables)
10309   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10310     (gnus-summary-save-article arg)))
10311
10312 (defun gnus-summary-save-article-rmail (&optional arg)
10313   "Append the current article to an rmail file.
10314 If N is a positive number, save the N next articles.
10315 If N is a negative number, save the N previous articles.
10316 If N is nil and any articles have been marked with the process mark,
10317 save those articles instead."
10318   (interactive "P")
10319   (gnus-set-global-variables)
10320   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10321     (gnus-summary-save-article arg)))
10322
10323 (defun gnus-summary-save-article-file (&optional arg)
10324   "Append the current article to a file.
10325 If N is a positive number, save the N next articles.
10326 If N is a negative number, save the N previous articles.
10327 If N is nil and any articles have been marked with the process mark,
10328 save those articles instead."
10329   (interactive "P")
10330   (gnus-set-global-variables)
10331   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10332     (gnus-summary-save-article arg)))
10333
10334 (defun gnus-read-save-file-name (prompt default-name)
10335   (let ((methods gnus-split-methods)
10336         split-name)
10337     (if (not gnus-split-methods)
10338         ()
10339       (save-excursion
10340         (set-buffer gnus-article-buffer)
10341         (gnus-narrow-to-headers)
10342         (while methods
10343           (goto-char (point-min))
10344           (and (condition-case () 
10345                    (re-search-forward (car (car methods)) nil t)
10346                  (error nil))
10347                (setq split-name (cons (nth 1 (car methods)) split-name)))
10348           (setq methods (cdr methods)))
10349         (widen)))
10350     (cond ((null split-name)
10351            (read-file-name
10352             (concat prompt " (default "
10353                     (file-name-nondirectory default-name) ") ")
10354             (file-name-directory default-name)
10355             default-name))
10356           ((= 1 (length split-name))
10357            (read-file-name
10358             (concat prompt " (default " (car split-name) ") ")
10359             gnus-article-save-directory
10360             (concat gnus-article-save-directory (car split-name))))
10361           (t
10362            (setq split-name (mapcar (lambda (el) (list el))
10363                                     (nreverse split-name)))
10364            (let ((result (completing-read 
10365                           (concat prompt " ")
10366                           split-name nil nil)))
10367              (concat gnus-article-save-directory
10368                      (if (string= result "")
10369                          (car (car split-name))
10370                        result)))))))
10371
10372 (defun gnus-summary-save-in-rmail (&optional filename)
10373   "Append this article to Rmail file.
10374 Optional argument FILENAME specifies file name.
10375 Directory to save to is default to `gnus-article-save-directory' which
10376 is initialized from the SAVEDIR environment variable."
10377   (interactive)
10378   (gnus-set-global-variables)
10379   (let ((default-name
10380           (funcall gnus-rmail-save-name gnus-newsgroup-name
10381                    gnus-current-headers gnus-newsgroup-last-rmail)))
10382     (or filename
10383         (setq filename (gnus-read-save-file-name 
10384                         "Save in rmail file:" default-name)))
10385     (gnus-make-directory (file-name-directory filename))
10386     (gnus-eval-in-buffer-window 
10387      gnus-article-buffer
10388      (save-excursion
10389        (save-restriction
10390          (widen)
10391          (gnus-output-to-rmail filename))))
10392     ;; Remember the directory name to save articles
10393     (setq gnus-newsgroup-last-rmail filename)))
10394
10395 (defun gnus-summary-save-in-mail (&optional filename)
10396   "Append this article to Unix mail file.
10397 Optional argument FILENAME specifies file name.
10398 Directory to save to is default to `gnus-article-save-directory' which
10399 is initialized from the SAVEDIR environment variable."
10400   (interactive)
10401   (gnus-set-global-variables)
10402   (let ((default-name
10403           (funcall gnus-mail-save-name gnus-newsgroup-name
10404                    gnus-current-headers gnus-newsgroup-last-mail)))
10405     (or filename
10406         (setq filename (gnus-read-save-file-name 
10407                         "Save in Unix mail file:" default-name)))
10408     (setq filename
10409           (expand-file-name filename
10410                             (and default-name
10411                                  (file-name-directory default-name))))
10412     (gnus-make-directory (file-name-directory filename))
10413     (gnus-eval-in-buffer-window 
10414      gnus-article-buffer
10415      (save-excursion
10416        (save-restriction
10417          (widen)
10418          (if (and (file-readable-p filename) (rmail-file-p filename))
10419              (gnus-output-to-rmail filename)
10420            (rmail-output filename 1 t t)))))
10421     ;; Remember the directory name to save articles.
10422     (setq gnus-newsgroup-last-mail filename)))
10423
10424 (defun gnus-summary-save-in-file (&optional filename)
10425   "Append this article to file.
10426 Optional argument FILENAME specifies file name.
10427 Directory to save to is default to `gnus-article-save-directory' which
10428 is initialized from the SAVEDIR environment variable."
10429   (interactive)
10430   (gnus-set-global-variables)
10431   (let ((default-name
10432           (funcall gnus-file-save-name gnus-newsgroup-name
10433                    gnus-current-headers gnus-newsgroup-last-file)))
10434     (or filename
10435         (setq filename (gnus-read-save-file-name 
10436                         "Save in file:" default-name)))
10437     (gnus-make-directory (file-name-directory filename))
10438     (gnus-eval-in-buffer-window 
10439      gnus-article-buffer
10440      (save-excursion
10441        (save-restriction
10442          (widen)
10443          (gnus-output-to-file filename))))
10444     ;; Remember the directory name to save articles.
10445     (setq gnus-newsgroup-last-file filename)))
10446
10447 (defun gnus-summary-save-in-pipe (&optional command)
10448   "Pipe this article to subprocess."
10449   (interactive)
10450   (gnus-set-global-variables)
10451   (let ((command (read-string "Shell command on article: "
10452                               gnus-last-shell-command)))
10453     (if (string-equal command "")
10454         (setq command gnus-last-shell-command))
10455     (gnus-eval-in-buffer-window 
10456      gnus-article-buffer
10457      (save-restriction
10458        (widen)
10459        (shell-command-on-region (point-min) (point-max) command nil)))
10460     (setq gnus-last-shell-command command)))
10461
10462 ;; Summary extract commands
10463
10464 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10465   (let ((buffer-read-only nil)
10466         (article (gnus-summary-article-number))
10467         b)
10468     (or (gnus-summary-goto-subject article)
10469         (error (format "No such article: %d" article)))
10470     (gnus-summary-position-cursor)
10471     ;; If all commands are to be bunched up on one line, we collect
10472     ;; them here.  
10473     (if gnus-view-pseudos-separately
10474         ()
10475       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10476             files action)
10477         (while ps
10478           (setq action (cdr (assq 'action (car ps))))
10479           (setq files (list (cdr (assq 'name (car ps)))))
10480           (while (and ps (cdr ps)
10481                       (string= (or action "1")
10482                                (or (cdr (assq 'action (car (cdr ps)))) "2")))
10483             (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
10484             (setcdr ps (cdr (cdr ps))))
10485           (if (not files)
10486               ()
10487             (if (not (string-match "%s" action))
10488                 (setq files (cons " " files)))
10489             (setq files (cons " " files))
10490             (and (assq 'execute (car ps))
10491                  (setcdr (assq 'execute (car ps))
10492                          (funcall (if (string-match "%s" action)
10493                                       'format 'concat)
10494                                   action 
10495                                   (mapconcat (lambda (f) f) files " ")))))
10496           (setq ps (cdr ps)))))
10497     (if (and gnus-view-pseudos (not not-view))
10498         (while pslist
10499           (and (assq 'execute (car pslist))
10500                (gnus-execute-command (cdr (assq 'execute (car pslist)))
10501                                      (eq gnus-view-pseudos 'not-confirm)))
10502           (setq pslist (cdr pslist)))
10503       (save-excursion
10504         (while pslist
10505           (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
10506                                          (gnus-summary-article-number)))
10507           (forward-line 1)
10508           (setq b (point))
10509           (insert "          " (file-name-nondirectory 
10510                                 (cdr (assq 'name (car pslist))))
10511                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10512           (add-text-properties 
10513            b (1+ b) (list 'gnus-number gnus-reffed-article-number
10514                           'gnus-mark gnus-unread-mark 
10515                           'gnus-level 0
10516                           'gnus-pseudo (car pslist)))
10517           (forward-line -1)
10518           (gnus-sethash (int-to-string gnus-reffed-article-number)
10519                         (car pslist) gnus-newsgroup-headers-hashtb-by-number)
10520           (setq gnus-newsgroup-unreads
10521                 (cons gnus-reffed-article-number gnus-newsgroup-unreads))
10522           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10523           (setq pslist (cdr pslist)))))))
10524
10525 (defun gnus-pseudos< (p1 p2)
10526   (let ((c1 (cdr (assq 'action p1)))
10527         (c2 (cdr (assq 'action p2))))
10528     (and c1 c2 (string< c1 c2))))
10529
10530 (defun gnus-request-pseudo-article (props)
10531   (cond ((assq 'execute props)
10532          (gnus-execute-command (cdr (assq 'execute props)))))
10533   (let ((gnus-current-article (gnus-summary-article-number)))
10534     (run-hooks 'gnus-mark-article-hook)))
10535
10536 (defun gnus-execute-command (command &optional automatic)
10537   (save-excursion
10538     (gnus-article-setup-buffer)
10539     (set-buffer gnus-article-buffer)
10540     (let ((command (if automatic command (read-string "Command: " command)))
10541           (buffer-read-only nil))
10542       (erase-buffer)
10543       (insert "$ " command "\n\n")
10544       (if gnus-view-pseudo-asynchronously
10545           (start-process "gnus-execute" nil "sh" "-c" command)
10546         (call-process "sh" nil t nil "-c" command)))))
10547
10548 (defun gnus-copy-file (file &optional to)
10549   "Copy FILE to TO."
10550   (interactive
10551    (list (read-file-name "Copy file: " default-directory)
10552          (read-file-name "Copy file to: " default-directory)))
10553   (gnus-set-global-variables)
10554   (or to (setq to (read-file-name "Copy file to: " default-directory)))
10555   (and (file-directory-p to) 
10556        (setq to (concat (file-name-as-directory to)
10557                         (file-name-nondirectory file))))
10558   (copy-file file to))
10559
10560 ;; Summary kill commands.
10561
10562 (defun gnus-summary-edit-global-kill (article)
10563   "Edit the \"global\" kill file."
10564   (interactive (list (gnus-summary-article-number)))
10565   (gnus-set-global-variables)
10566   (gnus-group-edit-global-kill article))
10567
10568 (defun gnus-summary-edit-local-kill ()
10569   "Edit a local kill file applied to the current newsgroup."
10570   (interactive)
10571   (gnus-set-global-variables)
10572   (setq gnus-current-headers 
10573         (gnus-gethash 
10574          (int-to-string (gnus-summary-article-number))
10575          gnus-newsgroup-headers-hashtb-by-number))
10576   (gnus-set-global-variables)
10577   (gnus-group-edit-local-kill 
10578    (gnus-summary-article-number) gnus-newsgroup-name))
10579
10580 \f
10581 ;;;
10582 ;;; Gnus article mode
10583 ;;;
10584
10585 (put 'gnus-article-mode 'mode-class 'special)
10586
10587 (if gnus-article-mode-map
10588     nil
10589   (setq gnus-article-mode-map (make-keymap))
10590   (suppress-keymap gnus-article-mode-map)
10591   (define-key gnus-article-mode-map " " 'gnus-article-next-page)
10592   (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page)
10593   (define-key gnus-article-mode-map "\C-c^" 'gnus-article-refer-article)
10594   (define-key gnus-article-mode-map "h" 'gnus-article-show-summary)
10595   (define-key gnus-article-mode-map "s" 'gnus-article-show-summary)
10596   (define-key gnus-article-mode-map "\C-c\C-m" 'gnus-article-mail)
10597   (define-key gnus-article-mode-map "\C-c\C-M" 'gnus-article-mail-with-original)
10598   (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly)
10599   (define-key gnus-article-mode-map gnus-mouse-2 'gnus-article-push-button)
10600   (define-key gnus-article-mode-map "\r" 'gnus-article-press-button)
10601   (define-key gnus-article-mode-map "\t" 'gnus-article-next-button)
10602   (define-key gnus-article-mode-map "\C-c\C-b" 'gnus-bug)
10603   
10604   ;; Duplicate almost all summary keystrokes in the article mode map.
10605   (let ((commands 
10606          (list 
10607           "p" "N" "P" "\M-\C-n" "\M-\C-p"
10608           "\M-n" "\M-p" "." "," "\M-s" "\M-r" "<" ">" "j"
10609           "u" "!" "U" "d" "D" "E" "\M-u" "\M-U" "k" "\C-k" "\M-\C-k"
10610           "\M-\C-l" "e" "#" "\M-#" "\M-\C-t" "\M-\C-s" "\M-\C-h"
10611           "\M-\C-f" "\M-\C-b" "\M-\C-u" "\M-\C-d" "&" "\C-w"
10612           "\C-t" "?" "\C-c\M-\C-s" "\C-c\C-s\C-n" "\C-c\C-s\C-a"
10613           "\C-c\C-s\C-s" "\C-c\C-s\C-d" "\C-c\C-s\C-i" "\C-x\C-s"
10614           "\M-g" "w" "\C-c\C-r" "\M-t" "C"
10615           "o" "\C-o" "|" "\M-k" "\M-K" "V" "\C-c\C-d"
10616           "\C-c\C-i" "x" "X" "t" "g" "?" "l"
10617           "\C-c\C-v\C-v" "\C-d" "v" 
10618 ;;        "Mt" "M!" "Md" "Mr"
10619 ;;        "Mc" "M " "Me" "Mx" "M?" "Mb" "MB" "M#" "M\M-#" "M\M-r"
10620 ;;        "M\M-\C-r" "MD" "M\M-D" "MS" "MC" "MH" "M\C-c" "Mk" "MK"
10621 ;;        "Ms" "Mc" "Mu" "Mm" "Mk" "Gn" "Gp" "GN" "GP" "G\C-n" "G\C-p"
10622 ;;        "G\M-n" "G\M-p" "Gf" "Gb" "Gg" "Gl" "Gp" "Tk" "Tl" "Ti" "TT"
10623 ;;        "Ts" "TS" "Th" "TH" "Tn" "Tp" "Tu" "Td" "T#" "A " "An" "A\177" "Ap"
10624 ;;        "A\r" "A<" "A>" "Ab" "Ae" "A^" "Ar" "Aw" "Ac" "Ag" "At" "Am"
10625 ;;        "As" "Wh" "Ws" "Wc" "Wo" "Ww" "Wd" "Wq" "Wf" "Wt" "W\C-t"
10626 ;;        "WT" "WA" "Wa" "WH" "WC" "WS" "Wb" "Hv" "Hf" "Hd" "Hh" "Hi"
10627 ;;        "Be" "B\177" "Bm" "Br" "Bw" "Bc" "Bq" "Bi" "Oo" "Om" "Or"
10628 ;;        "Of" "Oh" "Ov" "Op" "Vu" "V\C-s" "V\C-r" "Vr" "V&" "VT" "Ve"
10629 ;;        "VD" "Vk" "VK" "Vsn" "Vsa" "Vss" "Vsd" "Vsi"
10630           )))
10631     (while (and nil commands) ; disabled
10632       (define-key gnus-article-mode-map (car commands) 
10633         'gnus-article-summary-command)
10634       (setq commands (cdr commands))))
10635
10636   (let ((commands (list "q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
10637 ;;                      "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP" 
10638                          "=" "n"  "^" "\M-^")))
10639     (while (and nil commands) ; disabled
10640       (define-key gnus-article-mode-map (car commands) 
10641         'gnus-article-summary-command-nosave)
10642       (setq commands (cdr commands)))))
10643
10644
10645 (defun gnus-article-mode ()
10646   "Major mode for displaying an article.
10647
10648 All normal editing commands are switched off.
10649
10650 The following commands are available:
10651
10652 \\<gnus-article-mode-map>
10653 \\[gnus-article-next-page]\t Scroll the article one page forwards
10654 \\[gnus-article-prev-page]\t Scroll the article one page backwards
10655 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
10656 \\[gnus-article-show-summary]\t Display the summary buffer
10657 \\[gnus-article-mail]\t Send a reply to the address near point
10658 \\[gnus-article-mail-with-original]\t Send a reply to the address near point; include the original article
10659 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
10660 \\[gnus-info-find-node]\t Go to the Gnus info node"
10661   (interactive)
10662   (if gnus-visual (gnus-article-make-menu-bar))
10663   (kill-all-local-variables)
10664   (setq mode-line-modified "-- ")
10665   (make-local-variable 'mode-line-format)
10666   (setq mode-line-format (copy-sequence mode-line-format))
10667   (and (equal (nth 3 mode-line-format) "   ")
10668        (setcar (nthcdr 3 mode-line-format) ""))
10669   (setq mode-name "Article")
10670   (setq major-mode 'gnus-article-mode)
10671   (make-local-variable 'minor-mode-alist)
10672   (or (assq 'gnus-show-mime minor-mode-alist)
10673       (setq minor-mode-alist
10674             (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
10675   (use-local-map gnus-article-mode-map)
10676   (make-local-variable 'page-delimiter)
10677   (setq page-delimiter gnus-page-delimiter)
10678   (buffer-disable-undo (current-buffer))
10679   (setq buffer-read-only t)             ;Disable modification
10680   (run-hooks 'gnus-article-mode-hook))
10681
10682 (defun gnus-article-setup-buffer ()
10683   "Initialize article mode buffer."
10684   (if (get-buffer gnus-article-buffer)
10685       (save-excursion
10686         (set-buffer gnus-article-buffer)
10687         (buffer-disable-undo (current-buffer))
10688         (setq buffer-read-only t)
10689         (gnus-add-current-to-buffer-list)
10690         (or (eq major-mode 'gnus-article-mode)
10691             (gnus-article-mode)))
10692     (save-excursion
10693       (set-buffer (get-buffer-create gnus-article-buffer))
10694       (gnus-add-current-to-buffer-list)
10695       (gnus-article-mode))))
10696
10697 ;; Set article window start at LINE, where LINE is the number of lines
10698 ;; from the head of the article.
10699 (defun gnus-article-set-window-start (&optional line)
10700   (set-window-start 
10701    (get-buffer-window gnus-article-buffer)
10702    (save-excursion
10703      (set-buffer gnus-article-buffer)
10704      (goto-char (point-min))
10705      (if (not line)
10706          (point-min)
10707        (gnus-message 6 "Moved to bookmark")
10708        (search-forward "\n\n" nil t)
10709        (forward-line line)
10710        (point)))))
10711
10712 (defun gnus-request-article-this-buffer (article group)
10713   "Get an article and insert it into this buffer."
10714   (setq group (or group gnus-newsgroup-name))
10715
10716   ;; Open server if it has closed.
10717   (gnus-check-server (gnus-find-method-for-group group))
10718
10719   ;; Using `gnus-request-article' directly will insert the article into
10720   ;; `nntp-server-buffer' - so we'll save some time by not having to
10721   ;; copy it from the server buffer into the article buffer.
10722
10723   ;; We only request an article by message-id when we do not have the
10724   ;; headers for it, so we'll have to get those.
10725   (and (stringp article) 
10726        (let ((gnus-override-method gnus-refer-article-method))
10727          (gnus-read-header article)))
10728
10729   ;; If the article number is negative, that means that this article
10730   ;; doesn't belong in this newsgroup (possibly), so we find its
10731   ;; message-id and request it by id instead of number.
10732   (if (not (numberp article))
10733       ()
10734     (save-excursion
10735       (set-buffer gnus-summary-buffer)
10736       (let ((header (gnus-get-header-by-num article)))
10737         (if (< article 0)
10738             (if (vectorp header)
10739                 ;; It's a real article.
10740                 (setq article (header-id header))
10741               ;; It is an extracted pseudo-article.
10742               (setq article 'pseudo)
10743               (gnus-request-pseudo-article header)))
10744
10745         (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
10746           (if (not (eq (car method) 'nneething))
10747               ()
10748             (let ((dir (concat (file-name-as-directory (nth 1 method))
10749                                (header-subject header))))
10750               (if (file-directory-p dir)
10751                   (progn
10752                     (setq article 'nneething)
10753                     (gnus-group-enter-directory dir)))))))))
10754
10755   ;; Check the cache.
10756   (if (and gnus-use-cache
10757            (numberp article)
10758            (gnus-cache-request-article article group))
10759       'article
10760     ;; Get the article and into the article buffer.
10761     (if (or (stringp article) (numberp article))
10762         (progn
10763           (erase-buffer)
10764           (let ((gnus-override-method 
10765                  (and (stringp article) gnus-refer-article-method)))
10766             (and (gnus-request-article article group (current-buffer))
10767                  'article)))
10768       article)))
10769
10770 (defun gnus-read-header (id)
10771   "Read the headers of article ID and enter them into the Gnus system."
10772   (let (header)
10773     (if (not (setq header 
10774                    (car (if (let ((gnus-nov-is-evil t))
10775                               (gnus-retrieve-headers 
10776                                (list id) gnus-newsgroup-name))
10777                             (gnus-get-newsgroup-headers)))))
10778         nil
10779       (if (stringp id)
10780           (header-set-number header gnus-reffed-article-number))
10781       (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers))
10782       (gnus-sethash (int-to-string (header-number header)) header
10783                     gnus-newsgroup-headers-hashtb-by-number)
10784       (if (stringp id)
10785           (setq gnus-reffed-article-number (1- gnus-reffed-article-number)))
10786       (setq gnus-current-headers header)
10787       header)))
10788
10789 (defun gnus-article-prepare (article &optional all-headers header)
10790   "Prepare ARTICLE in article mode buffer.
10791 ARTICLE should either be an article number or a Message-ID.
10792 If ARTICLE is an id, HEADER should be the article headers.
10793 If ALL-HEADERS is non-nil, no headers are hidden."
10794   (save-excursion
10795     ;; Make sure we start in a summary buffer.
10796     (or (eq major-mode 'gnus-summary-mode)
10797         (set-buffer gnus-summary-buffer))
10798     (setq gnus-summary-buffer (current-buffer))
10799     ;; Make sure the connection to the server is alive.
10800     (or (gnus-server-opened (gnus-find-method-for-group gnus-newsgroup-name))
10801         (progn
10802           (gnus-check-server 
10803            (gnus-find-method-for-group gnus-newsgroup-name))
10804           (gnus-request-group gnus-newsgroup-name t)))
10805     (let* ((article (if header (header-number header) article))
10806            (summary-buffer (current-buffer))
10807            (internal-hook gnus-article-internal-prepare-hook)
10808            (group gnus-newsgroup-name)
10809            result)
10810       (save-excursion
10811         (gnus-article-setup-buffer)
10812         (set-buffer gnus-article-buffer)
10813         (if (not (setq result (let ((buffer-read-only nil))
10814                                 (gnus-request-article-this-buffer 
10815                                  article group))))
10816             ;; There is no such article.
10817             (save-excursion
10818               (if (not (numberp article))
10819                   ()
10820                 (setq gnus-article-current 
10821                       (cons gnus-newsgroup-name article))
10822                 (set-buffer gnus-summary-buffer)
10823                 (setq gnus-current-article article)
10824                 (gnus-summary-mark-article article gnus-canceled-mark))
10825               (gnus-message 1 "No such article (may be canceled)")
10826               (ding)
10827               nil)
10828           (if (or (eq result 'pseudo) (eq result 'nneething))
10829               (progn
10830                 (save-excursion
10831                   (set-buffer summary-buffer)
10832                   (setq gnus-last-article gnus-current-article
10833                         gnus-newsgroup-history (cons gnus-current-article
10834                                                      gnus-newsgroup-history)
10835                         gnus-current-article 0
10836                         gnus-current-headers nil
10837                         gnus-article-current nil)
10838                   (if (eq result 'nneething)
10839                       (gnus-configure-windows 'summary)
10840                     (gnus-configure-windows 'article))
10841                   (gnus-set-global-variables))
10842                 (gnus-set-mode-line 'article))
10843             ;; The result from the `request' was an actual article -
10844             ;; or at least some text that is now displayed in the
10845             ;; article buffer.
10846             (if (and (numberp article)
10847                      (not (eq article gnus-current-article)))
10848                 ;; Seems like a new article has been selected.
10849                 ;; `gnus-current-article' must be an article number.
10850                 (save-excursion
10851                   (set-buffer summary-buffer)
10852                   (setq gnus-last-article gnus-current-article
10853                         gnus-newsgroup-history (cons gnus-current-article
10854                                                      gnus-newsgroup-history)
10855                         gnus-current-article article
10856                         gnus-current-headers 
10857                         (gnus-get-header-by-num gnus-current-article)
10858                         gnus-article-current 
10859                         (cons gnus-newsgroup-name gnus-current-article))
10860                   (gnus-summary-show-thread)
10861                   (run-hooks 'gnus-mark-article-hook)
10862                   (gnus-set-mode-line 'summary)
10863                   (and gnus-visual 
10864                        (run-hooks 'gnus-visual-mark-article-hook))
10865                   ;; Set the global newsgroup variables here.
10866                   ;; Suggested by Jim Sisolak
10867                   ;; <sisolak@trans4.neep.wisc.edu>.
10868                   (gnus-set-global-variables)
10869                   (setq gnus-have-all-headers 
10870                         (or all-headers gnus-show-all-headers))
10871                   (and gnus-use-cache 
10872                        (vectorp (gnus-get-header-by-number article))
10873                        (gnus-cache-possibly-enter-article
10874                         group article
10875                         (gnus-get-header-by-number article)
10876                         (memq article gnus-newsgroup-marked)
10877                         (memq article gnus-newsgroup-dormant)
10878                         (memq article gnus-newsgroup-unreads)))))
10879             ;; Hooks for getting information from the article.
10880             ;; This hook must be called before being narrowed.
10881             (let (buffer-read-only)
10882               (run-hooks 'internal-hook)
10883               (run-hooks 'gnus-article-prepare-hook)
10884               ;; Decode MIME message.
10885               (if (and gnus-show-mime
10886                        (or (not gnus-strict-mime)
10887                            (gnus-fetch-field "Mime-Version")))
10888                   (funcall gnus-show-mime-method))
10889               ;; Perform the article display hooks.
10890               (run-hooks 'gnus-article-display-hook))
10891             ;; Do page break.
10892             (goto-char (point-min))
10893             (and gnus-break-pages (gnus-narrow-to-page))
10894             (gnus-set-mode-line 'article)
10895             (gnus-configure-windows 'article)
10896             (goto-char (point-min))
10897             t))))))
10898
10899 (defun gnus-article-show-all-headers ()
10900   "Show all article headers in article mode buffer."
10901   (save-excursion 
10902     (gnus-article-setup-buffer)
10903     (set-buffer gnus-article-buffer)
10904     (let ((buffer-read-only nil))
10905       (remove-text-properties (point-min) (point-max) 
10906                               gnus-hidden-properties))))
10907
10908 (defun gnus-article-hide-headers-if-wanted ()
10909   "Hide unwanted headers if `gnus-have-all-headers' is nil.
10910 Provided for backwards compatability."
10911   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
10912       (gnus-article-hide-headers)))
10913
10914 (defun gnus-article-hide-headers (&optional delete)
10915   "Hide unwanted headers and possibly sort them as well."
10916   (interactive "P")
10917   (save-excursion
10918     (set-buffer gnus-article-buffer)
10919     (save-restriction
10920       (let ((sorted gnus-sorted-header-list)
10921             (buffer-read-only nil)
10922             want-list beg want-l)
10923         ;; First we narrow to just the headers.
10924         (widen)
10925         (goto-char (point-min))
10926         ;; Hide any "From " lines at the beginning of (mail) articles. 
10927         (while (looking-at "From ")
10928           (forward-line 1))
10929         (or (bobp) 
10930             (add-text-properties (point-min) (point) gnus-hidden-properties))
10931         ;; Then treat the rest of the header lines.
10932         (narrow-to-region 
10933          (point) 
10934          (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
10935         ;; Then we use the two regular expressions
10936         ;; `gnus-ignored-headers' and `gnus-visible-headers' to
10937         ;; select which header lines is to remain visible in the
10938         ;; article buffer.
10939         (goto-char (point-min))
10940         (while (re-search-forward "^[^ \t]*:" nil t)
10941           (beginning-of-line)
10942           ;; We add the headers we want to keep to a list and delete
10943           ;; them from the buffer.
10944           (if (or (and (stringp gnus-visible-headers)
10945                        (looking-at gnus-visible-headers))
10946                   (and (not (stringp gnus-visible-headers))
10947                        (stringp gnus-ignored-headers)
10948                        (not (looking-at gnus-ignored-headers))))
10949               (progn
10950                 (setq beg (point))
10951                 (forward-line 1)
10952                 ;; Be sure to get multi-line headers...
10953                 (re-search-forward "^[^ \t]*:" nil t)
10954                 (beginning-of-line)
10955                 (setq want-list 
10956                       (cons (buffer-substring beg (point)) want-list))
10957                 (delete-region beg (point))
10958                 (goto-char beg))
10959             (forward-line 1)))
10960         ;; Next we perform the sorting by looking at
10961         ;; `gnus-sorted-header-list'. 
10962         (goto-char (point-min))
10963         (while (and sorted want-list)
10964           (setq want-l want-list)
10965           (while (and want-l
10966                       (not (string-match (car sorted) (car want-l))))
10967             (setq want-l (cdr want-l)))
10968           (if want-l 
10969               (progn
10970                 (insert (car want-l))
10971                 (setq want-list (delq (car want-l) want-list))))
10972           (setq sorted (cdr sorted)))
10973         ;; Any headers that were not matched by the sorted list we
10974         ;; just tack on the end of the visible header list.
10975         (while want-list
10976           (insert (car want-list))
10977           (setq want-list (cdr want-list)))
10978         ;; And finally we make the unwanted headers invisible.
10979         (if delete
10980             (delete-region (point) (point-max))
10981           ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
10982           (add-text-properties (point) (point-max) gnus-hidden-properties))))))
10983
10984 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
10985 (defun gnus-article-treat-overstrike ()
10986   "Translate overstrikes into bold text."
10987   (interactive)
10988   (save-excursion
10989     (set-buffer gnus-article-buffer)
10990     (let ((buffer-read-only nil))
10991       (while (search-forward "\b" nil t)
10992         (let ((next (following-char))
10993               (previous (char-after (- (point) 2))))
10994           (cond ((eq next previous)
10995                  (put-text-property (- (point) 2) (point)
10996                                     'invisible t)
10997                  (put-text-property (point) (1+ (point))
10998                                     'face 'bold))
10999                 ((eq next ?_)
11000                  (put-text-property (1- (point)) (1+ (point))
11001                                     'invisible t)
11002                  (put-text-property (1- (point)) (point)
11003                                     'face 'underline))
11004                 ((eq previous ?_)
11005                  (put-text-property (- (point) 2) (point)
11006                                     'invisible t)
11007                  (put-text-property (point) (1+ (point))
11008                                     'face 'underline))))))))
11009
11010 (defun gnus-article-word-wrap ()
11011   "Format too long lines."
11012   (interactive)
11013   (save-excursion
11014     (set-buffer gnus-article-buffer)
11015     (let ((buffer-read-only nil))
11016       (goto-char (point-min))
11017       (search-forward "\n\n" nil t)
11018       (end-of-line 1)
11019       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
11020             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
11021             (adaptive-fill-mode t))
11022         (while (not (eobp))
11023           (and (>= (current-column) (min fill-column (window-width)))
11024                (/= (preceding-char) ?:)
11025                (fill-paragraph nil))
11026           (end-of-line 2))))))
11027
11028 (defun gnus-article-remove-cr ()
11029   "Remove carriage returns from an article."
11030   (interactive)
11031   (save-excursion
11032     (set-buffer gnus-article-buffer)
11033     (let ((buffer-read-only nil))
11034       (goto-char (point-min))
11035       (while (search-forward "\r" nil t)
11036         (replace-match "" t t)))))
11037
11038 (defun gnus-article-display-x-face (&optional force)
11039   "Look for an X-Face header and display it if present."
11040   (interactive (list 'force))
11041   (save-excursion
11042     (set-buffer gnus-article-buffer)
11043     (let ((inhibit-point-motion-hooks t)
11044           (case-fold-search nil))
11045       (save-restriction
11046         (goto-char (point-min))
11047         (search-forward "\n\n")
11048         (narrow-to-region (point-min) (point))
11049         (goto-char (point-min))
11050         (if (not (and gnus-article-x-face-command
11051                       (or force
11052                           (not gnus-article-x-face-too-ugly)
11053                           (and gnus-article-x-face-too-ugly
11054                                (not (string-match gnus-article-x-face-too-ugly
11055                                                   (mail-fetch-field "from")))))
11056                       (progn
11057                         (goto-char (point-min))
11058                         (re-search-forward "^X-Face: " nil t))))
11059             nil
11060           (let ((beg (point))
11061                 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
11062             (if (symbolp gnus-article-x-face-command)
11063                 (and (or (fboundp gnus-article-x-face-command)
11064                          (error "%s is not a function"
11065                                 gnus-article-x-face-command))
11066                      (funcall gnus-article-x-face-command beg end))
11067               (call-process-region beg end "sh" nil 0 nil
11068                                    "-c" gnus-article-x-face-command))))))))
11069
11070 (defun gnus-article-de-quoted-unreadable (&optional force)
11071   "Do a naïve translation of a quoted-printable-encoded article.
11072 This is in no way, shape or form meant as a replacement for real MIME
11073 processing, but is simply a stop-gap measure until MIME support is
11074 written.
11075 If FORCE, decode the article whether it is marked as quoted-printable
11076 or not." 
11077   (interactive (list 'force))
11078   (save-excursion
11079     (set-buffer gnus-article-buffer)
11080     (let ((case-fold-search t)
11081           (buffer-read-only nil)
11082           (type (gnus-fetch-field "content-transfer-encoding")))
11083       (if (or force (and type (string-match "quoted-printable" type)))
11084           (progn
11085             (goto-char (point-min))
11086             (search-forward "\n\n" nil 'move)
11087             (gnus-mime-decode-quoted-printable (point) (point-max)))))))
11088
11089 (defun gnus-mime-decode-quoted-printable (from to)
11090   ;; Decode quoted-printable from region between FROM and TO.
11091   (save-excursion
11092     (goto-char from)
11093     (while (search-forward "=" to t)
11094       (cond ((eq (following-char) ?\n)
11095              (delete-char -1)
11096              (delete-char 1))
11097             ((looking-at "[0-9A-F][0-9A-F]")
11098              (delete-char -1)
11099              (insert (hexl-hex-string-to-integer
11100                       (buffer-substring (point) (+ 2 (point)))))
11101              (delete-char 2))
11102             ((looking-at "=")
11103              (delete-char 1))
11104             ((gnus-message 3 "Malformed MIME quoted-printable message"))))))
11105
11106 (defvar gnus-article-time-units
11107   (list (cons 'year (* 365.25 24 60 60))
11108         (cons 'week (* 7 24 60 60))
11109         (cons 'day (* 24 60 60))
11110         (cons 'hour (* 60 60))
11111         (cons 'minute 60)
11112         (cons 'second 1)))
11113
11114 (defun gnus-article-date-ut (&optional type)
11115   "Convert DATE date to universal time in the current article.
11116 If TYPE is `local', convert to local time; if it is `lapsed', output
11117 how much time has lapsed since DATE."
11118   (interactive (list 'ut))
11119   (let ((date (header-date (or gnus-current-headers 
11120                                (gnus-get-header-by-number
11121                                 (gnus-summary-article-number))"")))
11122         (date-regexp "^Date: \\|^X-Sent: "))
11123     (if (or (not date)
11124             (string= date ""))
11125         ()
11126       (save-excursion
11127         (set-buffer gnus-article-buffer)
11128         (let ((buffer-read-only nil))
11129           (goto-char (point-min))
11130           (if (and (re-search-forward date-regexp nil t)
11131                    (progn 
11132                      (beginning-of-line)
11133                      (looking-at date-regexp)))
11134               (delete-region (gnus-point-at-bol)
11135                              (progn (end-of-line) (1+ (point))))
11136             (goto-char (point-min))
11137             (goto-char (- (search-forward "\n\n") 2)))
11138           (insert
11139            (cond 
11140             ((eq type 'local)
11141              (concat "Date: " (condition-case ()
11142                                   (timezone-make-date-arpa-standard date)
11143                                 (error date))
11144                      "\n"))
11145             ((eq type 'ut)
11146              (concat "Date: "
11147                      (condition-case ()
11148                          (timezone-make-date-arpa-standard date nil "UT")
11149                        (error date))
11150                      "\n"))
11151             ((eq type 'lapsed)
11152              ;; If the date is seriously mangled, the timezone
11153              ;; functions are liable to bug out, so we condition-case
11154              ;; the entire thing.  
11155              (let* ((real-sec (condition-case ()
11156                                   (- (gnus-seconds-since-epoch 
11157                                       (timezone-make-date-arpa-standard
11158                                        (current-time-string) 
11159                                        (current-time-zone) "UT"))
11160                                      (gnus-seconds-since-epoch 
11161                                       (timezone-make-date-arpa-standard 
11162                                        date nil "UT")))
11163                                 (error 0)))
11164                     (sec (abs real-sec))
11165                     num prev)
11166                (if (zerop sec)
11167                    "X-Sent: Now\n"
11168                  (concat
11169                   "X-Sent: "
11170                   (mapconcat 
11171                    (lambda (unit)
11172                      (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
11173                          ""
11174                        (setq sec (- sec (* num (cdr unit))))
11175                        (prog1
11176                            (concat (if prev ", " "") (int-to-string 
11177                                                       (floor num))
11178                                    " " (symbol-name (car unit))
11179                                    (if (> num 1) "s" ""))
11180                          (setq prev t))))
11181                    gnus-article-time-units "")
11182                   (if (> real-sec 0)
11183                       " ago\n"
11184                     " in the future\n")))))
11185             (t
11186              (error "Unknown conversion type: %s" type)))))))))
11187
11188 (defun gnus-article-date-local ()
11189   "Convert the current article date to the local timezone."
11190   (interactive)
11191   (gnus-article-date-ut 'local))
11192
11193 (defun gnus-article-date-lapsed ()
11194   "Convert the current article date to time lapsed since it was sent."
11195   (interactive)
11196   (gnus-article-date-ut 'lapsed))
11197
11198 (defun gnus-article-maybe-highlight ()
11199   "Do some article highlighting if `gnus-visual' is non-nil."
11200   (if gnus-visual (gnus-article-highlight-some)))
11201
11202 ;; Article savers.
11203
11204 (defun gnus-output-to-rmail (file-name)
11205   "Append the current article to an Rmail file named FILE-NAME."
11206   (require 'rmail)
11207   ;; Most of these codes are borrowed from rmailout.el.
11208   (setq file-name (expand-file-name file-name))
11209   (setq rmail-default-rmail-file file-name)
11210   (let ((artbuf (current-buffer))
11211         (tmpbuf (get-buffer-create " *Gnus-output*")))
11212     (save-excursion
11213       (or (get-file-buffer file-name)
11214           (file-exists-p file-name)
11215           (if (gnus-yes-or-no-p
11216                (concat "\"" file-name "\" does not exist, create it? "))
11217               (let ((file-buffer (create-file-buffer file-name)))
11218                 (save-excursion
11219                   (set-buffer file-buffer)
11220                   (rmail-insert-rmail-file-header)
11221                   (let ((require-final-newline nil))
11222                     (write-region (point-min) (point-max) file-name t 1)))
11223                 (kill-buffer file-buffer))
11224             (error "Output file does not exist")))
11225       (set-buffer tmpbuf)
11226       (buffer-disable-undo (current-buffer))
11227       (erase-buffer)
11228       (insert-buffer-substring artbuf)
11229       (gnus-convert-article-to-rmail)
11230       ;; Decide whether to append to a file or to an Emacs buffer.
11231       (let ((outbuf (get-file-buffer file-name)))
11232         (if (not outbuf)
11233             (append-to-file (point-min) (point-max) file-name)
11234           ;; File has been visited, in buffer OUTBUF.
11235           (set-buffer outbuf)
11236           (let ((buffer-read-only nil)
11237                 (msg (and (boundp 'rmail-current-message)
11238                           (symbol-value 'rmail-current-message))))
11239             ;; If MSG is non-nil, buffer is in RMAIL mode.
11240             (if msg
11241                 (progn (widen)
11242                        (narrow-to-region (point-max) (point-max))))
11243             (insert-buffer-substring tmpbuf)
11244             (if msg
11245                 (progn
11246                   (goto-char (point-min))
11247                   (widen)
11248                   (search-backward "\^_")
11249                   (narrow-to-region (point) (point-max))
11250                   (goto-char (1+ (point-min)))
11251                   (rmail-count-new-messages t)
11252                   (rmail-show-message msg)))))))
11253     (kill-buffer tmpbuf)))
11254
11255 (defun gnus-output-to-file (file-name)
11256   "Append the current article to a file named FILE-NAME."
11257   (setq file-name (expand-file-name file-name))
11258   (let ((artbuf (current-buffer))
11259         (tmpbuf (get-buffer-create " *Gnus-output*")))
11260     (save-excursion
11261       (set-buffer tmpbuf)
11262       (buffer-disable-undo (current-buffer))
11263       (erase-buffer)
11264       (insert-buffer-substring artbuf)
11265       ;; Append newline at end of the buffer as separator, and then
11266       ;; save it to file.
11267       (goto-char (point-max))
11268       (insert "\n")
11269       (append-to-file (point-min) (point-max) file-name))
11270     (kill-buffer tmpbuf)))
11271
11272 (defun gnus-convert-article-to-rmail ()
11273   "Convert article in current buffer to Rmail message format."
11274   (let ((buffer-read-only nil))
11275     ;; Convert article directly into Babyl format.
11276     ;; Suggested by Rob Austein <sra@lcs.mit.edu>
11277     (goto-char (point-min))
11278     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
11279     (while (search-forward "\n\^_" nil t) ;single char
11280       (replace-match "\n^_" t t))               ;2 chars: "^" and "_"
11281     (goto-char (point-max))
11282     (insert "\^_")))
11283
11284 (defun gnus-narrow-to-page (&optional arg)
11285   "Make text outside current page invisible except for page delimiter.
11286 A numeric arg specifies to move forward or backward by that many pages,
11287 thus showing a page other than the one point was originally in."
11288   (interactive "P")
11289   (setq arg (if arg (prefix-numeric-value arg) 0))
11290   (save-excursion
11291     (forward-page -1)                   ;Beginning of current page.
11292     (widen)
11293     (if (> arg 0)
11294         (forward-page arg)
11295       (if (< arg 0)
11296           (forward-page (1- arg))))
11297     ;; Find the end of the page.
11298     (forward-page)
11299     ;; If we stopped due to end of buffer, stay there.
11300     ;; If we stopped after a page delimiter, put end of restriction
11301     ;; at the beginning of that line.
11302     ;; These are commented out.
11303     ;;    (if (save-excursion (beginning-of-line)
11304     ;;                  (looking-at page-delimiter))
11305     ;;  (beginning-of-line))
11306     (narrow-to-region (point)
11307                       (progn
11308                         ;; Find the top of the page.
11309                         (forward-page -1)
11310                         ;; If we found beginning of buffer, stay there.
11311                         ;; If extra text follows page delimiter on same line,
11312                         ;; include it.
11313                         ;; Otherwise, show text starting with following line.
11314                         (if (and (eolp) (not (bobp)))
11315                             (forward-line 1))
11316                         (point)))))
11317
11318 (defun gnus-gmt-to-local ()
11319   "Rewrite Date header described in GMT to local in current buffer.
11320 Intended to be used with gnus-article-prepare-hook."
11321   (save-excursion
11322     (save-restriction
11323       (widen)
11324       (goto-char (point-min))
11325       (narrow-to-region (point-min)
11326                         (progn (search-forward "\n\n" nil 'move) (point)))
11327       (goto-char (point-min))
11328       (if (re-search-forward "^Date:[ \t]\\(.*\\)$" nil t)
11329           (let ((buffer-read-only nil)
11330                 (date (buffer-substring-no-properties
11331                        (match-beginning 1) (match-end 1))))
11332             (delete-region (match-beginning 1) (match-end 1))
11333             (insert
11334              (timezone-make-date-arpa-standard 
11335               date nil (current-time-zone))))))))
11336
11337
11338 ;; Article mode commands
11339
11340 (defun gnus-article-next-page (&optional lines)
11341   "Show next page of current article.
11342 If end of article, return non-nil. Otherwise return nil.
11343 Argument LINES specifies lines to be scrolled up."
11344   (interactive "P")
11345   (move-to-window-line -1)
11346   ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
11347   (if (save-excursion
11348         (end-of-line)
11349         (and (pos-visible-in-window-p)  ;Not continuation line.
11350              (eobp)))
11351       ;; Nothing in this page.
11352       (if (or (not gnus-break-pages)
11353               (save-excursion
11354                 (save-restriction
11355                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
11356           t                             ;Nothing more.
11357         (gnus-narrow-to-page 1)         ;Go to next page.
11358         nil)
11359     ;; More in this page.
11360     (condition-case ()
11361         (scroll-up lines)
11362       (end-of-buffer
11363        ;; Long lines may cause an end-of-buffer error.
11364        (goto-char (point-max))))
11365     nil))
11366
11367 (defun gnus-article-prev-page (&optional lines)
11368   "Show previous page of current article.
11369 Argument LINES specifies lines to be scrolled down."
11370   (interactive "P")
11371   (move-to-window-line 0)
11372   (if (and gnus-break-pages
11373            (bobp)
11374            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
11375       (progn
11376         (gnus-narrow-to-page -1) ;Go to previous page.
11377         (goto-char (point-max))
11378         (recenter -1))
11379     (scroll-down lines)))
11380
11381 (defun gnus-article-refer-article ()
11382   "Read article specified by message-id around point."
11383   (interactive)
11384   (search-forward ">" nil t)    ;Move point to end of "<....>".
11385   (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
11386       (let ((message-id
11387              (buffer-substring (match-beginning 1) (match-end 1))))
11388         (set-buffer gnus-summary-buffer)
11389         (gnus-summary-refer-article message-id))
11390     (error "No references around point")))
11391
11392 (defun gnus-article-show-summary ()
11393   "Reconfigure windows to show summary buffer."
11394   (interactive)
11395   (gnus-configure-windows 'article)
11396   (gnus-summary-goto-subject gnus-current-article))
11397
11398 (defun gnus-article-describe-briefly ()
11399   "Describe article mode commands briefly."
11400   (interactive)
11401   (gnus-message 6
11402    (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")))
11403
11404 (defun gnus-article-summary-command ()
11405   "Execute the last keystroke in the summary buffer."
11406   (interactive)
11407   (let ((obuf (current-buffer))
11408         (owin (current-window-configuration))
11409         func)
11410     (switch-to-buffer gnus-summary-buffer 'norecord)
11411     (setq func (lookup-key (current-local-map) (this-command-keys)))
11412     (call-interactively func)
11413     (set-buffer obuf)
11414     (set-window-configuration owin)
11415     (set-window-point (get-buffer-window (current-buffer)) (point))))
11416
11417 (defun gnus-article-summary-command-nosave ()
11418   "Execute the last keystroke in the summary buffer."
11419   (interactive)
11420   (let (func)
11421     (pop-to-buffer gnus-summary-buffer 'norecord)
11422     (setq func (lookup-key (current-local-map) (this-command-keys)))
11423     (call-interactively func)))
11424
11425 \f
11426 ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti)
11427
11428 ;;;###autoload
11429 (defalias 'gnus-batch-kill 'gnus-batch-score)
11430 ;;;###autoload
11431 (defun gnus-batch-score ()
11432   "Run batched scoring.
11433 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
11434 Newsgroups is a list of strings in Bnews format.  If you want to score
11435 the comp hierarchy, you'd say \"comp.all\". If you would not like to
11436 score the alt hierarchy, you'd say \"!alt.all\"."
11437   (interactive)
11438   (let* ((yes-and-no
11439           (gnus-newsrc-parse-options
11440            (apply (function concat)
11441                   (mapcar (lambda (g) (concat g " "))
11442                           command-line-args-left))))
11443          (gnus-expert-user t)
11444          (nnmail-spool-file nil)
11445          (gnus-use-dribble-file nil)
11446          (yes (car yes-and-no))
11447          (no (cdr yes-and-no))
11448          group newsrc entry
11449          ;; Disable verbose message.
11450          gnus-novice-user gnus-large-newsgroup)
11451     ;; Eat all arguments.
11452     (setq command-line-args-left nil)
11453     ;; Start Gnus.
11454     (gnus)
11455     ;; Apply kills to specified newsgroups in command line arguments.
11456     (setq newsrc (cdr gnus-newsrc-alist))
11457     (while newsrc
11458       (setq group (car (car newsrc)))
11459       (setq entry (gnus-gethash group gnus-newsrc-hashtb))
11460       (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
11461                (and (car entry)
11462                     (or (eq (car entry) t)
11463                         (not (zerop (car entry)))))
11464                (if yes (string-match yes group) t)
11465                (or (null no) (not (string-match no group))))
11466           (progn
11467             (gnus-summary-read-group group nil t)
11468             (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
11469                  (gnus-summary-exit))))
11470       (setq newsrc (cdr newsrc)))
11471     ;; Exit Emacs.
11472     (switch-to-buffer gnus-group-buffer)
11473     (gnus-group-save-newsrc)))
11474
11475 (defun gnus-apply-kill-file ()
11476   "Apply a kill file to the current newsgroup.
11477 Returns the number of articles marked as read."
11478   (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
11479           (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11480       (gnus-apply-kill-file-internal)
11481     0))
11482
11483 (defun gnus-kill-save-kill-buffer ()
11484   (save-excursion
11485     (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
11486       (if (get-file-buffer file)
11487           (progn
11488             (set-buffer (get-file-buffer file))
11489             (and (buffer-modified-p) (save-buffer))
11490             (kill-buffer (current-buffer)))))))
11491
11492 (defvar gnus-kill-file-name "KILL"
11493   "Suffix of the kill files.")
11494
11495 (defun gnus-newsgroup-kill-file (newsgroup)
11496   "Return the name of a kill file name for NEWSGROUP.
11497 If NEWSGROUP is nil, return the global kill file name instead."
11498   (cond ((or (null newsgroup)
11499              (string-equal newsgroup ""))
11500          ;; The global KILL file is placed at top of the directory.
11501          (expand-file-name gnus-kill-file-name
11502                            (or gnus-kill-files-directory "~/News")))
11503         ((gnus-use-long-file-name 'not-kill)
11504          ;; Append ".KILL" to newsgroup name.
11505          (expand-file-name (concat (gnus-newsgroup-saveable-name newsgroup)
11506                                    "." gnus-kill-file-name)
11507                            (or gnus-kill-files-directory "~/News")))
11508         (t
11509          ;; Place "KILL" under the hierarchical directory.
11510          (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
11511                                    "/" gnus-kill-file-name)
11512                            (or gnus-kill-files-directory "~/News")))))
11513
11514 \f
11515 ;;;
11516 ;;; Dribble file
11517 ;;;
11518
11519 (defvar gnus-dribble-ignore nil)
11520 (defvar gnus-dribble-eval-file nil)
11521
11522 (defun gnus-dribble-file-name ()
11523   (concat gnus-current-startup-file "-dribble"))
11524
11525 (defun gnus-dribble-enter (string)
11526   (if (and (not gnus-dribble-ignore)
11527            gnus-dribble-buffer
11528            (buffer-name gnus-dribble-buffer))
11529       (let ((obuf (current-buffer)))
11530         (set-buffer gnus-dribble-buffer)
11531         (insert string "\n")
11532         (set-window-point (get-buffer-window (current-buffer)) (point-max))
11533         (set-buffer obuf))))
11534
11535 (defun gnus-dribble-read-file ()
11536   (let ((dribble-file (gnus-dribble-file-name)))
11537     (save-excursion 
11538       (set-buffer (setq gnus-dribble-buffer 
11539                         (get-buffer-create 
11540                          (file-name-nondirectory dribble-file))))
11541       (gnus-add-current-to-buffer-list)
11542       (erase-buffer)
11543       (set-visited-file-name dribble-file)
11544       (buffer-disable-undo (current-buffer))
11545       (bury-buffer (current-buffer))
11546       (set-buffer-modified-p nil)
11547       (let ((auto (make-auto-save-file-name))
11548             (gnus-dribble-ignore t))
11549         (if (or (file-exists-p auto) (file-exists-p dribble-file))
11550             (progn
11551               (if (file-newer-than-file-p auto dribble-file)
11552                   (setq dribble-file auto))
11553               (insert-file-contents dribble-file)
11554               (if (not (zerop (buffer-size)))
11555                   (set-buffer-modified-p t))
11556               (if (gnus-y-or-n-p 
11557                    "Auto-save file exists. Do you want to read it? ")
11558                   (setq gnus-dribble-eval-file t))))))))
11559
11560 (defun gnus-dribble-eval-file ()
11561   (if (not gnus-dribble-eval-file)
11562       ()
11563     (setq gnus-dribble-eval-file nil)
11564     (save-excursion
11565       (let ((gnus-dribble-ignore t))
11566         (set-buffer gnus-dribble-buffer)
11567         (eval-buffer (current-buffer))))))
11568
11569 (defun gnus-dribble-delete-file ()
11570   (if (file-exists-p (gnus-dribble-file-name))
11571       (delete-file (gnus-dribble-file-name)))
11572   (if gnus-dribble-buffer
11573       (save-excursion
11574         (set-buffer gnus-dribble-buffer)
11575         (let ((auto (make-auto-save-file-name)))
11576           (if (file-exists-p auto)
11577               (delete-file auto))
11578           (erase-buffer)
11579           (set-buffer-modified-p nil)))))
11580
11581 (defun gnus-dribble-save ()
11582   (if (and gnus-dribble-buffer
11583            (buffer-name gnus-dribble-buffer))
11584       (save-excursion
11585         (set-buffer gnus-dribble-buffer)
11586         (save-buffer))))
11587
11588 (defun gnus-dribble-clear ()
11589   (save-excursion
11590     (if (gnus-buffer-exists-p gnus-dribble-buffer)
11591         (progn
11592           (set-buffer gnus-dribble-buffer)
11593           (erase-buffer)
11594           (set-buffer-modified-p nil)
11595           (setq buffer-saved-size (buffer-size))))))
11596
11597 ;;;
11598 ;;; Server Communication
11599 ;;;
11600
11601 ;; All the Gnus backends have the same interface, and should return
11602 ;; data in a similar format. Below is an overview of what functions
11603 ;; these packages must supply and what results they should return.
11604 ;;
11605 ;; Variables:
11606 ;;
11607 ;; `nntp-server-buffer' - All data should be returned to Gnus in this
11608 ;; buffer. 
11609 ;;
11610 ;; Functions for the imaginary backend `choke':
11611 ;;
11612 ;; `choke-retrieve-headers ARTICLES &optional GROUP SERVER'
11613 ;; Should return all headers for all ARTICLES, or return NOV lines for
11614 ;; the same.
11615 ;;
11616 ;; `choke-request-group GROUP &optional SERVER DISCARD'
11617 ;; Switch to GROUP. If DISCARD is nil, active information on the group
11618 ;; must be returned.
11619 ;;
11620 ;; `choke-close-group GROUP &optional SERVER'
11621 ;; Close group. Most backends won't have to do anything with this
11622 ;; call, but it is an opportunity to clean up, if that is needed. It
11623 ;; is called when Gnus exits a group.
11624 ;;
11625 ;; `choke-request-article ARTICLE &optional GROUP SERVER'
11626 ;; Return ARTICLE, which is either an article number or
11627 ;; message-id. Note that not all backends can return articles based on
11628 ;; message-id. 
11629 ;;
11630 ;; `choke-request-list SERVER'
11631 ;; Return a list of all newsgroups on SERVER.
11632 ;;
11633 ;; `choke-request-list-newsgroups SERVER'
11634 ;; Return a list of descriptions of all newsgroups on SERVER.
11635 ;;
11636 ;; `choke-request-newgroups DATE &optional SERVER'
11637 ;; Return a list of all groups that have arrived after DATE on
11638 ;; SERVER. Note that the date doesn't have to be respected - Gnus will
11639 ;; always check whether the groups are old or not. Backends that do
11640 ;; not store date information may just return the entire list of
11641 ;; groups, although this might not be a good idea in general.
11642 ;;
11643 ;; `choke-request-post-buffer METHOD HEADER ARTICLE-BUFFER GROUP INFO'
11644 ;; Should return a buffer that is suitable for "posting". nnspool and
11645 ;; nntp return a `*post-buffer*', and nnmail return a `*mail*'
11646 ;; buffer. This function should fill out the appropriate headers. 
11647 ;;
11648 ;; `choke-request-post &optional SERVER'
11649 ;; Function that will be called from a buffer to be posted. 
11650 ;;
11651 ;; `choke-open-server SERVER &optional ARGUMENT'
11652 ;; Open a connection to SERVER.
11653 ;;
11654 ;; `choke-close-server &optional SERVER'
11655 ;; Close the connection to SERVER.
11656 ;;
11657 ;; `choke-server-opened &optional SERVER'
11658 ;; Whether the conenction to SERVER is opened or not.
11659 ;;
11660 ;; `choke-server-status &optional SERVER'
11661 ;; Should return a status string (not in the nntp buffer, but as the
11662 ;; result of the function).
11663 ;;
11664 ;; `choke-retrieve-groups GROUPS &optional SERVER'
11665 ;; Optional function for retrieving active file info on all groups in
11666 ;; GROUPS.  Two return formats are supported: The normal active file
11667 ;; format, and a list of GROUP lines.  This function should return (as
11668 ;; a function value) either `active' or `group', depending on what
11669 ;; format it returns.
11670 ;;
11671 ;; The following functions are optional and apply only to backends
11672 ;; that are able to control the contents of their groups totally
11673 ;; (ie. mail backends.)  Backends that aren't able to do that
11674 ;; shouldn't define these functions at all. Gnus will check for their
11675 ;; presence before attempting to call them.
11676 ;;
11677 ;; `choke-request-expire-articles ARTICLES &optional NEWSGROUP SERVER'
11678 ;; Should expire (according to some aging scheme) all ARTICLES. Most
11679 ;; backends will not be able to expire articles. Should return a list
11680 ;; of all articles that were not expired.
11681 ;;
11682 ;; `choke-request-move-article ARTICLE GROUP SERVER ACCEPT-FORM &optional LAST'
11683 ;; Should move ARTICLE from GROUP on SERVER by using ACCEPT-FORM.
11684 ;; Removes any information it has added to the article (extra headers,
11685 ;; whatever - make it as clean as possible), and then passes the
11686 ;; article on by evaling ACCEPT-FORM, which is normally a call to the
11687 ;; function described below. If the ACCEPT-FORM returns a non-nil
11688 ;; value, the article should then be deleted. If LAST is nil, that
11689 ;; means that there will be further calls to this function. This might
11690 ;; be taken as an advice not to save buffers/internal variables just
11691 ;; yet, but wait until the last call to speed things up.
11692 ;;
11693 ;; `choke-request-accept-article GROUP &optional LAST' 
11694 ;; The contents of the current buffer will be put into GROUP.  There
11695 ;; should, of course, be an article in the current buffer.  This
11696 ;; function is normally only called by the function described above,
11697 ;; and LAST works the same way as in that function.
11698 ;;
11699 ;; `choke-request-replace-article ARTICLE GROUP BUFFER'
11700 ;; Replace ARTICLE in GROUP with the contents of BUFFER.
11701 ;; This provides an easy interface for allowing editing of
11702 ;; articles. Note that even headers may be edited, so the backend has
11703 ;; to update any tables (nov buffers, etc) that it maintains after
11704 ;; replacing the article.
11705 ;;
11706 ;; `choke-request-create-group GROUP &optional SERVER'
11707 ;; Create GROUP on SERVER.  This might be a new, empty group, or it
11708 ;; might be a group that already exists, but hasn't been registered
11709 ;; yet. 
11710 ;;
11711 ;; All these functions must return nil if they couldn't service the
11712 ;; request. If the optional arguments are not supplied, some "current"
11713 ;; or "default" values should be used. In short, one should emulate an
11714 ;; NNTP server, in a way.
11715 ;;
11716 ;; If you want to write a new backend, you just have to supply the
11717 ;; functions listed above. In addition, you must enter the new backend
11718 ;; into the list of valid select methods:
11719 ;; (setq gnus-valid-select-methods 
11720 ;;       (cons '("choke" mail) gnus-valid-select-methods))
11721 ;; The first element in this list is the name of the backend. Other
11722 ;; elemnets may be `mail' (for mail groups),  `post' (for news
11723 ;; groups), `none' (neither), `respool' (for groups that can control
11724 ;; their contents). 
11725
11726 (defun gnus-start-news-server (&optional confirm)
11727   "Open a method for getting news.
11728 If CONFIRM is non-nil, the user will be asked for an NNTP server."
11729   (let (how)
11730     (if gnus-current-select-method
11731         ;; Stream is already opened.
11732         nil
11733       ;; Open NNTP server.
11734       (if (null gnus-nntp-service) (setq gnus-nntp-server nil))
11735       (if confirm
11736           (progn
11737             ;; Read server name with completion.
11738             (setq gnus-nntp-server
11739                   (completing-read "NNTP server: "
11740                                    (mapcar (lambda (server) (list server))
11741                                            (cons (list gnus-nntp-server)
11742                                                  gnus-secondary-servers))
11743                                    nil nil gnus-nntp-server))))
11744
11745       (if (and gnus-nntp-server 
11746                (stringp gnus-nntp-server)
11747                (not (string= gnus-nntp-server "")))
11748           (setq gnus-select-method
11749                 (cond ((or (string= gnus-nntp-server "")
11750                            (string= gnus-nntp-server "::"))
11751                        (list 'nnspool (system-name)))
11752                       ((string-match "^:" gnus-nntp-server)
11753                        (list 'nnmh gnus-nntp-server 
11754                              (list 'nnmh-directory 
11755                                    (file-name-as-directory
11756                                     (expand-file-name
11757                                      (concat "~/" (substring
11758                                                    gnus-nntp-server 1)))))
11759                              (list 'nnmh-get-new-mail nil)))
11760                       (t
11761                        (list 'nntp gnus-nntp-server)))))
11762
11763       (setq how (car gnus-select-method))
11764       (cond ((eq how 'nnspool)
11765              (require 'nnspool)
11766              (gnus-message 5 "Looking up local news spool..."))
11767             ((eq how 'nnmh)
11768              (require 'nnmh)
11769              (gnus-message 5 "Looking up mh spool..."))
11770             (t
11771              (require 'nntp)))
11772       (setq gnus-current-select-method gnus-select-method)
11773       (run-hooks 'gnus-open-server-hook)
11774       (or 
11775        ;; gnus-open-server-hook might have opened it
11776        (gnus-server-opened gnus-select-method)  
11777        (gnus-open-server gnus-select-method)
11778        (gnus-y-or-n-p
11779         (format
11780          "%s server on %s can't be opened. Continue? "
11781          (car gnus-select-method) (nth 1 gnus-select-method)))
11782        (progn
11783          (gnus-message 1 "Couldn't open server on %s" 
11784                        (nth 1 gnus-select-method))
11785          (ding)
11786          nil)))))
11787
11788 (defun gnus-check-server (&optional method)
11789   "If the news server is down, start it up again."
11790   (let ((method (if method method gnus-select-method)))
11791     (and (stringp method)
11792          (setq method (gnus-server-to-method method)))
11793     (if (gnus-server-opened method)
11794         ;; Stream is already opened.
11795         t
11796       ;; Open server.
11797       (gnus-message 5 "Opening server %s on %s..." (car method) (nth 1 method))
11798       (run-hooks 'gnus-open-server-hook)
11799       (prog1
11800           (gnus-open-server method)
11801         (message "")))))
11802
11803 (defun gnus-nntp-message (&optional message)
11804   "Check the status of the NNTP server.
11805 If the status of the server is clear and MESSAGE is non-nil, MESSAGE
11806 is returned insted of the status string."
11807   (let ((status (gnus-status-message (gnus-find-method-for-group 
11808                                       gnus-newsgroup-name)))
11809         (message (or message "")))
11810     (if (and (stringp status) (> (length status) 0))
11811         status message)))
11812
11813 (defun gnus-get-function (method function)
11814   (and (stringp method)
11815        (setq method (gnus-server-to-method method)))
11816   (let ((func (intern (format "%s-%s" (car method) function))))
11817     (if (not (fboundp func)) 
11818         (progn
11819           (require (car method))
11820           (if (not (fboundp func)) 
11821               (error "No such function: %s" func))))
11822     func))
11823
11824 ;;; Interface functions to the backends.
11825
11826 (defun gnus-open-server (method)
11827   (funcall (gnus-get-function method 'open-server)
11828            (nth 1 method) (nthcdr 2 method)))
11829
11830 (defun gnus-close-server (method)
11831   (funcall (gnus-get-function method 'close-server) (nth 1 method)))
11832
11833 (defun gnus-request-list (method)
11834   (funcall (gnus-get-function method 'request-list) (nth 1 method)))
11835
11836 (defun gnus-request-list-newsgroups (method)
11837   (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method)))
11838
11839 (defun gnus-request-newgroups (date method)
11840   (funcall (gnus-get-function method 'request-newgroups) 
11841            date (nth 1 method)))
11842
11843 (defun gnus-server-opened (method)
11844   (funcall (gnus-get-function method 'server-opened) (nth 1 method)))
11845
11846 (defun gnus-status-message (method)
11847   (let ((method (if (stringp method) (gnus-find-method-for-group method)
11848                   method)))
11849     (funcall (gnus-get-function method 'status-message) (nth 1 method))))
11850
11851 (defun gnus-request-group (group &optional dont-check)
11852   (let ((method (gnus-find-method-for-group group)))
11853 ;    (and t (message "%s GROUP %s" (car method) group))
11854     (funcall (gnus-get-function method 'request-group) 
11855              (gnus-group-real-name group) (nth 1 method) dont-check)))
11856
11857 (defun gnus-request-asynchronous (group &optional articles)
11858   (let ((method (gnus-find-method-for-group group)))
11859     (funcall (gnus-get-function method 'request-asynchronous) 
11860              (gnus-group-real-name group) (nth 1 method) articles)))
11861
11862 (defun gnus-list-active-group (group)
11863   (let ((method (gnus-find-method-for-group group))
11864         (func 'list-active-group))
11865     (and (gnus-check-backend-function func group)
11866          (funcall (gnus-get-function method func) 
11867                   (gnus-group-real-name group) (nth 1 method)))))
11868
11869 (defun gnus-request-group-description (group)
11870   (let ((method (gnus-find-method-for-group group))
11871         (func 'request-group-description))
11872     (and (gnus-check-backend-function func group)
11873          (funcall (gnus-get-function method func) 
11874                   (gnus-group-real-name group) (nth 1 method)))))
11875
11876 (defun gnus-close-group (group)
11877   (let ((method (gnus-find-method-for-group group)))
11878     (funcall (gnus-get-function method 'close-group) 
11879              (gnus-group-real-name group) (nth 1 method))))
11880
11881 (defun gnus-retrieve-headers (articles group)
11882   (let ((method (gnus-find-method-for-group group)))
11883     (if (and gnus-use-cache (numberp (car articles)))
11884         (gnus-cache-retrieve-headers articles group)
11885       (funcall (gnus-get-function method 'retrieve-headers) 
11886                articles (gnus-group-real-name group) (nth 1 method)))))
11887
11888 (defun gnus-retrieve-groups (groups method)
11889   (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method)))
11890
11891 (defun gnus-request-article (article group &optional buffer)
11892   (let ((method (gnus-find-method-for-group group)))
11893     (funcall (gnus-get-function method 'request-article) 
11894              article (gnus-group-real-name group) (nth 1 method) buffer)))
11895
11896 (defun gnus-request-head (article group)
11897   (let ((method (gnus-find-method-for-group group)))
11898     (funcall (gnus-get-function method 'request-head) 
11899              article (gnus-group-real-name group) (nth 1 method))))
11900
11901 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11902 (defun gnus-request-post-buffer (post group subject header artbuf
11903                                       info follow-to respect-poster)
11904    (let* ((info (or info (and group (nth 2 (gnus-gethash 
11905                                             group gnus-newsrc-hashtb)))))
11906           (method
11907            (if (and gnus-post-method
11908                     ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>.
11909                     (memq 'post (assoc
11910                                  (format "%s" (car (gnus-find-method-for-group
11911                                                     gnus-newsgroup-name)))
11912                                         gnus-valid-select-methods)))
11913                gnus-post-method
11914              (gnus-find-method-for-group gnus-newsgroup-name))))
11915      (or (gnus-check-server method)
11916          (error "Can't open server %s:%s" (car method) (nth 1 method)))
11917      (let ((mail-self-blind nil)
11918            (mail-archive-file-name nil))
11919        (funcall (gnus-get-function method 'request-post-buffer) 
11920                 post group subject header artbuf info follow-to
11921                 respect-poster))))
11922
11923 (defun gnus-request-post (method &optional force)
11924   (and (stringp method)
11925        (setq method (gnus-server-to-method method)))
11926   (and (not force) gnus-post-method
11927        (memq 'post (assoc (format "%s" (car method))
11928                           gnus-valid-select-methods))
11929        (setq method gnus-post-method))
11930   (funcall (gnus-get-function method 'request-post) 
11931            (nth 1 method)))
11932
11933 (defun gnus-request-expire-articles (articles group &optional force)
11934   (let ((method (gnus-find-method-for-group group)))
11935     (funcall (gnus-get-function method 'request-expire-articles) 
11936              articles (gnus-group-real-name group) (nth 1 method)
11937              force)))
11938
11939 (defun gnus-request-move-article 
11940   (article group server accept-function &optional last)
11941   (let ((method (gnus-find-method-for-group group)))
11942     (funcall (gnus-get-function method 'request-move-article) 
11943              article (gnus-group-real-name group) 
11944              (nth 1 method) accept-function last)))
11945
11946 (defun gnus-request-accept-article (group &optional last)
11947   (let ((func (if (symbolp group) group
11948                 (car (gnus-find-method-for-group group)))))
11949     (funcall (intern (format "%s-request-accept-article" func))
11950              (if (stringp group) (gnus-group-real-name group) group)
11951              last)))
11952
11953 (defun gnus-request-replace-article (article group buffer)
11954   (let ((func (car (gnus-find-method-for-group group))))
11955     (funcall (intern (format "%s-request-replace-article" func))
11956              article (gnus-group-real-name group) buffer)))
11957
11958 (defun gnus-request-create-group (group)
11959   (let ((method (gnus-find-method-for-group group)))
11960     (funcall (gnus-get-function method 'request-create-group) 
11961              (gnus-group-real-name group) (nth 1 method))))
11962
11963 (defun gnus-member-of-valid (symbol group)
11964   (memq symbol (assoc
11965                 (format "%s" (car (gnus-find-method-for-group group)))
11966                 gnus-valid-select-methods)))
11967
11968 (defun gnus-secondary-method-p (method)
11969   (let ((methods gnus-secondary-select-methods)
11970         (gmethod (gnus-server-get-method nil method)))
11971     (while (and methods
11972                 (not (equal (gnus-server-get-method nil (car methods)) 
11973                             gmethod)))
11974       (setq methods (cdr methods)))
11975     methods))
11976
11977 (defun gnus-find-method-for-group (group &optional info)
11978   (or gnus-override-method
11979       (and (not group)
11980            gnus-select-method)
11981       (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))
11982             method)
11983         (if (or (not info)
11984                 (not (setq method (nth 4 info))))
11985             (setq method gnus-select-method)
11986           (setq method
11987                 (cond ((stringp method)
11988                        (gnus-server-to-method method))
11989                       ((stringp (car method))
11990                        (gnus-server-extend-method group method))
11991                       (t
11992                        method))))
11993         (gnus-server-add-address method))))
11994
11995 (defun gnus-check-backend-function (func group)
11996   (let ((method (if (stringp group) (car (gnus-find-method-for-group group))
11997                  group)))
11998     (fboundp (intern (format "%s-%s" method func)))))
11999
12000 (defun gnus-methods-using (method)
12001   (let ((valids gnus-valid-select-methods)
12002         outs)
12003     (while valids
12004       (if (memq method (car valids)) 
12005           (setq outs (cons (car valids) outs)))
12006       (setq valids (cdr valids)))
12007     outs))
12008
12009 ;;; 
12010 ;;; Active & Newsrc File Handling
12011 ;;;
12012
12013 ;; Newsrc related functions.
12014 ;; Gnus internal format of gnus-newsrc-alist:
12015 ;; (("alt.general" 3 (1 . 1))
12016 ;;  ("alt.misc"    3 ((1 . 10) (12 . 15)))
12017 ;;  ("alt.test"    7 (1 . 99) (45 57 93)) ...)
12018 ;; The first item is the group name; the second is the subscription
12019 ;; level; the third is either a range of a list of ranges of read
12020 ;; articles, the optional fourth element is a list of marked articles,
12021 ;; the optional fifth element is the select method.
12022 ;;
12023 ;; Gnus internal format of gnus-newsrc-hashtb:
12024 ;; (95 ("alt.general" 3 (1 . 1)) ("alt.misc" 3 ((1 . 10) (12 . 15))) ...)
12025 ;; This is the entry for "alt.misc". The first element is the number
12026 ;; of unread articles in "alt.misc". The cdr of this entry is the
12027 ;; element *before* "alt.misc" in gnus-newsrc-alist, which makes is
12028 ;; trivial to remove or add new elements into gnus-newsrc-alist
12029 ;; without scanning the entire list. So, to get the actual information
12030 ;; of "alt.misc", you'd say something like 
12031 ;; (nth 2 (gnus-gethash "alt.misc" gnus-newsrc-hashtb))
12032 ;;
12033 ;; Gnus internal format of gnus-active-hashtb:
12034 ;; ((1 . 1))
12035 ;;  (5 . 10))
12036 ;;  (67 . 99)) ...)
12037 ;; The only element in each entry in this hash table is a range of
12038 ;; (possibly) available articles. (Articles in this range may have
12039 ;; been expired or canceled.)
12040 ;;
12041 ;; Gnus internal format of gnus-killed-list and gnus-zombie-list:
12042 ;; ("alt.misc" "alt.test" "alt.general" ...)
12043
12044 (defun gnus-setup-news (&optional rawfile level)
12045   "Setup news information.
12046 If RAWFILE is non-nil, the .newsrc file will also be read.
12047 If LEVEL is non-nil, the news will be set up at level LEVEL."
12048   (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
12049     ;; Clear some variables to re-initialize news information.
12050     (if init (setq gnus-newsrc-alist nil 
12051                    gnus-active-hashtb nil))
12052
12053     ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
12054     (if init (gnus-read-newsrc-file rawfile))
12055
12056     ;; If we don't read the complete active file, we fill in the
12057     ;; hashtb here. 
12058     (if (or (null gnus-read-active-file)
12059             (eq gnus-read-active-file 'some))
12060         (gnus-update-active-hashtb-from-killed))
12061
12062     ;; Read the active file and create `gnus-active-hashtb'.
12063     ;; If `gnus-read-active-file' is nil, then we just create an empty
12064     ;; hash table. The partial filling out of the hash table will be
12065     ;; done in `gnus-get-unread-articles'.
12066     (and gnus-read-active-file 
12067          (not level)
12068          (gnus-read-active-file))
12069
12070     (or gnus-active-hashtb
12071         (setq gnus-active-hashtb (make-vector 4095 0)))
12072
12073     ;; Possibly eval the dribble file.
12074     (and init gnus-use-dribble-file (gnus-dribble-eval-file))
12075
12076     (gnus-update-format-specifications)
12077
12078     ;; Find the number of unread articles in each non-dead group.
12079     (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
12080       (gnus-get-unread-articles (or level (1+ gnus-level-subscribed))))
12081     ;; Find new newsgroups and treat them.
12082     (if (and init gnus-check-new-newsgroups gnus-read-active-file (not level)
12083              (gnus-server-opened gnus-select-method))
12084         (gnus-find-new-newsgroups))
12085     (if (and init gnus-check-bogus-newsgroups 
12086              gnus-read-active-file (not level)
12087              (gnus-server-opened gnus-select-method))
12088         (gnus-check-bogus-newsgroups))))
12089
12090 (defun gnus-find-new-newsgroups ()
12091   "Search for new newsgroups and add them.
12092 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
12093 The `-n' option line from .newsrc is respected."
12094   (interactive)
12095   (or (gnus-check-first-time-used)
12096       (if (or (consp gnus-check-new-newsgroups)
12097               (eq gnus-check-new-newsgroups 'ask-server))
12098           (gnus-ask-server-for-new-groups)
12099         (let ((groups 0)
12100               group new-newsgroups)
12101           (gnus-message 5 "Checking for new newsgroups...")
12102           (or gnus-have-read-active-file (gnus-read-active-file))
12103           (setq gnus-newsrc-last-checked-date (current-time-string))
12104           (if (not gnus-killed-hashtb) (gnus-make-hashtable-from-killed))
12105           ;; Go though every newsgroup in `gnus-active-hashtb' and compare
12106           ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
12107           (mapatoms
12108            (lambda (sym)
12109              (if (or (null (setq group (symbol-name sym)))
12110                      (null (symbol-value sym))
12111                      (gnus-gethash group gnus-killed-hashtb)
12112                      (gnus-gethash group gnus-newsrc-hashtb))
12113                  ()
12114                (let ((do-sub (gnus-matches-options-n group)))
12115                  (cond 
12116                   ((eq do-sub 'subscribe)
12117                    (setq groups (1+ groups))
12118                    (gnus-sethash group group gnus-killed-hashtb)
12119                    (funcall gnus-subscribe-options-newsgroup-method group))
12120                   ((eq do-sub 'ignore)
12121                    nil)
12122                   (t
12123                    (setq groups (1+ groups))
12124                    (gnus-sethash group group gnus-killed-hashtb)
12125                    (if gnus-subscribe-hierarchical-interactive
12126                        (setq new-newsgroups (cons group new-newsgroups))
12127                      (funcall gnus-subscribe-newsgroup-method group)))))))
12128            gnus-active-hashtb)
12129           (if new-newsgroups 
12130               (gnus-subscribe-hierarchical-interactive new-newsgroups))
12131           ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12132           (if (> groups 0)
12133               (gnus-message 6 "%d new newsgroup%s arrived." 
12134                             groups (if (> groups 1) "s have" " has"))
12135             (gnus-message 6 "No new newsgroups."))))))
12136
12137 (defun gnus-matches-options-n (group)
12138   ;; Returns `subscribe' if the group is to be uncoditionally
12139   ;; subscribed, `ignore' if it is to be ignored, and nil if there is
12140   ;; no match for the group.
12141
12142   ;; First we check the two user variables.
12143   (cond
12144    ((and gnus-options-subscribe
12145          (string-match gnus-options-subscribe group))
12146     'subscribe)
12147    ((and gnus-options-not-subscribe
12148          (string-match gnus-options-not-subscribe group))
12149     'ignore)
12150    ;; Then we go through the list that was retrieved from the .newsrc
12151    ;; file.  This list has elements on the form 
12152    ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list
12153    ;; is in the reverse order of the options line) is returned.
12154    (t
12155     (let ((regs gnus-newsrc-options-n))
12156       (while (and regs
12157                   (not (string-match (car (car regs)) group)))
12158         (setq regs (cdr regs)))
12159       (and regs (cdr (car regs)))))))
12160
12161 (defun gnus-ask-server-for-new-groups ()
12162   (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
12163          (methods (cons gnus-select-method 
12164                         (append
12165                          (and (consp gnus-check-new-newsgroups)
12166                               gnus-check-new-newsgroups)
12167                          gnus-secondary-select-methods)))
12168          (groups 0)
12169          (new-date (current-time-string))
12170          (hashtb (gnus-make-hashtable 100))
12171          group new-newsgroups got-new method)
12172     ;; Go through both primary and secondary select methods and
12173     ;; request new newsgroups.  
12174     (while methods
12175       (setq method (gnus-server-get-method nil (car methods)))
12176       (and (gnus-check-server method)
12177            (gnus-request-newgroups date method)
12178            (save-excursion
12179              (setq got-new t)
12180              (set-buffer nntp-server-buffer)
12181              ;; Enter all the new groups in a hashtable.
12182              (gnus-active-to-gnus-format method hashtb 'ignore)))
12183       (setq methods (cdr methods)))
12184     (and got-new (setq gnus-newsrc-last-checked-date new-date))
12185     ;; Now all new groups from all select methods are in `hashtb'.
12186     (mapatoms
12187      (lambda (group-sym)
12188        (setq group (symbol-name group-sym))
12189        (if (or (null group)
12190                (null (symbol-value group-sym))
12191                (gnus-gethash group gnus-newsrc-hashtb)
12192                (member group gnus-zombie-list)
12193                (member group gnus-killed-list))
12194            ;; The group is already known.
12195            ()
12196          (and (symbol-value group-sym)
12197               (gnus-sethash group (symbol-value group-sym) gnus-active-hashtb))
12198          (let ((do-sub (gnus-matches-options-n group)))
12199            (cond ((eq do-sub 'subscribe)
12200                   (setq groups (1+ groups))
12201                   (gnus-sethash group group gnus-killed-hashtb)
12202                   (funcall 
12203                    gnus-subscribe-options-newsgroup-method group))
12204                  ((eq do-sub 'ignore)
12205                   nil)
12206                  (t
12207                   (setq groups (1+ groups))
12208                   (gnus-sethash group group gnus-killed-hashtb)
12209                   (if gnus-subscribe-hierarchical-interactive
12210                       (setq new-newsgroups (cons group new-newsgroups))
12211                     (funcall gnus-subscribe-newsgroup-method group)))))))
12212      hashtb)
12213     (if new-newsgroups 
12214         (gnus-subscribe-hierarchical-interactive new-newsgroups))
12215     ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
12216     (if (> groups 0)
12217         (gnus-message 6 "%d new newsgroup%s arrived." 
12218                       groups (if (> groups 1) "s have" " has")))
12219     got-new))
12220
12221 (defun gnus-check-first-time-used ()
12222   (if (or (> (length gnus-newsrc-alist) 1)
12223           (file-exists-p gnus-startup-file)
12224           (file-exists-p (concat gnus-startup-file ".el"))
12225           (file-exists-p (concat gnus-startup-file ".eld")))
12226       nil
12227     (gnus-message 6 "First time user; subscribing you to default groups")
12228     (or gnus-have-read-active-file (gnus-read-active-file))
12229     (setq gnus-newsrc-last-checked-date (current-time-string))
12230     (let ((groups gnus-default-subscribed-newsgroups)
12231           group)
12232       (if (eq groups t)
12233           nil
12234         (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
12235         (mapatoms
12236          (lambda (sym)
12237            (if (null (setq group (symbol-name sym)))
12238                ()
12239              (let ((do-sub (gnus-matches-options-n group)))
12240                (cond 
12241                 ((eq do-sub 'subscribe)
12242                  (gnus-sethash group group gnus-killed-hashtb)
12243                  (funcall gnus-subscribe-options-newsgroup-method group))
12244                 ((eq do-sub 'ignore)
12245                  nil)
12246                 (t
12247                  (setq gnus-killed-list (cons group gnus-killed-list)))))))
12248          gnus-active-hashtb)
12249         (while groups
12250           (if (gnus-gethash (car groups) gnus-active-hashtb)
12251               (gnus-group-change-level 
12252                (car groups) gnus-level-default-subscribed gnus-level-killed))
12253           (setq groups (cdr groups)))
12254         (gnus-group-make-help-group)
12255         (and gnus-novice-user
12256              (gnus-message 7 "`A k' to list killed groups"))))))
12257
12258 (defun gnus-subscribe-group (group previous &optional method)
12259   (gnus-group-change-level 
12260    (if method
12261        (list t group gnus-level-default-subscribed nil nil method)
12262      group) 
12263    gnus-level-default-subscribed gnus-level-killed previous t))
12264
12265 ;; `gnus-group-change-level' is the fundamental function for changing
12266 ;; subscription levels of newsgroups. This might mean just changing
12267 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
12268 ;; again, which subscribes/unsubscribes a group, which is equally
12269 ;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and
12270 ;; from 8-9 to 1-7 means that you remove the group from the list of
12271 ;; killed (or zombie) groups and add them to the (kinda) subscribed
12272 ;; groups. And last but not least, moving from 8 to 9 and 9 to 8,
12273 ;; which is trivial.
12274 ;; ENTRY can either be a string (newsgroup name) or a list (if
12275 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
12276 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
12277 ;; entries. 
12278 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
12279 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
12280 ;; after. 
12281 (defun gnus-group-change-level (entry level &optional oldlevel
12282                                       previous fromkilled)
12283   (let (group info active num)
12284     ;; Glean what info we can from the arguments
12285     (if (consp entry)
12286         (if fromkilled (setq group (nth 1 entry))
12287           (setq group (car (nth 2 entry))))
12288       (setq group entry))
12289     (if (and (stringp entry)
12290              oldlevel 
12291              (< oldlevel gnus-level-zombie))
12292         (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
12293     (if (and (not oldlevel)
12294              (consp entry))
12295         (setq oldlevel (car (cdr (nth 2 entry)))))
12296     (if (stringp previous)
12297         (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
12298
12299     (if (and (>= oldlevel gnus-level-zombie)
12300              (gnus-gethash group gnus-newsrc-hashtb))
12301         ;; We are trying to subscribe a group that is already
12302         ;; subscribed. 
12303         () ; Do nothing. 
12304
12305       (gnus-dribble-enter
12306        (format "(gnus-group-change-level %S %S %S %S %S)" 
12307                group level oldlevel (car (nth 2 previous)) fromkilled))
12308     
12309       ;; Then we remove the newgroup from any old structures, if needed.
12310       ;; If the group was killed, we remove it from the killed or zombie
12311       ;; list. If not, and it is in fact going to be killed, we remove
12312       ;; it from the newsrc hash table and assoc.
12313       (cond ((>= oldlevel gnus-level-zombie)
12314              (if (= oldlevel gnus-level-zombie)
12315                  (setq gnus-zombie-list (delete group gnus-zombie-list))
12316                (setq gnus-killed-list (delete group gnus-killed-list))))
12317             (t
12318              (if (and (>= level gnus-level-zombie)
12319                       entry)
12320                  (progn
12321                    (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
12322                    (if (nth 3 entry)
12323                        (setcdr (gnus-gethash (car (nth 3 entry))
12324                                              gnus-newsrc-hashtb)
12325                                (cdr entry)))
12326                    (setcdr (cdr entry) (cdr (cdr (cdr entry))))))))
12327
12328       ;; Finally we enter (if needed) the list where it is supposed to
12329       ;; go, and change the subscription level. If it is to be killed,
12330       ;; we enter it into the killed or zombie list.
12331       (cond ((>= level gnus-level-zombie)
12332              ;; Remove from the hash table.
12333              (gnus-sethash group nil gnus-newsrc-hashtb)
12334              (or (gnus-group-foreign-p group)
12335                  ;; We do not enter foreign groups into the list of dead
12336                  ;; groups.  
12337                  (if (= level gnus-level-zombie)
12338                      (setq gnus-zombie-list (cons group gnus-zombie-list))
12339                    (setq gnus-killed-list (cons group gnus-killed-list)))))
12340             (t
12341              ;; If the list is to be entered into the newsrc assoc, and
12342              ;; it was killed, we have to create an entry in the newsrc
12343              ;; hashtb format and fix the pointers in the newsrc assoc.
12344              (if (>= oldlevel gnus-level-zombie)
12345                  (progn
12346                    (if (listp entry)
12347                        (progn
12348                          (setq info (cdr entry))
12349                          (setq num (car entry)))
12350                      (setq active (gnus-gethash group gnus-active-hashtb))
12351                      (setq num 
12352                            (if active (- (1+ (cdr active)) (car active)) t))
12353                      ;; Check whether the group is foreign. If so, the
12354                      ;; foreign select method has to be entered into the
12355                      ;; info. 
12356                      (let ((method (gnus-group-method-name group)))
12357                        (if (eq method gnus-select-method)
12358                            (setq info (list group level nil))
12359                          (setq info (list group level nil nil method)))))
12360                    (or previous 
12361                        (setq previous 
12362                              (let ((p gnus-newsrc-alist))
12363                                (while (cdr (cdr p))
12364                                  (setq p (cdr p)))
12365                                p)))
12366                    (setq entry (cons info (cdr (cdr previous))))
12367                    (if (cdr previous)
12368                        (progn
12369                          (setcdr (cdr previous) entry)
12370                          (gnus-sethash group (cons num (cdr previous)) 
12371                                        gnus-newsrc-hashtb))
12372                      (setcdr previous entry)
12373                      (gnus-sethash group (cons num previous)
12374                                    gnus-newsrc-hashtb))
12375                    (if (cdr entry)
12376                        (setcdr (gnus-gethash (car (car (cdr entry)))
12377                                              gnus-newsrc-hashtb)
12378                                entry)))
12379                ;; It was alive, and it is going to stay alive, so we
12380                ;; just change the level and don't change any pointers or
12381                ;; hash table entries.
12382                (setcar (cdr (car (cdr (cdr entry)))) level)))))))
12383
12384 (defun gnus-kill-newsgroup (newsgroup)
12385   "Obsolete function. Kills a newsgroup."
12386   (gnus-group-change-level
12387    (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
12388
12389 (defun gnus-check-bogus-newsgroups (&optional confirm)
12390   "Remove bogus newsgroups.
12391 If CONFIRM is non-nil, the user has to confirm the deletion of every
12392 newsgroup." 
12393   (let ((newsrc (cdr gnus-newsrc-alist))
12394         bogus group entry)
12395     (gnus-message 5 "Checking bogus newsgroups...")
12396     (or gnus-have-read-active-file (gnus-read-active-file))
12397     ;; Find all bogus newsgroup that are subscribed.
12398     (while newsrc
12399       (setq group (car (car newsrc)))
12400       (if (or (gnus-gethash group gnus-active-hashtb) ; Active
12401               (nth 4 (car newsrc))      ; Foreign
12402               (and confirm
12403                    (not (gnus-y-or-n-p
12404                          (format "Remove bogus newsgroup: %s " group)))))
12405           ;; Don't remove.
12406           ()
12407         ;; Found a bogus newsgroup.
12408         (setq bogus (cons group bogus)))
12409       (setq newsrc (cdr newsrc)))
12410     ;; Remove all bogus subscribed groups by first killing them, and
12411     ;; then removing them from the list of killed groups.
12412     (while bogus
12413       (and (setq entry (gnus-gethash (car bogus) gnus-newsrc-hashtb))
12414            (progn
12415              (gnus-group-change-level entry gnus-level-killed)
12416              (setq gnus-killed-list (delete (car bogus) gnus-killed-list))))
12417       (setq bogus (cdr bogus)))
12418     ;; Then we remove all bogus groups from the list of killed and
12419     ;; zombie groups. They are are removed without confirmation.
12420     (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
12421           killed)
12422       (while dead-lists
12423         (setq killed (symbol-value (car dead-lists)))
12424         (while killed
12425           (setq group (car killed))
12426           (or (gnus-gethash group gnus-active-hashtb)
12427               ;; The group is bogus.
12428               (set (car dead-lists)
12429                    (delete group (symbol-value (car dead-lists)))))
12430           (setq killed (cdr killed)))
12431         (setq dead-lists (cdr dead-lists))))
12432     (gnus-message 5 "Checking bogus newsgroups...done")))
12433
12434 (defun gnus-check-duplicate-killed-groups ()
12435   "Remove duplicates from the list of killed groups."
12436   (interactive)
12437   (let ((killed gnus-killed-list))
12438     (while killed
12439       (gnus-message 9 "%d" (length killed))
12440       (setcdr killed (delete (car killed) (cdr killed)))
12441       (setq killed (cdr killed)))))
12442
12443 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
12444 ;; and compute how many unread articles there are in each group.
12445 (defun gnus-get-unread-articles (&optional level) 
12446   (let* ((newsrc (cdr gnus-newsrc-alist))
12447          (level (or level (1+ gnus-level-subscribed)))
12448          (foreign-level
12449           (min 
12450            (cond ((and gnus-activate-foreign-newsgroups 
12451                        (not (numberp gnus-activate-foreign-newsgroups)))
12452                   (1+ gnus-level-subscribed))
12453                  ((numberp gnus-activate-foreign-newsgroups)
12454                   gnus-activate-foreign-newsgroups)
12455                  (t 0))
12456            level))
12457          info group active virtuals method)
12458     (gnus-message 5 "Checking new news...")
12459
12460     (while newsrc
12461       (setq info (car newsrc)
12462             group (car info)
12463             active (gnus-gethash group gnus-active-hashtb))
12464
12465       ;; Check newsgroups. If the user doesn't want to check them, or
12466       ;; they can't be checked (for instance, if the news server can't
12467       ;; be reached) we just set the number of unread articles in this
12468       ;; newsgroup to t. This means that Gnus thinks that there are
12469       ;; unread articles, but it has no idea how many.
12470       (if (and (setq method (nth 4 info))
12471                (not (gnus-server-equal gnus-select-method
12472                                        (gnus-server-get-method nil method)))
12473                (not (gnus-secondary-method-p method)))
12474           ;; These groups are foreign. Check the level.
12475           (if (<= (nth 1 info) foreign-level)
12476               (if (eq (car (if (stringp method) 
12477                                (gnus-server-to-method method)
12478                              (nth 4 info))) 'nnvirtual)
12479                   ;; We have to activate the virtual groups after all
12480                   ;; the others, so we just pop them on a list for
12481                   ;; now. 
12482                   (setq virtuals (cons info virtuals))
12483                 (and (setq active (gnus-activate-group (car info)))
12484                      ;; Close the groups as we look at them!
12485                      (gnus-close-group group))))
12486
12487         ;; These groups are native or secondary. 
12488         (if (and (not gnus-read-active-file)
12489                  (<= (nth 1 info) level))
12490             (progn
12491               (or gnus-read-active-file (gnus-check-server method))
12492               (setq active (gnus-activate-group (car info))))))
12493       
12494       (if active
12495           (gnus-get-unread-articles-in-group info active)
12496         ;; The group couldn't be reached, so we nix out the number of
12497         ;; unread articles and stuff.
12498         (gnus-sethash group nil gnus-active-hashtb)
12499         (setcar (gnus-gethash group gnus-newsrc-hashtb) t))
12500
12501       (setq newsrc (cdr newsrc)))
12502
12503     ;; Activate the virtual groups. This has to be done after all the
12504     ;; other groups. 
12505     ;; !!! If one virtual group contains another virtual group, even
12506     ;; doing it this way might cause problems.
12507     (while virtuals
12508       (and (setq active (gnus-activate-group (car (car virtuals))))
12509            (gnus-get-unread-articles-in-group (car virtuals) active))
12510       (setq virtuals (cdr virtuals)))
12511
12512     (gnus-message 5 "Checking new news...done")))
12513
12514 ;; Create a hash table out of the newsrc alist. The `car's of the
12515 ;; alist elements are used as keys.
12516 (defun gnus-make-hashtable-from-newsrc-alist ()
12517   (let ((alist gnus-newsrc-alist)
12518         (ohashtb gnus-newsrc-hashtb)
12519         prev)
12520     (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
12521     (setq alist 
12522           (setq prev (setq gnus-newsrc-alist 
12523                            (if (equal (car (car gnus-newsrc-alist))
12524                                       "dummy.group")
12525                                gnus-newsrc-alist
12526                              (cons (list "dummy.group" 0 nil) alist)))))
12527     (while alist
12528       (gnus-sethash (car (car alist)) 
12529                     (cons (and ohashtb (car (gnus-gethash 
12530                                              (car (car alist)) ohashtb))) 
12531                           prev) gnus-newsrc-hashtb)
12532       (setq prev alist
12533             alist (cdr alist)))))
12534
12535 (defun gnus-make-hashtable-from-killed ()
12536   "Create a hash table from the killed and zombie lists."
12537   (let ((lists '(gnus-killed-list gnus-zombie-list))
12538         list)
12539     (setq gnus-killed-hashtb 
12540           (gnus-make-hashtable 
12541            (+ (length gnus-killed-list) (length gnus-zombie-list))))
12542     (while lists
12543       (setq list (symbol-value (car lists)))
12544       (setq lists (cdr lists))
12545       (while list
12546         (gnus-sethash (car list) (car list) gnus-killed-hashtb)
12547         (setq list (cdr list))))))
12548
12549 (defun gnus-get-unread-articles-in-group (info active)
12550   (let* ((range (nth 2 info))
12551          (num 0)
12552          (marked (nth 3 info)))
12553     ;; If a cache is present, we may have to alter the active info.
12554     (and gnus-use-cache
12555          (gnus-cache-possibly-alter-active (car info) active))
12556     ;; Modify the list of read articles according to what articles 
12557     ;; are available; then tally the unread articles and add the
12558     ;; number to the group hash table entry.
12559     (cond 
12560      ((zerop (cdr active))
12561       (setq num 0))
12562      ((not range)
12563       (setq num (- (1+ (cdr active)) (car active))))
12564      ((not (listp (cdr range)))
12565       ;; Fix a single (num . num) range according to the
12566       ;; active hash table.
12567       ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
12568       (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
12569       (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
12570       ;; Compute number of unread articles.
12571       (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
12572      (t
12573       ;; The read list is a list of ranges. Fix them according to
12574       ;; the active hash table.
12575       ;; First peel off any elements that are below the lower
12576       ;; active limit. 
12577       (while (and (cdr range) 
12578                   (>= (car active) 
12579                       (or (and (atom (car (cdr range))) (car (cdr range)))
12580                           (car (car (cdr range))))))
12581         (if (numberp (car range))
12582             (setcar range 
12583                     (cons (car range) 
12584                           (or (and (numberp (car (cdr range)))
12585                                    (car (cdr range))) 
12586                               (cdr (car (cdr range))))))
12587           (setcdr (car range) 
12588                   (or (and (numberp (nth 1 range)) (nth 1 range))
12589                       (cdr (car (cdr range))))))
12590         (setcdr range (cdr (cdr range))))
12591       ;; Adjust the first element to be the same as the lower limit. 
12592       (if (and (not (atom (car range))) 
12593                (< (cdr (car range)) (car active)))
12594           (setcdr (car range) (1- (car active))))
12595       ;; Then we want to peel off any elements that are higher
12596       ;; than the upper active limit.  
12597       (let ((srange range))
12598         ;; Go past all legal elements.
12599         (while (and (cdr srange) 
12600                     (<= (or (and (atom (car (cdr srange)))
12601                                  (car (cdr srange)))
12602                             (car (car (cdr srange)))) (cdr active)))
12603           (setq srange (cdr srange)))
12604         (if (cdr srange)
12605             ;; Nuke all remaining illegal elements.
12606             (setcdr srange nil))
12607
12608         ;; Adjust the final element.
12609         (if (and (not (atom (car srange)))
12610                  (> (cdr (car srange)) (cdr active)))
12611             (setcdr (car srange) (cdr active))))
12612       ;; Compute the number of unread articles.
12613       (while range
12614         (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
12615                                     (cdr (car range))))
12616                             (or (and (atom (car range)) (car range))
12617                                 (car (car range))))))
12618         (setq range (cdr range)))
12619       (setq num (max 0 (- (cdr active) num)))))
12620     (and info
12621          (progn
12622            (and (assq 'tick marked)
12623                 (inline (gnus-remove-illegal-marked-articles
12624                          (assq 'tick marked) (nth 2 info))))
12625            (and (assq 'dormant marked)
12626                 (inline (gnus-remove-illegal-marked-articles
12627                          (assq 'dormant marked) (nth 2 info))))
12628            (setcar
12629             (gnus-gethash (car info) gnus-newsrc-hashtb) 
12630             (setq num (max 0 (- num (length (cdr (assq 'tick marked)))
12631                                 (length (cdr (assq 'dormant marked)))))))))
12632     num))
12633
12634 (defun gnus-remove-illegal-marked-articles (marked ranges)
12635   (let ((m (cdr marked)))
12636     ;; Make sure that all ticked articles are a subset of the unread
12637     ;; articles. 
12638     (while m
12639       (if (gnus-member-of-range (car m) ranges)
12640           (setcdr marked (cdr m))
12641         (setq marked m))
12642       (setq m (cdr m)))))
12643
12644 (defun gnus-activate-group (group)
12645   ;; Check whether a group has been activated or not.
12646   (let ((method (gnus-find-method-for-group group))
12647         active)
12648     (and (gnus-check-server method)
12649          ;; We escape all bugs and quits here to make it possible to
12650          ;; continue if a group is so out-there that it reports bugs
12651          ;; and stuff.
12652          (condition-case ()
12653              (gnus-request-group group)
12654            (error nil)
12655            (quit nil))
12656          (save-excursion
12657            (set-buffer nntp-server-buffer)
12658            (goto-char (point-min))
12659            ;; Parse the result we got from `gnus-request-group'.
12660            (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
12661                 (progn
12662                   (goto-char (match-beginning 1))
12663                   (gnus-sethash 
12664                    group (setq active (cons (read (current-buffer))
12665                                             (read (current-buffer))))
12666                    gnus-active-hashtb))
12667                 ;; Return the new active info.
12668                 active)))))
12669
12670 (defun gnus-update-read-articles 
12671   (group unread unselected ticked &optional domarks replied expirable killed
12672          dormant bookmark score)
12673   "Update the list of read and ticked articles in GROUP using the
12674 UNREAD and TICKED lists.
12675 Note: UNSELECTED has to be sorted over `<'.
12676 Returns whether the updating was successful."
12677   (let* ((active (or gnus-newsgroup-active 
12678                      (gnus-gethash group gnus-active-hashtb)))
12679          (entry (gnus-gethash group gnus-newsrc-hashtb))
12680          (info (nth 2 entry))
12681          (marked (nth 3 info))
12682          (prev 1)
12683          (unread (sort (copy-sequence unread) (function <)))
12684          read)
12685     (if (or (not info) (not active))
12686         ;; There is no info on this group if it was, in fact,
12687         ;; killed. Gnus stores no information on killed groups, so
12688         ;; there's nothing to be done. 
12689         ;; One could store the information somewhere temporarily,
12690         ;; perhaps... Hmmm... 
12691         ()
12692       ;; Remove any negative articles numbers.
12693       (while (and unread (< (car unread) 0))
12694         (setq unread (cdr unread)))
12695       ;; Remove any expired article numbers
12696       (while (and unread (< (car unread) (car active)))
12697         (setq unread (cdr unread)))
12698       (while (and ticked (< (car ticked) (car active)))
12699         (setq ticked (cdr ticked)))
12700       (while (and dormant (< (car dormant) (car active)))
12701         (setq dormant (cdr dormant)))
12702       (setq unread (sort (append unselected unread) '<))
12703       ;; Compute the ranges of read articles by looking at the list of
12704       ;; unread articles.  
12705       (while unread
12706         (if (/= (car unread) prev)
12707             (setq read (cons (if (= prev (1- (car unread))) prev
12708                                (cons prev (1- (car unread)))) read)))
12709         (setq prev (1+ (car unread)))
12710         (setq unread (cdr unread)))
12711       (if (<= prev (cdr active))
12712           (setq read (cons (cons prev (cdr active)) read)))
12713       ;; Enter this list into the group info.
12714       (setcar (cdr (cdr info)) 
12715               (if (> (length read) 1) (nreverse read) read))
12716       ;; Enter the list of ticked articles.
12717       (gnus-set-marked-articles 
12718        info ticked
12719        (if domarks replied (cdr (assq 'reply marked)))
12720        (if domarks expirable (cdr (assq 'expire marked)))
12721        (if domarks killed (cdr (assq 'killed marked)))
12722        (if domarks dormant (cdr (assq 'dormant marked)))
12723        (if domarks bookmark (cdr (assq 'bookmark marked)))
12724        (if domarks score (cdr (assq 'score marked))))
12725       ;; Set the number of unread articles in gnus-newsrc-hashtb.
12726       (gnus-get-unread-articles-in-group 
12727        info (gnus-gethash group gnus-active-hashtb))
12728       t)))
12729
12730 (defun gnus-make-articles-unread (group articles)
12731   "Mark ARTICLES in GROUP as unread."
12732   (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
12733                           (gnus-gethash (gnus-group-real-name group)
12734                                         gnus-newsrc-hashtb))))
12735          (ranges (nth 2 info))
12736          news)
12737     (while articles
12738       (and (gnus-member-of-range (car articles) ranges)
12739            (setq news (cons (car articles) news)))
12740       (setq articles (cdr articles)))
12741     (if (not news)
12742         ()
12743       (setcar (nthcdr 2 info)
12744               (gnus-remove-from-range (nth 2 info) (nreverse news)))
12745       (gnus-group-update-group group t))))
12746
12747 ;; Enter all dead groups into the hashtb.
12748 (defun gnus-update-active-hashtb-from-killed ()
12749   (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
12750         (lists (list gnus-killed-list gnus-zombie-list))
12751         killed)
12752     (while lists
12753       (setq killed (car lists))
12754       (while killed
12755         (gnus-sethash (car killed) nil hashtb)
12756         (setq killed (cdr killed)))
12757       (setq lists (cdr lists)))))
12758
12759 ;; Get the active file(s) from the backend(s).
12760 (defun gnus-read-active-file ()
12761   (gnus-group-set-mode-line)
12762   (let ((methods (if (gnus-check-server gnus-select-method)
12763                      ;; The native server is available.
12764                      (cons gnus-select-method gnus-secondary-select-methods)
12765                    ;; The native server is down, so we just do the
12766                    ;; secondary ones.   
12767                    gnus-secondary-select-methods))
12768         list-type)
12769     (setq gnus-have-read-active-file nil)
12770     (save-excursion
12771       (set-buffer nntp-server-buffer)
12772       (while methods
12773         (let* ((method (gnus-server-get-method nil (car methods)))
12774                (where (nth 1 method))
12775                (mesg (format "Reading active file%s via %s..."
12776                              (if (and where (not (zerop (length where))))
12777                                  (concat " from " where) "")
12778                              (car method))))
12779           (gnus-message 5 mesg)
12780           (gnus-check-server method)
12781           (cond 
12782            ((and (eq gnus-read-active-file 'some)
12783                  (gnus-check-backend-function 'retrieve-groups (car method)))
12784             (let ((newsrc (cdr gnus-newsrc-alist))
12785                   (gmethod (gnus-server-get-method nil method))
12786                   groups)
12787               (while newsrc
12788                 (and (gnus-server-equal 
12789                       (gnus-find-method-for-group 
12790                        (car (car newsrc)) (car newsrc))
12791                       gmethod)
12792                      (setq groups (cons (gnus-group-real-name 
12793                                          (car (car newsrc))) groups)))
12794                 (setq newsrc (cdr newsrc)))
12795               (gnus-check-server method)
12796               (setq list-type (gnus-retrieve-groups groups method))
12797               (cond ((not list-type)
12798                      (gnus-message 
12799                       1 "Cannot read partial active file from %s server." 
12800                       (car method))
12801                      (ding)
12802                      (sit-for 2))
12803                     ((eq list-type 'active)
12804                      (gnus-active-to-gnus-format method gnus-active-hashtb))
12805                     (t
12806                      (gnus-groups-to-gnus-format method gnus-active-hashtb)))))
12807            (t
12808             (if (not (gnus-request-list method))
12809                 (progn
12810                   (gnus-message 1 "Cannot read active file from %s server." 
12811                                 (car method))
12812                   (ding))
12813               (gnus-active-to-gnus-format method)
12814               ;; We mark this active file as read.
12815               (setq gnus-have-read-active-file
12816                     (cons method gnus-have-read-active-file))
12817               (gnus-message 5 "%sdone" mesg)))))
12818         (setq methods (cdr methods))))))
12819
12820 ;; Read an active file and place the results in `gnus-active-hashtb'.
12821 (defun gnus-active-to-gnus-format (method &optional hashtb ignore-errors)
12822   (let ((cur (current-buffer))
12823         (hashtb (or hashtb 
12824                     (if (and gnus-active-hashtb 
12825                              (not (equal method gnus-select-method)))
12826                         gnus-active-hashtb
12827                       (setq gnus-active-hashtb
12828                             (if (equal method gnus-select-method)
12829                                 (gnus-make-hashtable 
12830                                  (count-lines (point-min) (point-max)))
12831                               (gnus-make-hashtable 4096))))))
12832         (flag-hashtb (gnus-make-hashtable 60)))
12833     ;; Delete unnecessary lines.
12834     (goto-char (point-min))
12835     (while (search-forward "\nto." nil t)
12836       (delete-region (1+ (match-beginning 0)) 
12837                      (progn (forward-line 1) (point))))
12838     (or (string= gnus-ignored-newsgroups "")
12839         (progn
12840           (goto-char (point-min))
12841           (delete-matching-lines gnus-ignored-newsgroups)))
12842     ;; Make the group names readable as a lisp expression even if they
12843     ;; contain special characters.
12844     ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
12845     (goto-char (point-max))
12846     (while (re-search-backward "[][';?()#]" nil t)
12847       (insert ?\\))
12848     ;; If these are groups from a foreign select method, we insert the
12849     ;; group prefix in front of the group names. 
12850     (and method (not (gnus-server-equal
12851                       (gnus-server-get-method nil method)
12852                       (gnus-server-get-method nil gnus-select-method)))
12853          (let ((prefix (gnus-group-prefixed-name "" method)))
12854            (goto-char (point-min))
12855            (while (and (not (eobp))
12856                        (progn (insert prefix)
12857                               (zerop (forward-line 1)))))))
12858     ;; Store the active file in a hash table.
12859     (goto-char (point-min))
12860     (if (string-match "%[oO]" gnus-group-line-format)
12861         ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
12862         ;; If we want information on moderated groups, we use this
12863         ;; loop...   
12864         (let* ((mod-hashtb (make-vector 7 0))
12865                (m (intern "m" mod-hashtb))
12866                group max min)
12867           (while (not (eobp))
12868             (condition-case nil
12869                 (progn
12870                   (narrow-to-region (point) (gnus-point-at-eol))
12871                   (setq group (let ((obarray hashtb)) (read cur)))
12872                   (if (and (numberp (setq max (read cur)))
12873                            (numberp (setq min (read cur)))
12874                            (progn 
12875                              (skip-chars-forward " \t")
12876                              (not
12877                               (or (= (following-char) ?=)
12878                                   (= (following-char) ?x)
12879                                   (= (following-char) ?j)))))
12880                       (set group (cons min max))
12881                     (set group nil))
12882                   ;; Enter moderated groups into a list.
12883                   (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
12884                       (setq gnus-moderated-list 
12885                             (cons (symbol-name group) gnus-moderated-list))))
12886               (error 
12887                (and group
12888                     (symbolp group)
12889                     (set group nil))))
12890             (widen)
12891             (forward-line 1)))
12892       ;; And if we do not care about moderation, we use this loop,
12893       ;; which is faster.
12894       (let (group max min)
12895         (while (not (eobp))
12896           (condition-case ()
12897               (progn
12898                 (narrow-to-region (point) (gnus-point-at-eol))
12899                 ;; group gets set to a symbol interned in the hash table
12900                 ;; (what a hack!!) - jwz
12901                 (setq group (let ((obarray hashtb)) (read cur)))
12902                 (if (and (numberp (setq max (read cur)))
12903                          (numberp (setq min (read cur)))
12904                          (progn 
12905                            (skip-chars-forward " \t")
12906                            (not
12907                             (or (= (following-char) ?=)
12908                                 (= (following-char) ?x)
12909                                 (= (following-char) ?j)))))
12910                     (set group (cons min max))
12911                   (set group nil)))
12912             (error 
12913              (progn 
12914                (and group
12915                     (symbolp group)
12916                     (set group nil))
12917                (or ignore-errors
12918                    (gnus-message 3 "Warning - illegal active: %s"
12919                                  (buffer-substring 
12920                                   (gnus-point-at-bol) (gnus-point-at-eol)))))))
12921           (widen)
12922           (forward-line 1))))))
12923
12924 (defun gnus-groups-to-gnus-format (method &optional hashtb)
12925   ;; Parse a "groups" active file.
12926   (let ((cur (current-buffer))
12927         (hashtb (or hashtb 
12928                     (if (and method gnus-active-hashtb)
12929                         gnus-active-hashtb
12930                       (setq gnus-active-hashtb
12931                             (gnus-make-hashtable 
12932                              (count-lines (point-min) (point-max)))))))
12933         (prefix (and method 
12934                      (not (gnus-server-equal
12935                            (gnus-server-get-method nil method)
12936                            (gnus-server-get-method nil gnus-select-method)))
12937                      (gnus-group-prefixed-name "" method))))
12938
12939     (goto-char (point-min))
12940     ;; We split this into to separate loops, one with the prefix
12941     ;; and one without to speed the reading up somewhat.
12942     (if prefix
12943         (let (min max opoint group)
12944           (while (not (eobp))
12945             (condition-case ()
12946                 (progn
12947                   (read cur) (read cur)
12948                   (setq min (read cur)
12949                         max (read cur)
12950                         opoint (point))
12951                   (skip-chars-forward " \t")
12952                   (insert prefix)
12953                   (goto-char opoint)
12954                   (set (let ((obarray hashtb)) (read cur)) 
12955                        (cons min max)))
12956               (error (and group (symbolp group) (set group nil))))
12957             (forward-line 1)))
12958       (let (min max group)
12959         (while (not (eobp))
12960           (condition-case ()
12961               (if (= (following-char) ?2)
12962                   (progn
12963                     (read cur) (read cur)
12964                     (setq min (read cur)
12965                           max (read cur))
12966                     (set (setq group (let ((obarray hashtb)) (read cur)))
12967                          (cons min max))))
12968             (error (and group (symbolp group) (set group nil))))
12969           (forward-line 1))))))
12970
12971 (defun gnus-read-newsrc-file (&optional force)
12972   "Read startup file.
12973 If FORCE is non-nil, the .newsrc file is read."
12974   ;; Reset variables that might be defined in the .newsrc.eld file.
12975   (let ((variables gnus-variable-list))
12976     (while variables
12977       (set (car variables) nil)
12978       (setq variables (cdr variables))))
12979   (let* ((newsrc-file gnus-current-startup-file)
12980          (quick-file (concat newsrc-file ".el")))
12981     (save-excursion
12982       ;; We always load the .newsrc.eld file. If always contains
12983       ;; much information that can not be gotten from the .newsrc
12984       ;; file (ticked articles, killed groups, foreign methods, etc.)
12985       (gnus-read-newsrc-el-file quick-file)
12986  
12987       (if (or force
12988               (and (file-newer-than-file-p newsrc-file quick-file)
12989                    (file-newer-than-file-p newsrc-file 
12990                                            (concat quick-file "d")))
12991               (not gnus-newsrc-alist))
12992           ;; We read the .newsrc file. Note that if there if a
12993           ;; .newsrc.eld file exists, it has already been read, and
12994           ;; the `gnus-newsrc-hashtb' has been created. While reading
12995           ;; the .newsrc file, Gnus will only use the information it
12996           ;; can find there for changing the data already read -
12997           ;; ie. reading the .newsrc file will not trash the data
12998           ;; already read (except for read articles).
12999           (save-excursion
13000             (gnus-message 5 "Reading %s..." newsrc-file)
13001             (set-buffer (find-file-noselect newsrc-file))
13002             (buffer-disable-undo (current-buffer))
13003             (gnus-newsrc-to-gnus-format)
13004             (kill-buffer (current-buffer))
13005             (gnus-message 5 "Reading %s...done" newsrc-file))))))
13006
13007 (defun gnus-read-newsrc-el-file (file)
13008   (let ((ding-file (concat file "d")))
13009     ;; We always, always read the .eld file.
13010     (gnus-message 5 "Reading %s..." ding-file)
13011     (let (gnus-newsrc-assoc)
13012       (condition-case nil
13013           (load ding-file t t t)
13014         (error nil))
13015       (and gnus-newsrc-assoc (setq gnus-newsrc-alist gnus-newsrc-assoc)))
13016     (let ((inhibit-quit t))
13017       (gnus-uncompress-newsrc-alist))
13018     (gnus-make-hashtable-from-newsrc-alist)
13019     (if (not (file-newer-than-file-p file ding-file))
13020         ()
13021       ;; Old format quick file
13022       (gnus-message 5 "Reading %s..." file)
13023       ;; The .el file is newer than the .eld file, so we read that one
13024       ;; as well. 
13025       (gnus-read-old-newsrc-el-file file))))
13026
13027 ;; Parse the old-style quick startup file
13028 (defun gnus-read-old-newsrc-el-file (file)
13029   (let (newsrc killed marked group m)
13030     (prog1
13031         (let ((gnus-killed-assoc nil)
13032               gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
13033           (prog1
13034               (condition-case nil
13035                   (load file t t t)
13036                 (error nil))
13037             (setq newsrc gnus-newsrc-assoc
13038                   killed gnus-killed-assoc
13039                   marked gnus-marked-assoc)))
13040       (setq gnus-newsrc-alist nil)
13041       (while newsrc
13042         (setq group (car newsrc))
13043         (let ((info (nth 2 (gnus-gethash (car group) gnus-newsrc-hashtb))))
13044           (if info
13045               (progn
13046                 (setcar (nthcdr 2 info) (cdr (cdr group)))
13047                 (setcar (cdr info)
13048                         (if (nth 1 group) gnus-level-default-subscribed 
13049                           gnus-level-default-unsubscribed))
13050                 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
13051             (setq gnus-newsrc-alist
13052                   (cons 
13053                    (setq info
13054                          (list (car group)
13055                                (if (nth 1 group) gnus-level-default-subscribed
13056                                  gnus-level-default-unsubscribed) 
13057                                (cdr (cdr group))))
13058                    gnus-newsrc-alist)))
13059           (if (setq m (assoc (car group) marked))
13060             (setcdr (cdr (cdr info)) (cons (list (cons 'tick (cdr m))) nil))))
13061         (setq newsrc (cdr newsrc)))
13062       (setq newsrc killed)
13063       (while newsrc
13064         (setcar newsrc (car (car newsrc)))
13065         (setq newsrc (cdr newsrc)))
13066       (setq gnus-killed-list killed))
13067     ;; The .el file version of this variable does not begin with
13068     ;; "options", while the .eld version does, so we just add it if it
13069     ;; isn't there.
13070     (and
13071      gnus-newsrc-options 
13072      (progn
13073        (and (not (string-match "^ *options" gnus-newsrc-options))
13074             (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
13075        (and (not (string-match "\n$" gnus-newsrc-options))
13076             (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))))
13077     (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
13078     (gnus-make-hashtable-from-newsrc-alist)))
13079       
13080 (defun gnus-make-newsrc-file (file)
13081   "Make server dependent file name by catenating FILE and server host name."
13082   (let* ((file (expand-file-name file nil))
13083          (real-file (concat file "-" (nth 1 gnus-select-method))))
13084     (if (or (file-exists-p real-file)
13085             (file-exists-p (concat real-file ".el"))
13086             (file-exists-p (concat real-file ".eld")))
13087         real-file file)))
13088
13089 (defun gnus-uncompress-newsrc-alist ()
13090   ;; Uncompress all lists of marked articles in the newsrc assoc.
13091   (let ((newsrc gnus-newsrc-alist)
13092         marked)
13093     (while newsrc
13094       (if (not (setq marked (nth 3 (car newsrc))))
13095           ()
13096         (while marked
13097           (or (eq 'score (car (car marked)))
13098               (eq 'bookmark (car (car marked)))
13099               (eq 'killed (car (car marked)))
13100               (setcdr (car marked) (gnus-uncompress-range (cdr (car marked)))))
13101           (setq marked (cdr marked))))
13102       (setq newsrc (cdr newsrc)))))
13103
13104 (defun gnus-compress-newsrc-alist ()
13105   ;; Compress all lists of marked articles in the newsrc assoc.
13106   (let ((newsrc gnus-newsrc-alist)
13107         marked)
13108     (while newsrc
13109       (if (not (setq marked (nth 3 (car newsrc))))
13110           ()
13111         (while marked
13112           (or (eq 'score (car (car marked)))
13113               (eq 'bookmark (car (car marked)))
13114               (eq 'killed (car (car marked)))
13115               (setcdr (car marked) 
13116                       (condition-case ()
13117                           (gnus-compress-sequence 
13118                            (sort (cdr (car marked)) '<) t)
13119                         (error (cdr (car marked))))))
13120           (setq marked (cdr marked))))
13121       (setq newsrc (cdr newsrc)))))
13122
13123 (defun gnus-newsrc-to-gnus-format ()
13124   (setq gnus-newsrc-options "")
13125   (setq gnus-newsrc-options-n nil)
13126
13127   (or gnus-active-hashtb
13128       (setq gnus-active-hashtb (make-vector 4095 0)))
13129   (let ((buf (current-buffer))
13130         (already-read (> (length gnus-newsrc-alist) 1))
13131         group subscribed options-symbol newsrc Options-symbol
13132         symbol reads num1)
13133     (goto-char (point-min))
13134     ;; We intern the symbol `options' in the active hashtb so that we
13135     ;; can `eq' against it later.
13136     (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
13137     (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
13138   
13139     (while (not (eobp))
13140       ;; We first read the first word on the line by narrowing and
13141       ;; then reading into `gnus-active-hashtb'.  Most groups will
13142       ;; already exist in that hashtb, so this will save some string
13143       ;; space.
13144       (narrow-to-region
13145        (point)
13146        (progn (skip-chars-forward "^ \t!:\n") (point)))
13147       (goto-char (point-min))
13148       (setq symbol 
13149             (and (/= (point-min) (point-max))
13150                  (let ((obarray gnus-active-hashtb)) (read buf))))
13151       (widen)
13152       ;; Now, the symbol we have read is either `options' or a group
13153       ;; name.  If it is an options line, we just add it to a string. 
13154       (cond 
13155        ((or (eq symbol options-symbol)
13156             (eq symbol Options-symbol))
13157         (setq gnus-newsrc-options
13158               ;; This concatting is quite inefficient, but since our
13159               ;; thorough studies show that approx 99.37% of all
13160               ;; .newsrc files only contain a single options line, we
13161               ;; don't give a damn, frankly, my dear.
13162               (concat gnus-newsrc-options
13163                       (buffer-substring 
13164                        (gnus-point-at-bol)
13165                        ;; Options may continue on the next line.
13166                        (or (and (re-search-forward "^[^ \t]" nil 'move)
13167                                 (progn (beginning-of-line) (point)))
13168                            (point))))))
13169        (symbol
13170         (or (boundp symbol) (set symbol nil))
13171         ;; It was a group name.
13172         (setq subscribed (= (following-char) ?:)
13173               group (symbol-name symbol)
13174               reads nil)
13175         (if (eolp)
13176             ;; If the line ends here, this is clearly a buggy line, so
13177             ;; we put point a the beginning of line and let the cond
13178             ;; below do the error handling.
13179             (beginning-of-line)
13180           ;; We skip to the beginning of the ranges.
13181           (skip-chars-forward "!: \t"))
13182         ;; We are now at the beginning of the list of read articles.
13183         ;; We read them range by range.
13184         (while
13185             (cond 
13186              ((looking-at "[0-9]+")
13187               ;; We narrow and read a number instead of buffer-substring/
13188               ;; string-to-int because it's faster. narrow/widen is
13189               ;; faster than save-restriction/narrow, and save-restriction
13190               ;; produces a garbage object.
13191               (setq num1 (progn
13192                            (narrow-to-region (match-beginning 0) (match-end 0))
13193                            (read buf)))
13194               (widen)
13195               ;; If the next character is a dash, then this is a range.
13196               (if (= (following-char) ?-)
13197                   (progn
13198                     ;; We read the upper bound of the range.
13199                     (forward-char 1)
13200                     (if (not (looking-at "[0-9]+"))
13201                         ;; This is a buggy line, by we pretend that
13202                         ;; it's kinda OK. Perhaps the user should be
13203                         ;; dinged? 
13204                         (setq reads (cons num1 reads))
13205                       (setq reads 
13206                             (cons 
13207                              (cons num1 (progn
13208                                           (narrow-to-region (match-beginning 0) 
13209                                                             (match-end 0))
13210                                           (read buf)))
13211                              reads))
13212                       (widen)))
13213                 ;; It was just a simple number, so we add it to the
13214                 ;; list of ranges.
13215                 (setq reads (cons num1 reads)))
13216               ;; If the next char in ?\n, then we have reached the end
13217               ;; of the line and return nil.
13218               (/= (following-char) ?\n))
13219              ((= (following-char) ?\n)
13220               ;; End of line, so we end.
13221               nil)
13222              (t
13223               ;; Not numbers and not eol, so this might be a buggy
13224               ;; line... 
13225               (or (eobp) ; If it was eob instead of ?\n, we allow it.
13226                   (progn
13227                     ;; The line was buggy.
13228                     (setq group nil)
13229                     (gnus-message 3 "Mangled line: %s" 
13230                                   (buffer-substring (gnus-point-at-bol) 
13231                                                     (gnus-point-at-eol)))
13232                     (ding)
13233                     (sit-for 1)))
13234               nil))
13235           ;; Skip past ", ". Spaces are illegal in these ranges, but
13236           ;; we allow them, because it's a common mistake to put a
13237           ;; space after the comma.
13238           (skip-chars-forward ", "))
13239
13240         ;; We have already read .newsrc.eld, so we gently update the
13241         ;; data in the hash table with the information we have just
13242         ;; read. 
13243         (if (not group)
13244             ()
13245           (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))
13246                 level)
13247             (if info
13248                 ;; There is an entry for this file in the alist.
13249                 (progn
13250                   (setcar (nthcdr 2 info) (nreverse reads))
13251                   ;; We update the level very gently.  In fact, we
13252                   ;; only change it if there's been a status change
13253                   ;; from subscribed to unsubscribed, or vice versa.
13254                   (setq level (nth 1 info))
13255                   (cond ((and (<= level gnus-level-subscribed)
13256                               (not subscribed))
13257                          (setq level (if reads
13258                                          gnus-level-default-unsubscribed 
13259                                        (1+ gnus-level-default-unsubscribed))))
13260                         ((and (> level gnus-level-subscribed) subscribed)
13261                          (setq level gnus-level-default-subscribed)))
13262                   (setcar (cdr info) level))
13263               ;; This is a new group.
13264               (setq info (list group 
13265                                (if subscribed
13266                                    gnus-level-default-subscribed 
13267                                  (if reads
13268                                      (1+ gnus-level-subscribed)
13269                                    gnus-level-default-unsubscribed))
13270                                (nreverse reads))))
13271             (setq newsrc (cons info newsrc))))))
13272       (forward-line 1))
13273     
13274     (setq newsrc (nreverse newsrc))
13275
13276     (if (not already-read)
13277         ()
13278       ;; We now have two newsrc lists - `newsrc', which is what we
13279       ;; have read from .newsrc, and `gnus-newsrc-alist', which is
13280       ;; what we've read from .newsrc.eld. We have to merge these
13281       ;; lists. We do this by "attaching" any (foreign) groups in the
13282       ;; gnus-newsrc-alist to the (native) group that precedes them. 
13283       (let ((rc (cdr gnus-newsrc-alist))
13284             (prev gnus-newsrc-alist)
13285             entry mentry)
13286         (while rc
13287           (or (null (nth 4 (car rc))) ; It's a native group.
13288               (assoc (car (car rc)) newsrc) ; It's already in the alist.
13289               (if (setq entry (assoc (car (car prev)) newsrc))
13290                   (setcdr (setq mentry (memq entry newsrc))
13291                           (cons (car rc) (cdr mentry)))
13292                 (setq newsrc (cons (car rc) newsrc))))
13293           (setq prev rc
13294                 rc (cdr rc)))))
13295
13296     (setq gnus-newsrc-alist newsrc)
13297     ;; We make the newsrc hashtb.
13298     (gnus-make-hashtable-from-newsrc-alist)
13299
13300     ;; Finally, if we read some options lines, we parse them.
13301     (or (string= gnus-newsrc-options "")
13302         (gnus-newsrc-parse-options gnus-newsrc-options))))
13303
13304 ;; Parse options lines to find "options -n !all rec.all" and stuff.
13305 ;; The return value will be a list on the form
13306 ;; ((regexp1 . ignore)
13307 ;;  (regexp2 . subscribe)...)
13308 ;; When handling new newsgroups, groups that match a `ignore' regexp
13309 ;; will be ignored, and groups that match a `subscribe' regexp will be
13310 ;; subscribed. A line like
13311 ;; options -n !all rec.all
13312 ;; will lead to a list that looks like
13313 ;; (("^rec\\..+" . subscribe) 
13314 ;;  ("^.+" . ignore))
13315 ;; So all "rec.*" groups will be subscribed, while all the other
13316 ;; groups will be ignored. Note that "options -n !all rec.all" is very
13317 ;; different from "options -n rec.all !all". 
13318 (defun gnus-newsrc-parse-options (options)
13319   (let (out eol)
13320     (save-excursion
13321       (gnus-set-work-buffer)
13322       (insert (regexp-quote options))
13323       ;; First we treat all continuation lines.
13324       (goto-char (point-min))
13325       (while (re-search-forward "\n[ \t]+" nil t)
13326         (replace-match " " t t))
13327       ;; Then we transform all "all"s into ".+"s.
13328       (goto-char (point-min))
13329       (while (re-search-forward "\\ball\\b" nil t)
13330         (replace-match ".+" t t))
13331       (goto-char (point-min))
13332       ;; We remove all other options than the "-n" ones.
13333       (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
13334         (replace-match " ")
13335         (forward-char -1))
13336       (goto-char (point-min))
13337
13338       ;; We are only interested in "options -n" lines - we
13339       ;; ignore the other option lines.
13340       (while (re-search-forward "[ \t]-n" nil t)
13341         (setq eol 
13342               (or (save-excursion
13343                     (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
13344                          (- (point) 2)))
13345                   (gnus-point-at-eol)))
13346         ;; Search for all "words"...
13347         (while (re-search-forward "[^ \t,\n]+" eol t)
13348           (if (= (char-after (match-beginning 0)) ?!)
13349               ;; If the word begins with a bang (!), this is a "not"
13350               ;; spec. We put this spec (minus the bang) and the
13351               ;; symbol `ignore' into the list.
13352               (setq out (cons (cons (concat 
13353                                      "^" (buffer-substring 
13354                                           (1+ (match-beginning 0))
13355                                           (match-end 0)))
13356                                     'ignore) out))
13357             ;; There was no bang, so this is a "yes" spec.
13358             (setq out (cons (cons (concat 
13359                                    "^" (buffer-substring (match-beginning 0)
13360                                                          (match-end 0)))
13361                                   'subscribe) out)))))
13362     
13363       (setq gnus-newsrc-options-n out))))
13364                
13365
13366 (defun gnus-save-newsrc-file ()
13367   "Save .newsrc file."
13368   ;; Note: We cannot save .newsrc file if all newsgroups are removed
13369   ;; from the variable gnus-newsrc-alist.
13370   (and (or gnus-newsrc-alist gnus-killed-list)
13371        gnus-current-startup-file
13372        (progn
13373          (run-hooks 'gnus-save-newsrc-hook)
13374          (save-excursion
13375            (if (and gnus-use-dribble-file
13376                     (or (not gnus-dribble-buffer)
13377                         (not (buffer-name gnus-dribble-buffer))
13378                         (zerop (save-excursion
13379                                  (set-buffer gnus-dribble-buffer)
13380                                  (buffer-size)))))
13381                (gnus-message 4 "(No changes need to be saved)")
13382              (if gnus-save-newsrc-file
13383                  (progn
13384                    (gnus-message 5 "Saving %s..." gnus-current-startup-file)
13385                    ;; Make backup file of master newsrc.
13386                    (gnus-gnus-to-newsrc-format)
13387                    (gnus-message 5 "Saving %s...done"
13388                                  gnus-current-startup-file)))
13389              ;; Quickly loadable .newsrc.
13390              (set-buffer (get-buffer-create " *Gnus-newsrc*"))
13391              (setq buffer-file-name (concat gnus-current-startup-file ".eld"))
13392              (gnus-add-current-to-buffer-list)
13393              (buffer-disable-undo (current-buffer))
13394              (erase-buffer)
13395              (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
13396              (gnus-gnus-to-quick-newsrc-format)
13397              (save-buffer)
13398              (kill-buffer (current-buffer))
13399              (gnus-message 5 "Saving %s.eld...done" gnus-current-startup-file)
13400              (gnus-dribble-delete-file))))))
13401
13402 (defun gnus-gnus-to-quick-newsrc-format ()
13403   "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
13404   (insert ";; Gnus startup file.\n")
13405   (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
13406   (insert ";; to read .newsrc.\n")
13407   (insert "(setq gnus-newsrc-file-version "
13408           (prin1-to-string gnus-version) ")\n")
13409   (let ((variables gnus-variable-list)
13410         (inhibit-quit t)
13411         (gnus-newsrc-alist (cdr gnus-newsrc-alist))
13412         variable)
13413     ;; insert lisp expressions.
13414     (gnus-compress-newsrc-alist)
13415     (while variables
13416       (setq variable (car variables))
13417       (and (boundp variable)
13418            (symbol-value variable)
13419            (or gnus-save-killed-list (not (eq variable 'gnus-killed-list)))
13420            (insert "(setq " (symbol-name variable) " '"
13421                    (prin1-to-string (symbol-value variable))
13422                    ")\n"))
13423       (setq variables (cdr variables)))
13424     (gnus-uncompress-newsrc-alist)))
13425
13426
13427 (defun gnus-gnus-to-newsrc-format ()
13428   ;; Generate and save the .newsrc file.
13429   (let ((newsrc (cdr gnus-newsrc-alist))
13430         info ranges range)
13431     (save-excursion
13432       (set-buffer (create-file-buffer gnus-current-startup-file))
13433       (setq buffer-file-name gnus-current-startup-file)
13434       (buffer-disable-undo (current-buffer))
13435       (erase-buffer)
13436       ;; Write options.
13437       (if gnus-newsrc-options (insert gnus-newsrc-options))
13438       ;; Write subscribed and unsubscribed.
13439       (while newsrc
13440         (setq info (car newsrc))
13441         (if (not (nth 4 info))          ;Don't write foreign groups to .newsrc.
13442             (progn
13443               (insert (car info) (if (> (nth 1 info) gnus-level-subscribed)
13444                                      "!" ":"))
13445               (if (setq ranges (nth 2 info))
13446                   (progn
13447                     (insert " ")
13448                     (if (not (listp (cdr ranges)))
13449                         (if (= (car ranges) (cdr ranges))
13450                             (insert (int-to-string (car ranges)))
13451                           (insert (int-to-string (car ranges)) "-" 
13452                                   (int-to-string (cdr ranges))))
13453                       (while ranges
13454                         (setq range (car ranges)
13455                               ranges (cdr ranges))
13456                         (if (or (atom range) (= (car range) (cdr range)))
13457                             (insert (int-to-string 
13458                                      (or (and (atom range) range) 
13459                                          (car range))))
13460                           (insert (int-to-string (car range)) "-"
13461                                   (int-to-string (cdr range))))
13462                         (if ranges (insert ","))))))
13463               (insert "\n")))
13464         (setq newsrc (cdr newsrc)))
13465       ;; It has been reported that sometime the modtime on the .newsrc
13466       ;; file seems to be off. We really do want to overwrite it, so
13467       ;; we clear the modtime here before saving. It's a bit odd,
13468       ;; though... 
13469       ;; sometimes the modtime clear isn't sufficient.  most brute force:
13470       ;; delete the silly thing entirely first.  but this fails to provide
13471       ;; such niceties as .newsrc~ creation.
13472       (if gnus-modtime-botch
13473           (delete-file gnus-startup-file)
13474         (clear-visited-file-modtime))
13475       (save-buffer)
13476       (kill-buffer (current-buffer)))))
13477
13478 (defun gnus-read-all-descriptions-files ()
13479   (let ((methods (cons gnus-select-method gnus-secondary-select-methods)))
13480     (while methods
13481       (gnus-read-descriptions-file (car methods))
13482       (setq methods (cdr methods)))
13483     t))
13484
13485 (defun gnus-read-descriptions-file (&optional method)
13486   (let ((method (or method gnus-select-method)))
13487     ;; We create the hashtable whether we manage to read the desc file
13488     ;; to avoid trying to re-read after a failed read.
13489     (or gnus-description-hashtb
13490         (setq gnus-description-hashtb 
13491               (gnus-make-hashtable (length gnus-active-hashtb))))
13492     ;; Mark this method's desc file as read.
13493     (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
13494                   gnus-description-hashtb)
13495
13496     (gnus-message 5 "Reading descriptions file via %s..." (car method))
13497     (cond 
13498      ((not (gnus-check-server method))
13499       (gnus-message 1 "Couldn't open server")
13500       nil)
13501      ((not (gnus-request-list-newsgroups method))
13502       (gnus-message 1 "Couldn't read newsgroups descriptions")
13503       nil)
13504      (t
13505       (let (group)
13506         (save-excursion
13507           (save-restriction
13508             (set-buffer nntp-server-buffer)
13509             (goto-char (point-min))
13510             (if (or (search-forward "\n.\n" nil t)
13511                     (goto-char (point-max)))
13512                 (progn
13513                   (beginning-of-line)
13514                   (narrow-to-region (point-min) (point))))
13515             (goto-char (point-min))
13516             (while (not (eobp))
13517               ;; If we get an error, we set group to 0, which is not a
13518               ;; symbol... 
13519               (setq group 
13520                     (condition-case ()
13521                         (let ((obarray gnus-description-hashtb))
13522                           ;; Group is set to a symbol interned in this
13523                           ;; hash table.
13524                           (read nntp-server-buffer))
13525                       (error 0)))
13526               (skip-chars-forward " \t")
13527               ;; ... which leads to this line being effectively ignored.
13528               (and (symbolp group)
13529                    (set group (buffer-substring 
13530                                (point) (progn (end-of-line) (point)))))
13531               (forward-line 1))))
13532         (gnus-message 5 "Reading descriptions file...done")
13533         t)))))
13534
13535 (defun gnus-group-get-description (group)
13536   ;; Get the description of a group by sending XGTITLE to the server.
13537   (and (gnus-request-group-description group)
13538        (save-excursion
13539          (set-buffer nntp-server-buffer)
13540          (goto-char (point-min))
13541          (and (looking-at "[^ \t]+[ \t]+\\(.*\\)")
13542               (buffer-substring (match-beginning 1) (match-end 1))))))
13543
13544 ;;;
13545 ;;; Server
13546 ;;;
13547
13548 (defvar gnus-server-mode-hook nil
13549   "Hook run in `gnus-server-mode' buffers.")
13550
13551 (defconst gnus-server-line-format "     {%(%h:%w%)}\n"
13552   "Format of server lines.
13553 It works along the same lines as a normal formatting string,
13554 with some simple extensions.")
13555
13556 (defvar gnus-server-mode-line-format "Gnus  List of servers"
13557   "The format specification for the server mode line.")
13558
13559 (defconst gnus-server-line-format-alist
13560   (list (list ?h 'how ?s)
13561         (list ?n 'name ?s)
13562         (list ?w 'where ?s)
13563         ))
13564
13565 (defconst gnus-server-mode-line-format-alist 
13566   (list (list ?S 'news-server ?s)
13567         (list ?M 'news-method ?s)
13568         (list ?u 'user-defined ?s)))
13569
13570 (defvar gnus-server-line-format-spec nil)
13571 (defvar gnus-server-mode-line-format-spec nil)
13572 (defvar gnus-server-killed-servers nil)
13573
13574 (defvar gnus-server-mode-map nil)
13575 (put 'gnus-server-mode 'mode-class 'special)
13576
13577 (if gnus-server-mode-map
13578     nil
13579   (setq gnus-server-mode-map (make-sparse-keymap))
13580   (suppress-keymap gnus-server-mode-map)
13581   (define-key gnus-server-mode-map " " 'gnus-server-read-server)
13582   (define-key gnus-server-mode-map "\r" 'gnus-server-read-server)
13583   (define-key gnus-server-mode-map gnus-mouse-2 'gnus-server-pick-server)
13584   (define-key gnus-server-mode-map "q" 'gnus-server-exit)
13585   (define-key gnus-server-mode-map "l" 'gnus-server-list-servers)
13586   (define-key gnus-server-mode-map "k" 'gnus-server-kill-server)
13587   (define-key gnus-server-mode-map "y" 'gnus-server-yank-server)
13588   (define-key gnus-server-mode-map "c" 'gnus-server-copy-server)
13589   (define-key gnus-server-mode-map "a" 'gnus-server-add-server)
13590   (define-key gnus-server-mode-map "e" 'gnus-server-edit-server))
13591
13592 (defun gnus-server-mode ()
13593   "Major mode for listing and editing servers.
13594
13595 All normal editing commands are switched off.
13596 \\<gnus-server-mode-map>
13597
13598 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). 
13599
13600 The following commands are available:
13601
13602 \\{gnus-server-mode-map}"
13603   (interactive)
13604   (if gnus-visual (gnus-server-make-menu-bar))
13605   (kill-all-local-variables)
13606   (setq mode-line-modified "-- ")
13607   (make-local-variable 'mode-line-format)
13608   (setq mode-line-format (copy-sequence mode-line-format))
13609   (and (equal (nth 3 mode-line-format) "   ")
13610        (setcar (nthcdr 3 mode-line-format) ""))
13611   (setq major-mode 'gnus-server-mode)
13612   (setq mode-name "Server")
13613 ;  (gnus-group-set-mode-line)
13614   (setq mode-line-process nil)
13615   (use-local-map gnus-server-mode-map)
13616   (buffer-disable-undo (current-buffer))
13617   (setq truncate-lines t)
13618   (setq buffer-read-only t)
13619   (run-hooks 'gnus-server-mode-hook))
13620
13621 (defun gnus-server-insert-server-line (sformat name method)
13622   (let* ((sformat (or sformat gnus-server-line-format-spec))
13623          (how (car method))
13624          (where (nth 1 method))
13625          b)
13626     (beginning-of-line)
13627     (setq b (point))
13628     ;; Insert the text.
13629     (insert (eval sformat))
13630     (add-text-properties b (1+ b) (list 'gnus-server (intern name)))))
13631
13632 (defun gnus-server-setup-buffer ()
13633   (if (get-buffer gnus-server-buffer)
13634       ()
13635     (save-excursion
13636       (set-buffer (get-buffer-create gnus-server-buffer))
13637       (gnus-server-mode)
13638       (and gnus-carpal (gnus-carpal-setup-buffer 'server)))))
13639
13640 (defun gnus-server-prepare ()
13641   (setq gnus-server-mode-line-format-spec 
13642         (gnus-parse-format gnus-server-mode-line-format 
13643                            gnus-server-mode-line-format-alist))
13644   (setq gnus-server-line-format-spec 
13645         (gnus-parse-format gnus-server-line-format 
13646                            gnus-server-line-format-alist))
13647   (let ((alist gnus-server-alist)
13648         (buffer-read-only nil))
13649     (erase-buffer)
13650     (while alist
13651       (gnus-server-insert-server-line nil (car (car alist)) (cdr (car alist)))
13652       (setq alist (cdr alist))))
13653   (goto-char (point-min))
13654   (gnus-server-position-cursor))
13655
13656 (defun gnus-server-server-name ()
13657   (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server)))
13658     (and server (symbol-name server))))
13659
13660 (defalias 'gnus-server-position-cursor 'gnus-goto-colon)
13661
13662 (defconst gnus-server-edit-buffer "*Gnus edit server*")
13663
13664 (defun gnus-server-update-server (server)
13665   (save-excursion
13666     (set-buffer gnus-server-buffer)
13667     (let ((buffer-read-only nil)
13668           (info (cdr (assoc server gnus-server-alist))))
13669       (gnus-dribble-enter 
13670        (concat "(gnus-server-set-info \"" server "\" '"
13671                (prin1-to-string info) ")"))
13672       ;; Buffer may be narrowed.
13673       (save-restriction
13674         (widen)
13675         (if (gnus-server-goto-server server)
13676             (delete-region (progn (beginning-of-line) (point))
13677                            (progn (forward-line 1) (point))))
13678         (let ((entry (assoc server gnus-server-alist)))
13679           (gnus-server-insert-server-line nil (car entry) (cdr entry))
13680           (gnus-server-position-cursor))))))
13681
13682 (defun gnus-server-set-info (server info)
13683   ;; Enter a select method into the virtual server alist.
13684   (gnus-dribble-enter 
13685    (concat "(gnus-server-set-info \"" server "\" '"
13686            (prin1-to-string info) ")"))
13687   (let* ((server (nth 1 info))
13688          (entry (assoc server gnus-server-alist)))
13689     (if entry (setcdr entry info)
13690       (setq gnus-server-alist
13691             (nconc gnus-server-alist (list (cons server info)))))))
13692
13693 (defun gnus-server-to-method (server)
13694   ;; Map virtual server names to select methods.
13695   (or (and (equal server "native") gnus-select-method)
13696       (cdr (assoc server gnus-server-alist))))
13697
13698 (defun gnus-server-extend-method (group method)
13699   ;; This function "extends" a virtual server.  If the server is
13700   ;; "hello", and the select method is ("hello" (my-var "something")) 
13701   ;; in the group "alt.alt", this will result in a new virtual server
13702   ;; called "helly+alt.alt".
13703   (let ((entry
13704          (gnus-copy-sequence 
13705           (if (equal (car method) "native") gnus-select-method
13706               (cdr (assoc (car method) gnus-server-alist))))))
13707     (setcar (cdr entry) (concat (nth 1 entry) "+" group))
13708     (nconc entry (cdr method))))
13709
13710 (defun gnus-server-get-method (group method)
13711   ;; Input either a server name, and extended server name, or a
13712   ;; select method, and return a select method. 
13713   (cond ((stringp method)
13714          (gnus-server-to-method method))
13715         ((and (stringp (car method)) group)
13716          (gnus-server-extend-method group method))
13717         (t
13718          (gnus-server-add-address method))))
13719
13720 (defun gnus-server-add-address (method)
13721   (let ((method-name (symbol-name (car method))))
13722     (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
13723              (not (assq (intern (concat method-name "-address")) method)))
13724         (append method (list (list (intern (concat method-name "-address"))
13725                                    (nth 1 method))))
13726       method)))
13727
13728 (defun gnus-server-equal (s1 s2)
13729   (or (equal s1 s2)
13730       (and (= (length s1) (length s2))
13731            (progn
13732              (while (and s1 (member (car s1) s2))
13733                (setq s1 (cdr s1)))
13734              (null s1)))))
13735
13736 ;;; Interactive server functions.
13737
13738 (defun gnus-server-kill-server (server)
13739   "Kill the server on the current line."
13740   (interactive (list (gnus-server-server-name)))
13741   (or (gnus-server-goto-server server)
13742       (if server (error "No such server: %s" server)
13743         (error "No server on the current line")))
13744   (let ((buffer-read-only nil))
13745     (delete-region (progn (beginning-of-line) (point))
13746                    (progn (forward-line 1) (point))))
13747   (setq gnus-server-killed-servers 
13748         (cons (assoc server gnus-server-alist) gnus-server-killed-servers))
13749   (setq gnus-server-alist (delq (car gnus-server-killed-servers)
13750                                 gnus-server-alist))
13751   (gnus-server-position-cursor))
13752
13753 (defun gnus-server-yank-server ()
13754   "Yank the previously killed server."
13755   (interactive)
13756   (or gnus-server-killed-servers
13757       (error "No killed servers to be yanked"))
13758   (let ((alist gnus-server-alist)
13759         (server (gnus-server-server-name))
13760         (killed (car gnus-server-killed-servers)))
13761     (if (not server) 
13762         (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
13763       (if (string= server (car (car gnus-server-alist)))
13764           (setq gnus-server-alist (cons killed gnus-server-alist))
13765         (while (and (cdr alist)
13766                     (not (string= server (car (car (cdr alist))))))
13767           (setq alist (cdr alist)))
13768         (setcdr alist (cons killed (cdr alist)))))
13769     (gnus-server-update-server (car killed))
13770     (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
13771     (gnus-server-position-cursor)))
13772
13773 (defun gnus-server-exit ()
13774   "Return to the group buffer."
13775   (interactive)
13776   (kill-buffer (current-buffer))
13777   (switch-to-buffer gnus-group-buffer))
13778
13779 (defun gnus-server-list-servers ()
13780   "List all available servers."
13781   (interactive)
13782   (let ((cur (gnus-server-server-name)))
13783     (gnus-server-prepare)
13784     (if cur (gnus-server-goto-server cur)
13785       (goto-char (point-max))
13786       (forward-line -1))
13787     (gnus-server-position-cursor)))
13788
13789 (defun gnus-server-copy-server (from to)
13790   (interactive
13791    (list
13792     (or (gnus-server-server-name)
13793         (error "No server on the current line"))
13794     (read-string "Copy to: ")))
13795   (or from (error "No server on current line"))
13796   (or (and to (not (string= to ""))) (error "No name to copy to"))
13797   (and (assoc to gnus-server-alist) (error "%s already exists" to))
13798   (or (assoc from gnus-server-alist) 
13799       (error "%s: no such server" from))
13800   (let ((to-entry (gnus-copy-sequence (assoc from gnus-server-alist))))
13801     (setcar to-entry to)
13802     (setcar (nthcdr 2 to-entry) to)
13803     (setq gnus-server-killed-servers 
13804           (cons to-entry gnus-server-killed-servers))
13805     (gnus-server-yank-server)))
13806
13807 (defun gnus-server-add-server (how where)
13808   (interactive 
13809    (list (intern (completing-read "Server method: "
13810                                   gnus-valid-select-methods nil t))
13811          (read-string "Server name: ")))
13812   (setq gnus-server-killed-servers 
13813         (cons (list where how where) gnus-server-killed-servers))
13814   (gnus-server-yank-server))
13815
13816 (defun gnus-server-goto-server (server)
13817   "Jump to a server line."
13818   (interactive
13819    (list (completing-read "Goto server: " gnus-server-alist nil t)))
13820   (let ((to (text-property-any (point-min) (point-max) 
13821                                'gnus-server (intern server))))
13822     (and to
13823          (progn
13824            (goto-char to) 
13825            (gnus-server-position-cursor)))))
13826
13827 (defun gnus-server-edit-server (server)
13828   "Edit the server on the current line."
13829   (interactive (list (gnus-server-server-name)))
13830   (or server
13831       (error "No server on current line"))
13832   (let ((winconf (current-window-configuration)))
13833     (get-buffer-create gnus-server-edit-buffer)
13834     (gnus-configure-windows 'edit-server)
13835     (gnus-add-current-to-buffer-list)
13836     (emacs-lisp-mode)
13837     (make-local-variable 'gnus-prev-winconf)
13838     (setq gnus-prev-winconf winconf)
13839     (use-local-map (copy-keymap (current-local-map)))
13840     (let ((done-func '(lambda () 
13841                         "Exit editing mode and update the information."
13842                         (interactive)
13843                         (gnus-server-edit-server-done 'group))))
13844       (setcar (cdr (nth 4 done-func)) server)
13845       (local-set-key "\C-c\C-c" done-func))
13846     (erase-buffer)
13847     (insert ";; Type `C-c C-c' after you have edited the server.\n\n")
13848     (insert (pp-to-string (cdr (assoc server gnus-server-alist))))))
13849
13850 (defun gnus-server-edit-server-done (server)
13851   (interactive)
13852   (set-buffer (get-buffer-create gnus-server-edit-buffer))
13853   (goto-char (point-min))
13854   (let ((form (read (current-buffer)))
13855         (winconf gnus-prev-winconf))
13856     (gnus-server-set-info server form)
13857     (kill-buffer (current-buffer))
13858     (and winconf (set-window-configuration winconf))
13859     (set-buffer gnus-server-buffer)
13860     (gnus-server-update-server (gnus-server-server-name))
13861     (gnus-server-position-cursor)))
13862
13863 (defun gnus-server-read-server (server)
13864   "Browse a server."
13865   (interactive (list (gnus-server-server-name)))
13866   (gnus-browse-foreign-server (gnus-server-to-method server) (current-buffer)))
13867
13868 (defun gnus-mouse-pick-server (e)
13869   (interactive "e")
13870   (mouse-set-point e)
13871   (gnus-server-read-server (gnus-server-server-name)))
13872
13873 ;;;
13874 ;;; entry points into gnus-score.el
13875 ;;;
13876
13877 ;;; Finding score files. 
13878
13879 (defvar gnus-global-score-files nil
13880   "*List of global score files and directories.
13881 Set this variable if you want to use people's score files.  One entry
13882 for each score file or each score file directory.  Gnus will decide
13883 by itself what score files are applicable to which group.
13884
13885 Say you want to use the single score file
13886 \"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all
13887 score files in the \"/ftp.some-where:/pub/score\" directory.
13888
13889  (setq gnus-global-score-files
13890        '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\"
13891          \"/ftp.some-where:/pub/score\"))")
13892
13893 (defun gnus-score-score-files (group)
13894   "Return a list of all possible score files."
13895   ;; Search and set any global score files.
13896   (and gnus-global-score-files 
13897        (or gnus-internal-global-score-files
13898            (gnus-score-search-global-directories gnus-global-score-files)))
13899   ;; Fix the kill-file dir variable.
13900   (setq gnus-kill-files-directory 
13901         (file-name-as-directory
13902          (or gnus-kill-files-directory "~/News/")))
13903   ;; If we can't read it, there are no score files.
13904   (if (not (file-exists-p (expand-file-name gnus-kill-files-directory)))
13905       (setq gnus-score-file-list nil)
13906     (if (gnus-use-long-file-name 'not-score)
13907         ;; We want long file names.
13908         (if (or (not gnus-score-file-list)
13909                 (not (car gnus-score-file-list))
13910                 (gnus-file-newer-than gnus-kill-files-directory
13911                                       (car gnus-score-file-list)))
13912               (setq gnus-score-file-list 
13913                     (cons (nth 5 (file-attributes gnus-kill-files-directory))
13914                           (nreverse 
13915                            (directory-files 
13916                             gnus-kill-files-directory t 
13917                             (gnus-score-file-regexp))))))
13918       ;; We do not use long file names, so we have to do some
13919       ;; directory traversing.  
13920       (let ((mdir (length (expand-file-name gnus-kill-files-directory)))
13921             (suffixes (list gnus-score-file-suffix gnus-adaptive-file-suffix))
13922             dir files suffix)
13923         (while suffixes
13924           (setq dir (expand-file-name
13925                      (concat gnus-kill-files-directory
13926                              (gnus-replace-chars-in-string group ?. ?/))))
13927           (setq dir (gnus-replace-chars-in-string dir ?: ?/))
13928           (setq suffix (car suffixes)
13929                 suffixes (cdr suffixes))
13930           (if (file-exists-p (concat dir "/" suffix))
13931               (setq files (cons (concat dir "/" suffix) files)))
13932           (while (>= (1+ (length dir)) mdir)
13933             (and (file-exists-p (concat dir "/all/" suffix))
13934                  (setq files (cons (concat dir "/all/" suffix) files)))
13935             (string-match "/[^/]*$" dir)
13936             (setq dir (substring dir 0 (match-beginning 0)))))
13937         (setq gnus-score-file-list 
13938               (cons nil (nreverse files)))))
13939     (cdr gnus-score-file-list)))
13940
13941 (defun gnus-score-file-regexp ()
13942   (concat "\\(" gnus-score-file-suffix 
13943           "\\|" gnus-adaptive-file-suffix "\\)$"))
13944         
13945 (defun gnus-score-find-bnews (group)
13946   "Return a list of score files for GROUP.
13947 The score files are those files in the ~/News directory which matches
13948 GROUP using BNews sys file syntax."
13949   (let* ((sfiles (append (gnus-score-score-files group)
13950                          gnus-internal-global-score-files))
13951          (kill-dir (file-name-as-directory 
13952                     (expand-file-name gnus-kill-files-directory)))
13953          (klen (length kill-dir))
13954          ofiles not-match regexp)
13955     (save-excursion
13956       (set-buffer (get-buffer-create "*gnus score files*"))
13957       (buffer-disable-undo (current-buffer))
13958       ;; Go through all score file names and create regexp with them
13959       ;; as the source.  
13960       (while sfiles
13961         (erase-buffer)
13962         (insert (car sfiles))
13963         (goto-char (point-min))
13964         ;; First remove the suffix itself.
13965         (re-search-forward (concat "." (gnus-score-file-regexp)))
13966         (replace-match "" t t) 
13967         (goto-char (point-min))
13968         (if (looking-at (regexp-quote kill-dir))
13969             ;; If the file name was just "SCORE", `klen' is one character
13970             ;; too much.
13971             (delete-char (min (1- (point-max)) klen))
13972           (goto-char (point-max))
13973           (search-backward "/")
13974           (delete-region (1+ (point)) (point-min)))
13975         ;; If short file names were used, we have to translate slashes.
13976         (goto-char (point-min))
13977         (while (re-search-forward "[/:]" nil t)
13978           (replace-match "." t t))
13979         ;; Translate "all" to ".*".
13980         (while (search-forward "all" nil t)
13981           (replace-match ".*" t t))
13982         (goto-char (point-min))
13983         ;; Deal with "not."s.
13984         (if (looking-at "not.")
13985             (progn
13986               (setq not-match t)
13987               (setq regexp (buffer-substring 5 (point-max))))
13988           (setq regexp (buffer-substring 1 (point-max)))
13989           (setq not-match nil))
13990         ;; Finally - if this resulting regexp matches the group name,
13991         ;; we add this score file to the list of score files
13992         ;; applicable to this group.
13993         (if (or (and not-match
13994                      (not (string-match regexp group)))
13995                 (and (not not-match)
13996                      (string-match regexp group)))
13997             (setq ofiles (cons (car sfiles) ofiles)))
13998         (setq sfiles (cdr sfiles)))
13999       (kill-buffer (current-buffer))
14000       ;; Slight kludge here - the last score file returned should be
14001       ;; the local score file, whether it exists or not. This is so
14002       ;; that any score commands the user enters will go to the right
14003       ;; file, and not end up in some global score file.
14004       (let ((localscore
14005              (expand-file-name
14006               (if (gnus-use-long-file-name 'not-score)
14007                   (concat gnus-kill-files-directory group "." 
14008                           gnus-score-file-suffix)
14009                 (concat gnus-kill-files-directory
14010                         (gnus-replace-chars-in-string group ?. ?/)
14011                         "/" gnus-score-file-suffix)))))
14012         (and (member localscore ofiles)
14013              (delete localscore ofiles))
14014         (setq ofiles (cons localscore ofiles)))
14015       (nreverse ofiles))))
14016
14017 (defun gnus-score-find-single (group)
14018   "Return list containing the score file for GROUP."
14019   (list (gnus-score-file-name group gnus-adaptive-file-suffix)
14020         (gnus-score-file-name group)))
14021
14022 (defun gnus-score-find-hierarchical (group)
14023   "Return list of score files for GROUP.
14024 This includes the score file for the group and all its parents."
14025   (let ((all (copy-sequence '(nil)))
14026         (start 0))
14027     (while (string-match "\\." group (1+ start))
14028       (setq start (match-beginning 0))
14029       (setq all (cons (substring group 0 start) all)))
14030     (setq all (cons group all))
14031     (nconc
14032      (mapcar (lambda (newsgroup)
14033                (gnus-score-file-name newsgroup gnus-adaptive-file-suffix))
14034              (setq all (nreverse all)))
14035      (mapcar 'gnus-score-file-name all))))
14036
14037 (defvar gnus-score-file-alist-cache nil)
14038
14039 (defun gnus-score-find-alist (group)
14040   "Return list of score files for GROUP.
14041 The list is determined from the variable gnus-score-file-alist."
14042   (let ((alist gnus-score-file-multiple-match-alist)
14043         score-files)
14044     ;; if this group has been seen before, return the cached entry
14045     (if (setq score-files (assoc group gnus-score-file-alist-cache))
14046         (cdr score-files)      ; ensures caching of groups with no matches
14047       ;; handle the multiple match alist
14048       (while alist
14049         (and (string-match (car (car alist)) group)
14050              (setq score-files
14051                    (nconc score-files (copy-sequence (cdr (car alist))))))
14052         (setq alist (cdr alist)))
14053       (setq alist gnus-score-file-single-match-alist)
14054       ;; handle the single match alist
14055       (while alist
14056         (and (string-match (car (car alist)) group)
14057              ;; progn used just in case ("regexp") has no files
14058              ;; and score-files is still nil. -sj
14059              ;; this can be construed as a "stop searching here" feature :>
14060              ;; and used to simplify regexps in the single-alist 
14061              (progn
14062                (setq score-files
14063                      (nconc score-files (copy-sequence (cdr (car alist)))))
14064                (setq alist nil)))
14065         (setq alist (cdr alist)))
14066       ;; cache the score files
14067       (setq gnus-score-file-alist-cache
14068             (cons (cons group score-files) gnus-score-file-alist-cache))
14069       score-files)))
14070
14071
14072 (defun gnus-possibly-score-headers (&optional trace)
14073   (let ((func gnus-score-find-score-files-function)
14074         score-files)
14075     (and func (not (listp func))
14076          (setq func (list func)))
14077     ;; Go through all the functions for finding score files (or actual
14078     ;; scores) and add them to a list.
14079     (setq score-files (gnus-score-find-alist gnus-newsgroup-name))
14080     (while func
14081       (and (symbolp (car func))
14082            (fboundp (car func))
14083            (setq score-files 
14084                  (nconc score-files (funcall (car func) gnus-newsgroup-name))))
14085       (setq func (cdr func)))
14086     (if score-files (gnus-score-headers score-files trace))))
14087
14088 (defun gnus-score-file-name (newsgroup &optional suffix)
14089   "Return the name of a score file for NEWSGROUP."
14090   (let ((suffix (or suffix gnus-score-file-suffix)))
14091     (cond 
14092      ((or (null newsgroup)
14093           (string-equal newsgroup ""))
14094       ;; The global score file is placed at top of the directory.
14095       (expand-file-name 
14096        suffix (or gnus-kill-files-directory "~/News")))
14097      ((gnus-use-long-file-name 'not-score)
14098       ;; Append ".SCORE" to newsgroup name.
14099       (expand-file-name (concat (gnus-newsgroup-saveable-name newsgroup)
14100                                 "." suffix)
14101                         (or gnus-kill-files-directory "~/News")))
14102      (t
14103       ;; Place "SCORE" under the hierarchical directory.
14104       (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
14105                                 "/" suffix)
14106                         (or gnus-kill-files-directory "~/News"))))))
14107
14108 (defun gnus-score-search-global-directories (files)
14109   "Scan all global score directories for score files."
14110   ;; Set the variable `gnus-internal-global-score-files' to all
14111   ;; available global score files.
14112   (interactive (list gnus-global-score-files))
14113   (let (out)
14114     (while files
14115       (if (string-match "/$" (car files))
14116           (setq out (nconc (directory-files 
14117                             (car files) t
14118                             (concat (gnus-score-file-regexp) "$"))))
14119         (setq out (cons (car files) out)))
14120       (setq files (cdr files)))
14121     (setq gnus-internal-global-score-files out)))
14122
14123 ;; Allow redefinition of Gnus functions.
14124
14125 (gnus-ems-redefine)
14126
14127 (provide 'gnus)
14128
14129 ;;; gnus.el ends here