*** 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 ;;; Code:
27
28 (eval '(run-hooks 'gnus-load-hook))
29
30 (require 'mail-utils)
31 (require 'timezone)
32 (require 'nnheader)
33
34 (eval-when-compile (require 'cl))
35
36 ;; Site dependent variables.  These variables should be defined in
37 ;; paths.el.
38
39 (defvar gnus-default-nntp-server nil
40   "Specify a default NNTP server.
41 This variable should be defined in paths.el, and should never be set
42 by the user.
43 If you want to change servers, you should use `gnus-select-method'.
44 See the documentation to that variable.")
45
46 (defconst gnus-backup-default-subscribed-newsgroups 
47   '("news.announce.newusers" "news.groups.questions" "gnu.emacs.gnus")
48   "Default default new newsgroups the first time Gnus is run.
49 Should be set in paths.el, and shouldn't be touched by the user.")
50
51 (defvar gnus-local-domain nil
52   "Local domain name without a host name.
53 The DOMAINNAME environment variable is used instead if it is defined.
54 If the `system-name' function returns the full Internet name, there is
55 no need to set this variable.")
56
57 (defvar gnus-local-organization nil
58   "String with a description of what organization (if any) the user belongs to.
59 The ORGANIZATION environment variable is used instead if it is defined.
60 If this variable contains a function, this function will be called
61 with the current newsgroup name as the argument.  The function should
62 return a string.
63
64 In any case, if the string (either in the variable, in the environment
65 variable, or returned by the function) is a file name, the contents of
66 this file will be used as the organization.")
67
68 (defvar gnus-use-generic-from nil
69   "If nil, the full host name will be the system name prepended to the domain name.
70 If this is a string, the full host name will be this string.
71 If this is non-nil, non-string, the domain name will be used as the
72 full host name.")
73
74 (defvar gnus-use-generic-path nil
75   "If nil, use the NNTP server name in the Path header.
76 If stringp, use this; if non-nil, use no host name (user name only).")
77
78
79 ;; Customization variables
80
81 ;; Don't touch this variable.
82 (defvar gnus-nntp-service "nntp"
83   "*NNTP service name (\"nntp\" or 119).
84 This is an obsolete variable, which is scarcely used.  If you use an
85 nntp server for your newsgroup and want to change the port number
86 used to 899, you would say something along these lines:
87
88  (setq gnus-select-method '(nntp \"my.nntp.server\" (nntp-port-number 899)))")
89
90 (defvar gnus-nntpserver-file "/etc/nntpserver"
91   "*A file with only the name of the nntp server in it.")
92
93 ;; This function is used to check both the environment variable
94 ;; NNTPSERVER and the /etc/nntpserver file to see whether one can find
95 ;; an nntp server name default.
96 (defun gnus-getenv-nntpserver ()
97   (or (getenv "NNTPSERVER")
98       (and (file-readable-p gnus-nntpserver-file)
99            (save-excursion
100              (set-buffer (get-buffer-create " *gnus nntp*"))
101              (buffer-disable-undo (current-buffer))
102              (insert-file-contents gnus-nntpserver-file)
103              (let ((name (buffer-string)))
104                (prog1
105                    (if (string-match "^[ \t\n]*$" name)
106                        nil
107                      name)
108                  (kill-buffer (current-buffer))))))))
109                  
110 (defvar gnus-select-method 
111   (nconc
112    (list 'nntp (or (condition-case ()
113                        (gnus-getenv-nntpserver)
114                      (error nil))
115                    (if (and gnus-default-nntp-server
116                             (not (string= gnus-default-nntp-server "")))
117                        gnus-default-nntp-server)
118                    (system-name)))
119    (if (or (null gnus-nntp-service)
120            (equal gnus-nntp-service "nntp"))
121        nil 
122      (list gnus-nntp-service)))
123   "*Default method for selecting a newsgroup.
124 This variable should be a list, where the first element is how the
125 news is to be fetched, the second is the address. 
126
127 For instance, if you want to get your news via NNTP from
128 \"flab.flab.edu\", you could say:
129
130 (setq gnus-select-method '(nntp \"flab.flab.edu\"))
131
132 If you want to use your local spool, say:
133
134 (setq gnus-select-method (list 'nnspool (system-name)))
135
136 If you use this variable, you must set `gnus-nntp-server' to nil.
137
138 There is a lot more to know about select methods and virtual servers -
139 see the manual for details.")
140
141 ;; Added by Sudish Joseph <joseph@cis.ohio-state.edu>.
142 (defvar gnus-post-method nil
143   "*Preferred method for posting USENET news.
144 If this variable is nil, Gnus will use the current method to decide
145 which method to use when posting.  If it is non-nil, it will override
146 the current method.  This method will not be used in mail groups and
147 the like, only in \"real\" newsgroups.
148
149 The value must be a valid method as discussed in the documentation of
150 `gnus-select-method'.")
151
152 (defvar gnus-refer-article-method nil
153   "*Preferred method for fetching an article by Message-ID.
154 If you are reading news from the local spool (with nnspool), fetching
155 articles by Message-ID is painfully slow.  By setting this method to an
156 nntp method, you might get acceptable results.
157
158 The value of this variable must be a valid select method as discussed
159 in the documentation of `gnus-select-method'")
160
161 (defvar gnus-secondary-select-methods nil
162   "*A list of secondary methods that will be used for reading news.
163 This is a list where each element is a complete select method (see
164 `gnus-select-method').  
165
166 If, for instance, you want to read your mail with the nnml backend,
167 you could set this variable:
168
169 (setq gnus-secondary-select-methods '((nnml \"\")))")
170
171 (defvar gnus-secondary-servers nil
172   "*List of NNTP servers that the user can choose between interactively.
173 To make Gnus query you for a server, you have to give `gnus' a
174 non-numeric prefix - `C-u M-x gnus', in short.")
175
176 (defvar gnus-nntp-server nil
177   "*The name of the host running the NNTP server.
178 This variable is semi-obsolete.  Use the `gnus-select-method'
179 variable instead.")
180
181 (defvar gnus-startup-file "~/.newsrc"
182   "*Your `.newsrc' file.
183 `.newsrc-SERVER' will be used instead if that exists.")
184
185 (defvar gnus-init-file "~/.gnus"
186   "*Your Gnus elisp startup file.
187 If a file with the .el or .elc suffixes exist, it will be read
188 instead.") 
189
190 (defvar gnus-group-faq-directory
191   '("/ftp@mirrors.aol.com:/pub/rtfm/usenet/"
192     "/ftp@ftp.uu.net:/usenet/news.answers/"
193     "/ftp@ftp.seas.gwu.edu:/pub/rtfm/"
194     "/ftp@rtfm.mit.edu:/pub/usenet/news.answers/"
195     "/ftp@ftp.uni-paderborn.de:/pub/FAQ/"
196     "/ftp@ftp.Germany.EU.net:/pub/newsarchive/news.answers/"
197     "/ftp@ftp.sunet.se:/pub/usenet/"
198     "/ftp@nctuccca.edu.tw:/USENET/FAQ/"
199     "/ftp@hwarang.postech.ac.kr:/pub/usenet/news.answers/"
200     "/ftp@ftp.hk.super.net:/mirror/faqs/")
201   "*Directory where the group FAQs are stored.
202 This will most commonly be on a remote machine, and the file will be
203 fetched by ange-ftp.
204
205 This variable can also be a list of directories.  In that case, the
206 first element in the list will be used by default, and the others will
207 be used as backup sites.
208
209 Note that Gnus uses an aol machine as the default directory.  If this
210 feels fundamentally unclean, just think of it as a way to finally get
211 something of value back from them.
212
213 If the default site is too slow, try one of these:
214
215    North America: ftp.uu.net                     /usenet/news.answers
216                   mirrors.aol.com                /pub/rtfm/usenet
217                   ftp.seas.gwu.edu               /pub/rtfm
218                   rtfm.mit.edu                   /pub/usenet/news.answers
219    Europe:        ftp.uni-paderborn.de           /pub/FAQ
220                   ftp.Germany.EU.net             /pub/newsarchive/news.answers
221                   ftp.sunet.se                   /pub/usenet
222    Asia:          nctuccca.edu.tw                /USENET/FAQ
223                   hwarang.postech.ac.kr          /pub/usenet/news.answers
224                   ftp.hk.super.net               /mirror/faqs")
225
226 (defvar gnus-group-archive-directory
227   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/" 
228   "*The address of the (ding) archives.")
229
230 (defvar gnus-group-recent-archive-directory
231   "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list-recent/"
232   "*The address of the most recent (ding) articles.")
233
234 (defvar gnus-default-subscribed-newsgroups nil
235   "*This variable lists what newsgroups should be subscribed the first time Gnus is used.
236 It should be a list of strings.
237 If it is `t', Gnus will not do anything special the first time it is
238 started; it'll just use the normal newsgroups subscription methods.")
239
240 (defvar gnus-use-cross-reference t
241   "*Non-nil means that cross referenced articles will be marked as read.
242 If nil, ignore cross references.  If t, mark articles as read in
243 subscribed newsgroups.  If neither t nor nil, mark as read in all
244 newsgroups.") 
245
246 (defvar gnus-use-dribble-file t
247   "*Non-nil means that Gnus will use a dribble file to store user updates.
248 If Emacs should crash without saving the .newsrc files, complete
249 information can be restored from the dribble file.")
250
251 (defvar gnus-dribble-directory nil
252   "*The directory where dribble files will be saved.
253 If this variable is nil, the directory where the .newsrc files are
254 saved will be used.")
255
256 (defvar gnus-asynchronous nil
257   "*If non-nil, Gnus will supply backends with data needed for async article fetching.")
258
259 (defvar gnus-large-newsgroup 200
260   "*The number of articles which indicates a large newsgroup.
261 If the number of articles in a newsgroup is greater than this value,
262 confirmation is required for selecting the newsgroup.")
263
264 ;; Suggested by Andrew Eskilsson <pi92ae@lelle.pt.hk-r.se>.
265 (defvar gnus-no-groups-message "No news is horrible news"
266   "*Message displayed by Gnus when no groups are available.")
267
268 (defvar gnus-use-long-file-name (not (memq system-type '(usg-unix-v xenix)))
269   "*Non-nil means that the default name of a file to save articles in is the group name.
270 If it's nil, the directory form of the group name is used instead.
271
272 If this variable is a list, and the list contains the element
273 `not-score', long file names will not be used for score files; if it
274 contains the element `not-save', long file names will not be used for
275 saving; and if it contains the element `not-kill', long file names
276 will not be used for kill files.")
277
278 (defvar gnus-article-save-directory (or (getenv "SAVEDIR") "~/News/")
279   "*Name of the directory articles will be saved in (default \"~/News\").
280 Initialized from the SAVEDIR environment variable.")
281
282 (defvar gnus-kill-files-directory (or (getenv "SAVEDIR") "~/News/")
283   "*Name of the directory where kill files will be stored (default \"~/News\").
284 Initialized from the SAVEDIR environment variable.")
285
286 (defvar gnus-default-article-saver 'gnus-summary-save-in-rmail
287   "*A function to save articles in your favorite format.
288 The function must be interactively callable (in other words, it must
289 be an Emacs command).
290
291 Gnus provides the following functions:
292
293 * gnus-summary-save-in-rmail (Rmail format)
294 * gnus-summary-save-in-mail (Unix mail format)
295 * gnus-summary-save-in-folder (MH folder)
296 * gnus-summary-save-in-file (article format).
297 * gnus-summary-save-in-vm (use VM's folder format).")
298
299 (defvar gnus-prompt-before-saving 'always
300   "*This variable says how much prompting is to be done when saving articles.
301 If it is nil, no prompting will be done, and the articles will be
302 saved to the default files.  If this variable is `always', each and
303 every article that is saved will be preceded by a prompt, even when
304 saving large batches of articles.  If this variable is neither nil not
305 `always', there the user will be prompted once for a file name for
306 each invocation of the saving commands.")
307
308 (defvar gnus-rmail-save-name (function gnus-plain-save-name)
309   "*A function generating a file name to save articles in Rmail format.
310 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
311
312 (defvar gnus-mail-save-name (function gnus-plain-save-name)
313   "*A function generating a file name to save articles in Unix mail format.
314 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.")
315
316 (defvar gnus-folder-save-name (function gnus-folder-save-name)
317   "*A function generating a file name to save articles in MH folder.
318 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.")
319
320 (defvar gnus-file-save-name (function gnus-numeric-save-name)
321   "*A function generating a file name to save articles in article format.
322 The function is called with NEWSGROUP, HEADERS, and optional
323 LAST-FILE.")
324
325 (defvar gnus-split-methods nil
326   "*Variable used to suggest where articles are to be saved.
327 The syntax of this variable is the same as `nnmail-split-methods'.  
328
329 For instance, if you would like to save articles related to Gnus in
330 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
331 you could set this variable to something like:
332
333  '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
334    (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))")
335
336 (defvar gnus-save-score nil
337   "*If non-nil, save group scoring info.")
338
339 (defvar gnus-use-adaptive-scoring nil
340   "*If non-nil, use some adaptive scoring scheme.")
341
342 (defvar gnus-use-cache nil
343   "*If non-nil, Gnus will cache (some) articles locally.")
344
345 (defvar gnus-keep-backlog nil
346   "*If non-nil, Gnus will keep read articles for later re-retrieval.
347 If it is a number N, then Gnus will only keep the last N articles
348 read.  If it is neither nil nor a number, Gnus will keep all read
349 articles.  This is not a good idea.")
350
351 (defvar gnus-use-nocem nil
352   "*If non-nil, Gnus will read NoCeM cancel messages.")
353
354 (defvar gnus-use-demon nil
355   "If non-nil, Gnus might use some demons.")
356
357 (defvar gnus-use-scoring t
358   "*If non-nil, enable scoring.")
359
360 (defvar gnus-fetch-old-headers nil
361   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
362 If an unread article in the group refers to an older, already read (or
363 just marked as read) article, the old article will not normally be
364 displayed in the Summary buffer.  If this variable is non-nil, Gnus
365 will attempt to grab the headers to the old articles, and thereby
366 build complete threads.  If it has the value `some', only enough
367 headers to connect otherwise loose threads will be displayed.
368 This variable can also be a number.  In that case, no more than that
369 number of old headers will be fetched. 
370
371 The server has to support NOV for any of this to work.")
372
373 ;see gnus-cus.el
374 ;(defvar gnus-visual t
375 ;  "*If non-nil, will do various highlighting.
376 ;If nil, no mouse highlights (or any other highlights) will be
377 ;performed.  This might speed up Gnus some when generating large group
378 ;and summary buffers.")
379
380 (defvar gnus-novice-user t
381   "*Non-nil means that you are a usenet novice.
382 If non-nil, verbose messages may be displayed and confirmations may be
383 required.")
384
385 (defvar gnus-expert-user nil
386   "*Non-nil means that you will never be asked for confirmation about anything.
387 And that means *anything*.")
388
389 (defvar gnus-verbose 7
390   "*Integer that says how verbose Gnus should be.
391 The higher the number, the more messages Gnus will flash to say what
392 it's doing.  At zero, Gnus will be totally mute; at five, Gnus will
393 display most important messages; and at ten, Gnus will keep on
394 jabbering all the time.")
395
396 (defvar gnus-keep-same-level nil
397   "*Non-nil means that the next newsgroup after the current will be on the same level.
398 When you type, for instance, `n' after reading the last article in the
399 current newsgroup, you will go to the next newsgroup.  If this variable
400 is nil, the next newsgroup will be the next from the group
401 buffer. 
402 If this variable is non-nil, Gnus will either put you in the
403 next newsgroup with the same level, or, if no such newsgroup is
404 available, the next newsgroup with the lowest possible level higher
405 than the current level.
406 If this variable is `best', Gnus will make the next newsgroup the one
407 with the best level.")
408
409 (defvar gnus-summary-make-false-root 'adopt
410   "*nil means that Gnus won't gather loose threads.
411 If the root of a thread has expired or been read in a previous
412 session, the information necessary to build a complete thread has been
413 lost.  Instead of having many small sub-threads from this original thread
414 scattered all over the summary buffer, Gnus can gather them. 
415
416 If non-nil, Gnus will try to gather all loose sub-threads from an
417 original thread into one large thread.
418
419 If this variable is non-nil, it should be one of `none', `adopt',
420 `dummy' or `empty'.
421
422 If this variable is `none', Gnus will not make a false root, but just
423 present the sub-threads after another.
424 If this variable is `dummy', Gnus will create a dummy root that will
425 have all the sub-threads as children.
426 If this variable is `adopt', Gnus will make one of the \"children\"
427 the parent and mark all the step-children as such.
428 If this variable is `empty', the \"children\" are printed with empty
429 subject fields.  (Or rather, they will be printed with a string
430 given by the `gnus-summary-same-subject' variable.)")
431
432 (defvar gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
433   "*A regexp to match subjects to be excluded from loose thread gathering.
434 As loose thread gathering is done on subjects only, that means that
435 there can be many false gatherings performed.  By rooting out certain
436 common subjects, gathering might become saner.")
437
438 (defvar gnus-summary-gather-subject-limit nil
439   "*Maximum length of subject comparisons when gathering loose threads.
440 Use nil to compare full subjects.  Setting this variable to a low
441 number will help gather threads that have been corrupted by
442 newsreaders chopping off subject lines, but it might also mean that
443 unrelated articles that have subject that happen to begin with the
444 same few characters will be incorrectly gathered.
445
446 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
447 comparing subjects.")
448
449 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
450 (defvar gnus-summary-same-subject ""
451   "*String indicating that the current article has the same subject as the previous.
452 This variable will only be used if the value of
453 `gnus-summary-make-false-root' is `empty'.")
454
455 (defvar gnus-summary-goto-unread t
456   "*If non-nil, marking commands will go to the next unread article.")
457
458 (defvar gnus-group-goto-unread t
459   "*If non-nil, movement commands will go to the next unread and subscribed group.")
460
461 (defvar gnus-check-new-newsgroups t
462   "*Non-nil means that Gnus will add new newsgroups at startup.
463 If this variable is `ask-server', Gnus will ask the server for new
464 groups since the last time it checked.  This means that the killed list
465 is no longer necessary, so you could set `gnus-save-killed-list' to
466 nil. 
467
468 A variant is to have this variable be a list of select methods.  Gnus
469 will then use the `ask-server' method on all these select methods to
470 query for new groups from all those servers.
471
472 Eg.
473   (setq gnus-check-new-newsgroups 
474         '((nntp \"some.server\") (nntp \"other.server\")))
475
476 If this variable is nil, then you have to tell Gnus explicitly to
477 check for new newsgroups with \\<gnus-group-mode-map>\\[gnus-find-new-newsgroups].")
478
479 (defvar gnus-check-bogus-newsgroups nil
480   "*Non-nil means that Gnus will check and remove bogus newsgroup at startup.
481 If this variable is nil, then you have to tell Gnus explicitly to
482 check for bogus newsgroups with \\<gnus-group-mode-map>\\[gnus-group-check-bogus-groups].")
483
484 (defvar gnus-read-active-file t
485   "*Non-nil means that Gnus will read the entire active file at startup.
486 If this variable is nil, Gnus will only know about the groups in your
487 `.newsrc' file.
488
489 If this variable is `some', Gnus will try to only read the relevant
490 parts of the active file from the server.  Not all servers support
491 this, and it might be quite slow with other servers, but this should
492 generally be faster than both the t and nil value.
493
494 If you set this variable to nil or `some', you probably still want to
495 be told about new newsgroups that arrive.  To do that, set
496 `gnus-check-new-newsgroups' to `ask-server'.  This may not work
497 properly with all servers.")
498
499 (defvar gnus-level-subscribed 5
500   "*Groups with levels less than or equal to this variable are subscribed.")
501
502 (defvar gnus-level-unsubscribed 7
503   "*Groups with levels less than or equal to this variable are unsubscribed.
504 Groups with levels less than `gnus-level-subscribed', which should be
505 less than this variable, are subscribed.")
506
507 (defvar gnus-level-zombie 8
508   "*Groups with this level are zombie groups.")
509
510 (defvar gnus-level-killed 9
511   "*Groups with this level are killed.")
512
513 (defvar gnus-level-default-subscribed 3
514   "*New subscribed groups will be subscribed at this level.")
515
516 (defvar gnus-level-default-unsubscribed 6
517   "*New unsubscribed groups will be unsubscribed at this level.")
518
519 (defvar gnus-activate-foreign-newsgroups 4
520   "*If nil, Gnus will not check foreign newsgroups at startup.
521 If it is non-nil, it should be a number between one and nine.  Foreign
522 newsgroups that have a level lower or equal to this number will be
523 activated on startup.  For instance, if you want to active all
524 subscribed newsgroups, but not the rest, you'd set this variable to 
525 `gnus-level-subscribed'.
526
527 If you subscribe to lots of newsgroups from different servers, startup
528 might take a while.  By setting this variable to nil, you'll save time,
529 but you won't be told how many unread articles there are in the
530 groups.")
531
532 (defvar gnus-save-newsrc-file t
533   "*Non-nil means that Gnus will save the `.newsrc' file.
534 Gnus always saves its own startup file, which is called
535 \".newsrc.eld\".  The file called \".newsrc\" is in a format that can
536 be readily understood by other newsreaders.  If you don't plan on
537 using other newsreaders, set this variable to nil to save some time on
538 exit.")
539
540 (defvar gnus-save-killed-list t
541   "*If non-nil, save the list of killed groups to the startup file.
542 This will save both time (when starting and quitting) and space (both
543 memory and disk), but it will also mean that Gnus has no record of
544 which groups are new and which are old, so the automatic new
545 newsgroups subscription methods become meaningless.  You should always
546 set `gnus-check-new-newsgroups' to `ask-server' or nil if you set this
547 variable to nil.")
548
549 (defvar gnus-interactive-catchup t
550   "*If non-nil, require your confirmation when catching up a group.")
551
552 (defvar gnus-interactive-post t
553   "*If non-nil, group name will be asked for when posting.")
554
555 (defvar gnus-interactive-exit t
556   "*If non-nil, require your confirmation when exiting Gnus.")
557
558 (defvar gnus-kill-killed t
559   "*If non-nil, Gnus will apply kill files to already killed articles.
560 If it is nil, Gnus will never apply kill files to articles that have
561 already been through the scoring process, which might very well save lots
562 of time.")
563
564 (defvar gnus-extract-address-components 'gnus-extract-address-components
565   "*Function for extracting address components from a From header.
566 Two pre-defined function exist: `gnus-extract-address-components',
567 which is the default, quite fast, and too simplistic solution, and
568 `mail-extract-address-components', which works much better, but is
569 slower.")
570
571 (defvar gnus-summary-default-score 0
572   "*Default article score level.
573 If this variable is nil, scoring will be disabled.")
574
575 (defvar gnus-summary-zcore-fuzz 0
576   "*Fuzziness factor for the zcore in the summary buffer.
577 Articles with scores closer than this to `gnus-summary-default-score'
578 will not be marked.")
579
580 (defvar gnus-simplify-subject-fuzzy-regexp nil
581   "*Strings to be removed when doing fuzzy matches.
582 This can either be a egular expression or list of regular expressions
583 that will be removed from subject strings if fuzzy subject
584 simplification is selected.")
585
586 (defvar gnus-permanently-visible-groups nil
587   "*Regexp to match groups that should always be listed in the group buffer.
588 This means that they will still be listed when there are no unread
589 articles in the groups.")
590
591 (defvar gnus-group-default-list-level gnus-level-subscribed
592   "*Default listing level. 
593 Ignored if `gnus-group-use-permanent-levels' is non-nil.")
594
595 (defvar gnus-group-use-permanent-levels nil
596   "*If non-nil, once you set a level, Gnus will use this level.")
597
598 (defvar gnus-show-mime nil
599   "*If non-nil, do mime processing of articles.
600 The articles will simply be fed to the function given by
601 `gnus-show-mime-method'.")
602
603 (defvar gnus-strict-mime t
604   "*If nil, decode MIME header even if there is not Mime-Version field.")
605  
606 (defvar gnus-show-mime-method 'metamail-buffer
607   "*Function to process a MIME message.
608 The function is called from the article buffer.")
609
610 (defvar gnus-decode-encoded-word-method (lambda ())
611   "*Function to decode a MIME encoded-words.
612 The function is called from the article buffer.")
613  
614 (defvar gnus-show-threads t
615   "*If non-nil, display threads in summary mode.")
616
617 (defvar gnus-thread-hide-subtree nil
618   "*If non-nil, hide all threads initially.
619 If threads are hidden, you have to run the command
620 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
621 to expose hidden threads.")
622
623 (defvar gnus-thread-hide-killed t
624   "*If non-nil, hide killed threads automatically.")
625
626 (defvar gnus-thread-ignore-subject nil
627   "*If non-nil, ignore subjects and do all threading based on the Reference header.
628 If nil, which is the default, articles that have different subjects
629 from their parents will start separate threads.")
630
631 (defvar gnus-thread-operation-ignore-subject t
632   "*If non-nil, subjects will be ignored when doing thread commands.
633 This affects commands like `gnus-summary-kill-thread' and
634 `gnus-summary-lower-thread'.  
635
636 If this variable is nil, articles in the same thread with different
637 subjects will not be included in the operation in question.  If this
638 variable is `fuzzy', only articles that have subjects that are fuzzily
639 equal will be included.")
640
641 (defvar gnus-thread-indent-level 4
642   "*Number that says how much each sub-thread should be indented.")
643
644 (defvar gnus-ignored-newsgroups 
645   (purecopy (mapconcat 'identity
646                        '("^to\\."       ; not "real" groups
647                          "^[0-9. \t]+ " ; all digits in name
648                          "[][\"#'()]"   ; bogus characters
649                          )
650                        "\\|"))
651   "*A regexp to match uninteresting newsgroups in the active file.
652 Any lines in the active file matching this regular expression are
653 removed from the newsgroup list before anything else is done to it,
654 thus making them effectively non-existent.")
655
656 (defvar gnus-ignored-headers
657   "^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:"
658   "*All headers that match this regexp will be hidden.
659 If `gnus-visible-headers' is non-nil, this variable will be ignored.")
660
661 (defvar gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copy-To:"
662   "*All headers that do not match this regexp will be hidden.
663 If this variable is non-nil, `gnus-ignored-headers' will be ignored.")
664
665 (defvar gnus-sorted-header-list
666   '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:" 
667     "^Cc:" "^Date:" "^Organization:")
668   "*This variable is a list of regular expressions.
669 If it is non-nil, headers that match the regular expressions will
670 be placed first in the article buffer in the sequence specified by
671 this list.")
672
673 (defvar gnus-show-all-headers nil
674   "*If non-nil, don't hide any headers.")
675
676 (defvar gnus-save-all-headers t
677   "*If non-nil, don't remove any headers before saving.")
678
679 (defvar gnus-saved-headers gnus-visible-headers
680   "*Headers to keep if `gnus-save-all-headers' is nil.
681 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
682 If that variable is nil, however, all headers that match this regexp
683 will be kept while the rest will be deleted before saving.")
684
685 (defvar gnus-inhibit-startup-message nil
686   "*If non-nil, the startup message will not be displayed.")
687
688 (defvar gnus-signature-separator "^-- *$"
689   "Regexp matching signature separator.")
690
691 (defvar gnus-auto-extend-newsgroup t
692   "*If non-nil, extend newsgroup forward and backward when requested.")
693
694 (defvar gnus-auto-select-first t
695   "*If nil, don't select the first unread article when entering a group.
696 If this variable is `best', select the highest-scored unread article
697 in the group.  If neither nil nor `best', select the first unread
698 article.
699
700 If you want to prevent automatic selection of the first unread article
701 in some newsgroups, set the variable to nil in
702 `gnus-select-group-hook'.") 
703
704 (defvar gnus-auto-select-next t
705   "*If non-nil, offer to go to the next group from the end of the previous.
706 If the value is t and the next newsgroup is empty, Gnus will exit
707 summary mode and go back to group mode.  If the value is neither nil
708 nor t, Gnus will select the following unread newsgroup.  In
709 particular, if the value is the symbol `quietly', the next unread
710 newsgroup will be selected without any confirmation, and if it is
711 `almost-quietly', the next group will be selected without any
712 confirmation if you are located on the last article in the group.")
713
714 (defvar gnus-auto-select-same nil
715   "*If non-nil, select the next article with the same subject.")
716
717 (defvar gnus-summary-check-current nil
718   "*If non-nil, consider the current article when moving.
719 The \"unread\" movement commands will stay on the same line if the
720 current article is unread.")
721
722 (defvar gnus-auto-center-summary t
723   "*If non-nil, always center the current summary buffer.")
724
725 (defvar gnus-break-pages t
726   "*If non-nil, do page breaking on articles.
727 The page delimiter is specified by the `gnus-page-delimiter'
728 variable.")
729
730 (defvar gnus-page-delimiter "^\^L"
731   "*Regexp describing what to use as article page delimiters.
732 The default value is \"^\^L\", which is a form linefeed at the
733 beginning of a line.")
734
735 (defvar gnus-use-full-window t
736   "*If non-nil, use the entire Emacs screen.")
737
738 (defvar gnus-window-configuration nil
739   "Obsolete variable.  See `gnus-buffer-configuration'.")
740
741 (defvar gnus-buffer-configuration
742   '((group ([group 1.0 point] 
743             (if gnus-carpal [group-carpal 4])))
744     (summary ([summary 1.0 point]
745               (if gnus-carpal [summary-carpal 4])))
746     (article ([summary 0.25 point] 
747               (if gnus-carpal [summary-carpal 4]) 
748               [article 1.0]))
749     (server ([server 1.0 point]
750              (if gnus-carpal [server-carpal 2])))
751     (browse ([browse 1.0 point]
752              (if gnus-carpal [browse-carpal 2])))
753     (group-mail ([mail 1.0 point]))
754     (summary-mail ([mail 1.0 point]))
755     (summary-reply ([article 0.5]
756                     [mail 1.0 point]))
757     (info ([nil 1.0 point]))
758     (summary-faq ([summary 0.25]
759                   [faq 1.0 point]))
760     (edit-group ([group 0.5]
761                  [edit-group 1.0 point]))
762     (edit-server ([server 0.5]
763                   [edit-server 1.0 point]))
764     (edit-score ([summary 0.25]
765                  [edit-score 1.0 point]))
766     (post ([post 1.0 point]))
767     (reply ([article 0.5]
768             [mail 1.0 point]))
769     (mail-forward ([mail 1.0 point]))
770     (post-forward ([post 1.0 point]))
771     (reply-yank ([mail 1.0 point]))
772     (mail-bounce ([article 0.5]
773                   [mail 1.0 point]))
774     (draft ([draft 1.0 point]))
775     (pipe ([summary 0.25 point] 
776            (if gnus-carpal [summary-carpal 4]) 
777            ["*Shell Command Output*" 1.0]))
778     (followup ([article 0.5]
779                [post 1.0 point]))
780     (followup-yank ([post 1.0 point])))
781   "Window configuration for all possible Gnus buffers.
782 This variable is a list of lists.  Each of these lists has a NAME and
783 a RULE.  The NAMEs are commonsense names like `group', which names a
784 rule used when displaying the group buffer; `summary', which names a
785 rule for what happens when you enter a group and do not display an
786 article buffer; and so on.  See the value of this variable for a
787 complete list of NAMEs.
788
789 Each RULE is a list of vectors.  The first element in this vector is
790 the name of the buffer to be displayed; the second element is the
791 percentage of the screen this buffer is to occupy (a number in the
792 0.0-0.99 range); the optional third element is `point', which should
793 be present to denote which buffer point is to go to after making this
794 buffer configuration.")
795
796 (defvar gnus-window-to-buffer
797   '((group . gnus-group-buffer)
798     (summary . gnus-summary-buffer)
799     (article . gnus-article-buffer)
800     (server . gnus-server-buffer)
801     (browse . "*Gnus Browse Server*")
802     (edit-group . gnus-group-edit-buffer)
803     (edit-server . gnus-server-edit-buffer)
804     (group-carpal . gnus-carpal-group-buffer)
805     (summary-carpal . gnus-carpal-summary-buffer)
806     (server-carpal . gnus-carpal-server-buffer)
807     (browse-carpal . gnus-carpal-browse-buffer)
808     (edit-score . gnus-score-edit-buffer)
809     (mail . gnus-mail-buffer)
810     (post . gnus-post-news-buffer)
811     (faq . gnus-faq-buffer)
812     (draft . gnus-draft-buffer))
813   "Mapping from short symbols to buffer names or buffer variables.")
814
815 (defvar gnus-carpal nil
816   "*If non-nil, display clickable icons.")
817
818 (defvar gnus-subscribe-newsgroup-method 'gnus-subscribe-zombies
819   "*Function called with a group name when new group is detected.
820 A few pre-made functions are supplied: `gnus-subscribe-randomly'
821 inserts new groups at the beginning of the list of groups;
822 `gnus-subscribe-alphabetically' inserts new groups in strict
823 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
824 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
825 for your decision.")
826
827 ;; Suggested by a bug report by Hallvard B Furuseth.
828 ;; <h.b.furuseth@usit.uio.no>. 
829 (defvar gnus-subscribe-options-newsgroup-method
830   (function gnus-subscribe-alphabetically)
831   "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines.
832 If, for instance, you want to subscribe to all newsgroups in the
833 \"no\" and \"alt\" hierarchies, you'd put the following in your
834 .newsrc file:
835
836 options -n no.all alt.all
837
838 Gnus will the subscribe all new newsgroups in these hierarchies with
839 the subscription method in this variable.")
840
841 (defvar gnus-subscribe-hierarchical-interactive nil
842   "*If non-nil, Gnus will offer to subscribe hierarchically.
843 When a new hierarchy appears, Gnus will ask the user:
844
845 'alt.binaries': Do you want to subscribe to this hierarchy? ([d]ys):
846
847 If the user pressed `d', Gnus will descend the hierarchy, `y' will
848 subscribe to all newsgroups in the hierarchy and `s' will skip this
849 hierarchy in its entirety.")
850
851 (defvar gnus-group-sort-function 'gnus-group-sort-by-alphabet
852   "*Function used for sorting the group buffer.
853 This function will be called with group info entries as the arguments
854 for the groups to be sorted.  Pre-made functions include
855 `gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread',
856 `gnus-group-sort-by-level', `gnus-group-sort-by-score', and
857 `gnus-group-sort-by-rank'.  
858
859 This variable can also be a list of sorting functions.  In that case,
860 the most significant sort function should be the last function in the
861 list.")
862
863 ;; Mark variables suggested by Thomas Michanek
864 ;; <Thomas.Michanek@telelogic.se>. 
865 (defvar gnus-unread-mark ? 
866   "*Mark used for unread articles.")
867 (defvar gnus-ticked-mark ?!
868   "*Mark used for ticked articles.")
869 (defvar gnus-dormant-mark ??
870   "*Mark used for dormant articles.")
871 (defvar gnus-del-mark ?r
872   "*Mark used for del'd articles.")
873 (defvar gnus-read-mark ?R
874   "*Mark used for read articles.")
875 (defvar gnus-expirable-mark ?E
876   "*Mark used for expirable articles.")
877 (defvar gnus-killed-mark ?K
878   "*Mark used for killed articles.")
879 (defvar gnus-souped-mark ?F
880   "*Mark used for killed articles.")
881 (defvar gnus-kill-file-mark ?X
882   "*Mark used for articles killed by kill files.")
883 (defvar gnus-low-score-mark ?Y
884   "*Mark used for articles with a low score.")
885 (defvar gnus-catchup-mark ?C
886   "*Mark used for articles that are caught up.")
887 (defvar gnus-replied-mark ?A
888   "*Mark used for articles that have been replied to.")
889 (defvar gnus-process-mark ?# 
890   "*Process mark.")
891 (defvar gnus-ancient-mark ?O
892   "*Mark used for ancient articles.")
893 (defvar gnus-canceled-mark ?G
894   "*Mark used for canceled articles.")
895 (defvar gnus-score-over-mark ?+
896   "*Score mark used for articles with high scores.")
897 (defvar gnus-score-below-mark ?-
898   "*Score mark used for articles with low scores.")
899 (defvar gnus-empty-thread-mark ? 
900   "*There is no thread under the article.")
901 (defvar gnus-not-empty-thread-mark ?=
902   "*There is a thread under the article.")
903
904 (defvar gnus-view-pseudo-asynchronously nil
905   "*If non-nil, Gnus will view pseudo-articles asynchronously.")
906
907 (defvar gnus-view-pseudos nil
908   "*If `automatic', pseudo-articles will be viewed automatically.
909 If `not-confirm', pseudos will be viewed automatically, and the user
910 will not be asked to confirm the command.")
911
912 (defvar gnus-view-pseudos-separately t
913   "*If non-nil, one pseudo-article will be created for each file to be viewed.
914 If nil, all files that use the same viewing command will be given as a
915 list of parameters to that command.")
916
917 (defvar gnus-group-line-format "%M%S%p%5y: %(%g%)\n"
918   "*Format of group lines.
919 It works along the same lines as a normal formatting string,
920 with some simple extensions.
921
922 %M    Only marked articles (character, \"*\" or \" \")
923 %S    Whether the group is subscribed (character, \"U\", \"K\", \"Z\" or \" \")
924 %L    Level of subscribedness (integer)
925 %N    Number of unread articles (integer)
926 %I    Number of dormant articles (integer)
927 %i    Number of ticked and dormant (integer)
928 %T    Number of ticked articles (integer)
929 %R    Number of read articles (integer)
930 %t    Total number of articles (integer)
931 %y    Number of unread, unticked articles (integer)
932 %G    Group name (string)
933 %g    Qualified group name (string)
934 %D    Group description (string)
935 %s    Select method (string)
936 %o    Moderated group (char, \"m\")
937 %p    Process mark (char)
938 %O    Moderated group (string, \"(m)\" or \"\")
939 %n    Select from where (string)
940 %z    A string that look like `<%s:%n>' if a foreign select method is used
941 %u    User defined specifier.  The next character in the format string should
942       be a letter.  Gnus will call the function gnus-user-format-function-X,
943       where X is the letter following %u.  The function will be passed the
944       current header as argument.  The function should return a string, which
945       will be inserted into the buffer just like information from any other
946       group specifier.
947
948 Text between %( and %) will be highlighted with `gnus-mouse-face' when
949 the mouse point move inside the area.  There can only be one such area.
950
951 Note that this format specification is not always respected.  For
952 reasons of efficiency, when listing killed groups, this specification
953 is ignored altogether.  If the spec is changed considerably, your
954 output may end up looking strange when listing both alive and killed
955 groups.
956
957 If you use %o or %O, reading the active file will be slower and quite
958 a bit of extra memory will be used. %D will also worsen performance.
959 Also note that if you change the format specification to include any
960 of these specs, you must probably re-start Gnus to see them go into
961 effect.") 
962
963 (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
964   "*The format specification of the lines in the summary buffer.
965
966 It works along the same lines as a normal formatting string,
967 with some simple extensions.
968
969 %N   Article number, left padded with spaces (string)
970 %S   Subject (string)
971 %s   Subject if it is at the root of a thread, and \"\" otherwise (string)
972 %n   Name of the poster (string)
973 %a   Extracted name of the poster (string)
974 %A   Extracted address of the poster (string)
975 %F   Contents of the From: header (string)
976 %x   Contents of the Xref: header (string)
977 %D   Date of the article (string)
978 %d   Date of the article (string) in DD-MMM format
979 %M   Message-id of the article (string)
980 %r   References of the article (string)
981 %c   Number of characters in the article (integer)
982 %L   Number of lines in the article (integer)
983 %I   Indentation based on thread level (a string of spaces)
984 %T   A string with two possible values: 80 spaces if the article
985      is on thread level two or larger and 0 spaces on level one
986 %R   \"A\" if this article has been replied to, \" \" otherwise (character)
987 %U   Status of this article (character, \"R\", \"K\", \"-\" or \" \")
988 %[   Opening bracket (character, \"[\" or \"<\")
989 %]   Closing bracket (character, \"]\" or \">\")
990 %>   Spaces of length thread-level (string)
991 %<   Spaces of length (- 20 thread-level) (string)
992 %i   Article score (number)
993 %z   Article zcore (character)
994 %t   Number of articles under the current thread (number).
995 %e   Whether the thread is empty or not (character).
996 %u   User defined specifier.  The next character in the format string should
997      be a letter.  Gnus will call the function gnus-user-format-function-X,
998      where X is the letter following %u.  The function will be passed the
999      current header as argument.  The function should return a string, which
1000      will be inserted into the summary just like information from any other
1001      summary specifier.
1002
1003 Text between %( and %) will be highlighted with `gnus-mouse-face'
1004 when the mouse point is placed inside the area.  There can only be one
1005 such area.
1006
1007 The %U (status), %R (replied) and %z (zcore) specs have to be handled
1008 with care.  For reasons of efficiency, Gnus will compute what column
1009 these characters will end up in, and \"hard-code\" that.  This means that
1010 it is illegal to have these specs after a variable-length spec.  Well,
1011 you might not be arrested, but your summary buffer will look strange,
1012 which is bad enough.
1013
1014 The smart choice is to have these specs as for to the left as
1015 possible. 
1016
1017 This restriction may disappear in later versions of Gnus.")
1018
1019 (defvar gnus-summary-dummy-line-format "*  :                          : %S\n"
1020   "*The format specification for the dummy roots in the summary buffer.
1021 It works along the same lines as a normal formatting string,
1022 with some simple extensions.
1023
1024 %S  The subject")
1025
1026 (defvar gnus-summary-mode-line-format "Gnus  %G/%A %Z"
1027   "*The format specification for the summary mode line.")
1028
1029 (defvar gnus-article-mode-line-format "Gnus  %G/%A %S"
1030   "*The format specification for the article mode line.")
1031
1032 (defvar gnus-group-mode-line-format "Gnus  List of groups   {%M:%S}  "
1033   "*The format specification for the group mode line.")
1034
1035 (defvar gnus-valid-select-methods
1036   '(("nntp" post address prompt-address)
1037     ("nnspool" post)
1038     ("nnvirtual" none virtual prompt-address) 
1039     ("nnmbox" mail respool) 
1040     ("nnml" mail respool)
1041     ("nnmh" mail respool) 
1042     ("nndir" none prompt-address address)
1043     ("nneething" none prompt-address)
1044     ("nndigest" none) 
1045     ("nndoc" none prompt-address) 
1046     ("nnbabyl" mail respool) 
1047     ("nnkiboze" post virtual) 
1048     ("nnsoup" post)
1049     ("nnfolder" mail respool))
1050   "An alist of valid select methods.
1051 The first element of each list lists should be a string with the name
1052 of the select method.  The other elements may be be the category of
1053 this method (ie. `post', `mail', `none' or whatever) or other
1054 properties that this method has (like being respoolable).
1055 If you implement a new select method, all you should have to change is
1056 this variable.  I think.")
1057
1058 (defvar gnus-updated-mode-lines '(group article summary)
1059   "*List of buffers that should update their mode lines.
1060 The list may contain the symbols `group', `article' and `summary'.  If
1061 the corresponding symbol is present, Gnus will keep that mode line
1062 updated with information that may be pertinent. 
1063 If this variable is nil, screen refresh may be quicker.")
1064
1065 ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
1066 (defvar gnus-mode-non-string-length 25
1067   "*Max length of mode-line non-string contents.
1068 If this is nil, Gnus will take space as is needed, leaving the rest
1069 of the modeline intact.")
1070
1071 ;see gnus-cus.el
1072 ;(defvar gnus-mouse-face 'highlight
1073 ;  "*Face used for mouse highlighting in Gnus.
1074 ;No mouse highlights will be done if `gnus-visual' is nil.")
1075
1076 (defvar gnus-summary-mark-below nil
1077   "*Mark all articles with a score below this variable as read.
1078 This variable is local to each summary buffer and usually set by the
1079 score file.")  
1080
1081 (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number)
1082   "*List of functions used for sorting threads in the summary buffer.
1083 By default, threads are sorted by article number.
1084
1085 Each function takes two threads and return non-nil if the first thread
1086 should be sorted before the other.  If you use more than one function,
1087 the primary sort function should be the last.
1088
1089 Ready-mady functions include `gnus-thread-sort-by-number',
1090 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
1091 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
1092 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').")
1093
1094 (defvar gnus-thread-score-function '+
1095   "*Function used for calculating the total score of a thread.
1096
1097 The function is called with the scores of the article and each
1098 subthread and should then return the score of the thread.
1099
1100 Some functions you can use are `+', `max', or `min'.")
1101
1102 (defvar gnus-auto-subscribed-groups 
1103   "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl"
1104   "*All new groups that match this regexp will be subscribed automatically.
1105 Note that this variable only deals with new groups.  It has no effect
1106 whatsoever on old groups.")
1107
1108 (defvar gnus-options-subscribe nil
1109   "*All new groups matching this regexp will be subscribed unconditionally.
1110 Note that this variable deals only with new newsgroups.  This variable
1111 does not affect old newsgroups.")
1112
1113 (defvar gnus-options-not-subscribe nil
1114   "*All new groups matching this regexp will be ignored.
1115 Note that this variable deals only with new newsgroups.  This variable
1116 does not affect old (already subscribed) newsgroups.")
1117
1118 (defvar gnus-auto-expirable-newsgroups nil
1119   "*Groups in which to automatically mark read articles as expirable.
1120 If non-nil, this should be a regexp that should match all groups in
1121 which to perform auto-expiry.  This only makes sense for mail groups.")
1122
1123 (defvar gnus-total-expirable-newsgroups nil
1124   "*Groups in which to perform expiry of all read articles.
1125 Use with extreme caution.  All groups that match this regexp will be
1126 expiring - which means that all read articles will be deleted after
1127 (say) one week.  (This only goes for mail groups and the like, of
1128 course.)")
1129
1130 (defvar gnus-hidden-properties '(invisible t intangible t)
1131   "Property list to use for hiding text.")
1132
1133 (defvar gnus-modtime-botch nil
1134   "*Non-nil means .newsrc should be deleted prior to save.  Its use is
1135 due to the bogus appearance that .newsrc was modified on disc.")
1136
1137 ;; Hooks.
1138
1139 (defvar gnus-group-mode-hook nil
1140   "*A hook for Gnus group mode.")
1141
1142 (defvar gnus-summary-mode-hook nil
1143   "*A hook for Gnus summary mode.
1144 This hook is run before any variables are set in the summary buffer.")
1145
1146 (defvar gnus-article-mode-hook nil
1147   "*A hook for Gnus article mode.")
1148
1149 (defun gnus-summary-prepare-exit-hook nil
1150   "*A hook called when preparing to exit from the summary buffer.
1151 It calls `gnus-summary-expire-articles' by default.")
1152 (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles)
1153
1154 (defun gnus-summary-exit-hook nil
1155   "*A hook called on exit from the summary buffer.")
1156
1157 (defvar gnus-open-server-hook nil
1158   "*A hook called just before opening connection to the news server.")
1159
1160 (defvar gnus-load-hook nil
1161   "*A hook run while Gnus is loaded.")
1162
1163 (defvar gnus-startup-hook nil
1164   "*A hook called at startup.
1165 This hook is called after Gnus is connected to the NNTP server.")
1166
1167 (defvar gnus-get-new-news-hook nil
1168   "*A hook run just before Gnus checks for new news.")
1169
1170 (defvar gnus-group-prepare-function 'gnus-group-prepare-flat
1171   "*A function that is called to generate the group buffer.
1172 The function is called with three arguments: The first is a number;
1173 all group with a level less or equal to that number should be listed,
1174 if the second is non-nil, empty groups should also be displayed.  If
1175 the third is non-nil, it is a number.  No groups with a level lower
1176 than this number should be displayed.
1177
1178 The only current function implemented are `gnus-group-prepare-flat'
1179 \(which does the normal boring group display) and
1180 `gnus-group-prepare-topics' (which does a folding display accoring to
1181 topics).")
1182
1183 (defvar gnus-group-prepare-hook nil
1184   "*A hook called after the group buffer has been generated.
1185 If you want to modify the group buffer, you can use this hook.")
1186
1187 (defvar gnus-summary-prepare-hook nil
1188   "*A hook called after the summary buffer has been generated.
1189 If you want to modify the summary buffer, you can use this hook.")
1190
1191 (defvar gnus-summary-generate-hook nil
1192   "*A hook run just before generating the summary buffer.
1193 This hook is commonly used to customize threading variables and the
1194 like.")
1195
1196 (defvar gnus-article-prepare-hook nil
1197   "*A hook called after an article has been prepared in the article buffer.
1198 If you want to run a special decoding program like nkf, use this hook.")
1199
1200 ;(defvar gnus-article-display-hook nil
1201 ;  "*A hook called after the article is displayed in the article buffer.
1202 ;The hook is designed to change the contents of the article
1203 ;buffer.  Typical functions that this hook may contain are
1204 ;`gnus-article-hide-headers' (hide selected headers),
1205 ;`gnus-article-maybe-highlight' (perform fancy article highlighting), 
1206 ;`gnus-article-hide-signature' (hide signature) and
1207 ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).")
1208 ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted)
1209 ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike)
1210 ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight)
1211
1212 (defvar gnus-article-x-face-command
1213   "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -"
1214   "String or function to be executed to display an X-Face header.
1215 If it is a string, the command will be executed in a sub-shell
1216 asynchronously.  The compressed face will be piped to this command.") 
1217
1218 (defvar gnus-article-x-face-too-ugly nil
1219   "Regexp matching posters whose face shouldn't be shown automatically.")
1220
1221 (defvar gnus-select-group-hook nil
1222   "*A hook called when a newsgroup is selected.
1223
1224 If you'd like to simplify subjects like the
1225 `gnus-summary-next-same-subject' command does, you can use the
1226 following hook:
1227
1228  (setq gnus-select-group-hook
1229       (list
1230         (lambda ()
1231           (mapcar (lambda (header)
1232                      (mail-header-set-subject
1233                       header
1234                       (gnus-simplify-subject
1235                        (mail-header-subject header) 're-only)))
1236                   gnus-newsgroup-headers))))")
1237
1238 (defvar gnus-select-article-hook
1239   '(gnus-summary-show-thread)
1240   "*A hook called when an article is selected.
1241 The default hook shows conversation thread subtrees of the selected
1242 article automatically using `gnus-summary-show-thread'.")
1243
1244 (defvar gnus-apply-kill-hook '(gnus-apply-kill-file)
1245   "*A hook called to apply kill files to a group.
1246 This hook is intended to apply a kill file to the selected newsgroup.
1247 The function `gnus-apply-kill-file' is called by default.
1248
1249 Since a general kill file is too heavy to use only for a few
1250 newsgroups, I recommend you to use a lighter hook function.  For
1251 example, if you'd like to apply a kill file to articles which contains
1252 a string `rmgroup' in subject in newsgroup `control', you can use the
1253 following hook:
1254
1255  (setq gnus-apply-kill-hook
1256       (list
1257         (lambda ()
1258           (cond ((string-match \"control\" gnus-newsgroup-name)
1259                  (gnus-kill \"Subject\" \"rmgroup\")
1260                  (gnus-expunge \"X\"))))))")
1261
1262 (defvar gnus-visual-mark-article-hook 
1263   (list 'gnus-highlight-selected-summary)
1264   "*Hook run after selecting an article in the summary buffer.
1265 It is meant to be used for highlighting the article in some way.  It
1266 is not run if `gnus-visual' is nil.")
1267
1268 (defvar gnus-exit-group-hook nil
1269   "*A hook called when exiting (not quitting) summary mode.")
1270
1271 (defvar gnus-suspend-gnus-hook nil
1272   "*A hook called when suspending (not exiting) Gnus.")
1273
1274 (defvar gnus-exit-gnus-hook nil
1275   "*A hook called when exiting Gnus.")
1276
1277 (defvar gnus-save-newsrc-hook nil
1278   "*A hook called before saving any of the newsrc files.")
1279
1280 (defvar gnus-save-quick-newsrc-hook nil
1281   "*A hook called just before saving the quick newsrc file.
1282 Can be used to turn version control on or off.")
1283
1284 (defvar gnus-save-standard-newsrc-hook nil
1285   "*A hook called just before saving the standard newsrc file.
1286 Can be used to turn version control on or off.")
1287
1288 (defvar gnus-summary-update-hook 
1289   (list 'gnus-summary-highlight-line)
1290   "*A hook called when a summary line is changed.
1291 The hook will not be called if `gnus-visual' is nil.
1292
1293 The default function `gnus-summary-highlight-line' will
1294 highlight the line according to the `gnus-summary-highlight'
1295 variable.")
1296
1297 (defvar gnus-mark-article-hook (list 'gnus-summary-mark-unread-as-read)
1298   "*A hook called when an article is selected for the first time.
1299 The hook is intended to mark an article as read (or unread)
1300 automatically when it is selected.")
1301
1302 ;; Remove any hilit infestation.
1303 (add-hook 'gnus-startup-hook
1304           (lambda ()
1305             (remove-hook 'gnus-summary-prepare-hook
1306                          'hilit-rehighlight-buffer-quietly)
1307             (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks)
1308             (setq gnus-mark-article-hook '(gnus-summary-mark-unread-as-read))
1309             (remove-hook 'gnus-article-prepare-hook
1310                          'hilit-rehighlight-buffer-quietly)))
1311
1312
1313 \f
1314 ;; Internal variables
1315
1316 ;; Avoid highlighting in kill files.
1317 (defvar gnus-summary-inhibit-highlight nil)
1318 (defvar gnus-newsgroup-selected-overlay nil)
1319
1320 (defvar gnus-inhibit-hiding nil)
1321
1322 (defvar gnus-article-mode-map nil)
1323 (defvar gnus-dribble-buffer nil)
1324 (defvar gnus-headers-retrieved-by nil)
1325 (defvar gnus-article-reply nil)
1326 (defvar gnus-override-method nil)
1327 (defvar gnus-article-check-size nil)
1328
1329 (defvar gnus-nocem-hashtb nil)
1330
1331 (defvar gnus-current-score-file nil)
1332 (defvar gnus-scores-exclude-files nil)
1333
1334 (defvar gnus-opened-servers nil)
1335
1336 (defvar gnus-current-move-group nil)
1337
1338 (defvar gnus-newsgroup-dependencies nil)
1339 (defvar gnus-newsgroup-async nil)
1340 (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*")
1341
1342 (defvar gnus-newsgroup-adaptive nil)
1343
1344 (defvar gnus-summary-display-table nil)
1345
1346 (defconst gnus-group-line-format-alist
1347   `((?M gnus-tmp-marked ?c)
1348     (?S gnus-tmp-subscribed ?c)
1349     (?L gnus-tmp-level ?d)
1350     (?N gnus-tmp-number ?s)
1351     (?R gnus-tmp-number-of-read ?s)
1352     (?t gnus-tmp-number-total ?d)
1353     (?y gnus-tmp-number-of-unread ?s)
1354     (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d)
1355     (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d)
1356     (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked)))
1357            (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d)
1358     (?g gnus-tmp-group ?s)
1359     (?G gnus-tmp-qualified-group ?s)
1360     (?D gnus-tmp-newsgroup-description ?s)
1361     (?o gnus-tmp-moderated ?c)
1362     (?O gnus-tmp-moderated-string ?s)
1363     (?p gnus-tmp-process-marked ?c)
1364     (?s gnus-tmp-news-server ?s)
1365     (?n gnus-tmp-news-method ?s)
1366     (?z gnus-tmp-news-method-string ?s)
1367     (?u gnus-tmp-user-defined ?s)))
1368
1369 (defconst gnus-summary-line-format-alist 
1370   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1371     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1372     (?s gnus-tmp-subject-or-nil ?s)
1373     (?n gnus-tmp-name ?s)
1374     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1375         ?s)
1376     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from)) 
1377             gnus-tmp-from) ?s)
1378     (?F gnus-tmp-from ?s)
1379     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1380     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1381     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1382     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1383     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1384     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1385     (?L gnus-tmp-lines ?d)
1386     (?I gnus-tmp-indentation ?s)
1387     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1388     (?R gnus-tmp-replied ?c)
1389     (?\[ gnus-tmp-opening-bracket ?c)
1390     (?\] gnus-tmp-closing-bracket ?c)
1391     (?\> (make-string gnus-tmp-level ? ) ?s)
1392     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1393     (?i gnus-tmp-score ?d)
1394     (?z gnus-tmp-score-char ?c)
1395     (?U gnus-tmp-unread ?c)
1396     (?t (gnus-summary-number-of-articles-in-thread 
1397          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1398         ?d)
1399     (?e (gnus-summary-number-of-articles-in-thread 
1400          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1401         ?c)
1402     (?u gnus-tmp-user-defined ?s))
1403   "An alist of format specifications that can appear in summary lines,
1404 and what variables they correspond with, along with the type of the
1405 variable (string, integer, character, etc).")
1406
1407 (defconst gnus-summary-dummy-line-format-alist
1408   (` ((?S gnus-tmp-subject ?s)
1409       (?N gnus-tmp-number ?d)
1410       (?u gnus-tmp-user-defined ?s))))
1411
1412 (defconst gnus-summary-mode-line-format-alist 
1413   (` ((?G gnus-tmp-group-name ?s)
1414       (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1415       (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1416       (?A gnus-tmp-article-number ?d)
1417       (?Z gnus-tmp-unread-and-unselected ?s)
1418       (?V gnus-version ?s)
1419       (?U gnus-tmp-unread ?d)
1420       (?S gnus-tmp-subject ?s)
1421       (?e gnus-tmp-unselected ?d)
1422       (?u gnus-tmp-user-defined ?s)
1423       (?d (length gnus-newsgroup-dormant) ?d)
1424       (?t (length gnus-newsgroup-marked) ?d)
1425       (?r (length gnus-newsgroup-reads) ?d)
1426       (?E gnus-newsgroup-expunged-tally ?d)
1427       (?s (gnus-current-score-file-nondirectory) ?s))))
1428
1429 (defconst gnus-group-mode-line-format-alist 
1430   (` ((?S gnus-tmp-news-server ?s)
1431       (?M gnus-tmp-news-method ?s)
1432       (?u gnus-tmp-user-defined ?s))))
1433
1434 (defvar gnus-have-read-active-file nil)
1435
1436 (defconst gnus-maintainer
1437   "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)"
1438   "The mail address of the Gnus maintainers.")
1439
1440 (defconst gnus-version "September Gnus v0.16"
1441   "Version number for this version of Gnus.")
1442
1443 (defvar gnus-info-nodes
1444   '((gnus-group-mode            "(gnus)The Group Buffer")
1445     (gnus-summary-mode          "(gnus)The Summary Buffer")
1446     (gnus-article-mode          "(gnus)The Article Buffer"))
1447   "Assoc list of major modes and related Info nodes.")
1448
1449 (defvar gnus-group-buffer "*Group*")
1450 (defvar gnus-summary-buffer "*Summary*")
1451 (defvar gnus-article-buffer "*Article*")
1452 (defvar gnus-server-buffer "*Server*")
1453
1454 (defvar gnus-work-buffer " *gnus work*")
1455
1456 (defvar gnus-original-article-buffer " *Original Article*")
1457 (defvar gnus-original-article nil)
1458
1459 (defvar gnus-buffer-list nil
1460   "Gnus buffers that should be killed on exit.")
1461
1462 (defvar gnus-server-alist nil
1463   "List of available servers.")
1464
1465 (defvar gnus-slave nil
1466   "Whether this Gnus is a slave or not.")
1467
1468 (defvar gnus-variable-list
1469   '(gnus-newsrc-options gnus-newsrc-options-n
1470     gnus-newsrc-last-checked-date 
1471     gnus-newsrc-alist gnus-server-alist
1472     gnus-killed-list gnus-zombie-list
1473     gnus-topic-topology)
1474   "Gnus variables saved in the quick startup file.")
1475
1476 (defvar gnus-newsrc-options nil
1477   "Options line in the .newsrc file.")
1478
1479 (defvar gnus-newsrc-options-n nil
1480   "List of regexps representing groups to be subscribed/ignored unconditionally.") 
1481
1482 (defvar gnus-newsrc-last-checked-date nil
1483   "Date Gnus last asked server for new newsgroups.")
1484
1485 (defvar gnus-topic-topology nil
1486   "The complete topic hierarchy.")
1487
1488 (defvar gnus-newsrc-alist nil
1489   "Assoc list of read articles.
1490 gnus-newsrc-hashtb should be kept so that both hold the same information.")
1491
1492 (defvar gnus-newsrc-hashtb nil
1493   "Hashtable of gnus-newsrc-alist.")
1494
1495 (defvar gnus-killed-list nil
1496   "List of killed newsgroups.")
1497
1498 (defvar gnus-killed-hashtb nil
1499   "Hash table equivalent of gnus-killed-list.")
1500
1501 (defvar gnus-zombie-list nil
1502   "List of almost dead newsgroups.")
1503
1504 (defvar gnus-description-hashtb nil
1505   "Descriptions of newsgroups.")
1506
1507 (defvar gnus-list-of-killed-groups nil
1508   "List of newsgroups that have recently been killed by the user.")
1509
1510 (defvar gnus-active-hashtb nil
1511   "Hashtable of active articles.")
1512
1513 (defvar gnus-moderated-list nil
1514   "List of moderated newsgroups.")
1515
1516 (defvar gnus-group-marked nil)
1517
1518 (defvar gnus-current-startup-file nil
1519   "Startup file for the current host.")
1520
1521 (defvar gnus-last-search-regexp nil
1522   "Default regexp for article search command.")
1523
1524 (defvar gnus-last-shell-command nil
1525   "Default shell command on article.")
1526
1527 (defvar gnus-current-select-method nil
1528   "The current method for selecting a newsgroup.")
1529
1530 (defvar gnus-group-list-mode nil)
1531
1532 (defvar gnus-article-internal-prepare-hook nil)
1533
1534 (defvar gnus-newsgroup-name nil)
1535 (defvar gnus-newsgroup-begin nil)
1536 (defvar gnus-newsgroup-end nil)
1537 (defvar gnus-newsgroup-last-rmail nil)
1538 (defvar gnus-newsgroup-last-mail nil)
1539 (defvar gnus-newsgroup-last-folder nil)
1540 (defvar gnus-newsgroup-last-file nil)
1541 (defvar gnus-newsgroup-auto-expire nil)
1542 (defvar gnus-newsgroup-active nil)
1543
1544 (defvar gnus-newsgroup-data nil)
1545 (defvar gnus-newsgroup-data-reverse nil)
1546 (defvar gnus-newsgroup-limit nil)
1547 (defvar gnus-newsgroup-limits nil)
1548
1549 (defvar gnus-newsgroup-unreads nil
1550   "List of unread articles in the current newsgroup.")
1551
1552 (defvar gnus-newsgroup-unselected nil
1553   "List of unselected unread articles in the current newsgroup.")
1554
1555 (defvar gnus-newsgroup-reads nil
1556   "Alist of read articles and article marks in the current newsgroup.")
1557
1558 (defvar gnus-newsgroup-expunged-tally nil)
1559
1560 (defvar gnus-newsgroup-marked nil
1561   "List of ticked articles in the current newsgroup (a subset of unread art).")
1562
1563 (defvar gnus-newsgroup-killed nil
1564   "List of ranges of articles that have been through the scoring process.")
1565
1566 (defvar gnus-newsgroup-kill-headers nil)
1567
1568 (defvar gnus-newsgroup-replied nil
1569   "List of articles that have been replied to in the current newsgroup.")
1570
1571 (defvar gnus-newsgroup-expirable nil
1572   "List of articles in the current newsgroup that can be expired.")
1573
1574 (defvar gnus-newsgroup-processable nil
1575   "List of articles in the current newsgroup that can be processed.")
1576
1577 (defvar gnus-newsgroup-bookmarks nil
1578   "List of articles in the current newsgroup that have bookmarks.")
1579
1580 (defvar gnus-newsgroup-dormant nil
1581   "List of dormant articles in the current newsgroup.")
1582
1583 (defvar gnus-newsgroup-scored nil
1584   "List of scored articles in the current newsgroup.")
1585
1586 (defvar gnus-newsgroup-headers nil
1587   "List of article headers in the current newsgroup.")
1588
1589 (defvar gnus-newsgroup-threads nil)
1590
1591 (defvar gnus-newsgroup-prepared nil
1592   "Whether the current group has been prepared properly.")
1593
1594 (defvar gnus-newsgroup-ancient nil
1595   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1596
1597 (defvar gnus-current-article nil)
1598 (defvar gnus-article-current nil)
1599 (defvar gnus-current-headers nil)
1600 (defvar gnus-have-all-headers nil)
1601 (defvar gnus-last-article nil)
1602 (defvar gnus-newsgroup-history nil)
1603 (defvar gnus-current-kill-article nil)
1604
1605 ;; Save window configuration.
1606 (defvar gnus-prev-winconf nil)
1607
1608 (defvar gnus-summary-mark-positions nil)
1609 (defvar gnus-group-mark-positions nil)
1610
1611 (defvar gnus-summary-expunge-below nil)
1612 (defvar gnus-reffed-article-number nil)
1613
1614 ;;; Let the byte-compiler know that we know about this variable.
1615 (defvar rmail-default-rmail-file)
1616
1617 (defvar gnus-cache-removeable-articles nil)
1618
1619 (defconst gnus-summary-local-variables 
1620   '(gnus-newsgroup-name 
1621     gnus-newsgroup-begin gnus-newsgroup-end 
1622     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail 
1623     gnus-newsgroup-last-folder gnus-newsgroup-last-file 
1624     gnus-newsgroup-auto-expire gnus-newsgroup-unreads 
1625     gnus-newsgroup-unselected gnus-newsgroup-marked
1626     gnus-newsgroup-reads
1627     gnus-newsgroup-replied gnus-newsgroup-expirable
1628     gnus-newsgroup-processable gnus-newsgroup-killed
1629     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1630     gnus-newsgroup-headers gnus-newsgroup-threads
1631     gnus-newsgroup-prepared
1632     gnus-current-article gnus-current-headers gnus-have-all-headers
1633     gnus-last-article gnus-article-internal-prepare-hook
1634     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1635     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1636     gnus-newsgroup-async
1637     gnus-score-alist gnus-current-score-file gnus-summary-expunge-below 
1638     gnus-summary-mark-below gnus-newsgroup-active gnus-scores-exclude-files
1639     gnus-newsgroup-history gnus-newsgroup-ancient
1640     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1641     (gnus-newsgroup-expunged-tally . 0)
1642     gnus-cache-removeable-articles
1643     gnus-newsgroup-data gnus-newsgroup-data-reverse
1644     gnus-newsgroup-limit gnus-newsgroup-limits)
1645   "Variables that are buffer-local to the summary buffers.")
1646
1647 (defconst gnus-bug-message
1648   "Sending a bug report to the Gnus Towers.
1649 ========================================
1650
1651 The buffer below is a mail buffer.  When you press `C-c C-c', it will
1652 be sent to the Gnus Bug Exterminators. 
1653
1654 At the bottom of the buffer you'll see lots of variable settings.
1655 Please do not delete those.  They will tell the Bug People what your
1656 environment is, so that it will be easier to locate the bugs.
1657
1658 If you have found a bug that makes Emacs go \"beep\", set
1659 debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET') 
1660 and include the backtrace in your bug report.
1661
1662 Please describe the bug in annoying, painstaking detail.
1663
1664 Thank you for your help in stamping out bugs.
1665 ")
1666
1667 ;;; End of variables.
1668
1669 ;; Define some autoload functions Gnus might use.
1670 (eval-and-compile
1671
1672   ;; This little mapcar goes through the list below and marks the
1673   ;; symbols in question as autoloaded functions.
1674   (mapcar 
1675    (lambda (package)
1676      (let ((interactive (nth 1 (memq ':interactive package))))
1677        (mapcar 
1678         (lambda (function)
1679           (let (keymap)
1680             (when (consp function)
1681               (setq keymap (car (memq 'keymap function)))
1682               (setq function (car function)))
1683             (autoload function (car package) nil interactive keymap)))
1684         (if (eq (nth 1 package) ':interactive)
1685             (cdddr package)
1686           (cdr package)))))
1687    '(("metamail" metamail-buffer)
1688      ("info" Info-goto-node)
1689      ("hexl" hexl-hex-string-to-integer)
1690      ("pp" pp pp-to-string pp-eval-expression)
1691      ("mail-extr" mail-extract-address-components)
1692      ("nnmail" nnmail-split-fancy nnmail-article-group)
1693      ("nnvirtual" nnvirtual-catchup-group)
1694      ("timezone" timezone-make-date-arpa-standard timezone-fix-time
1695       timezone-make-sortable-date timezone-make-time-string)
1696      ("sendmail" mail-position-on-field mail-setup)
1697      ("rmailout" rmail-output)
1698      ("rnewspost" news-mail-other-window news-reply-yank-original 
1699       news-caesar-buffer-body)
1700      ("rmail" rmail-insert-rmail-file-header rmail-count-new-messages
1701       rmail-show-message)
1702      ("gnus-soup" :interactive t
1703       gnus-group-brew-soup gnus-brew-soup gnus-soup-add-article 
1704       gnus-soup-send-replies gnus-soup-save-areas gnus-soup-pack-packet)
1705      ("nnsoup" nnsoup-pack-replies)
1706      ("gnus-mh" gnus-mh-mail-setup gnus-summary-save-article-folder 
1707       gnus-Folder-save-name gnus-folder-save-name)
1708      ("gnus-mh" :interactive t gnus-summary-save-in-folder)
1709      ("gnus-vis" gnus-group-make-menu-bar gnus-summary-make-menu-bar
1710       gnus-server-make-menu-bar gnus-article-make-menu-bar
1711       gnus-browse-make-menu-bar gnus-highlight-selected-summary
1712       gnus-summary-highlight-line gnus-carpal-setup-buffer
1713       gnus-article-add-button)
1714      ("gnus-vis" :interactive t
1715       gnus-article-push-button gnus-article-press-button 
1716       gnus-article-highlight gnus-article-highlight-some 
1717       gnus-article-hide gnus-article-hide-signature 
1718       gnus-article-highlight-headers gnus-article-highlight-signature 
1719       gnus-article-add-buttons gnus-article-add-buttons-to-head 
1720       gnus-article-next-button)
1721      ("gnus-demon" gnus-demon-add-nocem gnus-demon-add-scanmail
1722       gnus-demon-add-disconnection gnus-demon-add-handler
1723       gnus-demon-remove-handler)
1724      ("gnus-demon" :interactive t
1725       gnus-demon-init gnus-demon-cancel)
1726      ("gnus-nocem" gnus-nocem-scan-groups gnus-nocem-close)
1727      ("gnus-srvr" gnus-enter-server-buffer gnus-server-set-info)
1728      ("gnus-cite" :interactive t
1729       gnus-article-highlight-citation gnus-article-hide-citation-maybe 
1730       gnus-article-hide-citation)
1731      ("gnus-kill" gnus-kill gnus-apply-kill-file-internal 
1732       gnus-kill-file-edit-file gnus-kill-file-raise-followups-to-author 
1733       gnus-execute gnus-expunge)
1734      ("gnus-cache" gnus-cache-possibly-enter-article gnus-cache-save-buffers
1735       gnus-cache-possibly-remove-articles gnus-cache-request-article
1736       gnus-cache-retrieve-headers gnus-cache-possibly-alter-active
1737       gnus-cache-enter-remove-article)
1738      ("gnus-cache" :interactive t gnus-jog-cache)
1739      ("gnus-score" :interactive t
1740       gnus-summary-increase-score gnus-summary-lower-score
1741       gnus-score-flush-cache gnus-score-close 
1742       gnus-score-raise-same-subject-and-select 
1743       gnus-score-raise-same-subject gnus-score-default 
1744       gnus-score-raise-thread gnus-score-lower-same-subject-and-select 
1745       gnus-score-lower-same-subject gnus-score-lower-thread 
1746       gnus-possibly-score-headers)
1747      ("gnus-score" 
1748       (gnus-summary-score-map keymap) gnus-score-save gnus-score-headers
1749       gnus-current-score-file-nondirectory gnus-score-adaptive
1750       gnus-score-find-trace gnus-score-file-name)
1751      ("gnus-edit" :interactive t gnus-score-customize)
1752      ("gnus-topic" :interactive t gnus-topic-mode)
1753      ("gnus-uu" (gnus-uu-extract-map keymap) (gnus-uu-mark-map keymap))
1754      ("gnus-uu" :interactive t
1755       gnus-uu-digest-mail-forward gnus-uu-digest-post-forward 
1756       gnus-uu-mark-series gnus-uu-mark-region 
1757       gnus-uu-mark-by-regexp gnus-uu-mark-all 
1758       gnus-uu-mark-sparse gnus-uu-mark-thread gnus-uu-decode-uu 
1759       gnus-uu-decode-uu-and-save gnus-uu-decode-unshar 
1760       gnus-uu-decode-unshar-and-save gnus-uu-decode-save 
1761       gnus-uu-decode-binhex gnus-uu-decode-uu-view 
1762       gnus-uu-decode-uu-and-save-view gnus-uu-decode-unshar-view 
1763       gnus-uu-decode-unshar-and-save-view gnus-uu-decode-save-view 
1764       gnus-uu-decode-binhex-view)
1765      ("gnus-msg" (gnus-summary-send-map keymap)
1766       gnus-mail-yank-original gnus-mail-send-and-exit
1767       gnus-sendmail-setup-mail gnus-article-mail 
1768       gnus-inews-message-id)
1769      ("gnus-msg" :interactive t
1770       gnus-group-post-news gnus-group-mail gnus-summary-post-news
1771       gnus-summary-followup gnus-summary-followup-with-original
1772       gnus-summary-followup-and-reply
1773       gnus-summary-followup-and-reply-with-original
1774       gnus-summary-cancel-article gnus-summary-supersede-article
1775       gnus-post-news gnus-inews-news gnus-cancel-news
1776       gnus-summary-reply gnus-summary-reply-with-original
1777       gnus-summary-mail-forward gnus-summary-mail-other-window
1778       gnus-bug)
1779      ("gnus-vm" gnus-vm-mail-setup)
1780      ("gnus-vm" :interactive t gnus-summary-save-in-vm
1781       gnus-summary-save-article-vm gnus-yank-article))))
1782
1783 \f
1784
1785 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1786 ;; If you want the cursor to go somewhere else, set these two
1787 ;; functions in some startup hook to whatever you want.
1788 (defalias 'gnus-summary-position-point 'gnus-goto-colon)
1789 (defalias 'gnus-group-position-point 'gnus-goto-colon)
1790
1791 ;;; Various macros and substs.
1792
1793 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
1794   "Pop to BUFFER, evaluate FORMS, and then return to the original window."
1795   `(let ((GnusStartBufferWindow (selected-window)))
1796      (unwind-protect
1797          (progn
1798            (pop-to-buffer ,buffer)
1799            ,@forms)
1800        (select-window GnusStartBufferWindow))))
1801
1802 (defmacro gnus-gethash (string hashtable)
1803   "Get hash value of STRING in HASHTABLE."
1804   `(symbol-value (intern-soft ,string ,hashtable)))
1805
1806 (defmacro gnus-sethash (string value hashtable)
1807   "Set hash value.  Arguments are STRING, VALUE, and HASHTABLE."
1808   `(set (intern ,string ,hashtable) ,value))
1809
1810 (defmacro gnus-intern-safe (string hashtable)
1811   "Set hash value.  Arguments are STRING, VALUE, and HASHTABLE."
1812   `(let ((symbol (intern ,string ,hashtable)))
1813      (or (boundp symbol)
1814          (setq symbol nil))
1815      symbol))
1816
1817 (defmacro gnus-group-unread (group)
1818   "Get the currently computed number of unread articles in GROUP."
1819   `(car (gnus-gethash ,group gnus-newsrc-hashtb)))
1820
1821 (defmacro gnus-active (group)
1822   "Get active info on GROUP."
1823   `(gnus-gethash ,group gnus-active-hashtb))
1824
1825 (defmacro gnus-set-active (group active)
1826   "Set GROUP's active info."
1827   `(gnus-sethash ,group ,active gnus-active-hashtb))
1828
1829 ;; modified by MORIOKA Tomohiko <morioka@jaist.ac.jp>
1830 ;;   function `substring' might cut on a middle of multi-octet
1831 ;;   character.
1832 (defun gnus-truncate-string (str width)
1833   (substring str 0 width))
1834
1835 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>.  A safe way
1836 ;; to limit the length of a string.  This function is necessary since
1837 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
1838 (defsubst gnus-limit-string (str width)
1839   (if (> (length str) width)
1840       (substring str 0 width)
1841     str))
1842
1843 (defsubst gnus-simplify-subject-re (subject)
1844   "Remove \"Re:\" from subject lines."
1845   (if (string-match "^[Rr][Ee]: *" subject)
1846       (substring subject (match-end 0))
1847     subject))
1848
1849 (defsubst gnus-goto-char (point)
1850   (and point (goto-char point)))
1851
1852 (defmacro gnus-buffer-exists-p (buffer)
1853   `(and ,buffer
1854         (funcall (if (stringp ,buffer) 'get-buffer 'buffer-name)
1855                  ,buffer)))
1856
1857 (defmacro gnus-kill-buffer (buffer)
1858   `(let ((buf ,buffer))
1859      (if (gnus-buffer-exists-p buf)
1860          (kill-buffer buf))))
1861
1862 (defsubst gnus-point-at-bol ()
1863   "Return point at the beginning of the line."
1864   (let ((p (point)))
1865     (beginning-of-line)
1866     (prog1
1867         (point)
1868       (goto-char p))))
1869
1870 (defsubst gnus-point-at-eol ()
1871   "Return point at the end of the line."
1872   (let ((p (point)))
1873     (end-of-line)
1874     (prog1
1875         (point)
1876       (goto-char p))))
1877
1878 ;; Delete the current line (and the next N lines.);
1879 (defmacro gnus-delete-line (&optional n)
1880   `(delete-region (progn (beginning-of-line) (point))
1881                   (progn (forward-line ,(or n 1)) (point))))
1882
1883 ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
1884 (defvar gnus-init-inhibit nil)
1885 (defun gnus-read-init-file (&optional inhibit-next)
1886   (if gnus-init-inhibit
1887       (setq gnus-init-inhibit nil)
1888     (setq gnus-init-inhibit inhibit-next)
1889     (and gnus-init-file
1890          (or (and (file-exists-p gnus-init-file) 
1891                   ;; Don't try to load a directory.
1892                   (not (file-directory-p gnus-init-file)))
1893              (file-exists-p (concat gnus-init-file ".el"))
1894              (file-exists-p (concat gnus-init-file ".elc")))
1895          (load gnus-init-file nil t))))
1896
1897 ;; Info access macros.
1898
1899 (defmacro gnus-info-group (info)
1900   `(nth 0 ,info))
1901 (defmacro gnus-info-rank (info)
1902   `(nth 1 ,info))
1903 (defmacro gnus-info-read (info)
1904   `(nth 2 ,info))
1905 (defmacro gnus-info-marks (info)
1906   `(nth 3 ,info))
1907 (defmacro gnus-info-method (info)
1908   `(nth 4 ,info))
1909 (defmacro gnus-info-params (info)
1910   `(nth 5 ,info))
1911
1912 (defmacro gnus-info-level (info)
1913   `(let ((rank (gnus-info-rank ,info)))
1914      (if (consp rank)
1915          (car rank)
1916        rank)))
1917 (defmacro gnus-info-score (info)
1918   `(let ((rank (gnus-info-rank ,info)))
1919      (or (and (consp rank) (cdr rank)) 0)))
1920
1921 (defmacro gnus-info-set-group (info group)
1922   `(setcar ,info ,group))
1923 (defmacro gnus-info-set-rank (info rank)
1924   `(setcar (nthcdr 1 ,info) ,rank))
1925 (defmacro gnus-info-set-read (info read)
1926   `(setcar (nthcdr 2 ,info) ,read))
1927 (defmacro gnus-info-set-marks (info marks)
1928   `(setcar (nthcdr 3 ,info) ,marks))
1929 (defmacro gnus-info-set-method (info method)
1930   `(setcar (nthcdr 4 ,info) ,method))
1931 (defmacro gnus-info-set-params (info params)
1932   `(setcar (nthcdr 5 ,info) ,params))
1933
1934 (defmacro gnus-info-set-level (info level)
1935   `(let ((rank (cdr ,info)))
1936      (if (consp (car rank))
1937          (setcar (car rank) ,level)
1938        (setcar rank ,level))))
1939 (defmacro gnus-info-set-score (info score)
1940   `(let ((rank (cdr ,info)))
1941      (if (consp (car rank))
1942          (setcdr (car rank) ,score)
1943        (setcar rank (cons (car rank) ,score)))))
1944
1945 (defmacro gnus-get-info (group)
1946   `(nth 2 (gnus-gethash ,group gnus-newsrc-hashtb)))
1947
1948 (defun gnus-byte-code (func)
1949   "Return a form that can be `eval'ed based on FUNC."
1950   (let ((fval (symbol-function func)))
1951     (if (byte-code-function-p fval)
1952         (let ((flist (append fval nil)))
1953           (setcar flist 'byte-code)
1954           flist)
1955       (cons 'progn (cdr (cdr fval))))))
1956
1957 ;;; Load the user startup file.
1958 ;; (eval '(gnus-read-init-file 'inhibit))
1959
1960 ;;; Load the compatability functions. 
1961
1962 (require 'gnus-cus)
1963 (require 'gnus-ems)
1964
1965 \f
1966
1967 ;; Format specs.  The chunks below are the machine-generated forms
1968 ;; that are to be evaled as the result of the default format strings.
1969 ;; We write them in here to get them byte-compiled.  That way the
1970 ;; default actions will be quite fast, while still retaining the full
1971 ;; flexibility of the user-defined format specs. 
1972
1973 ;; First we have lots of dummy defvars to let the compiler know these
1974 ;; are really dynamic variables.
1975
1976 (defvar gnus-tmp-unread)
1977 (defvar gnus-tmp-replied)
1978 (defvar gnus-tmp-score-char)
1979 (defvar gnus-tmp-indentation)
1980 (defvar gnus-tmp-opening-bracket)
1981 (defvar gnus-tmp-lines)
1982 (defvar gnus-tmp-name)
1983 (defvar gnus-tmp-closing-bracket)
1984 (defvar gnus-tmp-subject-or-nil)
1985 (defvar gnus-tmp-subject)
1986 (defvar gnus-tmp-marked)
1987 (defvar gnus-tmp-subscribed)
1988 (defvar gnus-tmp-process-marked)
1989 (defvar gnus-tmp-number-of-unread)
1990 (defvar gnus-tmp-group-name)
1991 (defvar gnus-tmp-group)
1992 (defvar gnus-tmp-article-number)
1993 (defvar gnus-tmp-unread-and-unselected)
1994 (defvar gnus-tmp-news-method)
1995 (defvar gnus-tmp-news-server)
1996 (defvar gnus-tmp-article-number)
1997 (defvar gnus-mouse-face)
1998 (defvar gnus-mouse-face-prop)
1999
2000 (defun gnus-summary-line-format-spec ()
2001   (insert gnus-tmp-unread gnus-tmp-replied 
2002           gnus-tmp-score-char gnus-tmp-indentation)
2003   (put-text-property
2004    (point)
2005    (progn
2006      (insert 
2007       gnus-tmp-opening-bracket 
2008       (format "%4d: %-20s" 
2009               gnus-tmp-lines 
2010               (if (> (length gnus-tmp-name) 20) 
2011                   (substring gnus-tmp-name 0 20) 
2012                 gnus-tmp-name))
2013       gnus-tmp-closing-bracket)
2014      (point))
2015    gnus-mouse-face-prop gnus-mouse-face)
2016   (insert " " gnus-tmp-subject-or-nil "\n"))
2017
2018 (defvar gnus-summary-line-format-spec 
2019   (gnus-byte-code 'gnus-summary-line-format-spec))
2020
2021 (defun gnus-summary-dummy-line-format-spec ()
2022   (insert "*  :                          : " gnus-tmp-subject "\n"))
2023 (defvar gnus-summary-dummy-line-format-spec 
2024   (gnus-byte-code 'gnus-summary-dummy-line-format-spec))
2025
2026 (defun gnus-group-line-format-spec ()
2027   (insert gnus-tmp-marked gnus-tmp-subscribed 
2028           gnus-tmp-process-marked
2029           (format "%5s: " gnus-tmp-number-of-unread))
2030   (put-text-property 
2031    (point)
2032    (progn
2033      (insert gnus-tmp-group "\n")
2034      (1- (point)))
2035    gnus-mouse-face-prop gnus-mouse-face))
2036 (defvar gnus-group-line-format-spec 
2037   (gnus-byte-code 'gnus-group-line-format-spec))
2038
2039 (defun gnus-summary-mode-line-format-spec ()
2040   (format "Gnus  %s/%d %s" gnus-tmp-group-name
2041           gnus-tmp-article-number gnus-tmp-unread-and-unselected))
2042 (defvar gnus-summary-mode-line-format-spec
2043   (gnus-byte-code 'gnus-summary-mode-line-format-spec))
2044
2045 (defun gnus-group-mode-line-format-spec ()
2046   (format "Gnus  List of groups   {%s:%s}  "
2047           gnus-tmp-news-method gnus-tmp-news-server))
2048 (defvar gnus-group-mode-line-format-spec 
2049   (gnus-byte-code 'gnus-group-mode-line-format-spec))
2050
2051 (defun gnus-article-mode-line-format-spec ()
2052   (format "Gnus  %s/%d %s" gnus-tmp-group-name
2053           gnus-tmp-article-number gnus-tmp-subject))
2054 (defvar gnus-article-mode-line-format-spec
2055   (gnus-byte-code 'gnus-article-mode-line-format-spec))
2056
2057 (defvar gnus-old-specs 
2058   '((article-mode . "Gnus  %G/%A %S")
2059     (group-mode . "Gnus  List of groups   {%M:%S}  ")
2060     (summary-mode . "Gnus  %G/%A %Z")
2061     (group . "%M%S%p%5y: %(%g%)\n")
2062     (summary-dummy . "*  :                          : %S\n")
2063     (summary . "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n")))
2064
2065 ;;; Phew.  All that gruft is over, fortunately.  
2066
2067 \f
2068 ;;;
2069 ;;; Gnus Utility Functions
2070 ;;;
2071
2072 (defun gnus-extract-address-components (from)
2073   (let (name address)
2074     ;; First find the address - the thing with the @ in it.  This may
2075     ;; not be accurate in mail addresses, but does the trick most of
2076     ;; the time in news messages.
2077     (if (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
2078         (setq address (substring from (match-beginning 0) (match-end 0))))
2079     ;; Then we check whether the "name <address>" format is used.
2080     (and address
2081          ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>
2082          ;; Linear white space is not required.
2083          (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
2084          (and (setq name (substring from 0 (match-beginning 0)))
2085               ;; Strip any quotes from the name.
2086               (string-match "\".*\"" name)
2087               (setq name (substring name 1 (1- (match-end 0))))))
2088     ;; If not, then "address (name)" is used.
2089     (or name
2090         (and (string-match "(.+)" from)
2091              (setq name (substring from (1+ (match-beginning 0)) 
2092                                    (1- (match-end 0)))))
2093         (and (string-match "()" from)
2094              (setq name address))
2095         ;; Fix by MORIOKA Tomohiko <morioka@jaist.ac.jp>.
2096         ;; XOVER might not support folded From headers.
2097         (and (string-match "(.*" from)
2098              (setq name (substring from (1+ (match-beginning 0)) 
2099                                    (match-end 0)))))
2100     ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
2101     (list (or name from) (or address from))))
2102
2103 (defun gnus-fetch-field (field)
2104   "Return the value of the header FIELD of current article."
2105   (save-excursion
2106     (save-restriction
2107       (let ((case-fold-search t))
2108         (gnus-narrow-to-headers)
2109         (mail-fetch-field field)))))
2110
2111 (defun gnus-goto-colon ()
2112   (beginning-of-line)
2113   (search-forward ":" (gnus-point-at-eol) t))
2114
2115 (defun gnus-narrow-to-headers ()
2116   "Narrow to the head of an article."
2117   (widen)
2118   (narrow-to-region
2119    (goto-char (point-min))
2120    (if (search-forward "\n\n" nil t)
2121        (1- (point))
2122      (point-max)))
2123   (goto-char (point-min)))
2124
2125 ;;;###autoload
2126 (defun gnus-update-format (var)
2127   "Update the format specification near point."
2128   (interactive
2129    (list
2130     (save-excursion
2131       (eval-defun nil)
2132       ;; Find the end of the current word.
2133       (re-search-forward "[ \t\n]" nil t)
2134       ;; Search backward.
2135       (when (re-search-backward "\\(gnus-[-a-z]+-line-format\\)" nil t)
2136         (match-string 1)))))
2137   (set
2138    (intern (format "%s-spec" var))
2139    (gnus-parse-format (symbol-value (intern var))
2140                       (symbol-value (intern (format "%s-alist" var)))
2141                       (not (string-match "mode" var))))
2142   (pop-to-buffer "*Gnus Format*")
2143   (erase-buffer)
2144   (lisp-interaction-mode)
2145   (insert (pp-to-string (symbol-value (intern (format "%s-spec" var))))))
2146
2147
2148 (defun gnus-update-format-specifications (&optional force)
2149   (gnus-make-thread-indent-array)
2150
2151   (when force
2152     (setq gnus-old-specs nil))
2153
2154   (let ((formats '(summary summary-dummy group 
2155                            summary-mode group-mode article-mode))
2156         old-format new-format)
2157     (while formats
2158       (setq new-format (symbol-value
2159                         (intern (format "gnus-%s-line-format" (car formats)))))
2160       (or (and (setq old-format (cdr (assq (car formats) gnus-old-specs)))
2161                (equal old-format new-format))
2162           (set (intern (format "gnus-%s-line-format-spec" (car formats)))
2163                (if (not (stringp new-format)) new-format
2164                  (gnus-parse-format
2165                   new-format
2166                   (symbol-value 
2167                    (intern (format "gnus-%s-line-format-alist"
2168                                    (if (eq (car formats) 'article-mode)
2169                                        'summary-mode (car formats)))))
2170                   (not (string-match "mode$" (symbol-name (car formats))))))))
2171       (setq gnus-old-specs (cons (cons (car formats) new-format)
2172                                  (delq (assq (car formats) gnus-old-specs)
2173                                        gnus-old-specs)))
2174       (setq formats (cdr formats))))
2175       
2176   (gnus-update-group-mark-positions)
2177   (gnus-update-summary-mark-positions)
2178
2179   (if (and (string-match "%D" gnus-group-line-format)
2180            (not gnus-description-hashtb)
2181            gnus-read-active-file)
2182       (gnus-read-all-descriptions-files)))
2183
2184 (defun gnus-update-summary-mark-positions ()
2185   (save-excursion
2186     (let ((gnus-replied-mark 129)
2187           (gnus-score-below-mark 130)
2188           (gnus-score-over-mark 130)
2189           (thread nil)
2190           pos)
2191       (gnus-set-work-buffer)
2192       (gnus-summary-insert-line 
2193        [0 "" "" "" "" "" 0 0 ""]  0 nil 128 t nil "" nil 1)
2194       (goto-char (point-min))
2195       (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2196                                          (- (point) 2)))))
2197       (goto-char (point-min))
2198       (setq pos (cons (cons 'replied (and (search-forward "\201" nil t)
2199                                           (- (point) 2))) pos))
2200       (goto-char (point-min))
2201       (setq pos (cons (cons 'score (and (search-forward "\202" nil t)
2202                                         (- (point) 2))) pos))
2203       (setq gnus-summary-mark-positions pos))))
2204
2205 (defun gnus-update-group-mark-positions ()
2206   (save-excursion
2207     (let ((gnus-process-mark 128)
2208           (gnus-group-marked '("dummy.group")))
2209       (gnus-set-active "dummy.group" '(0 . 0))
2210       (gnus-set-work-buffer)
2211       (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil)
2212       (goto-char (point-min))
2213       (setq gnus-group-mark-positions
2214             (list (cons 'process (and (search-forward "\200" nil t)
2215                                       (- (point) 2))))))))
2216
2217 (defvar gnus-mouse-face-0 'highlight)
2218 (defvar gnus-mouse-face-1 'highlight)
2219 (defvar gnus-mouse-face-2 'highlight)
2220 (defvar gnus-mouse-face-3 'highlight)
2221 (defvar gnus-mouse-face-4 'highlight)
2222
2223 (defun gnus-mouse-face-function (form type)
2224   `(put-text-property
2225     (point) (progn ,@form (point))
2226     gnus-mouse-face-prop 
2227     ,(if (equal type 0)
2228          'gnus-mouse-face
2229        `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type)))))))
2230
2231 (defvar gnus-face-0 'bold)
2232 (defvar gnus-face-1 'italic)
2233 (defvar gnus-face-2 'bold-italic)
2234 (defvar gnus-face-3 'bold)
2235 (defvar gnus-face-4 'bold)
2236
2237 (defun gnus-face-face-function (form type)
2238   `(put-text-property
2239     (point) (progn ,@form (point))
2240     'face ',(symbol-value (intern (format "gnus-face-%d" type)))))
2241
2242 (defun gnus-max-width-function (el max-width)
2243   (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width)))
2244   (if (symbolp el)
2245       `(if (> (length ,el) ,max-width)
2246            (substring ,el 0 ,max-width)
2247          ,el)
2248     `(let ((val (eval ,el)))
2249        (if (numberp val)
2250            (setq val (int-to-string val)))
2251        (if (> (length val) ,max-width)
2252            (substring val 0 ,max-width))
2253        val)))
2254
2255 (defun gnus-parse-format (format spec-alist &optional insert)
2256   ;; This function parses the FORMAT string with the help of the
2257   ;; SPEC-ALIST and returns a list that can be eval'ed to return the
2258   ;; string.  If the FORMAT string contains the specifiers %( and %)
2259   ;; the text between them will have the mouse-face text property.
2260   (if (string-match 
2261        "\\`\\(.*\\)%[0-9]?[[(]\\(.*\\)%[0-9]?[])]\\(.*\n?\\)\\'"
2262        format)
2263       (gnus-parse-complex-format format spec-alist)
2264     ;; This is a simple format.
2265     (gnus-parse-simple-format format spec-alist insert)))
2266
2267 (defun gnus-parse-complex-format (format spec-alist)
2268   (save-excursion
2269     (gnus-set-work-buffer)
2270     (insert format)
2271     (goto-char (point-min))
2272     (while (re-search-forward "\"" nil t)
2273       (replace-match "\\\"" nil t))
2274     (goto-char (point-min))
2275     (insert "(\"")
2276     (while (re-search-forward "%\\([0-9]+\\)?\\([][()]\\)" nil t)
2277       (let ((number (if (match-beginning 1)
2278                         (match-string 1) "0"))
2279             (delim (aref (match-string 2) 0)))
2280         (if (or (= delim ?\() (= delim ?\[))
2281             (replace-match (concat "\"(" (if (= delim ?\() "mouse" "face")
2282                                    " " number " \""))
2283           (replace-match "\")\""))))
2284     (goto-char (point-max))
2285     (insert "\")")
2286     (goto-char (point-min))
2287     (let ((form (read (current-buffer))))
2288       (cons 'progn (gnus-complex-form-to-spec form spec-alist)))))
2289
2290 (defun gnus-complex-form-to-spec (form spec-alist)
2291   (delq nil
2292         (mapcar
2293          (lambda (sform)
2294            (if (stringp sform)
2295                (gnus-parse-simple-format sform spec-alist t)
2296              (funcall (intern (format "gnus-%s-face-function"
2297                                       (car sform)))
2298                       (gnus-complex-form-to-spec 
2299                        (cdr (cdr sform)) spec-alist)
2300                       (nth 1 sform))))
2301          form)))
2302     
2303 (defun gnus-parse-simple-format (format spec-alist &optional insert)
2304   ;; This function parses the FORMAT string with the help of the
2305   ;; SPEC-ALIST and returns a list that can be eval'ed to return a
2306   ;; string.  
2307   (let ((max-width 0)
2308         spec flist fstring newspec elem beg result dontinsert)
2309     (save-excursion
2310       (gnus-set-work-buffer)
2311       (insert format)
2312       (goto-char (point-min))
2313       (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?"
2314                                 nil t)
2315         (setq spec (string-to-char (match-string 2)))
2316         ;; First check if there are any specs that look anything like
2317         ;; "%12,12A", ie. with a "max width specification".  These have
2318         ;; to be treated specially.
2319         (if (setq beg (match-beginning 1))
2320             (setq max-width 
2321                   (string-to-int 
2322                    (buffer-substring (1+ (match-beginning 1)) (match-end 1))))
2323           (setq max-width 0)
2324           (setq beg (match-beginning 2)))
2325         ;; Find the specification from `spec-alist'.
2326         (unless (setq elem (cdr (assq spec spec-alist)))
2327           (setq elem '("*" ?s)))
2328         ;; Treat user defined format specifiers specially.
2329         (when (eq (car elem) 'gnus-tmp-user-defined)
2330           (setq elem
2331                 (list 
2332                  (list (intern (concat "gnus-user-format-function-"
2333                                        (match-string 3)))
2334                        'gnus-tmp-header) ?s))
2335           (delete-region (match-beginning 3) (match-end 3)))
2336         (if (not (zerop max-width))
2337             (let ((el (car elem)))
2338               (cond ((= (car (cdr elem)) ?c) 
2339                      (setq el (list 'char-to-string el)))
2340                     ((= (car (cdr elem)) ?d)
2341                      (numberp el) (setq el (list 'int-to-string el))))
2342               (setq flist (cons (gnus-max-width-function el max-width)
2343                                 flist))
2344               (setq newspec ?s))
2345           (setq flist (cons (car elem) flist))
2346           (setq newspec (car (cdr elem))))
2347         ;; Remove the old specification (and possibly a ",12" string).
2348         (delete-region beg (match-end 2))
2349         ;; Insert the new specification.
2350         (goto-char beg)
2351         (insert newspec))
2352       (setq fstring (buffer-substring 1 (point-max))))
2353     ;; Do some postprocessing to increase efficiency.
2354     (setq 
2355      result
2356      (cond 
2357       ;; Emptyness.
2358       ((string= fstring "")
2359        nil)
2360       ;; Not a format string.
2361       ((not (string-match "%" fstring))
2362        (list fstring))
2363       ;; A format string with just a single string spec.
2364       ((string= fstring "%s")
2365        (list (car flist)))
2366       ;; A single character.
2367       ((string= fstring "%c")
2368        (list (car flist)))
2369       ;; A single number.
2370       ((string= fstring "%d")
2371        (setq dontinsert)
2372        (if insert
2373            (list `(princ ,(car flist)))
2374          (list `(int-to-string ,(car flist)))))
2375       ;; Just lots of chars and strings.
2376       ((string-match "\\`\\(%[cs]\\)+\\'" fstring)
2377        (nreverse flist))
2378       ;; A single string spec at the beginning of the spec.
2379       ((string-match "\\`%[sc][^%]+\\'" fstring)
2380        (list (car flist) (substring fstring 2)))
2381       ;; A single string spec in the middle of the spec.
2382       ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring)
2383        (list (match-string 1 fstring) (car flist) (match-string 2 fstring)))
2384       ;; A single string spec in the end of the spec.
2385       ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring)
2386        (list (match-string 1 fstring) (car flist)))
2387       ;; A more complex spec.
2388       (t
2389        (list (cons 'format (cons fstring (nreverse flist)))))))
2390
2391     (if insert
2392         (when result
2393           (if dontinsert
2394               result
2395             (cons 'insert result)))
2396       (or (car result) ""))))
2397
2398 (defun gnus-set-work-buffer ()
2399   (if (get-buffer gnus-work-buffer)
2400       (progn
2401         (set-buffer gnus-work-buffer)
2402         (erase-buffer))
2403     (set-buffer (get-buffer-create gnus-work-buffer))
2404     (kill-all-local-variables)
2405     (buffer-disable-undo (current-buffer))
2406     (gnus-add-current-to-buffer-list)))
2407
2408 ;; Article file names when saving.
2409
2410 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
2411   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2412 If variable `gnus-use-long-file-name' is nil, it is ~/News/News.group/num.
2413 Otherwise, it is like ~/News/news/group/num."
2414   (let ((default
2415           (expand-file-name
2416            (concat (if (gnus-use-long-file-name 'not-save)
2417                        (gnus-capitalize-newsgroup newsgroup)
2418                      (gnus-newsgroup-directory-form newsgroup))
2419                    "/" (int-to-string (mail-header-number headers)))
2420            (or gnus-article-save-directory "~/News"))))
2421     (if (and last-file
2422              (string-equal (file-name-directory default)
2423                            (file-name-directory last-file))
2424              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2425         default
2426       (or last-file default))))
2427
2428 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
2429   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2430 If variable `gnus-use-long-file-name' is non-nil, it is
2431 ~/News/news.group/num.  Otherwise, it is like ~/News/news/group/num."
2432   (let ((default
2433           (expand-file-name
2434            (concat (if (gnus-use-long-file-name 'not-save)
2435                        newsgroup
2436                      (gnus-newsgroup-directory-form newsgroup))
2437                    "/" (int-to-string (mail-header-number headers)))
2438            (or gnus-article-save-directory "~/News"))))
2439     (if (and last-file
2440              (string-equal (file-name-directory default)
2441                            (file-name-directory last-file))
2442              (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
2443         default
2444       (or last-file default))))
2445
2446 (defun gnus-Plain-save-name (newsgroup headers &optional last-file)
2447   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2448 If variable `gnus-use-long-file-name' is non-nil, it is
2449 ~/News/News.group.  Otherwise, it is like ~/News/news/group/news."
2450   (or last-file
2451       (expand-file-name
2452        (if (gnus-use-long-file-name 'not-save)
2453            (gnus-capitalize-newsgroup newsgroup)
2454          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2455        (or gnus-article-save-directory "~/News"))))
2456
2457 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
2458   "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
2459 If variable `gnus-use-long-file-name' is non-nil, it is
2460 ~/News/news.group.  Otherwise, it is like ~/News/news/group/news."
2461   (or last-file
2462       (expand-file-name
2463        (if (gnus-use-long-file-name 'not-save)
2464            newsgroup
2465          (concat (gnus-newsgroup-directory-form newsgroup) "/news"))
2466        (or gnus-article-save-directory "~/News"))))
2467
2468 ;; For subscribing new newsgroup
2469
2470 (defun gnus-subscribe-hierarchical-interactive (groups)
2471   (let ((groups (sort groups 'string<))
2472         prefixes prefix start ans group starts)
2473     (while groups
2474       (setq prefixes (list "^"))
2475       (while (and groups prefixes)
2476         (while (not (string-match (car prefixes) (car groups)))
2477           (setq prefixes (cdr prefixes)))
2478         (setq prefix (car prefixes))
2479         (setq start (1- (length prefix)))
2480         (if (and (string-match "[^\\.]\\." (car groups) start)
2481                  (cdr groups)
2482                  (setq prefix 
2483                        (concat "^" (substring (car groups) 0 (match-end 0))))
2484                  (string-match prefix (car (cdr groups))))
2485             (progn
2486               (setq prefixes (cons prefix prefixes))
2487               (message "Descend hierarchy %s? ([y]nsq): " 
2488                        (substring prefix 1 (1- (length prefix))))
2489               (setq ans (read-char))
2490               (cond ((= ans ?n)
2491                      (while (and groups 
2492                                  (string-match prefix 
2493                                                (setq group (car groups))))
2494                        (setq gnus-killed-list 
2495                              (cons group gnus-killed-list))
2496                        (gnus-sethash group group gnus-killed-hashtb)
2497                        (setq groups (cdr groups)))
2498                      (setq starts (cdr starts)))
2499                     ((= ans ?s)
2500                      (while (and groups 
2501                                  (string-match prefix 
2502                                                (setq group (car groups))))
2503                        (gnus-sethash group group gnus-killed-hashtb)
2504                        (gnus-subscribe-alphabetically (car groups))
2505                        (setq groups (cdr groups)))
2506                      (setq starts (cdr starts)))
2507                     ((= ans ?q)
2508                      (while groups
2509                        (setq group (car groups))
2510                        (setq gnus-killed-list (cons group gnus-killed-list))
2511                        (gnus-sethash group group gnus-killed-hashtb)
2512                        (setq groups (cdr groups))))
2513                     (t nil)))
2514           (message "Subscribe %s? ([n]yq)" (car groups))
2515           (setq ans (read-char))
2516           (setq group (car groups))
2517           (cond ((= ans ?y)
2518                  (gnus-subscribe-alphabetically (car groups))
2519                  (gnus-sethash group group gnus-killed-hashtb))
2520                 ((= ans ?q)
2521                  (while groups
2522                    (setq group (car groups))
2523                    (setq gnus-killed-list (cons group gnus-killed-list))
2524                    (gnus-sethash group group gnus-killed-hashtb)
2525                    (setq groups (cdr groups))))
2526                 (t 
2527                  (setq gnus-killed-list (cons group gnus-killed-list))
2528                  (gnus-sethash group group gnus-killed-hashtb)))
2529           (setq groups (cdr groups)))))))
2530
2531 (defun gnus-subscribe-randomly (newsgroup)
2532   "Subscribe new NEWSGROUP by making it the first newsgroup."
2533   (gnus-subscribe-newsgroup newsgroup))
2534
2535 (defun gnus-subscribe-alphabetically (newgroup)
2536   "Subscribe new NEWSGROUP and insert it in alphabetical order."
2537   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2538   (let ((groups (cdr gnus-newsrc-alist))
2539         before)
2540     (while (and (not before) groups)
2541       (if (string< newgroup (car (car groups)))
2542           (setq before (car (car groups)))
2543         (setq groups (cdr groups))))
2544     (gnus-subscribe-newsgroup newgroup before)))
2545
2546 (defun gnus-subscribe-hierarchically (newgroup)
2547   "Subscribe new NEWSGROUP and insert it in hierarchical newsgroup order."
2548   ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams)
2549   (save-excursion
2550     (set-buffer (find-file-noselect gnus-current-startup-file))
2551     (let ((groupkey newgroup)
2552           before)
2553       (while (and (not before) groupkey)
2554         (goto-char (point-min))
2555         (let ((groupkey-re
2556                (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]")))
2557           (while (and (re-search-forward groupkey-re nil t)
2558                       (progn
2559                         (setq before (match-string 1))
2560                         (string< before newgroup)))))
2561         ;; Remove tail of newsgroup name (eg. a.b.c -> a.b)
2562         (setq groupkey
2563               (if (string-match "^\\(.*\\)\\.[^.]+$" groupkey)
2564                   (substring groupkey (match-beginning 1) (match-end 1)))))
2565       (gnus-subscribe-newsgroup newgroup before))))
2566
2567 (defun gnus-subscribe-interactively (newsgroup)
2568   "Subscribe new NEWSGROUP interactively.
2569 It is inserted in hierarchical newsgroup order if subscribed.  If not,
2570 it is killed."
2571   (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup))
2572       (gnus-subscribe-hierarchically newsgroup)
2573     (setq gnus-killed-list (cons newsgroup gnus-killed-list))))
2574
2575 (defun gnus-subscribe-zombies (newsgroup)
2576   "Make new NEWSGROUP a zombie group."
2577   (setq gnus-zombie-list (cons newsgroup gnus-zombie-list)))
2578
2579 (defun gnus-subscribe-newsgroup (newsgroup &optional next)
2580   "Subscribe new NEWSGROUP.
2581 If NEXT is non-nil, it is inserted before NEXT.  Otherwise it is made
2582 the first newsgroup."
2583   ;; We subscribe the group by changing its level to `subscribed'.
2584   (gnus-group-change-level 
2585    newsgroup gnus-level-default-subscribed
2586    gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb))
2587   (gnus-message 5 "Subscribe newsgroup: %s" newsgroup))
2588
2589 ;; For directories
2590
2591 (defun gnus-newsgroup-directory-form (newsgroup)
2592   "Make hierarchical directory name from NEWSGROUP name."
2593   (let ((newsgroup (gnus-newsgroup-saveable-name newsgroup))
2594         (len (length newsgroup))
2595         idx)
2596     ;; If this is a foreign group, we don't want to translate the
2597     ;; entire name.  
2598     (if (setq idx (string-match ":" newsgroup))
2599         (aset newsgroup idx ?/)
2600       (setq idx 0))
2601     ;; Replace all occurrences of `.' with `/'.
2602     (while (< idx len)
2603       (if (= (aref newsgroup idx) ?.)
2604           (aset newsgroup idx ?/))
2605       (setq idx (1+ idx)))
2606     newsgroup))
2607
2608 (defun gnus-newsgroup-saveable-name (group)
2609   ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
2610   ;; with dots.
2611   (gnus-replace-chars-in-string group ?/ ?.))
2612
2613 (defun gnus-make-directory (dir)
2614   "Make DIRECTORY recursively."
2615   ;; Why don't we use `(make-directory dir 'parents)'? That's just one
2616   ;; of the many mysteries of the universe.
2617   (let* ((dir (expand-file-name dir default-directory))
2618          dirs err)
2619     (if (string-match "/$" dir)
2620         (setq dir (substring dir 0 (match-beginning 0))))
2621     ;; First go down the path until we find a directory that exists.
2622     (while (not (file-exists-p dir))
2623       (setq dirs (cons dir dirs))
2624       (string-match "/[^/]+$" dir)
2625       (setq dir (substring dir 0 (match-beginning 0))))
2626     ;; Then create all the subdirs.
2627     (while (and dirs (not err))
2628       (condition-case ()
2629           (make-directory (car dirs))
2630         (error (setq err t)))
2631       (setq dirs (cdr dirs)))
2632     ;; We return whether we were successful or not. 
2633     (not dirs)))
2634
2635 (defun gnus-capitalize-newsgroup (newsgroup)
2636   "Capitalize NEWSGROUP name."
2637   (and (not (zerop (length newsgroup)))
2638        (concat (char-to-string (upcase (aref newsgroup 0)))
2639                (substring newsgroup 1))))
2640
2641 ;; Var
2642
2643 (defun gnus-simplify-subject (subject &optional re-only)
2644   "Remove `Re:' and words in parentheses.
2645 If optional argument RE-ONLY is non-nil, strip `Re:' only."
2646   (let ((case-fold-search t))           ;Ignore case.
2647     ;; Remove `Re:' and `Re^N:'.
2648     (if (string-match "^re:[ \t]*" subject)
2649         (setq subject (substring subject (match-end 0))))
2650     ;; Remove words in parentheses from end.
2651     (or re-only
2652         (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
2653           (setq subject (substring subject 0 (match-beginning 0)))))
2654     ;; Return subject string.
2655     subject))
2656
2657 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
2658 ;; all whitespace.
2659 ;; Written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
2660 (defun gnus-simplify-buffer-fuzzy ()
2661   (goto-char (point-min))
2662   (while (or
2663           (looking-at "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*")
2664           (looking-at "^[[].*:[ \t].*[]]$"))
2665     (goto-char (point-min))
2666     (while (re-search-forward "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*"
2667                               nil t)
2668       (replace-match "" t t))
2669     (goto-char (point-min))
2670     (while (re-search-forward "^[[].*:[ \t].*[]]$" nil t)
2671       (goto-char (match-end 0))
2672       (delete-char -1)
2673       (delete-region 
2674        (progn (goto-char (match-beginning 0)))
2675        (re-search-forward ":"))))
2676   (goto-char (point-min))
2677   (while (re-search-forward "[ \t\n]*([^()]*)[ \t]*$" nil t)
2678     (replace-match "" t t))
2679   (goto-char (point-min))
2680   (while (re-search-forward "[ \t]+" nil t)
2681     (replace-match " " t t))
2682   (goto-char (point-min))
2683   (while (re-search-forward "[ \t]+$" nil t)
2684     (replace-match "" t t))
2685   (goto-char (point-min))
2686   (while (re-search-forward "^[ \t]+" nil t)
2687     (replace-match "" t t))
2688   (goto-char (point-min))
2689   (if gnus-simplify-subject-fuzzy-regexp
2690       (if (listp gnus-simplify-subject-fuzzy-regexp)
2691           (let ((list gnus-simplify-subject-fuzzy-regexp))
2692             (while list
2693               (goto-char (point-min))
2694               (while (re-search-forward (car list) nil t)
2695                 (replace-match "" t t))
2696               (setq list (cdr list))))
2697         (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t)
2698           (replace-match "" t t)))))
2699
2700 (defun gnus-simplify-subject-fuzzy (subject)
2701   "Siplify a subject string fuzzily."
2702   (let ((case-fold-search t))
2703     (save-excursion
2704       (gnus-set-work-buffer)
2705       (insert subject)
2706       (inline (gnus-simplify-buffer-fuzzy))
2707       (buffer-string))))
2708
2709 ;; Add the current buffer to the list of buffers to be killed on exit. 
2710 (defun gnus-add-current-to-buffer-list ()
2711   (or (memq (current-buffer) gnus-buffer-list)
2712       (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list))))
2713
2714 (defun gnus-string> (s1 s2)
2715   (not (or (string< s1 s2)
2716            (string= s1 s2))))
2717
2718 ;; Functions accessing headers.
2719 ;; Functions are more convenient than macros in some cases.
2720
2721 (defun gnus-header-number (header)
2722   (mail-header-number header))
2723
2724 (defun gnus-header-subject (header)
2725   (mail-header-subject header))
2726
2727 (defun gnus-header-from (header)
2728   (mail-header-from header))
2729
2730 (defun gnus-header-xref (header)
2731   (mail-header-xref header))
2732
2733 (defun gnus-header-lines (header)
2734   (mail-header-lines header))
2735
2736 (defun gnus-header-date (header)
2737   (mail-header-date header))
2738
2739 (defun gnus-header-id (header)
2740   (mail-header-id header))
2741
2742 (defun gnus-header-message-id (header)
2743   (mail-header-id header))
2744
2745 (defun gnus-header-chars (header)
2746   (mail-header-chars header))
2747
2748 (defun gnus-header-references (header)
2749   (mail-header-references header))
2750
2751 ;;; General various misc type functions.
2752
2753 (defun gnus-clear-system ()
2754   "Clear all variables and buffers."
2755   ;; Clear Gnus variables.
2756   (let ((variables gnus-variable-list))
2757     (while variables
2758       (set (car variables) nil)
2759       (setq variables (cdr variables))))
2760   ;; Clear other internal variables.
2761   (setq gnus-list-of-killed-groups nil
2762         gnus-have-read-active-file nil
2763         gnus-newsrc-alist nil
2764         gnus-newsrc-hashtb nil
2765         gnus-killed-list nil
2766         gnus-zombie-list nil
2767         gnus-killed-hashtb nil
2768         gnus-active-hashtb nil
2769         gnus-moderated-list nil
2770         gnus-description-hashtb nil
2771         gnus-newsgroup-headers nil
2772         gnus-newsgroup-name nil
2773         gnus-server-alist nil
2774         gnus-opened-servers nil
2775         gnus-current-select-method nil)
2776   ;; Reset any score variables.
2777   (and gnus-use-scoring (gnus-score-close))
2778   ;; Kill the startup file.
2779   (and gnus-current-startup-file
2780        (get-file-buffer gnus-current-startup-file)
2781        (kill-buffer (get-file-buffer gnus-current-startup-file)))
2782   ;; Save any cache buffers.
2783   (and gnus-use-cache (gnus-cache-save-buffers))
2784   ;; Clear the dribble buffer.
2785   (gnus-dribble-clear)
2786   ;; Close down NoCeM.
2787   (and gnus-use-nocem (gnus-nocem-close))
2788   ;; Shut down the demons.
2789   (and gnus-use-demon (gnus-demon-cancel))
2790   ;; Kill global KILL file buffer.
2791   (if (get-file-buffer (gnus-newsgroup-kill-file nil))
2792       (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil))))
2793   (gnus-kill-buffer nntp-server-buffer)
2794   ;; Kill Gnus buffers.
2795   (while gnus-buffer-list
2796     (gnus-kill-buffer (car gnus-buffer-list))
2797     (setq gnus-buffer-list (cdr gnus-buffer-list))))
2798
2799 (defun gnus-windows-old-to-new (setting)
2800   ;; First we take care of the really, really old Gnus 3 actions.
2801   (if (symbolp setting)
2802       (setq setting 
2803             (cond ((memq setting '(SelectArticle))
2804                    'article)
2805                   ((memq setting '(SelectSubject ExpandSubject))
2806                    'summary)
2807                   ((memq setting '(SelectNewsgroup ExitNewsgroup))
2808                    'group)
2809                   (t setting))))
2810   (if (or (listp setting)
2811           (not (and gnus-window-configuration
2812                     (memq setting '(group summary article)))))
2813       setting
2814     (let* ((setting (if (eq setting 'group) 
2815                         (if (assq 'newsgroup gnus-window-configuration)
2816                             'newsgroup
2817                           'newsgroups) setting))
2818            (elem (car (cdr (assq setting gnus-window-configuration))))
2819            (total (apply '+ elem))
2820            (types '(group summary article))
2821            (pbuf (if (eq setting 'newsgroups) 'group 'summary))
2822            (i 0)
2823            perc
2824            out)
2825       (while (< i 3)
2826         (or (not (numberp (nth i elem)))
2827             (zerop (nth i elem))
2828             (progn
2829               (setq perc  (/ (* 1.0 (nth 0 elem)) total))
2830               (setq out (cons (if (eq pbuf (nth i types))
2831                                   (vector (nth i types) perc 'point)
2832                                 (vector (nth i types) perc))
2833                               out))))
2834         (setq i (1+ i)))
2835       (list (nreverse out)))))
2836            
2837 (defun gnus-add-configuration (conf)
2838   (setq gnus-buffer-configuration 
2839         (cons conf (delq (assq (car conf) gnus-buffer-configuration)
2840                          gnus-buffer-configuration))))
2841
2842 (defun gnus-configure-windows (setting &optional force)
2843   (setq setting (gnus-windows-old-to-new setting))
2844   (let ((r (if (symbolp setting)
2845                (cdr (assq setting gnus-buffer-configuration))
2846              setting))
2847         (in-buf (current-buffer))
2848         rule val w height hor ohor heights sub jump-buffer
2849         rel total to-buf all-visible)
2850     (or r (error "No such setting: %s" setting))
2851
2852     (if (and (not force) (setq all-visible (gnus-all-windows-visible-p r)))
2853         ;; All the windows mentioned are already visible, so we just
2854         ;; put point in the assigned buffer, and do not touch the
2855         ;; winconf. 
2856         (select-window (get-buffer-window all-visible t))
2857          
2858
2859       ;; Either remove all windows or just remove all Gnus windows.
2860       (if gnus-use-full-window
2861           (delete-other-windows)
2862         (gnus-remove-some-windows)
2863         (switch-to-buffer nntp-server-buffer))
2864
2865       (while r
2866         (setq hor (car r)
2867               ohor nil)
2868
2869         ;; We have to do the (possible) horizontal splitting before the
2870         ;; vertical. 
2871         (if (and (listp (car hor)) 
2872                  (eq (car (car hor)) 'horizontal))
2873             (progn
2874               (split-window 
2875                nil
2876                (if (integerp (nth 1 (car hor)))
2877                    (nth 1 (car hor))
2878                  (- (frame-width) (floor (* (frame-width) (nth 1 (car hor))))))
2879                t)
2880               (setq hor (cdr hor))))
2881
2882         ;; Go through the rules and eval the elements that are to be
2883         ;; evaled.  
2884         (while hor
2885           (if (setq val (if (vectorp (car hor)) (car hor) (eval (car hor))))
2886               (progn
2887                 ;; Expand short buffer name.
2888                 (setq w (aref val 0))
2889                 (and (setq w (cdr (assq w gnus-window-to-buffer)))
2890                      (progn
2891                        (setq val (apply 'vector (mapcar 'identity val)))
2892                        (aset val 0 w)))
2893                 (setq ohor (cons val ohor))))
2894           (setq hor (cdr hor)))
2895         (setq rule (cons (nreverse ohor) rule))
2896         (setq r (cdr r)))
2897       (setq rule (nreverse rule))
2898
2899       ;; We tally the window sizes.
2900       (setq total (window-height))
2901       (while rule
2902         (setq hor (car rule))
2903         (if (and (listp (car hor)) (eq (car (car hor)) 'horizontal))
2904             (setq hor (cdr hor)))
2905         (setq sub 0)
2906         (while hor
2907           (setq rel (aref (car hor) 1)
2908                 heights (cons
2909                          (cond ((and (floatp rel) (= 1.0 rel))
2910                                 'x)
2911                                ((integerp rel)
2912                                 rel)
2913                                (t
2914                                 (max (floor (* total rel)) 4)))
2915                          heights)
2916                 sub (+ sub (if (numberp (car heights)) (car heights) 0))
2917                 hor (cdr hor)))
2918         (setq heights (nreverse heights)
2919               hor (car rule))
2920
2921         ;; We then go through these heighs and create windows for them.
2922         (while heights
2923           (setq height (car heights)
2924                 heights (cdr heights))
2925           (and (eq height 'x)
2926                (setq height (- total sub)))
2927           (and heights
2928                (split-window nil height))
2929           (setq to-buf (aref (car hor) 0))
2930           (switch-to-buffer 
2931            (cond ((not to-buf)
2932                   in-buf)
2933                  ((symbolp to-buf)
2934                   (symbol-value (aref (car hor) 0)))
2935                  (t
2936                   (aref (car hor) 0))))
2937           (and (> (length (car hor)) 2)
2938                (eq (aref (car hor) 2) 'point)
2939                (setq jump-buffer (current-buffer)))
2940           (other-window 1)
2941           (setq hor (cdr hor)))
2942       
2943         (setq rule (cdr rule)))
2944
2945       ;; Finally, we pop to the buffer that's supposed to have point. 
2946       (or jump-buffer (error "Missing `point' in spec for %s" setting))
2947
2948       (select-window (get-buffer-window jump-buffer t))
2949       (set-buffer jump-buffer))))
2950
2951 (defun gnus-all-windows-visible-p (rule)
2952   (let (invisible hor jump-buffer val buffer)
2953     ;; Go through the rules and eval the elements that are to be
2954     ;; evaled.  
2955     (while (and rule (not invisible))
2956       (setq hor (car rule)
2957             rule (cdr rule))
2958       (while (and hor (not invisible))
2959         (if (setq val (if (vectorp (car hor)) 
2960                           (car hor)
2961                         (if (not (eq (car (car hor)) 'horizontal))
2962                             (eval (car hor)))))
2963             (progn
2964               ;; Expand short buffer name.
2965               (setq buffer (or (cdr (assq (aref val 0) gnus-window-to-buffer))
2966                                (aref val 0)))
2967               (setq buffer (if (symbolp buffer) (symbol-value buffer)
2968                              buffer))
2969               (and (> (length val) 2) (eq 'point (aref val 2))
2970                    (setq jump-buffer buffer))
2971               (setq invisible (not (and buffer (get-buffer-window buffer))))))
2972         (setq hor (cdr hor))))
2973     (and (not invisible) jump-buffer)))
2974
2975 (defun gnus-window-top-edge (&optional window)
2976   (nth 1 (window-edges window)))
2977
2978 (defun gnus-remove-some-windows ()
2979   (let ((buffers gnus-window-to-buffer)
2980         buf bufs lowest-buf lowest)
2981     (save-excursion
2982       ;; Remove windows on all known Gnus buffers.
2983       (while buffers
2984         (setq buf (cdr (car buffers)))
2985         (if (symbolp buf)
2986             (setq buf (and (boundp buf) (symbol-value buf))))
2987         (and buf 
2988              (get-buffer-window buf)
2989              (progn
2990                (setq bufs (cons buf bufs))
2991                (pop-to-buffer buf)
2992                (if (or (not lowest)
2993                        (< (gnus-window-top-edge) lowest))
2994                    (progn
2995                      (setq lowest (gnus-window-top-edge))
2996                      (setq lowest-buf buf)))))
2997         (setq buffers (cdr buffers)))
2998       ;; Remove windows on *all* summary buffers.
2999       (let (wins)
3000         (walk-windows
3001          (lambda (win)
3002            (let ((buf (window-buffer win)))
3003              (if (string-match  "^\\*Summary" (buffer-name buf))
3004                  (progn
3005                    (setq bufs (cons buf bufs))
3006                    (pop-to-buffer buf)
3007                    (if (or (not lowest)
3008                            (< (gnus-window-top-edge) lowest))
3009                        (progn
3010                          (setq lowest-buf buf)
3011                          (setq lowest (gnus-window-top-edge))))))))))
3012       (and lowest-buf 
3013            (progn
3014              (pop-to-buffer lowest-buf)
3015              (switch-to-buffer nntp-server-buffer)))
3016       (while bufs
3017         (and (not (eq (car bufs) lowest-buf))
3018              (delete-windows-on (car bufs)))
3019         (setq bufs (cdr bufs))))))
3020                           
3021 (defun gnus-version ()
3022   "Version numbers of this version of Gnus."
3023   (interactive)
3024   (let ((methods gnus-valid-select-methods)
3025         (mess gnus-version)
3026         meth)
3027     ;; Go through all the legal select methods and add their version
3028     ;; numbers to the total version string.  Only the backends that are
3029     ;; currently in use will have their message numbers taken into
3030     ;; consideration. 
3031     (while methods
3032       (setq meth (intern (concat (car (car methods)) "-version")))
3033       (and (boundp meth)
3034            (stringp (symbol-value meth))
3035            (setq mess (concat mess "; " (symbol-value meth))))
3036       (setq methods (cdr methods)))
3037     (gnus-message 2 mess)))
3038
3039 (defun gnus-info-find-node ()
3040   "Find Info documentation of Gnus."
3041   (interactive)
3042   ;; Enlarge info window if needed.
3043   (let ((mode major-mode))
3044     (gnus-configure-windows 'info)
3045     (Info-goto-node (car (cdr (assq mode gnus-info-nodes))))))
3046
3047 (defun gnus-replace-chars-in-string (string &rest pairs)
3048   "Replace characters in STRING from FROM to TO."
3049   (let ((string (substring string 0))   ;Copy string.
3050         (len (length string))
3051         (idx 0)
3052         sym to)
3053     (or (zerop (% (length pairs) 2)) 
3054         (error "Odd number of translation pairs"))
3055     (setplist 'sym pairs)
3056     ;; Replace all occurrences of FROM with TO.
3057     (while (< idx len)
3058       (if (setq to (get 'sym (aref string idx)))
3059           (aset string idx to))
3060       (setq idx (1+ idx)))
3061     string))
3062
3063 (defun gnus-days-between (date1 date2)
3064   ;; Return the number of days between date1 and date2.
3065   (- (gnus-day-number date1) (gnus-day-number date2)))
3066
3067 (defun gnus-day-number (date)
3068   (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) )
3069                      (timezone-parse-date date))))
3070     (timezone-absolute-from-gregorian 
3071      (nth 1 dat) (nth 2 dat) (car dat))))
3072
3073 ;; Returns a floating point number that says how many seconds have
3074 ;; lapsed between Jan 1 12:00:00 1970 and DATE.
3075 (defun gnus-seconds-since-epoch (date)
3076   (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti)))
3077                         (timezone-parse-date date)))
3078          (ttime (mapcar (lambda (ti) (and ti (string-to-int ti)))
3079                         (timezone-parse-time
3080                          (aref (timezone-parse-date date) 3))))
3081          (edate (mapcar (lambda (ti) (and ti (string-to-int ti)))
3082                         (timezone-parse-date "Jan 1 12:00:00 1970")))
3083          (tday (- (timezone-absolute-from-gregorian 
3084                    (nth 1 tdate) (nth 2 tdate) (nth 0 tdate))
3085                   (timezone-absolute-from-gregorian 
3086                    (nth 1 edate) (nth 2 edate) (nth 0 edate)))))
3087     (+ (nth 2 ttime)
3088        (* (nth 1 ttime) 60)
3089        (* 1.0 (nth 0 ttime) 60 60)
3090        (* 1.0 tday 60 60 24))))
3091
3092 (defun gnus-file-newer-than (file date)
3093   (let ((fdate (nth 5 (file-attributes file))))
3094     (or (> (car fdate) (car date))
3095         (and (= (car fdate) (car date))
3096              (> (nth 1 fdate) (nth 1 date))))))
3097
3098 (defun gnus-group-read-only-p (&optional group)
3099   "Check whether GROUP supports editing or not.
3100 If GROUP is nil, `gnus-newsgroup-name' will be checked instead.  Note
3101 that that variable is buffer-local to the summary buffers."
3102   (let ((group (or group gnus-newsgroup-name)))
3103     (not (gnus-check-backend-function 'request-replace-article group))))
3104
3105 (defun gnus-group-total-expirable-p (group)
3106   "Check whether GROUP is total-expirable or not."
3107   (let ((params (gnus-info-params (gnus-get-info group))))
3108     (or (memq 'total-expire params) 
3109         (cdr (assq 'total-expire params)) ; (total-expire . t)
3110         (and gnus-total-expirable-newsgroups ; Check var.
3111              (string-match gnus-total-expirable-newsgroups group)))))
3112
3113 (defun gnus-group-auto-expirable-p (group)
3114   "Check whether GROUP is total-expirable or not."
3115   (let ((params (gnus-info-params (gnus-get-info group))))
3116     (or (memq 'auto-expire params) 
3117         (cdr (assq 'auto-expire params)) ; (auto-expire . t)
3118         (and gnus-auto-expirable-newsgroups ; Check var.
3119              (string-match gnus-auto-expirable-newsgroups group)))))
3120
3121 (defun gnus-subject-equal (s1 s2)
3122   "Check whether two subjects are equal."
3123   (cond
3124    ((null gnus-summary-gather-subject-limit)
3125     (equal (gnus-simplify-subject-re s1)
3126            (gnus-simplify-subject-re s2)))
3127    ((eq gnus-summary-gather-subject-limit 'fuzzy)
3128     (equal (gnus-simplify-subject-fuzzy s1)
3129            (gnus-simplify-subject-fuzzy s2)))
3130    ((numberp gnus-summary-gather-subject-limit)
3131     (equal (gnus-limit-string s1 gnus-summary-gather-subject-limit)
3132            (gnus-limit-string s2 gnus-summary-gather-subject-limit)))
3133    (t
3134     (equal s1 s2))))
3135
3136 ;; Returns a list of writable groups.
3137 (defun gnus-writable-groups ()
3138   (let ((alist gnus-newsrc-alist)
3139         groups)
3140     (while alist
3141       (or (gnus-group-read-only-p (car (car alist)))
3142           (setq groups (cons (car (car alist)) groups)))
3143       (setq alist (cdr alist)))
3144     (nreverse groups)))
3145
3146 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
3147 ;; the echo area.
3148 (defun gnus-y-or-n-p (prompt)
3149   (prog1
3150       (y-or-n-p prompt)
3151     (message "")))
3152
3153 (defun gnus-yes-or-no-p (prompt)
3154   (prog1
3155       (yes-or-no-p prompt)
3156     (message "")))
3157
3158 ;; Check whether to use long file names.
3159 (defun gnus-use-long-file-name (symbol)
3160   ;; The variable has to be set...
3161   (and gnus-use-long-file-name
3162        ;; If it isn't a list, then we return t.
3163        (or (not (listp gnus-use-long-file-name))
3164            ;; If it is a list, and the list contains `symbol', we
3165            ;; return nil.  
3166            (not (memq symbol gnus-use-long-file-name)))))
3167
3168 ;; I suspect there's a better way, but I haven't taken the time to do
3169 ;; it yet. -erik selberg@cs.washington.edu
3170 (defun gnus-dd-mmm (messy-date)
3171   "Return a string like DD-MMM from a big messy string"
3172   (let ((datevec (timezone-parse-date messy-date)))
3173     (format "%2s-%s"
3174             (or (aref datevec 2) "??")
3175             (capitalize
3176              (or (car 
3177                   (nth (1- (string-to-number (aref datevec 1)))
3178                        timezone-months-assoc))
3179                  "???")))))
3180
3181 ;; Make a hash table (default and minimum size is 255).
3182 ;; Optional argument HASHSIZE specifies the table size.
3183 (defun gnus-make-hashtable (&optional hashsize)
3184   (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 255) 255) 0))
3185
3186 ;; Make a number that is suitable for hashing; bigger than MIN and one
3187 ;; less than 2^x.
3188 (defun gnus-create-hash-size (min)
3189   (let ((i 1))
3190     (while (< i min)
3191       (setq i (* 2 i)))
3192     (1- i)))
3193
3194 ;; Show message if message has a lower level than `gnus-verbose'. 
3195 ;; Guide-line for numbers:
3196 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
3197 ;; for things that take a long time, 7 - not very important messages
3198 ;; on stuff, 9 - messages inside loops.
3199 (defun gnus-message (level &rest args)
3200   (if (<= level gnus-verbose)
3201       (apply 'message args)
3202     ;; We have to do this format thingie here even if the result isn't
3203     ;; shown - the return value has to be the same as the return value
3204     ;; from `message'.
3205     (apply 'format args)))
3206
3207 ;; Generate a unique new group name.
3208 (defun gnus-generate-new-group-name (leaf)
3209   (let ((name leaf)
3210         (num 0))
3211     (while (gnus-gethash name gnus-newsrc-hashtb)
3212       (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
3213     name))
3214
3215 ;; Find out whether the gnus-visual TYPE is wanted.
3216 (defun gnus-visual-p (&optional type class)
3217   (and gnus-visual                      ; Has to be non-nil, at least.
3218        (if (not type)                   ; We don't care about type.
3219            gnus-visual
3220          (if (listp gnus-visual)        ; It's a list, so we check it.
3221              (or (memq type gnus-visual)
3222                  (memq class gnus-visual))
3223            t))))
3224
3225 (defun gnus-parent-id (references)
3226   "Return the last Message-ID in REFERENCES."
3227   (and references
3228        (string-match "\\(<[^<>]+>\\) *$" references)
3229        (substring references (match-beginning 1) (match-end 1))))
3230
3231 (defun gnus-ephemeral-group-p (group)
3232   "Say whether GROUP is ephemeral or not."
3233   (assoc 'quit-config (gnus-find-method-for-group group)))
3234
3235 (defun gnus-group-quit-config (group)
3236   "Return the quit-config of GROUP."
3237   (nth 1 (assoc 'quit-config (gnus-find-method-for-group group))))
3238
3239 ;;; List and range functions
3240
3241 (defun gnus-last-element (list)
3242   "Return last element of LIST."
3243   (while (cdr list)
3244     (setq list (cdr list)))
3245   (car list))
3246
3247 (defun gnus-copy-sequence (list)
3248   "Do a complete, total copy of a list."
3249   (if (and (consp list) (not (consp (cdr list))))
3250       (cons (car list) (cdr list))
3251     (mapcar (lambda (elem) (if (consp elem) 
3252                                (if (consp (cdr elem))
3253                                    (gnus-copy-sequence elem)
3254                                  (cons (car elem) (cdr elem)))
3255                              elem))
3256             list)))
3257
3258 (defun gnus-set-difference (list1 list2)
3259   "Return a list of elements of LIST1 that do not appear in LIST2."
3260   (let ((list1 (copy-sequence list1)))
3261     (while list2
3262       (setq list1 (delq (car list2) list1))
3263       (setq list2 (cdr list2)))
3264     list1))
3265
3266 (defun gnus-sorted-complement (list1 list2)
3267   "Return a list of elements of LIST1 that do not appear in LIST2.
3268 Both lists have to be sorted over <."
3269   (let (out)
3270     (if (or (null list1) (null list2))
3271         (or list1 list2)
3272       (while (and list1 list2)
3273         (cond ((= (car list1) (car list2))
3274                (setq list1 (cdr list1)
3275                      list2 (cdr list2)))
3276               ((< (car list1) (car list2))
3277                (setq out (cons (car list1) out))
3278                (setq list1 (cdr list1)))
3279               (t
3280                (setq out (cons (car list2) out))
3281                (setq list2 (cdr list2)))))
3282       (nconc (nreverse out) (or list1 list2)))))
3283
3284 (defun gnus-intersection (list1 list2)      
3285   (let ((result nil))
3286     (while list2
3287       (if (memq (car list2) list1)
3288           (setq result (cons (car list2) result)))
3289       (setq list2 (cdr list2)))
3290     result))
3291
3292 (defun gnus-sorted-intersection (list1 list2)
3293   ;; LIST1 and LIST2 have to be sorted over <.
3294   (let (out)
3295     (while (and list1 list2)
3296       (cond ((= (car list1) (car list2))
3297              (setq out (cons (car list1) out)
3298                    list1 (cdr list1)
3299                    list2 (cdr list2)))
3300             ((< (car list1) (car list2))
3301              (setq list1 (cdr list1)))
3302             (t
3303              (setq list2 (cdr list2)))))
3304     (nreverse out)))
3305
3306 (defun gnus-set-sorted-intersection (list1 list2)
3307   ;; LIST1 and LIST2 have to be sorted over <.
3308   ;; This function modifies LIST1.
3309   (let* ((top (cons nil list1))
3310          (prev top))
3311     (while (and list1 list2)
3312       (cond ((= (car list1) (car list2))
3313              (setq prev list1
3314                    list1 (cdr list1)
3315                    list2 (cdr list2)))
3316             ((< (car list1) (car list2))
3317              (setcdr prev (cdr list1))
3318              (setq list1 (cdr list1)))
3319             (t
3320              (setq list2 (cdr list2)))))
3321     (setcdr prev nil)
3322     (cdr top)))
3323
3324 (defun gnus-compress-sequence (numbers &optional always-list)
3325   "Convert list of numbers to a list of ranges or a single range.
3326 If ALWAYS-LIST is non-nil, this function will always release a list of
3327 ranges."
3328   (let* ((first (car numbers))
3329          (last (car numbers))
3330          result)
3331     (if (null numbers)
3332         nil
3333       (if (not (listp (cdr numbers)))
3334           numbers
3335         (while numbers
3336           (cond ((= last (car numbers)) nil) ;Omit duplicated number
3337                 ((= (1+ last) (car numbers)) ;Still in sequence
3338                  (setq last (car numbers)))
3339                 (t                      ;End of one sequence
3340                  (setq result 
3341                        (cons (if (= first last) first
3342                                (cons first last)) result))
3343                  (setq first (car numbers))
3344                  (setq last  (car numbers))))
3345           (setq numbers (cdr numbers)))
3346         (if (and (not always-list) (null result))
3347             (if (= first last) (list first) (cons first last))
3348           (nreverse (cons (if (= first last) first (cons first last))
3349                           result)))))))
3350
3351 (defalias 'gnus-uncompress-sequence 'gnus-uncompress-range)
3352 (defun gnus-uncompress-range (ranges)
3353   "Expand a list of ranges into a list of numbers.
3354 RANGES is either a single range on the form `(num . num)' or a list of
3355 these ranges."
3356   (let (first last result)
3357     (cond 
3358      ((null ranges)
3359       nil)
3360      ((not (listp (cdr ranges)))
3361       (setq first (car ranges))
3362       (setq last (cdr ranges))
3363       (while (<= first last)
3364         (setq result (cons first result))
3365         (setq first (1+ first)))
3366       (nreverse result))
3367      (t
3368       (while ranges
3369         (if (atom (car ranges))
3370             (if (numberp (car ranges))
3371                 (setq result (cons (car ranges) result)))
3372           (setq first (car (car ranges)))
3373           (setq last  (cdr (car ranges)))
3374           (while (<= first last)
3375             (setq result (cons first result))
3376             (setq first (1+ first))))
3377         (setq ranges (cdr ranges)))
3378       (nreverse result)))))
3379
3380 (defun gnus-add-to-range (ranges list)
3381   "Return a list of ranges that has all articles from both RANGES and LIST.
3382 Note: LIST has to be sorted over `<'."
3383   (if (not ranges)
3384       (gnus-compress-sequence list t)
3385     (setq list (copy-sequence list))
3386     (or (listp (cdr ranges))
3387         (setq ranges (list ranges)))
3388     (let ((out ranges)
3389           ilist lowest highest temp)
3390       (while (and ranges list)
3391         (setq ilist list)
3392         (setq lowest (or (and (atom (car ranges)) (car ranges))
3393                          (car (car ranges))))
3394         (while (and list (cdr list) (< (car (cdr list)) lowest))
3395           (setq list (cdr list)))
3396         (if (< (car ilist) lowest)
3397             (progn
3398               (setq temp list)
3399               (setq list (cdr list))
3400               (setcdr temp nil)
3401               (setq out (nconc (gnus-compress-sequence ilist t) out))))
3402         (setq highest (or (and (atom (car ranges)) (car ranges))
3403                           (cdr (car ranges))))
3404         (while (and list (<= (car list) highest))
3405           (setq list (cdr list)))
3406         (setq ranges (cdr ranges)))
3407       (if list
3408           (setq out (nconc (gnus-compress-sequence list t) out)))
3409       (setq out (sort out (lambda (r1 r2) 
3410                             (< (or (and (atom r1) r1) (car r1))
3411                                (or (and (atom r2) r2) (car r2))))))
3412       (setq ranges out)
3413       (while ranges
3414         (if (atom (car ranges))
3415             (if (cdr ranges)
3416                 (if (atom (car (cdr ranges)))
3417                     (if (= (1+ (car ranges)) (car (cdr ranges)))
3418                         (progn
3419                           (setcar ranges (cons (car ranges) 
3420                                                (car (cdr ranges))))
3421                           (setcdr ranges (cdr (cdr ranges)))))
3422                   (if (= (1+ (car ranges)) (car (car (cdr ranges))))
3423                       (progn
3424                         (setcar (car (cdr ranges)) (car ranges))
3425                         (setcar ranges (car (cdr ranges)))
3426                         (setcdr ranges (cdr (cdr ranges)))))))
3427           (if (cdr ranges)
3428               (if (atom (car (cdr ranges)))
3429                   (if (= (1+ (cdr (car ranges))) (car (cdr ranges)))
3430                       (progn
3431                         (setcdr (car ranges) (car (cdr ranges)))
3432                         (setcdr ranges (cdr (cdr ranges)))))
3433                 (if (= (1+ (cdr (car ranges))) (car (car (cdr ranges))))
3434                     (progn
3435                       (setcdr (car ranges) (cdr (car (cdr ranges))))
3436                       (setcdr ranges (cdr (cdr ranges))))))))
3437         (setq ranges (cdr ranges)))
3438       out)))
3439
3440 (defun gnus-remove-from-range (ranges list)
3441   "Return a list of ranges that has all articles from LIST removed from RANGES.
3442 Note: LIST has to be sorted over `<'."
3443   ;; !!! This function shouldn't look like this, but I've got a headache.
3444   (gnus-compress-sequence 
3445    (gnus-sorted-complement
3446     (gnus-uncompress-range ranges) list)))
3447
3448 (defun gnus-member-of-range (number ranges)
3449   (if (not (listp (cdr ranges)))
3450       (and (>= number (car ranges)) 
3451            (<= number (cdr ranges)))
3452     (let ((not-stop t))
3453       (while (and ranges 
3454                   (if (numberp (car ranges))
3455                       (>= number (car ranges))
3456                     (>= number (car (car ranges))))
3457                   not-stop)
3458         (if (if (numberp (car ranges))
3459                 (= number (car ranges))
3460               (and (>= number (car (car ranges)))
3461                    (<= number (cdr (car ranges)))))
3462             (setq not-stop nil))
3463         (setq ranges (cdr ranges)))
3464       (not not-stop))))
3465
3466 (defun gnus-range-length (range)
3467   "Return the length RANGE would have if uncompressed."
3468   (length (gnus-uncompress-range range)))
3469
3470 (defun gnus-sublist-p (list sublist)
3471   "Test whether all elements in SUBLIST are members of LIST."
3472   (let ((sublistp t))
3473     (while sublist
3474       (unless (memq (pop sublist) list)
3475         (setq sublistp nil
3476               sublist nil)))
3477     sublistp))
3478
3479 \f
3480 ;;;
3481 ;;; Gnus group mode
3482 ;;;
3483
3484 (defvar gnus-group-mode-map nil)
3485 (defvar gnus-group-group-map nil)
3486 (defvar gnus-group-mark-map nil)
3487 (defvar gnus-group-list-map nil)
3488 (defvar gnus-group-sort-map nil)
3489 (defvar gnus-group-soup-map nil)
3490 (defvar gnus-group-sub-map nil)
3491 (defvar gnus-group-sub-map nil)
3492 (defvar gnus-group-help-map nil)
3493 (defvar gnus-group-score-map nil)
3494 (put 'gnus-group-mode 'mode-class 'special)
3495
3496 (if gnus-group-mode-map
3497     nil
3498   (setq gnus-group-mode-map (make-keymap))
3499   (suppress-keymap gnus-group-mode-map)
3500   (define-key gnus-group-mode-map " " 'gnus-group-read-group)
3501   (define-key gnus-group-mode-map "=" 'gnus-group-select-group)
3502   (define-key gnus-group-mode-map "\r" 'gnus-group-select-group)
3503   (define-key gnus-group-mode-map "\M-\r" 'gnus-group-quick-select-group)
3504   (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group)
3505   (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group)
3506   (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group)
3507   (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group)
3508   (define-key gnus-group-mode-map "N" 'gnus-group-next-group)
3509   (define-key gnus-group-mode-map "P" 'gnus-group-prev-group)
3510   (define-key gnus-group-mode-map
3511     "\M-n" 'gnus-group-next-unread-group-same-level)
3512   (define-key gnus-group-mode-map 
3513     "\M-p" 'gnus-group-prev-unread-group-same-level)
3514   (define-key gnus-group-mode-map "," 'gnus-group-best-unread-group)
3515   (define-key gnus-group-mode-map "." 'gnus-group-first-unread-group)
3516   (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group)
3517   (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group)
3518   (define-key gnus-group-mode-map "c" 'gnus-group-catchup-current)
3519   (define-key gnus-group-mode-map "C" 'gnus-group-catchup-current-all)
3520   (define-key gnus-group-mode-map "l" 'gnus-group-list-groups)
3521   (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups)
3522   (define-key gnus-group-mode-map "m" 'gnus-group-mail)
3523   (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news)
3524   (define-key gnus-group-mode-map "\M-g" 'gnus-group-get-new-news-this-group)
3525   (define-key gnus-group-mode-map "R" 'gnus-group-restart)
3526   (define-key gnus-group-mode-map "r" 'gnus-group-read-init-file)
3527   (define-key gnus-group-mode-map "B" 'gnus-group-browse-foreign-server)
3528   (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups)
3529   (define-key gnus-group-mode-map "F" 'gnus-find-new-newsgroups)
3530   (define-key gnus-group-mode-map "\C-c\C-d" 'gnus-group-describe-group)
3531   (define-key gnus-group-mode-map "\M-d" 'gnus-group-describe-all-groups)
3532   (define-key gnus-group-mode-map "\C-c\C-a" 'gnus-group-apropos)
3533   (define-key gnus-group-mode-map "\C-c\M-\C-a" 'gnus-group-description-apropos)
3534   (define-key gnus-group-mode-map "a" 'gnus-group-post-news)
3535   (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill)
3536   (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill)
3537   (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group)
3538   (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group)
3539   (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region)
3540   (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups)
3541   (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-group-list-killed)
3542   (define-key gnus-group-mode-map "\C-c\C-x" 'gnus-group-expire-articles)
3543   (define-key gnus-group-mode-map "\C-c\M-\C-x" 'gnus-group-expire-all-groups)
3544   (define-key gnus-group-mode-map "V" 'gnus-version)
3545   (define-key gnus-group-mode-map "s" 'gnus-group-save-newsrc)
3546   (define-key gnus-group-mode-map "z" 'gnus-group-suspend)
3547   (define-key gnus-group-mode-map "Z" 'gnus-group-clear-dribble)
3548   (define-key gnus-group-mode-map "q" 'gnus-group-exit)
3549   (define-key gnus-group-mode-map "Q" 'gnus-group-quit)
3550   (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly)
3551   (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node)
3552   (define-key gnus-group-mode-map "\M-e" 'gnus-group-edit-group-method)
3553   (define-key gnus-group-mode-map "^" 'gnus-group-enter-server-mode)
3554   (define-key gnus-group-mode-map gnus-mouse-2 'gnus-mouse-pick-group)
3555   (define-key gnus-group-mode-map "<" 'beginning-of-buffer)
3556   (define-key gnus-group-mode-map ">" 'end-of-buffer)
3557   (define-key gnus-group-mode-map "\C-c\C-b" 'gnus-bug)
3558   (define-key gnus-group-mode-map "\C-c\C-s" 'gnus-group-sort-groups)
3559   (define-key gnus-group-mode-map "t" 'gnus-topic-mode)
3560
3561   (define-key gnus-group-mode-map "#" 'gnus-group-mark-group)
3562   (define-key gnus-group-mode-map "\M-#" 'gnus-group-unmark-group)
3563   (define-prefix-command 'gnus-group-mark-map)
3564   (define-key gnus-group-mode-map "M" 'gnus-group-mark-map)
3565   (define-key gnus-group-mark-map "m" 'gnus-group-mark-group)
3566   (define-key gnus-group-mark-map "u" 'gnus-group-unmark-group)
3567   (define-key gnus-group-mark-map "w" 'gnus-group-mark-region)
3568
3569   (define-prefix-command 'gnus-group-group-map)
3570   (define-key gnus-group-mode-map "G" 'gnus-group-group-map)
3571   (define-key gnus-group-group-map "d" 'gnus-group-make-directory-group)
3572   (define-key gnus-group-group-map "h" 'gnus-group-make-help-group)
3573   (define-key gnus-group-group-map "a" 'gnus-group-make-archive-group)
3574   (define-key gnus-group-group-map "k" 'gnus-group-make-kiboze-group)
3575   (define-key gnus-group-group-map "m" 'gnus-group-make-group)
3576   (define-key gnus-group-group-map "E" 'gnus-group-edit-group)
3577   (define-key gnus-group-group-map "e" 'gnus-group-edit-group-method)
3578   (define-key gnus-group-group-map "p" 'gnus-group-edit-group-parameters)
3579   (define-key gnus-group-group-map "v" 'gnus-group-add-to-virtual)
3580   (define-key gnus-group-group-map "V" 'gnus-group-make-empty-virtual)
3581   (define-key gnus-group-group-map "D" 'gnus-group-enter-directory)
3582   (define-key gnus-group-group-map "f" 'gnus-group-make-doc-group)
3583   (define-key gnus-group-group-map "r" 'gnus-group-rename-group)
3584   (define-key gnus-group-group-map "\177" 'gnus-group-delete-group)
3585
3586   (define-prefix-command 'gnus-group-soup-map)
3587   (define-key gnus-group-group-map "s" 'gnus-group-soup-map)
3588   (define-key gnus-group-soup-map "b" 'gnus-group-brew-soup)
3589   (define-key gnus-group-soup-map "w" 'gnus-soup-save-areas)
3590   (define-key gnus-group-soup-map "s" 'gnus-soup-send-replies)
3591   (define-key gnus-group-soup-map "p" 'gnus-soup-pack-packet)
3592   (define-key gnus-group-soup-map "r" 'nnsoup-pack-replies)
3593
3594   (define-prefix-command 'gnus-group-sort-map)
3595   (define-key gnus-group-group-map "S" 'gnus-group-sort-map)
3596   (define-key gnus-group-sort-map "s" 'gnus-group-sort-groups)
3597   (define-key gnus-group-sort-map "a" 'gnus-group-sort-groups-by-alphabet)
3598   (define-key gnus-group-sort-map "u" 'gnus-group-sort-groups-by-unread)
3599   (define-key gnus-group-sort-map "l" 'gnus-group-sort-groups-by-level)
3600   (define-key gnus-group-sort-map "v" 'gnus-group-sort-groups-by-score)
3601   (define-key gnus-group-sort-map "r" 'gnus-group-sort-groups-by-rank)
3602   (define-key gnus-group-sort-map "m" 'gnus-group-sort-groups-by-method)
3603
3604   (define-prefix-command 'gnus-group-help-map)
3605   (define-key gnus-group-mode-map "H" 'gnus-group-help-map)
3606   (define-key gnus-group-help-map "f" 'gnus-group-fetch-faq)
3607
3608   (define-prefix-command 'gnus-group-list-map)
3609   (define-key gnus-group-mode-map "A" 'gnus-group-list-map)
3610   (define-key gnus-group-list-map "k" 'gnus-group-list-killed)
3611   (define-key gnus-group-list-map "z" 'gnus-group-list-zombies)
3612   (define-key gnus-group-list-map "s" 'gnus-group-list-groups)
3613   (define-key gnus-group-list-map "u" 'gnus-group-list-all-groups)
3614   (define-key gnus-group-list-map "A" 'gnus-group-list-active)
3615   (define-key gnus-group-list-map "a" 'gnus-group-apropos)
3616   (define-key gnus-group-list-map "d" 'gnus-group-description-apropos)
3617   (define-key gnus-group-list-map "m" 'gnus-group-list-matching)
3618   (define-key gnus-group-list-map "M" 'gnus-group-list-all-matching)
3619
3620   (define-prefix-command 'gnus-group-score-map)
3621   (define-key gnus-group-mode-map "W" 'gnus-group-score-map)
3622   (define-key gnus-group-score-map "f" 'gnus-score-flush-cache)
3623
3624   (define-prefix-command 'gnus-group-sub-map)
3625   (define-key gnus-group-mode-map "S" 'gnus-group-sub-map)
3626   (define-key gnus-group-sub-map "l" 'gnus-group-set-current-level)
3627   (define-key gnus-group-sub-map "t" 'gnus-group-unsubscribe-current-group)
3628   (define-key gnus-group-sub-map "s" 'gnus-group-unsubscribe-group)
3629   (define-key gnus-group-sub-map "k" 'gnus-group-kill-group)
3630   (define-key gnus-group-sub-map "y" 'gnus-group-yank-group)
3631   (define-key gnus-group-sub-map "w" 'gnus-group-kill-region)
3632   (define-key gnus-group-sub-map "z" 'gnus-group-kill-all-zombies))
3633
3634 (defun gnus-group-mode ()
3635   "Major mode for reading news.
3636
3637 All normal editing commands are switched off.
3638 \\<gnus-group-mode-map>
3639 The group buffer lists (some of) the groups available.  For instance,
3640 `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]'
3641 lists all zombie groups. 
3642
3643 Groups that are displayed can be entered with `\\[gnus-group-read-group]'.  To subscribe 
3644 to a group not displayed, type `\\[gnus-group-unsubscribe-group]'. 
3645
3646 For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). 
3647
3648 The following commands are available:
3649
3650 \\{gnus-group-mode-map}"
3651   (interactive)
3652   (when (and menu-bar-mode
3653              (gnus-visual-p 'group-menu 'menu))
3654     (gnus-group-make-menu-bar))
3655   (kill-all-local-variables)
3656   (setq mode-line-modified "-- ")
3657   (make-local-variable 'mode-line-format)
3658   (setq mode-line-format (copy-sequence mode-line-format))
3659   (and (equal (nth 3 mode-line-format) "   ")
3660        (setcar (nthcdr 3 mode-line-format) ""))
3661   (setq major-mode 'gnus-group-mode)
3662   (setq mode-name "Group")
3663   (gnus-group-set-mode-line)
3664   (setq mode-line-process nil)
3665   (use-local-map gnus-group-mode-map)
3666   (buffer-disable-undo (current-buffer))
3667   (setq truncate-lines t)
3668   (setq buffer-read-only t)
3669   (run-hooks 'gnus-group-mode-hook))
3670
3671 (defun gnus-mouse-pick-group (e)
3672   (interactive "e")
3673   (mouse-set-point e)
3674   (gnus-group-read-group nil))
3675
3676 ;; Look at LEVEL and find out what the level is really supposed to be.
3677 ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens
3678 ;; will depend on whether `gnus-group-use-permanent-levels' is used.
3679 (defun gnus-group-default-level (&optional level number-or-nil)
3680   (cond  
3681    (gnus-group-use-permanent-levels
3682     (setq gnus-group-default-list-level 
3683           (or level gnus-group-default-list-level))
3684     (or gnus-group-default-list-level gnus-level-subscribed))
3685    (number-or-nil
3686     level)
3687    (t
3688     (or level gnus-group-default-list-level gnus-level-subscribed))))
3689   
3690
3691 ;;;###autoload
3692 (defun gnus-no-server (&optional arg)
3693   "Read network news.
3694 If ARG is a positive number, Gnus will use that as the
3695 startup level.  If ARG is nil, Gnus will be started at level 2. 
3696 If ARG is non-nil and not a positive number, Gnus will
3697 prompt the user for the name of an NNTP server to use.
3698 As opposed to `gnus', this command will not connect to the local server."
3699   (interactive "P")
3700   (make-local-variable gnus-group-use-permanent-levels)
3701   (setq gnus-group-use-permanent-levels t)
3702   (gnus (or arg (1- gnus-level-default-subscribed)) t))
3703
3704 ;;;###autoload
3705 (defun gnus-slave (&optional arg)
3706   "Read news as a slave."
3707   (interactive "P")
3708   (gnus arg nil 'slave))
3709
3710 ;;;###autoload
3711 (defun gnus (&optional arg dont-connect slave)
3712   "Read network news.
3713 If ARG is non-nil and a positive number, Gnus will use that as the
3714 startup level.  If ARG is non-nil and not a positive number, Gnus will
3715 prompt the user for the name of an NNTP server to use."
3716   (interactive "P")
3717   (if (get-buffer gnus-group-buffer)
3718       (progn
3719         (switch-to-buffer gnus-group-buffer)
3720         (gnus-group-get-new-news))
3721
3722     (gnus-clear-system)
3723
3724     (nnheader-init-server-buffer)
3725
3726     (gnus-read-init-file)
3727
3728     (setq gnus-slave slave)
3729
3730     (gnus-group-setup-buffer)
3731     (let ((buffer-read-only nil))
3732       (erase-buffer)
3733       (if (not gnus-inhibit-startup-message)
3734           (progn
3735             (gnus-group-startup-message)
3736             (sit-for 0))))
3737     
3738     (let ((level (and arg (numberp arg) (> arg 0) arg))
3739           did-connect)
3740       (unwind-protect
3741           (progn
3742             (or dont-connect 
3743                 (setq did-connect
3744                       (gnus-start-news-server (and arg (not level))))))
3745         (if (and (not dont-connect) 
3746                  (not did-connect))
3747             (gnus-group-quit)
3748           (run-hooks 'gnus-startup-hook)
3749           ;; NNTP server is successfully open. 
3750
3751           ;; Find the current startup file name.
3752           (setq gnus-current-startup-file 
3753                 (gnus-make-newsrc-file gnus-startup-file))
3754
3755           ;; Read the dribble file.
3756           (and (or gnus-slave gnus-use-dribble-file) (gnus-dribble-read-file))
3757
3758           (gnus-summary-make-display-table)
3759           (gnus-setup-news nil level)
3760           (gnus-group-list-groups level)
3761           (gnus-configure-windows 'group)
3762           (gnus-group-set-mode-line))))))
3763
3764 (defun gnus-unload ()
3765   "Unload all Gnus features."
3766   (interactive)
3767   (or (boundp 'load-history)
3768       (error "Sorry, `gnus-unload' is not implemented in this Emacs version."))
3769   (let ((history load-history)
3770         feature)
3771     (while history
3772       (and (string-match "^gnus" (car (car history)))
3773            (setq feature (cdr (assq 'provide (car history))))
3774            (unload-feature feature 'force))
3775       (setq history (cdr history)))))
3776
3777 (defun gnus-compile ()
3778   "Byte-compile the Gnus startup file.
3779 This will also compile the user-defined format specs."
3780   (interactive)
3781   (let ((file (concat (make-temp-name "/tmp/gnuss") ".el")))
3782     (save-excursion
3783       (gnus-message 7 "Compiling user file...")
3784       (nnheader-set-temp-buffer " *compile gnus*")
3785       (and (file-exists-p gnus-init-file)
3786            (insert-file gnus-init-file))
3787       (goto-char (point-max))
3788
3789       (let ((formats '(summary summary-dummy group 
3790                                summary-mode group-mode article-mode))
3791             format fs)
3792         
3793         (while formats
3794           (setq format (symbol-name (car formats))
3795                 formats (cdr formats)
3796                 fs (cons (symbol-value 
3797                           (intern (format "gnus-%s-line-format" format)))
3798                          fs))
3799           (insert "(defun gnus-" format "-line-format-spec ()\n")
3800           (insert 
3801            (prin1-to-string
3802             (symbol-value 
3803              (intern (format "gnus-%s-line-format-spec" format)))))
3804           (insert ")\n")
3805           (insert "(setq gnus-" format 
3806                   "-line-format-spec (list 'gnus-byte-code 'gnus-"
3807                   format "-line-format-spec))\n"))
3808
3809         (insert "(setq gnus-old-specs '" (prin1-to-string fs) ")\n")
3810
3811         (write-region (point-min) (point-max) file nil 'silent)
3812         (byte-compile-file file)
3813         (rename-file
3814          (concat file "c") 
3815          (concat gnus-init-file 
3816                  (if (string-match "\\.el$" gnus-init-file) "c" ".elc"))
3817          t)
3818         (when (file-exists-p file)
3819           (delete-file file))
3820         (kill-buffer (current-buffer)))
3821       (gnus-message 7 "Compiling user file...done"))))
3822
3823 (defun gnus-indent-rigidly (start end arg)
3824   "Indent rigidly using only spaces and no tabs."
3825   (save-excursion
3826     (save-restriction
3827       (narrow-to-region start end)
3828       (indent-rigidly start end arg)
3829       (goto-char (point-min))
3830       (while (search-forward "\t" nil t)
3831         (replace-match "        " t t)))))
3832
3833 (defun gnus-group-startup-message (&optional x y)
3834   "Insert startup message in current buffer."
3835   ;; Insert the message.
3836   (erase-buffer)
3837   (insert
3838    (format "              %s
3839           _    ___ _             _      
3840           _ ___ __ ___  __    _ ___     
3841           __   _     ___    __  ___     
3842               _           ___     _     
3843              _  _ __             _      
3844              ___   __            _      
3845                    __           _       
3846                     _      _   _        
3847                    _      _    _        
3848                       _  _    _         
3849                   __  ___               
3850                  _   _ _     _          
3851                 _   _                   
3852               _    _                    
3853              _    _                     
3854             _                         
3855           __                             
3856
3857
3858            ""))
3859   ;; And then hack it.
3860   (gnus-indent-rigidly (point-min) (point-max) 
3861                        (/ (max (- (window-width) (or x 46)) 0) 2))
3862   (goto-char (point-min))
3863   (forward-line 1)
3864   (let* ((pheight (count-lines (point-min) (point-max)))
3865          (wheight (window-height))
3866          (rest (- wheight pheight)))
3867     (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
3868   ;; Fontify some.
3869   (goto-char (point-min))
3870   (and (search-forward "Praxis" nil t)
3871        (put-text-property (match-beginning 0) (match-end 0) 'face 'bold))
3872   (goto-char (point-min))
3873   (let* ((mode-string (gnus-group-set-mode-line)))
3874     (setq mode-line-buffer-identification 
3875           (concat gnus-version (substring mode-string 4)))
3876     (set-buffer-modified-p t)))
3877
3878 (defun gnus-group-startup-message-old (&optional x y)
3879   "Insert startup message in current buffer."
3880   ;; Insert the message.
3881   (erase-buffer)
3882   (insert
3883    (format "
3884      %s
3885            A newsreader 
3886       for GNU Emacs
3887
3888         Based on GNUS 
3889              written by 
3890      Masanobu UMEDA
3891
3892        A Praxis Release
3893       larsi@ifi.uio.no
3894
3895            gnus-version))
3896   ;; And then hack it.
3897   ;; 18 is the longest line.
3898   (indent-rigidly (point-min) (point-max) 
3899                   (/ (max (- (window-width) (or x 28)) 0) 2))
3900   (goto-char (point-min))
3901   ;; +4 is fuzzy factor.
3902   (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2))
3903
3904   ;; Fontify some.
3905   (goto-char (point-min))
3906   (search-forward "Praxis")
3907   (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
3908   (goto-char (point-min)))
3909
3910 (defun gnus-group-setup-buffer ()
3911   (or (get-buffer gnus-group-buffer)
3912       (progn
3913         (switch-to-buffer gnus-group-buffer)
3914         (gnus-add-current-to-buffer-list)
3915         (gnus-group-mode)
3916         (and gnus-carpal (gnus-carpal-setup-buffer 'group)))))
3917
3918 (defun gnus-group-list-groups (&optional level unread)
3919   "List newsgroups with level LEVEL or lower that have unread articles.
3920 Default is all subscribed groups.
3921 If argument UNREAD is non-nil, groups with no unread articles are also
3922 listed." 
3923   (interactive (list (if current-prefix-arg
3924                          (prefix-numeric-value current-prefix-arg)
3925                        (or
3926                         (gnus-group-default-level nil t)
3927                         gnus-group-default-list-level
3928                         gnus-level-subscribed))))
3929   (or level
3930       (setq level (car gnus-group-list-mode)
3931             unread (cdr gnus-group-list-mode)))
3932   (setq level (gnus-group-default-level level))
3933   (gnus-group-setup-buffer)             ;May call from out of group buffer
3934   (gnus-update-format-specifications)
3935   (let ((case-fold-search nil)
3936         (group (gnus-group-group-name)))
3937     (funcall gnus-group-prepare-function level unread nil)
3938     (if (zerop (buffer-size))
3939         (gnus-message 5 gnus-no-groups-message)
3940       (goto-char (point-min))
3941       (if (not group)
3942           ;; Go to the first group with unread articles.
3943           (gnus-group-search-forward nil nil nil t)
3944         ;; Find the right group to put point on.  If the current group
3945         ;; has disapeared in the new listing, try to find the next
3946         ;; one.  If no next one can be found, just leave point at the
3947         ;; first newsgroup in the buffer.
3948         (if (not (gnus-goto-char
3949                   (text-property-any
3950                    (point-min) (point-max) 
3951                    'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
3952             (let ((newsrc (nthcdr 3 (gnus-gethash group gnus-newsrc-hashtb))))
3953               (while (and newsrc
3954                           (not (gnus-goto-char 
3955                                 (text-property-any 
3956                                  (point-min) (point-max) 'gnus-group 
3957                                  (gnus-intern-safe 
3958                                   (car (car newsrc)) gnus-active-hashtb)))))
3959                 (setq newsrc (cdr newsrc)))
3960               (or newsrc (progn (goto-char (point-max))
3961                                 (forward-line -1))))))
3962       ;; Adjust cursor point.
3963       (gnus-group-position-point))))
3964
3965 (defun gnus-group-prepare-flat (level &optional all lowest regexp) 
3966   "List all newsgroups with unread articles of level LEVEL or lower.
3967 If ALL is non-nil, list groups that have no unread articles.
3968 If LOWEST is non-nil, list all newsgroups of level LOWEST or higher.
3969 If REGEXP, only list groups matching REGEXP."
3970   (set-buffer gnus-group-buffer)
3971   (let ((buffer-read-only nil)
3972         (newsrc (cdr gnus-newsrc-alist))
3973         (lowest (or lowest 1))
3974         info clevel unread group params)
3975     (erase-buffer)
3976     (if (< lowest gnus-level-zombie)
3977         ;; List living groups.
3978         (while newsrc
3979           (setq info (car newsrc)
3980                 group (gnus-info-group info)
3981                 params (gnus-info-params info)
3982                 newsrc (cdr newsrc)
3983                 unread (car (gnus-gethash group gnus-newsrc-hashtb)))
3984           (and unread                   ; This group might be bogus
3985                (or (not regexp)
3986                    (string-match regexp group))
3987                (<= (setq clevel (gnus-info-level info)) level) 
3988                (>= clevel lowest)
3989                (or all                  ; We list all groups?
3990                    (eq unread t)        ; We list unactivated groups
3991                    (> unread 0)         ; We list groups with unread articles
3992                    (cdr (assq 'tick (gnus-info-marks info)))
3993                                         ; And groups with tickeds
3994                    ;; Check for permanent visibility.
3995                    (and gnus-permanently-visible-groups
3996                         (string-match gnus-permanently-visible-groups
3997                                       group))
3998                    (memq 'visible params)
3999                    (cdr (assq 'visible params)))
4000                (gnus-group-insert-group-line 
4001                 group (gnus-info-level info) 
4002                 (gnus-info-marks info) unread (gnus-info-method info)))))
4003       
4004     ;; List dead groups.
4005     (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie)
4006          (gnus-group-prepare-flat-list-dead 
4007           (setq gnus-zombie-list (sort gnus-zombie-list 'string<)) 
4008           gnus-level-zombie ?Z
4009           regexp))
4010     (and (>= level gnus-level-killed) (<= lowest gnus-level-killed)
4011          (gnus-group-prepare-flat-list-dead 
4012           (setq gnus-killed-list (sort gnus-killed-list 'string<)) 
4013           gnus-level-killed ?K regexp))
4014
4015     (gnus-group-set-mode-line)
4016     (setq gnus-group-list-mode (cons level all))
4017     (run-hooks 'gnus-group-prepare-hook)))
4018
4019 (defun gnus-group-prepare-flat-list-dead (groups level mark regexp)
4020   ;; List zombies and killed lists somehwat faster, which was
4021   ;; suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.  It does
4022   ;; this by ignoring the group format specification altogether.
4023   (let (group beg)
4024     (if regexp
4025         ;; This loop is used when listing groups that match some
4026         ;; regexp. 
4027         (while groups
4028           (setq group (pop groups))
4029           (when (string-match regexp group)
4030             (add-text-properties 
4031              (point) (prog1 (1+ (point))
4032                        (insert " " mark "     *: " group "\n"))
4033              (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
4034                    'gnus-unread t
4035                    'gnus-level level))))
4036       ;; This loop is used when listing all groups.
4037       (while groups
4038         (add-text-properties 
4039          (point) (prog1 (1+ (point))
4040                    (insert " " mark "     *: " 
4041                            (setq group (pop groups)) "\n"))
4042          (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb)
4043                'gnus-unread t
4044                'gnus-level level))))))
4045
4046 (defmacro gnus-group-real-name (group)
4047   "Find the real name of a foreign newsgroup."
4048   `(let ((gname ,group))
4049      (if (string-match ":[^:]+$" gname)
4050          (substring gname (1+ (match-beginning 0)))
4051        gname)))
4052
4053 (defsubst gnus-server-add-address (method)
4054   (let ((method-name (symbol-name (car method))))
4055     (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
4056              (not (assq (intern (concat method-name "-address")) method)))
4057         (append method (list (list (intern (concat method-name "-address"))
4058                                    (nth 1 method))))
4059       method)))
4060
4061 (defsubst gnus-server-get-method (group method)
4062   ;; Input either a server name, and extended server name, or a
4063   ;; select method, and return a select method. 
4064   (cond ((stringp method)
4065          (gnus-server-to-method method))
4066         ((and (stringp (car method)) group)
4067          (gnus-server-extend-method group method))
4068         (t
4069          (gnus-server-add-address method))))
4070
4071 (defun gnus-server-to-method (server)
4072   "Map virtual server names to select methods."
4073   (or (and (equal server "native") gnus-select-method)
4074       (cdr (assoc server gnus-server-alist))))
4075
4076 (defun gnus-group-prefixed-name (group method)
4077   "Return the whole name from GROUP and METHOD."
4078   (and (stringp method) (setq method (gnus-server-to-method method)))
4079   (concat (format "%s" (car method))
4080           (if (and 
4081                (assoc (format "%s" (car method)) (gnus-methods-using 'address))
4082                (not (string= (nth 1 method) "")))
4083               (concat "+" (nth 1 method)))
4084           ":" group))
4085
4086 (defun gnus-group-real-prefix (group)
4087   "Return the prefix of the current group name."
4088   (if (string-match "^[^:]+:" group)
4089       (substring group 0 (match-end 0))
4090     ""))
4091
4092 (defun gnus-group-method-name (group)
4093   "Return the method used for selecting GROUP."
4094   (let ((prefix (gnus-group-real-prefix group)))
4095     (if (equal prefix "")
4096         gnus-select-method
4097       (if (string-match "^[^\\+]+\\+" prefix)
4098           (list (intern (substring prefix 0 (1- (match-end 0))))
4099                 (substring prefix (match-end 0) (1- (length prefix))))
4100         (list (intern (substring prefix 0 (1- (length prefix)))) "")))))
4101
4102 (defsubst gnus-secondary-method-p (method)
4103   "Return whether METHOD is a secondary select method."
4104   (let ((methods gnus-secondary-select-methods)
4105         (gmethod (gnus-server-get-method nil method)))
4106     (while (and methods
4107                 (not (equal (gnus-server-get-method nil (car methods)) 
4108                             gmethod)))
4109       (setq methods (cdr methods)))
4110     methods))
4111
4112 (defun gnus-group-foreign-p (group)
4113   "Say whether a group is foreign or not."
4114   (and (not (gnus-group-native-p group))
4115        (not (gnus-group-secondary-p group))))
4116
4117 (defun gnus-group-native-p (group)
4118   "Say whether the group is native or not."
4119   (not (string-match ":" group)))
4120
4121 (defun gnus-group-secondary-p (group)
4122   "Say whether the group is secondary or not."
4123   (gnus-secondary-method-p (gnus-find-method-for-group group)))
4124
4125 (defun gnus-group-get-parameter (group &optional symbol)
4126   "Returns the group parameters for GROUP.
4127 If SYMBOL, return the value of that symbol in the group parameters."
4128   (let ((params (gnus-info-params (gnus-get-info group))))
4129     (if symbol
4130         (gnus-group-parameter-value params symbol)
4131       params)))
4132
4133 (defun gnus-group-parameter-value (params symbol)
4134   "Return the value of SYMBOL in group PARAMS."
4135   (or (car (memq symbol params))        ; It's either a simple symbol
4136       (cdr (assq symbol params))))      ; or a cons.
4137
4138 (defun gnus-group-add-parameter (group param)
4139   "Add parameter PARAM to GROUP."
4140   (let ((info (gnus-get-info group)))
4141     (if (not info)
4142         () ; This is a dead group.  We just ignore it.
4143       ;; Cons the new param to the old one and update.
4144       (gnus-group-set-info (cons param (gnus-info-params info)) 
4145                            group 'params))))
4146
4147 (defun gnus-group-add-score (group &optional score)
4148   "Add SCORE to the GROUP score.  
4149 If SCORE is nil, add 1 to the score of GROUP."
4150   (let ((info (gnus-get-info group)))
4151     (gnus-info-set-score info (+ (gnus-info-score info) (or score 1)))))
4152
4153 (defun gnus-summary-bubble-group ()
4154   "Increase the score of the current group.
4155 This is a handy function to add to `gnus-summary-exit-hook' to
4156 increase the score of each group you read."
4157   (gnus-group-add-score gnus-newsgroup-name))
4158
4159 (defun gnus-group-set-info (info &optional method-only-group part)
4160   (let* ((entry (gnus-gethash
4161                  (or method-only-group (gnus-info-group info))
4162                  gnus-newsrc-hashtb))
4163          (part-info info)
4164          (info (if method-only-group (nth 2 entry) info)))
4165     (when method-only-group
4166       (unless entry
4167         (error "Trying to change non-existent group %s" method-only-group))
4168       ;; We have recevied parts of the actual group info - either the
4169       ;; select method or the group parameters.  We first check
4170       ;; whether we have to extend the info, and if so, do that.
4171       (let ((len (length info))
4172             (total (if (eq part 'method) 5 6)))
4173         (when (< len total)
4174           (setcdr (nthcdr (1- len) info)
4175                   (make-list (- total len) nil)))
4176         ;; Then we enter the new info.
4177         (setcar (nthcdr (1- total) info) part-info)))
4178     (unless entry
4179       ;; This is a new group, so we just create it.
4180       (save-excursion
4181         (set-buffer gnus-group-buffer)
4182         (if (gnus-info-method info)
4183             ;; It's a foreign group...
4184             (gnus-group-make-group 
4185              (gnus-group-real-name (gnus-info-group info))
4186              (prin1-to-string (car (gnus-info-method info)))
4187              (nth 1 (gnus-info-method info)))
4188           ;; It's a native group.
4189           (gnus-group-make-group (gnus-info-group info)))
4190         (gnus-message 6 "Note: New group created")
4191         (setq entry 
4192               (gnus-gethash (gnus-group-prefixed-name 
4193                              (gnus-group-real-name (gnus-info-group info))
4194                              (or (gnus-info-method info) gnus-select-method))
4195                             gnus-newsrc-hashtb))))
4196     ;; Whether it was a new group or not, we now have the entry, so we
4197     ;; can do the update.
4198     (if entry
4199         (progn
4200           (setcar (nthcdr 2 entry) info)
4201           (when (and (not (eq (car entry) t)) 
4202                      (gnus-active (gnus-info-group info)))
4203             (let ((marked (gnus-info-marks info)))
4204               (setcar entry (length (gnus-list-of-unread-articles 
4205                                      (car info)))))))
4206       (error "No such group: %s" (gnus-info-group info)))))
4207
4208 (defun gnus-group-set-method-info (group select-method)
4209   (gnus-group-set-info select-method group 'method))
4210
4211 (defun gnus-group-set-params-info (group params)
4212   (gnus-group-set-info params group 'params))
4213
4214 (defun gnus-group-update-group-line ()
4215   "Update the current line in the group buffer."
4216   (let* ((buffer-read-only nil)
4217          (group (gnus-group-group-name))
4218          (entry (and group (gnus-gethash group gnus-newsrc-hashtb))))
4219     (and entry 
4220          (not (gnus-ephemeral-group-p group))
4221          (gnus-dribble-enter 
4222           (concat "(gnus-group-set-info '" 
4223                   (prin1-to-string (nth 2 entry)) ")")))
4224     (gnus-delete-line)
4225     (gnus-group-insert-group-line-info group)
4226     (forward-line -1)
4227     (gnus-group-position-point)))
4228
4229 (defun gnus-group-insert-group-line-info (group)
4230   "Insert GROUP on the current line."
4231   (let ((entry (gnus-gethash group gnus-newsrc-hashtb)) 
4232         active info)
4233     (if entry
4234         (progn
4235           ;; (Un)subscribed group.
4236           (setq info (nth 2 entry))
4237           (gnus-group-insert-group-line 
4238            group (gnus-info-level info) (gnus-info-marks info)
4239            (or (car entry) t) (gnus-info-method info)))
4240       ;; This group is dead.
4241       (gnus-group-insert-group-line 
4242        group 
4243        (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed)
4244        nil 
4245        (if (setq active (gnus-active group))
4246            (- (1+ (cdr active)) (car active)) 0) 
4247        nil))))
4248
4249 (defalias 'gnus-group-remove-excess-properties (lambda ()))
4250
4251 (defun gnus-group-insert-group-line 
4252   (gnus-tmp-group gnus-tmp-level gnus-tmp-marked gnus-tmp-number
4253                   gnus-tmp-method)
4254   (let* ((gnus-tmp-active (gnus-active gnus-tmp-group))
4255          (gnus-tmp-number-total 
4256           (if gnus-tmp-active 
4257               (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active)))
4258             0))
4259          (gnus-tmp-number-of-unread 
4260           (if (numberp gnus-tmp-number) (int-to-string (max 0 gnus-tmp-number))
4261             "*"))
4262          (gnus-tmp-number-of-read
4263           (if (numberp gnus-tmp-number)
4264               (max 0 (- gnus-tmp-number-total gnus-tmp-number))
4265             "*"))
4266          (gnus-tmp-subscribed
4267           (cond ((<= gnus-tmp-level gnus-level-subscribed) ? )
4268                 ((<= gnus-tmp-level gnus-level-unsubscribed) ?U)
4269                 ((= gnus-tmp-level gnus-level-zombie) ?Z)
4270                 (t ?K)))
4271          (gnus-tmp-qualified-group (gnus-group-real-name gnus-tmp-group))
4272          (gnus-tmp-newsgroup-description 
4273           (if gnus-description-hashtb
4274               (or (gnus-gethash gnus-tmp-group gnus-description-hashtb) "")
4275             ""))
4276          (gnus-tmp-moderated
4277           (if (member gnus-tmp-group gnus-moderated-list) ?m ? ))
4278          (gnus-tmp-moderated-string 
4279           (if (eq gnus-tmp-moderated ?m) "(m)" ""))
4280          (gnus-tmp-method
4281           (gnus-server-get-method gnus-tmp-group gnus-tmp-method))
4282          (gnus-tmp-news-server (or (car (cdr gnus-tmp-method)) ""))
4283          (gnus-tmp-news-method (or (car gnus-tmp-method) ""))
4284          (gnus-tmp-news-method-string 
4285           (if gnus-tmp-method
4286               (format "(%s:%s)" (car gnus-tmp-method)
4287                       (car (cdr gnus-tmp-method))) ""))
4288          (gnus-tmp-marked 
4289           (if (and (numberp gnus-tmp-number) 
4290                    (zerop gnus-tmp-number)
4291                    (cdr (assq 'tick gnus-tmp-marked)))
4292               ?* ? ))
4293          (gnus-tmp-number
4294           (if (eq gnus-tmp-number t) "*" 
4295             gnus-tmp-number))
4296          (gnus-tmp-process-marked
4297           (if (member gnus-tmp-group gnus-group-marked)
4298               gnus-process-mark ? ))
4299          (buffer-read-only nil)
4300          header                         ; passed as parameter to user-funcs.
4301          b)
4302     (beginning-of-line)
4303     (setq b (point))
4304     ;; Insert the text.
4305     (eval gnus-group-line-format-spec)
4306
4307     (add-text-properties 
4308      b (1+ b) (list 'gnus-group (gnus-intern-safe
4309                                  gnus-tmp-group gnus-active-hashtb)
4310                     'gnus-unread (if (numberp gnus-tmp-number)
4311                                      (string-to-int 
4312                                       gnus-tmp-number-of-unread)
4313                                    t)
4314                     'gnus-marked gnus-tmp-marked
4315                     'gnus-level gnus-tmp-level))
4316     (gnus-group-remove-excess-properties)))
4317
4318 (defun gnus-group-update-group (group &optional visible-only)
4319   "Update all lines where GROUP appear.
4320 If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't
4321 already." 
4322   (save-excursion
4323     (set-buffer gnus-group-buffer)
4324     ;; The buffer may be narrowed.
4325     (save-restriction
4326       (widen)
4327       (let ((ident (gnus-intern-safe group gnus-active-hashtb))
4328             (loc (point-min))
4329             found buffer-read-only visible)
4330         ;; Enter the current status into the dribble buffer.
4331         (let ((entry (gnus-gethash group gnus-newsrc-hashtb)))
4332           (if (and entry (not (gnus-ephemeral-group-p group)))
4333               (gnus-dribble-enter 
4334                (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry))
4335                        ")"))))
4336         ;; Find all group instances.  If topics are in use, each group
4337         ;; may be listed in more than once.
4338         (while (setq loc (text-property-any 
4339                           loc (point-max) 'gnus-group ident))
4340           (setq found t)
4341           (goto-char loc)
4342           (gnus-delete-line)
4343           (gnus-group-insert-group-line-info group)
4344           (setq loc (1+ loc)))
4345         (if (or found visible-only)
4346             ()
4347           ;; No such line in the buffer, find out where it's supposed to
4348           ;; go, and insert it there (or at the end of the buffer).
4349           ;; Fix by Per Abrahamsen <amanda@iesd.auc.dk>.
4350           (let ((entry (cdr (cdr (gnus-gethash group gnus-newsrc-hashtb)))))
4351             (while (and entry (car entry)
4352                         (not
4353                          (gnus-goto-char
4354                           (text-property-any
4355                            (point-min) (point-max) 
4356                            'gnus-group (gnus-intern-safe 
4357                                         (car (car entry)) 
4358                                         gnus-active-hashtb)))))
4359               (setq entry (cdr entry)))
4360             (or entry (goto-char (point-max))))
4361           ;; Finally insert the line.
4362           (gnus-group-insert-group-line-info group))
4363         (gnus-group-set-mode-line)))))
4364
4365 (defun gnus-group-set-mode-line ()
4366   (when (memq 'group gnus-updated-mode-lines)
4367     (let* ((gformat (or gnus-group-mode-line-format-spec
4368                         (setq gnus-group-mode-line-format-spec
4369                               (gnus-parse-format 
4370                                gnus-group-mode-line-format 
4371                                gnus-group-mode-line-format-alist))))
4372            (gnus-tmp-news-server (car (cdr gnus-select-method)))
4373            (gnus-tmp-news-method (car gnus-select-method))
4374            (max-len 60)
4375            ;; Get the resulting string.
4376            (mode-string (eval gformat)))
4377       ;; If the line is too long, we chop it off.
4378       (when (> (length mode-string) max-len) 
4379         (setq mode-string (substring mode-string 0 (- max-len 4))))
4380       (prog1
4381           (setq mode-line-buffer-identification mode-string)
4382         (set-buffer-modified-p t)))))
4383
4384 (defun gnus-group-group-name ()
4385   "Get the name of the newsgroup on the current line."
4386   (let ((group (get-text-property (gnus-point-at-bol) 'gnus-group)))
4387     (and group (symbol-name group))))
4388
4389 (defun gnus-group-group-level ()
4390   "Get the level of the newsgroup on the current line."
4391   (get-text-property (gnus-point-at-bol) 'gnus-level))
4392
4393 (defun gnus-group-group-unread ()
4394   "Get the number of unread articles of the newsgroup on the current line."
4395   (get-text-property (gnus-point-at-bol) 'gnus-unread))
4396
4397 (defun gnus-group-search-forward (&optional backward all level first-too)
4398   "Find the next newsgroup with unread articles.
4399 If BACKWARD is non-nil, find the previous newsgroup instead.
4400 If ALL is non-nil, just find any newsgroup.
4401 If LEVEL is non-nil, find group with level LEVEL, or higher if no such
4402 group exists.
4403 If FIRST-TOO, the current line is also eligible as a target."
4404   (let ((way (if backward -1 1))
4405         (low gnus-level-killed)
4406         (beg (point))
4407         pos found lev)
4408     (if (and backward (progn (beginning-of-line)) (bobp))
4409         nil
4410       (or first-too (forward-line way))
4411       (while (and 
4412               (not (eobp))
4413               (not (setq 
4414                     found 
4415                     (and (or all
4416                              (and
4417                               (let ((unread 
4418                                      (get-text-property (point) 'gnus-unread)))
4419                                 (or (eq unread t) (and unread (> unread 0))))
4420                               (setq lev (get-text-property (point)
4421                                                            'gnus-level))
4422                               (<= lev gnus-level-subscribed)))
4423                          (or (not level)
4424                              (and (setq lev (get-text-property (point)
4425                                                                'gnus-level))
4426                                   (or (= lev level)
4427                                       (and (< lev low)
4428                                            (< level lev)
4429                                            (progn
4430                                              (setq low lev)
4431                                              (setq pos (point))
4432                                              nil))))))))
4433               (zerop (forward-line way)))))
4434     (if found 
4435         (progn (gnus-group-position-point) t)
4436       (goto-char (or pos beg))
4437       (and pos t))))
4438
4439 ;;; Gnus group mode commands
4440
4441 ;; Group marking.
4442
4443 (defun gnus-group-mark-group (n &optional unmark no-advance)
4444   "Mark the current group."
4445   (interactive "p")
4446   (let ((buffer-read-only nil)
4447         group)
4448     (while 
4449         (and (> n 0) 
4450              (setq group (gnus-group-group-name))
4451              (progn
4452                (beginning-of-line)
4453                (forward-char 
4454                 (or (cdr (assq 'process gnus-group-mark-positions)) 2))
4455                (delete-char 1)
4456                (if unmark
4457                    (progn
4458                      (insert " ")
4459                      (setq gnus-group-marked (delete group gnus-group-marked)))
4460                  (insert "#")
4461                  (setq gnus-group-marked
4462                        (cons group (delete group gnus-group-marked))))
4463                t)
4464              (or no-advance (zerop (gnus-group-next-group 1))))
4465       (setq n (1- n)))
4466     (gnus-summary-position-point)
4467     n))
4468
4469 (defun gnus-group-unmark-group (n)
4470   "Remove the mark from the current group."
4471   (interactive "p")
4472   (gnus-group-mark-group n 'unmark))
4473
4474 (defun gnus-group-mark-region (unmark beg end)
4475   "Mark all groups between point and mark.
4476 If UNMARK, remove the mark instead."
4477   (interactive "P\nr")
4478   (let ((num (count-lines beg end)))
4479     (save-excursion
4480       (goto-char beg)
4481       (- num (gnus-group-mark-group num unmark)))))
4482
4483 (defun gnus-group-remove-mark (group)
4484   (and (gnus-group-goto-group group)
4485        (save-excursion
4486          (gnus-group-mark-group 1 'unmark t))))
4487
4488 ;; Return a list of groups to work on.  Take into consideration N (the
4489 ;; prefix) and the list of marked groups.
4490 (defun gnus-group-process-prefix (n)
4491   (cond
4492    (n
4493     (setq n (prefix-numeric-value n))
4494     ;; There is a prefix, so we return a list of the N next
4495     ;; groups. 
4496     (let ((way (if (< n 0) -1 1))
4497           (n (abs n))
4498           group groups)
4499       (save-excursion
4500         (while (and (> n 0)
4501                     (setq group (gnus-group-group-name)))
4502           (setq groups (cons group groups))
4503           (setq n (1- n))
4504           (gnus-group-next-group way)))
4505       (nreverse groups)))
4506    ((and (boundp 'transient-mark-mode)
4507          transient-mark-mode
4508          mark-active)
4509     ;; Work on the region between point and mark.
4510     (let ((max (max (point) (mark)))
4511           groups)
4512       (save-excursion
4513         (goto-char (min (point) (mark)))
4514         (while 
4515             (and 
4516              (push (gnus-group-group-name) groups)
4517              (zerop (gnus-group-next-group 1))
4518              (< (point) max)))
4519         (nreverse groups))))
4520    (gnus-group-marked
4521     ;; No prefix, but a list of marked articles.
4522     (reverse gnus-group-marked))
4523    (t
4524     ;; Neither marked articles or a prefix, so we return the
4525     ;; current group.
4526     (let ((group (gnus-group-group-name)))
4527       (and group (list group))))))
4528
4529 ;; Selecting groups.
4530
4531 (defun gnus-group-read-group (&optional all no-article group)
4532   "Read news in this newsgroup.
4533 If the prefix argument ALL is non-nil, already read articles become
4534 readable.  IF ALL is a number, fetch this number of articles.  If the
4535 optional argument NO-ARTICLE is non-nil, no article will be
4536 auto-selected upon group entry.  If GROUP is non-nil, fetch that
4537 group."
4538   (interactive "P")
4539   (let ((group (or group (gnus-group-group-name)))
4540         number active marked entry)
4541     (or group (error "No group on current line"))
4542     (setq marked (nth 3 (nth 2 (setq entry (gnus-gethash
4543                                             group gnus-newsrc-hashtb)))))
4544     ;; This group might be a dead group.  In that case we have to get
4545     ;; the number of unread articles from `gnus-active-hashtb'.
4546     (setq number
4547           (cond ((numberp all) all)
4548                 (entry (car entry))
4549                 ((setq active (gnus-active group))
4550                  (- (1+ (cdr active)) (car active)))))
4551     (gnus-summary-read-group 
4552      group (or all (and (numberp number) 
4553                         (zerop (+ number (length (cdr (assq 'tick marked)))
4554                                   (length (cdr (assq 'dormant marked)))))))
4555      no-article)))
4556
4557 (defun gnus-group-select-group (&optional all)
4558   "Select this newsgroup.
4559 No article is selected automatically.
4560 If ALL is non-nil, already read articles become readable.
4561 If ALL is a number, fetch this number of articles."
4562   (interactive "P")
4563   (gnus-group-read-group all t))
4564
4565 (defun gnus-group-quick-select-group (&optional all)
4566   "Select the current group \"quickly\". 
4567 This means that no highlighting or scoring will be performed."
4568   (interactive "P")
4569   (let (gnus-visual
4570         gnus-score-find-score-files-function
4571         gnus-apply-kill-hook
4572         gnus-summary-expunge-below)
4573     (gnus-group-read-group all t)))
4574
4575 ;;;###autoload
4576 (defun gnus-fetch-group (group)
4577   "Start Gnus if necessary and enter GROUP.
4578 Returns whether the fetching was successful or not."
4579   (interactive "sGroup name: ")
4580   (or (get-buffer gnus-group-buffer)
4581       (gnus))
4582   (gnus-group-select-group))
4583
4584 ;; Enter a group that is not in the group buffer.  Non-nil is returned
4585 ;; if selection was successful.
4586 (defun gnus-group-read-ephemeral-group 
4587   (group method &optional activate quit-config)
4588   (let ((group (if (gnus-group-foreign-p group) group
4589                  (gnus-group-prefixed-name group method))))
4590     (gnus-sethash 
4591      group
4592      (list t nil (list group gnus-level-default-subscribed nil nil 
4593                        (append method
4594                                (list
4595                                 (list 'quit-config 
4596                                       (if quit-config quit-config
4597                                         (cons (current-buffer) 'summary)))))))
4598      gnus-newsrc-hashtb)
4599     (set-buffer gnus-group-buffer)
4600     (or (gnus-check-server method)
4601         (error "Unable to contact server: %s" (gnus-status-message method)))
4602     (if activate (or (gnus-request-group group)
4603                      (error "Couldn't request group")))
4604     (condition-case ()
4605         (gnus-group-read-group t t group)
4606       (error nil)
4607       (quit nil))
4608     (not (equal major-mode 'gnus-group-mode))))
4609   
4610 (defun gnus-group-jump-to-group (group)
4611   "Jump to newsgroup GROUP."
4612   (interactive 
4613    (list (completing-read 
4614           "Group: " gnus-active-hashtb nil 
4615           (memq gnus-select-method gnus-have-read-active-file))))
4616
4617   (if (equal group "")
4618       (error "Empty group name"))
4619
4620   (let ((b (text-property-any 
4621             (point-min) (point-max) 
4622             'gnus-group (gnus-intern-safe group gnus-active-hashtb))))
4623     (if b
4624         ;; Either go to the line in the group buffer...
4625         (goto-char b)
4626       ;; ... or insert the line.
4627       (or
4628        (gnus-active group)
4629        (gnus-activate-group group)
4630        (error "%s error: %s" group (gnus-status-message group)))
4631
4632       (gnus-group-update-group group)
4633       (goto-char (text-property-any 
4634                   (point-min) (point-max)
4635                   'gnus-group (gnus-intern-safe group gnus-active-hashtb)))))
4636   ;; Adjust cursor point.
4637   (gnus-group-position-point))
4638
4639 (defun gnus-group-goto-group (group)
4640   "Goto to newsgroup GROUP."
4641   (let ((b (text-property-any (point-min) (point-max) 
4642                               'gnus-group (gnus-intern-safe
4643                                            group gnus-active-hashtb))))
4644     (and b (goto-char b))))
4645
4646 (defun gnus-group-next-group (n)
4647   "Go to next N'th newsgroup.
4648 If N is negative, search backward instead.
4649 Returns the difference between N and the number of skips actually
4650 done."
4651   (interactive "p")
4652   (gnus-group-next-unread-group n t))
4653
4654 (defun gnus-group-next-unread-group (n &optional all level)
4655   "Go to next N'th unread newsgroup.
4656 If N is negative, search backward instead.
4657 If ALL is non-nil, choose any newsgroup, unread or not.
4658 If LEVEL is non-nil, choose the next group with level LEVEL, or, if no
4659 such group can be found, the next group with a level higher than
4660 LEVEL.
4661 Returns the difference between N and the number of skips actually
4662 made."
4663   (interactive "p")
4664   (let ((backward (< n 0))
4665         (n (abs n)))
4666     (while (and (> n 0)
4667                 (gnus-group-search-forward 
4668                  backward (or (not gnus-group-goto-unread) all) level))
4669       (setq n (1- n)))
4670     (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread")
4671                                (if level " on this level or higher" "")))
4672     n))
4673
4674 (defun gnus-group-prev-group (n)
4675   "Go to previous N'th newsgroup.
4676 Returns the difference between N and the number of skips actually
4677 done."
4678   (interactive "p")
4679   (gnus-group-next-unread-group (- n) t))
4680
4681 (defun gnus-group-prev-unread-group (n)
4682   "Go to previous N'th unread newsgroup.
4683 Returns the difference between N and the number of skips actually
4684 done."  
4685   (interactive "p")
4686   (gnus-group-next-unread-group (- n)))
4687
4688 (defun gnus-group-next-unread-group-same-level (n)
4689   "Go to next N'th unread newsgroup on the same level.
4690 If N is negative, search backward instead.
4691 Returns the difference between N and the number of skips actually
4692 done."
4693   (interactive "p")
4694   (gnus-group-next-unread-group n t (gnus-group-group-level))
4695   (gnus-group-position-point))
4696
4697 (defun gnus-group-prev-unread-group-same-level (n)
4698   "Go to next N'th unread newsgroup on the same level.
4699 Returns the difference between N and the number of skips actually
4700 done."
4701   (interactive "p")
4702   (gnus-group-next-unread-group (- n) t (gnus-group-group-level))
4703   (gnus-group-position-point))
4704
4705 (defun gnus-group-best-unread-group (&optional exclude-group)
4706   "Go to the group with the highest level.
4707 If EXCLUDE-GROUP, do not go to that group."
4708   (interactive)
4709   (goto-char (point-min))
4710   (let ((best 100000)
4711         unread best-point)
4712     (while (setq unread (get-text-property (point) 'gnus-unread))
4713       (if (and (numberp unread) (> unread 0))
4714           (progn
4715             (if (and (< (get-text-property (point) 'gnus-level) best)
4716                      (or (not exclude-group)
4717                          (not (equal exclude-group (gnus-group-group-name)))))
4718                 (progn 
4719                   (setq best (get-text-property (point) 'gnus-level))
4720                   (setq best-point (point))))))
4721       (forward-line 1))
4722     (if best-point (goto-char best-point))
4723     (gnus-summary-position-point)
4724     (and best-point (gnus-group-group-name))))
4725
4726 (defun gnus-group-first-unread-group ()
4727   "Go to the first group with unread articles."
4728   (interactive)
4729   (prog1
4730       (let ((opoint (point))
4731             unread)
4732         (goto-char (point-min))
4733         (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active.
4734                 (and (numberp unread)   ; Not a topic.
4735                      (not (zerop unread))) ; Has unread articles.
4736                 (zerop (gnus-group-next-unread-group 1))) ; Next unread group.
4737             (point)                     ; Success.
4738           (goto-char opoint)
4739           nil))                         ; Not success.
4740     (gnus-group-position-point)))
4741
4742 (defun gnus-group-enter-server-mode ()
4743   "Jump to the server buffer."
4744   (interactive)
4745   (gnus-enter-server-buffer))
4746
4747 (defun gnus-group-make-group (name &optional method address)
4748   "Add a new newsgroup.
4749 The user will be prompted for a NAME, for a select METHOD, and an
4750 ADDRESS."
4751   (interactive
4752    (cons 
4753     (read-string "Group name: ")
4754     (let ((method
4755            (completing-read 
4756             "Method: " (append gnus-valid-select-methods gnus-server-alist)
4757             nil t)))
4758       (if (assoc method gnus-valid-select-methods)
4759           (list method
4760                 (if (memq 'prompt-address
4761                           (assoc method gnus-valid-select-methods))
4762                     (read-string "Address: ")
4763                   ""))
4764         (list method nil)))))
4765   
4766   (save-excursion
4767     (set-buffer gnus-group-buffer)
4768     (let* ((meth (and method (if address (list (intern method) address) 
4769                                method)))
4770            (nname (if method (gnus-group-prefixed-name name meth) name))
4771            info)
4772       (and (gnus-gethash nname gnus-newsrc-hashtb)
4773            (error "Group %s already exists" nname))
4774       (gnus-group-change-level 
4775        (setq info (list t nname gnus-level-default-subscribed nil nil meth))
4776        gnus-level-default-subscribed gnus-level-killed 
4777        (and (gnus-group-group-name)
4778             (gnus-gethash (gnus-group-group-name)
4779                           gnus-newsrc-hashtb))
4780        t)
4781       (gnus-set-active nname (cons 1 0))
4782       (or (gnus-ephemeral-group-p name)
4783           (gnus-dribble-enter 
4784            (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")")))
4785       (gnus-group-insert-group-line-info nname)
4786
4787       (if (assoc method gnus-valid-select-methods)
4788           (require (intern method)))
4789       (and (gnus-check-backend-function 'request-create-group nname)
4790            (gnus-request-create-group nname))
4791       t)))
4792
4793 (defun gnus-group-delete-group (group &optional force)
4794   "Delete the current group.
4795 If FORCE (the prefix) is non-nil, all the articles in the group will
4796 be deleted.  This is \"deleted\" as in \"removed forever from the face
4797 of the Earth\".  There is no undo."
4798   (interactive 
4799    (list (gnus-group-group-name)
4800          current-prefix-arg))
4801   (or group (error "No group to rename"))
4802   (or (gnus-check-backend-function 'request-delete-group group)
4803       (error "This backend does not support group deletion"))
4804   (prog1
4805       (if (not (gnus-yes-or-no-p
4806                 (format
4807                  "Do you really want to delete %s%s? " 
4808                  group (if force " and all its contents" ""))))
4809           () ; Whew!
4810         (gnus-message 6 "Deleting group %s..." group)
4811         (if (not (gnus-request-delete-group group force))
4812             (progn
4813               (gnus-message 3 "Couldn't delete group %s" group)
4814               (ding))
4815           (gnus-message 6 "Deleting group %s...done" group)
4816           (gnus-group-goto-group group)
4817           (gnus-group-kill-group 1 t)
4818           t))
4819     (gnus-group-position-point)))
4820
4821 (defun gnus-group-rename-group (group new-name)
4822   (interactive
4823    (list
4824     (gnus-group-group-name)
4825     (progn
4826       (or (gnus-check-backend-function 
4827            'request-rename-group (gnus-group-group-name))
4828           (error "This backend does not support renaming groups"))
4829       (read-string "New group name: "))))
4830
4831   (or (gnus-check-backend-function 'request-rename-group group)
4832       (error "This backend does not support renaming groups"))
4833
4834   (or group (error "No group to rename"))
4835   (and (string-match "^[ \t]*$" new-name) 
4836        (error "Not a valid group name"))
4837
4838   ;; We find the proper prefixed name.
4839   (setq new-name
4840         (gnus-group-prefixed-name 
4841          (gnus-group-real-name new-name)
4842          (gnus-info-method (gnus-get-info group))))
4843
4844   (gnus-message 6 "Renaming group %s to %s..." group new-name)
4845   (prog1
4846       (if (not (gnus-request-rename-group group new-name))
4847           (progn
4848             (gnus-message 3 "Couldn't rename group %s to %s" group new-name)
4849             (ding))
4850         ;; We rename the group internally by killing it...
4851         (gnus-group-goto-group group)
4852         (gnus-group-kill-group)
4853         ;; ... changing its name ...
4854         (setcar (cdr (car gnus-list-of-killed-groups))
4855                 new-name)
4856         ;; ... and then yanking it.  Magic!
4857         (gnus-group-yank-group) 
4858         (gnus-message 6 "Renaming group %s to %s...done" group new-name)
4859         new-name)
4860     (gnus-group-position-point)))
4861
4862
4863 (defun gnus-group-edit-group (group &optional part)
4864   "Edit the group on the current line."
4865   (interactive (list (gnus-group-group-name)))
4866   (let ((done-func '(lambda () 
4867                       "Exit editing mode and update the information."
4868                       (interactive)
4869                       (gnus-group-edit-group-done 'part 'group)))
4870         (part (or part 'info))
4871         (winconf (current-window-configuration))
4872         info)
4873     (or group (error "No group on current line"))
4874     (or (setq info (gnus-get-info group))
4875         (error "Killed group; can't be edited"))
4876     (set-buffer (get-buffer-create gnus-group-edit-buffer))
4877     (gnus-configure-windows 'edit-group)
4878     (gnus-add-current-to-buffer-list)
4879     (emacs-lisp-mode)
4880     ;; Suggested by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4881     (use-local-map (copy-keymap emacs-lisp-mode-map))
4882     (local-set-key "\C-c\C-c" done-func)
4883     (make-local-variable 'gnus-prev-winconf)
4884     (setq gnus-prev-winconf winconf)
4885     ;; We modify the func to let it know what part it is editing.
4886     (setcar (cdr (nth 4 done-func)) (list 'quote part))
4887     (setcar (cdr (cdr (nth 4 done-func))) group)
4888     (erase-buffer)
4889     (insert
4890      (cond 
4891       ((eq part 'method)
4892        ";; Type `C-c C-c' after editing the select method.\n\n")
4893       ((eq part 'params)
4894        ";; Type `C-c C-c' after editing the group parameters.\n\n")
4895       ((eq part 'info)
4896        ";; Type `C-c C-c' after editing the group info.\n\n")))
4897     (insert 
4898      (pp-to-string
4899       (cond ((eq part 'method)
4900              (or (gnus-info-method info) "native"))
4901             ((eq part 'params)
4902              (gnus-info-params info))
4903             (t info)))
4904      "\n")))
4905
4906 (defun gnus-group-edit-group-method (group)
4907   "Edit the select method of GROUP."
4908   (interactive (list (gnus-group-group-name)))
4909   (gnus-group-edit-group group 'method))
4910
4911 (defun gnus-group-edit-group-parameters (group)
4912   "Edit the group parameters of GROUP."
4913   (interactive (list (gnus-group-group-name)))
4914   (gnus-group-edit-group group 'params))
4915
4916 (defun gnus-group-edit-group-done (part group)
4917   "Get info from buffer, update variables and jump to the group buffer."
4918   (set-buffer (get-buffer-create gnus-group-edit-buffer))
4919   (goto-char (point-min))
4920   (let ((form (read (current-buffer)))
4921         (winconf gnus-prev-winconf))
4922     (if (eq part 'info) 
4923         (gnus-group-set-info form)
4924       (gnus-group-set-info form group part))
4925     (kill-buffer (current-buffer))
4926     (and winconf (set-window-configuration winconf))
4927     (set-buffer gnus-group-buffer)
4928     (gnus-group-update-group (gnus-group-group-name))
4929     (gnus-group-position-point)))
4930
4931 (defun gnus-group-make-help-group ()
4932   "Create the Gnus documentation group."
4933   (interactive)
4934   (let ((path (cons (concat installation-directory "etc/") load-path))
4935         (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help")))
4936         file)
4937     (and (gnus-gethash name gnus-newsrc-hashtb)
4938          (error "Documentation group already exists"))
4939     (while (and path
4940                 (not (file-exists-p 
4941                       (setq file (concat (file-name-as-directory (car path))
4942                                          "gnus-tut.txt")))))
4943       (setq path (cdr path)))
4944     (if (not path)
4945         (message "Couldn't find doc group")
4946       (gnus-group-make-group 
4947        (gnus-group-real-name name)
4948        (list 'nndoc name
4949              (list 'nndoc-address file)
4950              (list 'nndoc-article-type 'mbox)))))
4951   (gnus-group-position-point))
4952
4953 (defun gnus-group-make-doc-group (file type)
4954   "Create a group that uses a single file as the source."
4955   (interactive 
4956    (list (read-file-name "File name: ") 
4957          (and current-prefix-arg 'ask)))
4958   (when (eq type 'ask)
4959     (let ((err "")
4960           char found)
4961       (while (not found)
4962         (message 
4963          "%sFile type (mbox, babyl, digest, forward, mmfd, guess) [mbdfag]: "
4964          err)
4965         (setq found (cond ((= (setq char (read-char)) ?m) 'mbox)
4966                           ((= char ?b) 'babyl)
4967                           ((= char ?d) 'digest)
4968                           ((= char ?f) 'forward)
4969                           ((= char ?a) 'mmfd)
4970                           (t (setq err (format "%c unknown. " char))
4971                              nil))))
4972       (setq type found)))
4973   (let* ((file (expand-file-name file))
4974          (name (gnus-generate-new-group-name
4975                 (gnus-group-prefixed-name
4976                  (file-name-nondirectory file) '(nndoc "")))))
4977     (gnus-group-make-group 
4978      (gnus-group-real-name name)
4979      (list 'nndoc name
4980            (list 'nndoc-address file)
4981            (list 'nndoc-article-type (or type 'guess))))
4982     (forward-line -1)
4983     (gnus-group-position-point)))
4984
4985 (defun gnus-group-make-archive-group (&optional all)
4986   "Create the (ding) Gnus archive group of the most recent articles.
4987 Given a prefix, create a full group."
4988   (interactive "P")
4989   (let ((group (gnus-group-prefixed-name 
4990                 (if all "ding.archives" "ding.recent") '(nndir ""))))
4991     (and (gnus-gethash group gnus-newsrc-hashtb)
4992          (error "Archive group already exists"))
4993     (gnus-group-make-group
4994      (gnus-group-real-name group)
4995      (list 'nndir (if all "hpc" "edu")
4996            (list 'nndir-directory  
4997                  (if all gnus-group-archive-directory 
4998                    gnus-group-recent-archive-directory)))))
4999   (forward-line -1)
5000   (gnus-group-position-point))
5001
5002 (defun gnus-group-make-directory-group (dir)
5003   "Create an nndir group.
5004 The user will be prompted for a directory.  The contents of this
5005 directory will be used as a newsgroup.  The directory should contain
5006 mail messages or news articles in files that have numeric names."
5007   (interactive
5008    (list (read-file-name "Create group from directory: ")))
5009   (or (file-exists-p dir) (error "No such directory"))
5010   (or (file-directory-p dir) (error "Not a directory"))
5011   (let ((ext "")
5012         (i 0)
5013         group)
5014     (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb))
5015       (setq group
5016             (gnus-group-prefixed-name 
5017              (concat (file-name-as-directory (directory-file-name dir))
5018                      ext)
5019              '(nndir "")))
5020       (setq ext (format "<%d>" (setq i (1+ i)))))
5021     (gnus-group-make-group 
5022      (gnus-group-real-name group)
5023      (list 'nndir group (list 'nndir-directory dir))))
5024   (forward-line -1)
5025   (gnus-group-position-point))
5026
5027 (defun gnus-group-make-kiboze-group (group address scores)
5028   "Create an nnkiboze group.
5029 The user will be prompted for a name, a regexp to match groups, and
5030 score file entries for articles to include in the group."
5031   (interactive
5032    (list
5033     (read-string "nnkiboze group name: ")
5034     (read-string "Source groups (regexp): ")
5035     (let ((headers (mapcar (lambda (group) (list group))
5036                            '("subject" "from" "number" "date" "message-id"
5037                              "references" "chars" "lines" "xref"
5038                              "followup" "all" "body" "head")))
5039           scores header regexp regexps)
5040       (while (not (equal "" (setq header (completing-read 
5041                                           "Match on header: " headers nil t))))
5042         (setq regexps nil)
5043         (while (not (equal "" (setq regexp (read-string 
5044                                             (format "Match on %s (string): "
5045                                                     header)))))
5046           (setq regexps (cons (list regexp nil nil 'r) regexps)))
5047         (setq scores (cons (cons header regexps) scores)))
5048       scores)))
5049   (gnus-group-make-group group "nnkiboze" address)
5050   (save-excursion
5051     (gnus-set-work-buffer)
5052     (let (emacs-lisp-mode-hook)
5053       (pp scores (current-buffer)))
5054     (write-region (point-min) (point-max) 
5055                   (gnus-score-file-name (concat "nnkiboze:" group))))
5056   (forward-line -1)
5057   (gnus-group-position-point))
5058
5059 (defun gnus-group-add-to-virtual (n vgroup)
5060   "Add the current group to a virtual group."
5061   (interactive
5062    (list current-prefix-arg
5063          (completing-read "Add to virtual group: " gnus-newsrc-hashtb nil t
5064                           "nnvirtual:")))
5065   (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual)
5066       (error "%s is not an nnvirtual group" vgroup))
5067   (let* ((groups (gnus-group-process-prefix n))
5068          (method (gnus-info-method (gnus-get-info vgroup))))
5069     (setcar (cdr method)
5070             (concat 
5071              (nth 1 method) "\\|"
5072              (mapconcat 
5073               (lambda (s) 
5074                 (gnus-group-remove-mark s)
5075                 (concat "\\(^" (regexp-quote s) "$\\)"))
5076               groups "\\|"))))
5077   (gnus-group-position-point))
5078
5079 (defun gnus-group-make-empty-virtual (group)
5080   "Create a new, fresh, empty virtual group."
5081   (interactive "sCreate new, empty virtual group: ")
5082   (let* ((method (list 'nnvirtual "^$"))
5083          (pgroup (gnus-group-prefixed-name group method)))
5084     ;; Check whether it exists already.
5085     (and (gnus-gethash pgroup gnus-newsrc-hashtb)
5086          (error "Group %s already exists." pgroup))
5087     ;; Subscribe the new group after the group on the current line.
5088     (gnus-subscribe-group pgroup (gnus-group-group-name) method)
5089     (gnus-group-update-group pgroup)
5090     (forward-line -1)
5091     (gnus-group-position-point)))
5092
5093 (defun gnus-group-enter-directory (dir)
5094   "Enter an ephemeral nneething group."
5095   (interactive "DDirectory to read: ")
5096   (let* ((method (list 'nneething dir))
5097          (leaf (gnus-group-prefixed-name
5098                 (file-name-nondirectory (directory-file-name dir))
5099                 method))
5100          (name (gnus-generate-new-group-name leaf)))
5101     (let ((nneething-read-only t))
5102       (or (gnus-group-read-ephemeral-group 
5103            name method t
5104            (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode)
5105                                       'summary 'group)))
5106           (error "Couldn't enter %s" dir)))))
5107
5108 ;; Group sorting commands
5109 ;; Suggested by Joe Hildebrand <hildjj@idaho.fuentez.com>.
5110
5111 (defun gnus-group-sort-groups (func &optional reverse)
5112   "Sort the group buffer according to FUNC.
5113 If REVERSE, reverse the sorting order."
5114   (interactive (list gnus-group-sort-function
5115                      current-prefix-arg))
5116   (unless (listp func)
5117     (setq func (list func)))
5118   ;; We peel off the dummy group from the alist.
5119   (when (equal (car (gnus-info-group gnus-newsrc-alist)) "dummy.group")
5120     (pop gnus-newsrc-alist))
5121   ;; Do the sorting.
5122   (while func
5123     (setq gnus-newsrc-alist 
5124           (sort gnus-newsrc-alist (pop func))))
5125   (when reverse
5126     (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
5127   ;; Regenerate the hash table.
5128   (gnus-make-hashtable-from-newsrc-alist)
5129   (gnus-group-list-groups))
5130
5131 (defun gnus-group-sort-groups-by-alphabet (&optional reverse)
5132   "Sort the group buffer alphabetically by group name.
5133 If REVERSE, sort in reverse order."
5134   (interactive "P")
5135   (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse))
5136
5137 (defun gnus-group-sort-groups-by-unread (&optional reverse)
5138   "Sort the group buffer by number of unread articles.
5139 If REVERSE, sort in reverse order."
5140   (interactive "P")
5141   (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse))
5142
5143 (defun gnus-group-sort-groups-by-level (&optional reverse)
5144   "Sort the group buffer by group level.
5145 If REVERSE, sort in reverse order."
5146   (interactive "P")
5147   (gnus-group-sort-groups 'gnus-group-sort-by-level reverse))
5148
5149 (defun gnus-group-sort-groups-by-score (&optional reverse)
5150   "Sort the group buffer by group score.
5151 If REVERSE, sort in reverse order."
5152   (interactive "P")
5153   (gnus-group-sort-groups 'gnus-group-sort-by-score reverse))
5154
5155 (defun gnus-group-sort-groups-by-rank (&optional reverse)
5156   "Sort the group buffer by group rank.
5157 If REVERSE, sort in reverse order."
5158   (interactive "P")
5159   (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse))
5160
5161 (defun gnus-group-sort-groups-by-method (&optional reverse)
5162   "Sort the group buffer alphabetically by backend name.
5163 If REVERSE, sort in reverse order."
5164   (interactive "P")
5165   (gnus-group-sort-groups 'gnus-group-sort-by-method reverse))
5166
5167 (defun gnus-group-sort-by-alphabet (info1 info2)
5168   "Sort alphabetically."
5169   (string< (gnus-info-group info1) (gnus-info-group info2)))
5170
5171 (defun gnus-group-sort-by-unread (info1 info2)
5172   "Sort by number of unread articles."
5173   (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb)))
5174         (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb))))
5175     (< (or (and (numberp n1) n1) 0)
5176        (or (and (numberp n2) n2) 0))))
5177
5178 (defun gnus-group-sort-by-level (info1 info2)
5179   "Sort by level."
5180   (< (gnus-info-level info1) (gnus-info-level info2)))
5181
5182 (defun gnus-group-sort-by-method (info1 info2)
5183   "Sort alphabetically by backend name."
5184   (string< (symbol-name (car (gnus-find-method-for-group
5185                               (gnus-info-group info1))))
5186            (symbol-name (car (gnus-find-method-for-group 
5187                               (gnus-info-group info2))))))
5188
5189 (defun gnus-group-sort-by-score (info1 info2)
5190   "Sort by group score."
5191   (< (gnus-info-score info1) (gnus-info-score info2)))
5192
5193 (defun gnus-group-sort-by-rank (info1 info2)
5194   "Sort by level and score."
5195   (let ((level1 (gnus-info-level info1))
5196         (level2 (gnus-info-level info2)))
5197     (or (< level1 level2)
5198         (and (= level1 level2)
5199              (< (gnus-info-score info1) (gnus-info-score info2))))))
5200
5201 ;; Group catching up.
5202
5203 (defun gnus-group-catchup-current (&optional n all)
5204   "Mark all articles not marked as unread in current newsgroup as read.
5205 If prefix argument N is numeric, the ARG next newsgroups will be
5206 caught up.  If ALL is non-nil, marked articles will also be marked as
5207 read.  Cross references (Xref: header) of articles are ignored.
5208 The difference between N and actual number of newsgroups that were
5209 caught up is returned."
5210   (interactive "P")
5211   (if (not (or (not gnus-interactive-catchup) ;Without confirmation?
5212                gnus-expert-user
5213                (gnus-y-or-n-p
5214                 (if all
5215                     "Do you really want to mark all articles as read? "
5216                   "Mark all unread articles as read? "))))
5217       n
5218     (let ((groups (gnus-group-process-prefix n))
5219           (ret 0))
5220       (while groups
5221         ;; Virtual groups have to be given special treatment. 
5222         (let ((method (gnus-find-method-for-group (car groups))))
5223           (if (eq 'nnvirtual (car method))
5224               (nnvirtual-catchup-group
5225                (gnus-group-real-name (car groups)) (nth 1 method) all)))
5226         (gnus-group-remove-mark (car groups))
5227         (if (prog1
5228                 (gnus-group-goto-group (car groups))
5229               (gnus-group-catchup (car groups) all))
5230             (gnus-group-update-group-line)
5231           (setq ret (1+ ret)))
5232         (setq groups (cdr groups)))
5233       (gnus-group-next-unread-group 1)
5234       ret)))
5235
5236 (defun gnus-group-catchup-current-all (&optional n)
5237   "Mark all articles in current newsgroup as read.
5238 Cross references (Xref: header) of articles are ignored."
5239   (interactive "P")
5240   (gnus-group-catchup-current n 'all))
5241
5242 (defun gnus-group-catchup (group &optional all)
5243   "Mark all articles in GROUP as read.
5244 If ALL is non-nil, all articles are marked as read.
5245 The return value is the number of articles that were marked as read,
5246 or nil if no action could be taken."
5247   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5248          (num (car entry))
5249          (marked (nth 3 (nth 2 entry))))
5250     (if (not (numberp (car entry)))
5251         (gnus-message 1 "Can't catch up; non-active group")
5252       ;; Do the updating only if the newsgroup isn't killed.
5253       (when entry
5254         (gnus-update-read-articles group nil)
5255         ;; Also nix out the lists of marks and dormants. 
5256         (when all 
5257           (gnus-add-marked-articles group 'tick nil nil 'force)
5258           (gnus-add-marked-articles group 'dormant nil nil 'force))
5259         num))))
5260
5261 (defun gnus-group-expire-articles (&optional n)
5262   "Expire all expirable articles in the current newsgroup."
5263   (interactive "P")
5264   (let ((groups (gnus-group-process-prefix n))
5265         group)
5266     (or groups (error "No groups to expire"))
5267     (while groups
5268       (setq group (car groups)
5269             groups (cdr groups))
5270       (gnus-group-remove-mark group)
5271       (if (not (gnus-check-backend-function 'request-expire-articles group))
5272           ()
5273         (let* ((info (gnus-get-info group))
5274                (expirable (if (gnus-group-total-expirable-p group)
5275                               (cons nil (gnus-list-of-read-articles group))
5276                             (assq 'expire (gnus-info-marks info)))))
5277           (and expirable 
5278                (setcdr expirable
5279                        (gnus-request-expire-articles 
5280                         (cdr expirable) group))))))))
5281
5282 (defun gnus-group-expire-all-groups ()
5283   "Expire all expirable articles in all newsgroups."
5284   (interactive)
5285   (save-excursion
5286     (gnus-message 5 "Expiring...")
5287     (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info))
5288                                      (cdr gnus-newsrc-alist))))
5289       (gnus-group-expire-articles nil)))
5290   (gnus-group-position-point)
5291   (gnus-message 5 "Expiring...done"))
5292
5293 (defun gnus-group-set-current-level (n level)
5294   "Set the level of the next N groups to LEVEL."
5295   (interactive 
5296    (list
5297     current-prefix-arg
5298     (string-to-int
5299      (let ((s (read-string 
5300                (format "Level (default %s): " (gnus-group-group-level)))))
5301        (if (string-match "^\\s-*$" s)
5302            (int-to-string (gnus-group-group-level))
5303          s)))))
5304   (or (and (>= level 1) (<= level gnus-level-killed))
5305       (error "Illegal level: %d" level))
5306   (let ((groups (gnus-group-process-prefix n))
5307         group)
5308     (while groups
5309       (setq group (car groups)
5310             groups (cdr groups))
5311       (gnus-group-remove-mark group)
5312       (gnus-message 6 "Changed level of %s from %d to %d" 
5313                     group (gnus-group-group-level) level)
5314       (gnus-group-change-level group level
5315                                (gnus-group-group-level))
5316       (gnus-group-update-group-line)))
5317   (gnus-group-position-point))
5318
5319 (defun gnus-group-unsubscribe-current-group (&optional n)
5320   "Toggle subscription of the current group.
5321 If given numerical prefix, toggle the N next groups."
5322   (interactive "P")
5323   (let ((groups (gnus-group-process-prefix n))
5324         group)
5325     (while groups
5326       (setq group (car groups)
5327             groups (cdr groups))
5328       (gnus-group-remove-mark group)
5329       (gnus-group-unsubscribe-group
5330        group (if (<= (gnus-group-group-level) gnus-level-subscribed)
5331                  gnus-level-default-unsubscribed
5332                gnus-level-default-subscribed))
5333       (gnus-group-update-group-line))
5334     (gnus-group-next-group 1)))
5335
5336 (defun gnus-group-unsubscribe-group (group &optional level)
5337   "Toggle subscribe from/to unsubscribe GROUP.
5338 New newsgroup is added to .newsrc automatically."
5339   (interactive
5340    (list (completing-read
5341           "Group: " gnus-active-hashtb nil 
5342           (memq gnus-select-method gnus-have-read-active-file))))
5343   (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb)))
5344     (cond
5345      ((string-match "^[ \t]$" group)
5346       (error "Empty group name"))
5347      (newsrc
5348       ;; Toggle subscription flag.
5349       (gnus-group-change-level 
5350        newsrc (if level level (if (<= (nth 1 (nth 2 newsrc)) 
5351                                       gnus-level-subscribed) 
5352                                   (1+ gnus-level-subscribed)
5353                                 gnus-level-default-subscribed)))
5354       (gnus-group-update-group group))
5355      ((and (stringp group)
5356            (or (not (memq gnus-select-method gnus-have-read-active-file))
5357                (gnus-active group)))
5358       ;; Add new newsgroup.
5359       (gnus-group-change-level 
5360        group 
5361        (if level level gnus-level-default-subscribed) 
5362        (or (and (member group gnus-zombie-list) 
5363                 gnus-level-zombie) 
5364            gnus-level-killed)
5365        (and (gnus-group-group-name)
5366             (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)))
5367       (gnus-group-update-group group))
5368      (t (error "No such newsgroup: %s" group)))
5369     (gnus-group-position-point)))
5370
5371 (defun gnus-group-transpose-groups (n)
5372   "Move the current newsgroup up N places.
5373 If given a negative prefix, move down instead.  The difference between
5374 N and the number of steps taken is returned." 
5375   (interactive "p")
5376   (or (gnus-group-group-name)
5377       (error "No group on current line"))
5378   (gnus-group-kill-group 1)
5379   (prog1
5380       (forward-line (- n))
5381     (gnus-group-yank-group)
5382     (gnus-group-position-point)))
5383
5384 (defun gnus-group-kill-all-zombies ()
5385   "Kill all zombie newsgroups."
5386   (interactive)
5387   (setq gnus-killed-list (nconc gnus-zombie-list gnus-killed-list))
5388   (setq gnus-zombie-list nil)
5389   (gnus-group-list-groups))
5390
5391 (defun gnus-group-kill-region (begin end)
5392   "Kill newsgroups in current region (excluding current point).
5393 The killed newsgroups can be yanked by using \\[gnus-group-yank-group]."
5394   (interactive "r")
5395   (let ((lines
5396          ;; Count lines.
5397          (save-excursion
5398            (count-lines
5399             (progn
5400               (goto-char begin)
5401               (beginning-of-line)
5402               (point))
5403             (progn
5404               (goto-char end)
5405               (beginning-of-line)
5406               (point))))))
5407     (goto-char begin)
5408     (beginning-of-line)                 ;Important when LINES < 1
5409     (gnus-group-kill-group lines)))
5410
5411 (defun gnus-group-kill-group (&optional n discard)
5412   "Kill the next N groups.
5413 The killed newsgroups can be yanked by using \\[gnus-group-yank-group].
5414 However, only groups that were alive can be yanked; already killed 
5415 groups or zombie groups can't be yanked.
5416 The return value is the name of the (last) group that was killed."
5417   (interactive "P")
5418   (let ((buffer-read-only nil)
5419         (groups (gnus-group-process-prefix n))
5420         group entry level)
5421     (if (or t (< (length groups) 10))
5422         ;; This is faster when there are few groups.
5423         (while groups
5424           (setq group (car groups)
5425                 groups (cdr groups))
5426           (gnus-group-remove-mark group)
5427           (setq level (gnus-group-group-level))
5428           (gnus-delete-line)
5429           (if (and (not discard)
5430                    (setq entry (gnus-gethash group gnus-newsrc-hashtb)))
5431               (setq gnus-list-of-killed-groups 
5432                     (cons (cons (car entry) (nth 2 entry)) 
5433                           gnus-list-of-killed-groups)))
5434           (gnus-group-change-level 
5435            (if entry entry group) gnus-level-killed (if entry nil level)))
5436       ;; If there are lots and lots of groups to be killed, we use
5437       ;; this thing instead.
5438       ;; !!! Not written.
5439       )
5440       
5441     (gnus-group-position-point)
5442     group))
5443
5444 (defun gnus-group-yank-group (&optional arg)
5445   "Yank the last newsgroups killed with \\[gnus-group-kill-group],
5446 inserting it before the current newsgroup.  The numeric ARG specifies
5447 how many newsgroups are to be yanked.  The name of the (last)
5448 newsgroup yanked is returned."
5449   (interactive "p")
5450   (if (not arg) (setq arg 1))
5451   (let (info group prev)
5452     (while (>= (setq arg (1- arg)) 0)
5453       (if (not (setq info (car gnus-list-of-killed-groups)))
5454           (error "No more newsgroups to yank"))
5455       (setq group (nth 2 info))
5456       ;; Find which newsgroup to insert this one before - search
5457       ;; backward until something suitable is found.  If there are no
5458       ;; other newsgroups in this buffer, just make this newsgroup the
5459       ;; first newsgroup.
5460       (setq prev (gnus-group-group-name))
5461       (gnus-group-change-level 
5462        info (nth 2 info) gnus-level-killed 
5463        (and prev (gnus-gethash prev gnus-newsrc-hashtb))
5464        t)
5465       (gnus-group-insert-group-line-info (nth 1 info))
5466       (setq gnus-list-of-killed-groups 
5467             (cdr gnus-list-of-killed-groups)))
5468     (forward-line -1)
5469     (gnus-group-position-point)
5470     group))
5471       
5472 (defun gnus-group-list-all-groups (&optional arg)
5473   "List all newsgroups with level ARG or lower.
5474 Default is gnus-level-unsubscribed, which lists all subscribed and most
5475 unsubscribed groups."
5476   (interactive "P")
5477   (gnus-group-list-groups (or arg gnus-level-unsubscribed) t))
5478
5479 ;; Redefine this to list ALL killed groups if prefix arg used.
5480 ;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom).
5481 (defun gnus-group-list-killed (&optional arg)
5482   "List all killed newsgroups in the group buffer.
5483 If ARG is non-nil, list ALL killed groups known to Gnus.  This may
5484 entail asking the server for the groups."
5485   (interactive "P")
5486   ;; Find all possible killed newsgroups if arg.
5487   (when arg
5488     ;; First make sure active file has been read.
5489     (or gnus-have-read-active-file (gnus-read-active-file))
5490     (or gnus-killed-hashtb (gnus-make-hashtable-from-killed))
5491     ;; Go through all newsgroups that are known to Gnus - enlarge kill list
5492     (mapatoms
5493      (lambda (sym)
5494        (let ((groups 0)
5495              (group (symbol-name sym)))
5496          (if (or (null group)
5497                  (gnus-gethash group gnus-killed-hashtb)
5498                  (gnus-gethash group gnus-newsrc-hashtb))
5499              ()
5500            (let ((do-sub (gnus-matches-options-n group)))
5501              (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore))
5502                  ()
5503                (setq groups (1+ groups))
5504                (setq gnus-killed-list 
5505                      (cons group gnus-killed-list))
5506                (gnus-sethash group group gnus-killed-hashtb))))))
5507      gnus-active-hashtb))
5508   (if (not gnus-killed-list)
5509       (gnus-message 6 "No killed groups")
5510     (let (gnus-group-list-mode)
5511       (funcall gnus-group-prepare-function 
5512                gnus-level-killed t gnus-level-killed))
5513     (goto-char (point-min)))
5514   (gnus-group-position-point))
5515
5516 (defun gnus-group-list-zombies ()
5517   "List all zombie newsgroups in the group buffer."
5518   (interactive)
5519   (if (not gnus-zombie-list)
5520       (gnus-message 6 "No zombie groups")
5521     (let (gnus-group-list-mode)
5522       (funcall gnus-group-prepare-function
5523                gnus-level-zombie t gnus-level-zombie))
5524     (goto-char (point-min)))
5525   (gnus-group-position-point))
5526
5527 (defun gnus-group-list-active ()
5528   "List all groups that are available from the server(s)."
5529   (interactive)
5530   ;; First we make sure that we have really read the active file. 
5531   (or gnus-have-read-active-file
5532       (gnus-read-active-file))
5533   ;; Find all groups and sort them.
5534   (let ((groups 
5535          (sort 
5536           (let (list)
5537             (mapatoms
5538              (lambda (sym)
5539                (and (symbol-value sym)
5540                     (setq list (cons (symbol-name sym) list))))
5541              gnus-active-hashtb)
5542             list)
5543           'string<))
5544         (buffer-read-only nil))
5545     (erase-buffer)
5546     (while groups
5547       (gnus-group-insert-group-line-info (car groups))
5548       (setq groups (cdr groups)))
5549     (goto-char (point-min))))
5550
5551 (defun gnus-group-get-new-news (&optional arg)
5552   "Get newly arrived articles.
5553 If ARG is a number, it specifies which levels you are interested in
5554 re-scanning.  If ARG is non-nil and not a number, this will force
5555 \"hard\" re-reading of the active files from all servers."
5556   (interactive "P")
5557   (run-hooks 'gnus-get-new-news-hook)
5558   ;; We might read in new NoCeM messages here.
5559   (and gnus-use-nocem (gnus-nocem-scan-groups))
5560   ;; If ARG is not a number, then we read the active file.
5561   (and arg
5562        (not (numberp arg))
5563        (progn
5564          (let ((gnus-read-active-file t))
5565            (gnus-read-active-file))
5566          (setq arg nil)))
5567
5568   (setq arg (gnus-group-default-level arg t))
5569   (if (and gnus-read-active-file (not arg))
5570       (progn
5571         (gnus-read-active-file)
5572         (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed))))
5573     (let ((gnus-read-active-file (if arg nil gnus-read-active-file)))
5574       (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed)))))
5575   (gnus-group-list-groups))
5576
5577 (defun gnus-group-get-new-news-this-group (&optional n)
5578   "Check for newly arrived news in the current group (and the N-1 next groups).
5579 The difference between N and the number of newsgroup checked is returned.
5580 If N is negative, this group and the N-1 previous groups will be checked."
5581   (interactive "P")
5582   (let* ((groups (gnus-group-process-prefix n))
5583          (ret (if (numberp n) (- n (length groups)) 0))
5584          group)
5585     (while groups
5586       (setq group (car groups)
5587             groups (cdr groups))
5588       (gnus-group-remove-mark group)
5589       (or (gnus-get-new-news-in-group group)
5590           (progn 
5591             (ding) 
5592             (message "%s error: %s" group (gnus-status-message group))
5593             (sit-for 2))))
5594     (gnus-group-next-unread-group 1 t)
5595     (gnus-summary-position-point)
5596     ret))
5597
5598 (defun gnus-get-new-news-in-group (group)
5599   (when (and group (gnus-activate-group group 'scan))
5600     (gnus-get-unread-articles-in-group 
5601      (gnus-get-info group) (gnus-active group))
5602     (gnus-group-update-group-line)
5603     t))
5604
5605 (defun gnus-group-fetch-faq (group &optional faq-dir)
5606   "Fetch the FAQ for the current group."
5607   (interactive 
5608    (list
5609     (gnus-group-real-name (gnus-group-group-name))
5610     (cond (current-prefix-arg
5611            (completing-read 
5612             "Faq dir: " (and (listp gnus-group-faq-directory) 
5613                              gnus-group-faq-directory))))))
5614   (or faq-dir
5615       (setq faq-dir (if (listp gnus-group-faq-directory)
5616                         (car gnus-group-faq-directory)
5617                       gnus-group-faq-directory)))
5618   (or group (error "No group name given"))
5619   (let ((file (concat (file-name-as-directory faq-dir)
5620                       (gnus-group-real-name group))))
5621     (if (not (file-exists-p file))
5622         (error "No such file: %s" file)
5623       (find-file file))))
5624   
5625 (defun gnus-group-describe-group (force &optional group)
5626   "Display a description of the current newsgroup."
5627   (interactive (list current-prefix-arg (gnus-group-group-name)))
5628   (and force (setq gnus-description-hashtb nil))
5629   (let ((method (gnus-find-method-for-group group))
5630         desc)
5631     (or group (error "No group name given"))
5632     (and (or (and gnus-description-hashtb
5633                   ;; We check whether this group's method has been
5634                   ;; queried for a description file.  
5635                   (gnus-gethash 
5636                    (gnus-group-prefixed-name "" method) 
5637                    gnus-description-hashtb))
5638              (setq desc (gnus-group-get-description group))
5639              (gnus-read-descriptions-file method))
5640          (message
5641           (or desc (gnus-gethash group gnus-description-hashtb)
5642               "No description available")))))
5643
5644 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5645 (defun gnus-group-describe-all-groups (&optional force)
5646   "Pop up a buffer with descriptions of all newsgroups."
5647   (interactive "P")
5648   (and force (setq gnus-description-hashtb nil))
5649   (if (not (or gnus-description-hashtb
5650                (gnus-read-all-descriptions-files)))
5651       (error "Couldn't request descriptions file"))
5652   (let ((buffer-read-only nil)
5653         b)
5654     (erase-buffer)
5655     (mapatoms
5656      (lambda (group)
5657        (setq b (point))
5658        (insert (format "      *: %-20s %s\n" (symbol-name group)
5659                        (symbol-value group)))
5660        (add-text-properties 
5661         b (1+ b) (list 'gnus-group group
5662                        'gnus-unread t 'gnus-marked nil
5663                        'gnus-level (1+ gnus-level-subscribed))))
5664      gnus-description-hashtb)
5665     (goto-char (point-min))
5666     (gnus-group-position-point)))
5667
5668 ;; Suggested by by Daniel Quinlan <quinlan@best.com>.
5669 (defun gnus-group-apropos (regexp &optional search-description)
5670   "List all newsgroups that have names that match a regexp."
5671   (interactive "sGnus apropos (regexp): ")
5672   (let ((prev "")
5673         (obuf (current-buffer))
5674         groups des)
5675     ;; Go through all newsgroups that are known to Gnus.
5676     (mapatoms 
5677      (lambda (group)
5678        (and (symbol-name group)
5679             (string-match regexp (symbol-name group))
5680             (setq groups (cons (symbol-name group) groups))))
5681      gnus-active-hashtb)
5682     ;; Go through all descriptions that are known to Gnus. 
5683     (if search-description
5684         (mapatoms 
5685          (lambda (group)
5686            (and (string-match regexp (symbol-value group))
5687                 (gnus-active (symbol-name group))
5688                 (setq groups (cons (symbol-name group) groups))))
5689          gnus-description-hashtb))
5690     (if (not groups)
5691         (gnus-message 3 "No groups matched \"%s\"." regexp)
5692       ;; Print out all the groups.
5693       (save-excursion
5694         (pop-to-buffer "*Gnus Help*")
5695         (buffer-disable-undo (current-buffer))
5696         (erase-buffer)
5697         (setq groups (sort groups 'string<))
5698         (while groups
5699           ;; Groups may be entered twice into the list of groups.
5700           (if (not (string= (car groups) prev))
5701               (progn
5702                 (insert (setq prev (car groups)) "\n")
5703                 (if (and gnus-description-hashtb
5704                          (setq des (gnus-gethash (car groups) 
5705                                                  gnus-description-hashtb)))
5706                     (insert "  " des "\n"))))
5707           (setq groups (cdr groups)))
5708         (goto-char (point-min))))
5709     (pop-to-buffer obuf)))
5710
5711 (defun gnus-group-description-apropos (regexp)
5712   "List all newsgroups that have names or descriptions that match a regexp."
5713   (interactive "sGnus description apropos (regexp): ")
5714   (if (not (or gnus-description-hashtb
5715                (gnus-read-all-descriptions-files)))
5716       (error "Couldn't request descriptions file"))
5717   (gnus-group-apropos regexp t))
5718
5719 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5720 (defun gnus-group-list-matching (level regexp &optional all lowest) 
5721   "List all groups with unread articles that match REGEXP.
5722 If the prefix LEVEL is non-nil, it should be a number that says which
5723 level to cut off listing groups. 
5724 If ALL, also list groups with no unread articles.
5725 If LOWEST, don't list groups with level lower than LOWEST."
5726   (interactive "P\nsList newsgroups matching: ")
5727   (gnus-group-prepare-flat (or level gnus-level-subscribed)
5728                            all (or lowest 1) regexp)
5729   (goto-char (point-min))
5730   (gnus-group-position-point))
5731
5732 (defun gnus-group-list-all-matching (level regexp &optional lowest) 
5733   "List all groups that match REGEXP.
5734 If the prefix LEVEL is non-nil, it should be a number that says which
5735 level to cut off listing groups. 
5736 If LOWEST, don't list groups with level lower than LOWEST."
5737   (interactive "P\nsList newsgroups matching: ")
5738   (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest))
5739
5740 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
5741 (defun gnus-group-save-newsrc (&optional force)
5742   "Save the Gnus startup files.
5743 If FORCE, force saving whether it is necessary or not."
5744   (interactive "P")
5745   (gnus-save-newsrc-file force))
5746
5747 (defun gnus-group-restart (&optional arg)
5748   "Force Gnus to read the .newsrc file."
5749   (interactive "P")
5750   (gnus-save-newsrc-file)
5751   (gnus-setup-news 'force)
5752   (gnus-group-list-groups arg))
5753
5754 (defun gnus-group-read-init-file ()
5755   "Read the Gnus elisp init file."
5756   (interactive)
5757   (gnus-read-init-file))
5758
5759 (defun gnus-group-check-bogus-groups (&optional silent)
5760   "Check bogus newsgroups.
5761 If given a prefix, don't ask for confirmation before removing a bogus
5762 group."
5763   (interactive "P")
5764   (gnus-check-bogus-newsgroups (and (not silent) (not gnus-expert-user)))
5765   (gnus-group-list-groups))
5766
5767 (defun gnus-group-edit-global-kill (&optional article group)
5768   "Edit the global kill file.
5769 If GROUP, edit that local kill file instead."
5770   (interactive "P")
5771   (setq gnus-current-kill-article article)
5772   (gnus-kill-file-edit-file group)
5773   (gnus-message 
5774    6
5775    (substitute-command-keys
5776     "Editing a global kill file (Type \\[gnus-kill-file-exit] to exit)")))
5777
5778 (defun gnus-group-edit-local-kill (article group)
5779   "Edit a local kill file."
5780   (interactive (list nil (gnus-group-group-name)))
5781   (gnus-group-edit-global-kill article group))
5782
5783 (defun gnus-group-force-update ()
5784   "Update `.newsrc' file."
5785   (interactive)
5786   (gnus-save-newsrc-file))
5787
5788 (defun gnus-group-suspend ()
5789   "Suspend the current Gnus session.
5790 In fact, cleanup buffers except for group mode buffer.
5791 The hook gnus-suspend-gnus-hook is called before actually suspending."
5792   (interactive)
5793   (run-hooks 'gnus-suspend-gnus-hook)
5794   ;; Kill Gnus buffers except for group mode buffer.
5795   (let ((group-buf (get-buffer gnus-group-buffer)))
5796     ;; Do this on a separate list in case the user does a ^G before we finish
5797     (let ((gnus-buffer-list
5798            (delq group-buf (delq gnus-dribble-buffer
5799                                  (append gnus-buffer-list nil)))))
5800       (while gnus-buffer-list
5801         (gnus-kill-buffer (car gnus-buffer-list))
5802         (setq gnus-buffer-list (cdr gnus-buffer-list))))
5803     (if group-buf
5804         (progn
5805           (setq gnus-buffer-list (list group-buf))
5806           (bury-buffer group-buf)
5807           (delete-windows-on group-buf t)))))
5808
5809 (defun gnus-group-clear-dribble ()
5810   "Clear all information from the dribble buffer."
5811   (interactive)
5812   (gnus-dribble-clear))
5813
5814 (defun gnus-group-exit ()
5815   "Quit reading news after updating .newsrc.eld and .newsrc.
5816 The hook `gnus-exit-gnus-hook' is called before actually exiting."
5817   (interactive)
5818   (if (or noninteractive                ;For gnus-batch-kill
5819           (not (gnus-server-opened gnus-select-method)) ;NNTP connection closed
5820           (not gnus-interactive-exit)   ;Without confirmation
5821           gnus-expert-user
5822           (gnus-y-or-n-p "Are you sure you want to quit reading news? "))
5823       (progn
5824         (run-hooks 'gnus-exit-gnus-hook)
5825         ;; Offer to save data from non-quitted summary buffers.
5826         (gnus-offer-save-summaries)
5827         ;; Save the newsrc file(s).
5828         (gnus-save-newsrc-file)
5829         ;; Kill-em-all.
5830         (gnus-close-backends)
5831         ;; Reset everything.
5832         (gnus-clear-system))))
5833
5834 (defun gnus-close-backends ()
5835   ;; Send a close request to all backends that support such a request. 
5836   (let ((methods gnus-valid-select-methods)
5837         func)
5838     (while methods
5839       (if (fboundp (setq func (intern (concat (car (car methods))
5840                                               "-request-close"))))
5841           (funcall func))
5842       (setq methods (cdr methods)))))
5843
5844 (defun gnus-group-quit ()
5845   "Quit reading news without updating .newsrc.eld or .newsrc.
5846 The hook `gnus-exit-gnus-hook' is called before actually exiting."
5847   (interactive)
5848   (when (or noninteractive              ;For gnus-batch-kill
5849             (zerop (buffer-size))
5850             (not (gnus-server-opened gnus-select-method))
5851             gnus-expert-user
5852             (not gnus-current-startup-file)
5853             (gnus-yes-or-no-p
5854              (format "Quit reading news without saving %s? "
5855                      (file-name-nondirectory gnus-current-startup-file))))
5856     (run-hooks 'gnus-exit-gnus-hook)
5857     (if gnus-use-full-window
5858         (delete-other-windows)
5859       (gnus-remove-some-windows))
5860     (gnus-dribble-save)
5861     (gnus-close-backends)
5862     (gnus-clear-system)))
5863
5864 (defun gnus-offer-save-summaries ()
5865   "Offer to save all active summary buffers."
5866   (save-excursion
5867     (let ((buflist (buffer-list)) 
5868           buffers bufname)
5869       ;; Go through all buffers and find all summaries.
5870       (while buflist
5871         (and (setq bufname (buffer-name (car buflist)))
5872              (string-match "Summary" bufname)
5873              (save-excursion
5874                (set-buffer bufname)
5875                ;; We check that this is, indeed, a summary buffer.
5876                (and (eq major-mode 'gnus-summary-mode)
5877                     ;; Also make sure this isn't bogus.
5878                     gnus-newsgroup-prepared))
5879              (push bufname buffers))
5880         (setq buflist (cdr buflist)))
5881       ;; Go through all these summary buffers and offer to save them.
5882       (when buffers
5883         (map-y-or-n-p 
5884          "Update summary buffer %s? "
5885          (lambda (buf) (set-buffer buf) (gnus-summary-exit))
5886          buffers)))))
5887
5888 (defun gnus-group-describe-briefly ()
5889   "Give a one line description of the group mode commands."
5890   (interactive)
5891   (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")))
5892
5893 (defun gnus-group-browse-foreign-server (method)
5894   "Browse a foreign news server.
5895 If called interactively, this function will ask for a select method
5896  (nntp, nnspool, etc.) and a server address (eg. nntp.some.where). 
5897 If not, METHOD should be a list where the first element is the method
5898 and the second element is the address."
5899   (interactive
5900    (list (let ((how (completing-read 
5901                      "Which backend: "
5902                      (append gnus-valid-select-methods gnus-server-alist)
5903                      nil t "nntp")))
5904            ;; We either got a backend name or a virtual server name.
5905            ;; If the first, we also need an address.
5906            (if (assoc how gnus-valid-select-methods)
5907                (list (intern how)
5908                      ;; Suggested by mapjph@bath.ac.uk.
5909                      (completing-read 
5910                       "Address: " 
5911                       (mapcar (lambda (server) (list server))
5912                               gnus-secondary-servers)))
5913              ;; We got a server name, so we find the method.
5914              (gnus-server-to-method how)))))
5915   (gnus-browse-foreign-server method))
5916
5917 \f
5918 ;;;
5919 ;;; Browse Server Mode
5920 ;;;
5921
5922 (defvar gnus-browse-mode-hook nil)
5923 (defvar gnus-browse-mode-map nil)
5924 (put 'gnus-browse-mode 'mode-class 'special)
5925
5926 (if gnus-browse-mode-map
5927     nil
5928   (setq gnus-browse-mode-map (make-keymap))
5929   (suppress-keymap gnus-browse-mode-map)
5930   (define-key gnus-browse-mode-map " " 'gnus-browse-read-group)
5931   (define-key gnus-browse-mode-map "=" 'gnus-browse-select-group)
5932   (define-key gnus-browse-mode-map "n" 'gnus-browse-next-group)
5933   (define-key gnus-browse-mode-map "p" 'gnus-browse-prev-group)
5934   (define-key gnus-browse-mode-map "\177" 'gnus-browse-prev-group)
5935   (define-key gnus-browse-mode-map "N" 'gnus-browse-next-group)
5936   (define-key gnus-browse-mode-map "P" 'gnus-browse-prev-group)
5937   (define-key gnus-browse-mode-map "\M-n" 'gnus-browse-next-group)
5938   (define-key gnus-browse-mode-map "\M-p" 'gnus-browse-prev-group)
5939   (define-key gnus-browse-mode-map "\r" 'gnus-browse-select-group)
5940   (define-key gnus-browse-mode-map "u" 'gnus-browse-unsubscribe-current-group)
5941   (define-key gnus-browse-mode-map "l" 'gnus-browse-exit)
5942   (define-key gnus-browse-mode-map "L" 'gnus-browse-exit)
5943   (define-key gnus-browse-mode-map "q" 'gnus-browse-exit)
5944   (define-key gnus-browse-mode-map "Q" 'gnus-browse-exit)
5945   (define-key gnus-browse-mode-map "\C-c\C-c" 'gnus-browse-exit)
5946   (define-key gnus-browse-mode-map "?" 'gnus-browse-describe-briefly)
5947   (define-key gnus-browse-mode-map "\C-c\C-i" 'gnus-info-find-node)
5948   )
5949
5950 (defvar gnus-browse-current-method nil)
5951 (defvar gnus-browse-return-buffer nil)
5952
5953 (defvar gnus-browse-buffer "*Gnus Browse Server*")
5954
5955 (defun gnus-browse-foreign-server (method &optional return-buffer)
5956   "Browse the server METHOD."
5957   (setq gnus-browse-current-method method)
5958   (setq gnus-browse-return-buffer return-buffer)
5959   (let ((gnus-select-method method)
5960         groups group)
5961     (gnus-message 5 "Connecting to %s..." (nth 1 method))
5962     (cond 
5963      ((not (gnus-check-server method))
5964       (gnus-message 
5965        1 "Unable to contact server: %s" (gnus-status-message method))
5966       nil)
5967      ((not (gnus-request-list method))
5968       (gnus-message 
5969        1 "Couldn't request list: %s" (gnus-status-message method))
5970       nil)
5971      (t
5972       (get-buffer-create gnus-browse-buffer)
5973       (gnus-add-current-to-buffer-list)
5974       (and gnus-carpal (gnus-carpal-setup-buffer 'browse))
5975       (gnus-configure-windows 'browse)
5976       (buffer-disable-undo (current-buffer))
5977       (let ((buffer-read-only nil))
5978         (erase-buffer))
5979       (gnus-browse-mode)
5980       (setq mode-line-buffer-identification
5981             (format
5982              "Gnus  Browse Server {%s:%s}" (car method) (car (cdr method))))
5983       (save-excursion
5984         (set-buffer nntp-server-buffer)
5985         (let ((cur (current-buffer)))
5986           (goto-char (point-min))
5987           (or (string= gnus-ignored-newsgroups "")
5988               (delete-matching-lines gnus-ignored-newsgroups))
5989           (while (re-search-forward 
5990                   "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
5991             (goto-char (match-end 1))
5992             (setq groups (cons (cons (match-string 1)
5993                                      (max 0 (- (1+ (read cur)) (read cur))))
5994                                groups)))))
5995       (setq groups (sort groups 
5996                          (lambda (l1 l2)
5997                            (string< (car l1) (car l2)))))
5998       (let ((buffer-read-only nil))
5999         (while groups
6000           (setq group (car groups))
6001           (insert 
6002            (format "K%7d: %s\n" (cdr group) (car group)))
6003           (setq groups (cdr groups))))
6004       (switch-to-buffer (current-buffer))
6005       (goto-char (point-min))
6006       (gnus-group-position-point)
6007       t))))
6008
6009 (defun gnus-browse-mode ()
6010   "Major mode for browsing a foreign server.
6011
6012 All normal editing commands are switched off.
6013
6014 \\<gnus-browse-mode-map>
6015 The only things you can do in this buffer is
6016
6017 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
6018 The group will be inserted into the group buffer upon exit from this
6019 buffer.  
6020
6021 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
6022
6023 3) `\\[gnus-browse-exit]' to return to the group buffer."
6024   (interactive)
6025   (kill-all-local-variables)
6026   (when (and menu-bar-mode
6027              (gnus-visual-p 'browse-menu 'menu))
6028     (gnus-browse-make-menu-bar))
6029   (setq mode-line-modified "-- ")
6030   (make-local-variable 'mode-line-format)
6031   (setq mode-line-format (copy-sequence mode-line-format))
6032   (and (equal (nth 3 mode-line-format) "   ")
6033        (setcar (nthcdr 3 mode-line-format) ""))
6034   (setq major-mode 'gnus-browse-mode)
6035   (setq mode-name "Browse Server")
6036   (setq mode-line-process nil)
6037   (use-local-map gnus-browse-mode-map)
6038   (buffer-disable-undo (current-buffer))
6039   (setq truncate-lines t)
6040   (setq buffer-read-only t)
6041   (run-hooks 'gnus-browse-mode-hook))
6042
6043 (defun gnus-browse-read-group (&optional no-article)
6044   "Enter the group at the current line."
6045   (interactive)
6046   (let ((group (gnus-browse-group-name)))
6047     (or (gnus-group-read-ephemeral-group 
6048          group gnus-browse-current-method nil
6049          (cons (current-buffer) 'browse))
6050         (error "Couldn't enter %s" group))))
6051
6052 (defun gnus-browse-select-group ()
6053   "Select the current group."
6054   (interactive)
6055   (gnus-browse-read-group 'no))
6056
6057 (defun gnus-browse-next-group (n)
6058   "Go to the next group."
6059   (interactive "p")
6060   (prog1
6061       (forward-line n)
6062     (gnus-group-position-point)))
6063
6064 (defun gnus-browse-prev-group (n)
6065   "Go to the next group."
6066   (interactive "p")
6067   (gnus-browse-next-group (- n)))
6068
6069 (defun gnus-browse-unsubscribe-current-group (arg)
6070   "(Un)subscribe to the next ARG groups."
6071   (interactive "p")
6072   (and (eobp)
6073        (error "No group at current line."))
6074   (let ((ward (if (< arg 0) -1 1))
6075         (arg (abs arg)))
6076     (while (and (> arg 0)
6077                 (not (eobp))
6078                 (gnus-browse-unsubscribe-group)
6079                 (zerop (gnus-browse-next-group ward)))
6080       (setq arg (1- arg)))
6081     (gnus-group-position-point)
6082     (if (/= 0 arg) (gnus-message 7 "No more newsgroups"))
6083     arg))
6084
6085 (defun gnus-browse-group-name ()
6086   (save-excursion
6087     (beginning-of-line)
6088     (when (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t)
6089       (gnus-group-prefixed-name (match-string 1) gnus-browse-current-method))))
6090   
6091 (defun gnus-browse-unsubscribe-group ()
6092   "Toggle subscription of the current group in the browse buffer."
6093   (let ((sub nil)
6094         (buffer-read-only nil)
6095         group)
6096     (save-excursion
6097       (beginning-of-line)
6098       ;; If this group it killed, then we want to subscribe it.
6099       (if (= (following-char) ?K) (setq sub t))
6100       (setq group (gnus-browse-group-name))
6101       (delete-char 1)
6102       (if sub
6103           (progn
6104             (gnus-group-change-level 
6105              (list t group gnus-level-default-subscribed
6106                    nil nil gnus-browse-current-method) 
6107              gnus-level-default-subscribed gnus-level-killed
6108              (and (car (nth 1 gnus-newsrc-alist))
6109                   (gnus-gethash (car (nth 1 gnus-newsrc-alist))
6110                                 gnus-newsrc-hashtb))
6111              t)
6112             (insert ? ))
6113         (gnus-group-change-level 
6114          group gnus-level-killed gnus-level-default-subscribed)
6115         (insert ?K)))
6116     t))
6117
6118 (defun gnus-browse-exit ()
6119   "Quit browsing and return to the group buffer."
6120   (interactive)
6121   (if (eq major-mode 'gnus-browse-mode)
6122       (kill-buffer (current-buffer)))
6123   (if gnus-browse-return-buffer
6124       (gnus-configure-windows 'server 'force)
6125     (gnus-configure-windows 'group 'force)
6126     (gnus-group-list-groups nil)))
6127
6128 (defun gnus-browse-describe-briefly ()
6129   "Give a one line description of the group mode commands."
6130   (interactive)
6131   (gnus-message 6
6132                 (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")))
6133       
6134 \f
6135 ;;;
6136 ;;; Gnus summary mode
6137 ;;;
6138
6139 (defvar gnus-summary-mode-map nil)
6140 (defvar gnus-summary-mark-map nil)
6141 (defvar gnus-summary-mscore-map nil)
6142 (defvar gnus-summary-article-map nil)
6143 (defvar gnus-summary-thread-map nil)
6144 (defvar gnus-summary-goto-map nil)
6145 (defvar gnus-summary-exit-map nil)
6146 (defvar gnus-summary-interest-map nil)
6147 (defvar gnus-summary-sort-map nil)
6148 (defvar gnus-summary-backend-map nil)
6149 (defvar gnus-summary-save-map nil)
6150 (defvar gnus-summary-wash-map nil)
6151 (defvar gnus-summary-wash-hide-map nil)
6152 (defvar gnus-summary-wash-highlight-map nil)
6153 (defvar gnus-summary-wash-time-map nil)
6154 (defvar gnus-summary-help-map nil)
6155 (defvar gnus-summary-limit-map nil)
6156
6157 (put 'gnus-summary-mode 'mode-class 'special)
6158
6159 (if gnus-summary-mode-map
6160     nil
6161   (setq gnus-summary-mode-map (make-keymap))
6162   (suppress-keymap gnus-summary-mode-map)
6163
6164   ;; Non-orthogonal keys
6165
6166   (define-key gnus-summary-mode-map " " 'gnus-summary-next-page)
6167   (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page)
6168   (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up)
6169   (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article)
6170   (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article)
6171   (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article)
6172   (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article)
6173   (define-key gnus-summary-mode-map "\M-\C-n" 'gnus-summary-next-same-subject)
6174   (define-key gnus-summary-mode-map "\M-\C-p" 'gnus-summary-prev-same-subject)
6175   (define-key gnus-summary-mode-map "\M-n" 'gnus-summary-next-unread-subject)
6176   (define-key gnus-summary-mode-map "\M-p" 'gnus-summary-prev-unread-subject)
6177   (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article)
6178   (define-key gnus-summary-mode-map "," 'gnus-summary-best-unread-article)
6179   (define-key gnus-summary-mode-map 
6180     "\M-s" 'gnus-summary-search-article-forward)
6181   (define-key gnus-summary-mode-map 
6182     "\M-r" 'gnus-summary-search-article-backward)
6183   (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article)
6184   (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article)
6185   (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-article)
6186   (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article)
6187   (define-key gnus-summary-mode-map "\M-^" 'gnus-summary-refer-article)
6188   (define-key gnus-summary-mode-map "u" 'gnus-summary-tick-article-forward)
6189   (define-key gnus-summary-mode-map "!" 'gnus-summary-tick-article-forward)
6190   (define-key gnus-summary-mode-map "U" 'gnus-summary-tick-article-backward)
6191   (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward)
6192   (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward)
6193   (define-key gnus-summary-mode-map "E" 'gnus-summary-mark-as-expirable)
6194   (define-key gnus-summary-mode-map "\M-u" 'gnus-summary-clear-mark-forward)
6195   (define-key gnus-summary-mode-map "\M-U" 'gnus-summary-clear-mark-backward)
6196   (define-key gnus-summary-mode-map 
6197     "k" 'gnus-summary-kill-same-subject-and-select)
6198   (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject)
6199   (define-key gnus-summary-mode-map "\M-\C-k" 'gnus-summary-kill-thread)
6200   (define-key gnus-summary-mode-map "\M-\C-l" 'gnus-summary-lower-thread)
6201   (define-key gnus-summary-mode-map "e" 'gnus-summary-edit-article)
6202   (define-key gnus-summary-mode-map "#" 'gnus-summary-mark-as-processable)
6203   (define-key gnus-summary-mode-map "\M-#" 'gnus-summary-unmark-as-processable)
6204   (define-key gnus-summary-mode-map "\M-\C-t" 'gnus-summary-toggle-threads)
6205   (define-key gnus-summary-mode-map "\M-\C-s" 'gnus-summary-show-thread)
6206   (define-key gnus-summary-mode-map "\M-\C-h" 'gnus-summary-hide-thread)
6207   (define-key gnus-summary-mode-map "\M-\C-f" 'gnus-summary-next-thread)
6208   (define-key gnus-summary-mode-map "\M-\C-b" 'gnus-summary-prev-thread)
6209   (define-key gnus-summary-mode-map "\M-\C-u" 'gnus-summary-up-thread)
6210   (define-key gnus-summary-mode-map "\M-\C-d" 'gnus-summary-down-thread)
6211   (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command)
6212   (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit)
6213   (define-key gnus-summary-mode-map "\C-w" 'gnus-summary-mark-region-as-read)
6214   (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation)
6215   (define-key gnus-summary-mode-map "?" 'gnus-summary-mark-as-dormant)
6216   (define-key gnus-summary-mode-map 
6217     "\C-c\M-\C-s" 'gnus-summary-limit-include-expunged)
6218   (define-key gnus-summary-mode-map 
6219     "\C-c\C-s\C-n" 'gnus-summary-sort-by-number)
6220   (define-key gnus-summary-mode-map 
6221     "\C-c\C-s\C-a" 'gnus-summary-sort-by-author)
6222   (define-key gnus-summary-mode-map 
6223     "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject)
6224   (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date)
6225   (define-key gnus-summary-mode-map "\C-c\C-s\C-i" 'gnus-summary-sort-by-score)
6226   (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window)
6227   (define-key gnus-summary-mode-map 
6228     "\C-x\C-s" 'gnus-summary-reselect-current-group)
6229   (define-key gnus-summary-mode-map "\M-g" 'gnus-summary-rescan-group)
6230   (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking)
6231   (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message)
6232   (define-key gnus-summary-mode-map "\M-t" 'gnus-summary-toggle-mime)
6233   (define-key gnus-summary-mode-map "f" 'gnus-summary-followup)
6234   (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original)
6235   (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article)
6236   (define-key gnus-summary-mode-map "r" 'gnus-summary-reply)
6237   (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original)
6238   (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)
6239   (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article)
6240   (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-article-mail)
6241   (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output)
6242   (define-key gnus-summary-mode-map "\M-k" 'gnus-summary-edit-local-kill)
6243   (define-key gnus-summary-mode-map "\M-K" 'gnus-summary-edit-global-kill)
6244   (define-key gnus-summary-mode-map "V" 'gnus-version)
6245   (define-key gnus-summary-mode-map "\C-c\C-d" 'gnus-summary-describe-group)
6246   (define-key gnus-summary-mode-map "q" 'gnus-summary-exit)
6247   (define-key gnus-summary-mode-map "Q" 'gnus-summary-exit-no-update)
6248   (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node)
6249   (define-key gnus-summary-mode-map gnus-mouse-2 'gnus-mouse-pick-article)
6250   (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)
6251   (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news)
6252   (define-key gnus-summary-mode-map "x" 'gnus-summary-limit-to-unread)
6253   (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article)
6254   (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header)
6255   (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article)
6256 ;  (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly)
6257   (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article)
6258   (define-key gnus-summary-mode-map "\C-c\C-v\C-v" 'gnus-uu-decode-uu-view)
6259   (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-enter-digest-group)
6260   (define-key gnus-summary-mode-map "v" 'gnus-summary-verbose-headers)
6261   (define-key gnus-summary-mode-map "\C-c\C-b" 'gnus-bug)
6262
6263
6264   ;; Sort of orthogonal keymap
6265   (define-prefix-command 'gnus-summary-mark-map)
6266   (define-key gnus-summary-mode-map "M" 'gnus-summary-mark-map)
6267   (define-key gnus-summary-mark-map "t" 'gnus-summary-tick-article-forward)
6268   (define-key gnus-summary-mark-map "!" 'gnus-summary-tick-article-forward)
6269   (define-key gnus-summary-mark-map "d" 'gnus-summary-mark-as-read-forward)
6270   (define-key gnus-summary-mark-map "r" 'gnus-summary-mark-as-read-forward)
6271   (define-key gnus-summary-mark-map "c" 'gnus-summary-clear-mark-forward)
6272   (define-key gnus-summary-mark-map " " 'gnus-summary-clear-mark-forward)
6273   (define-key gnus-summary-mark-map "e" 'gnus-summary-mark-as-expirable)
6274   (define-key gnus-summary-mark-map "x" 'gnus-summary-mark-as-expirable)
6275   (define-key gnus-summary-mark-map "?" 'gnus-summary-mark-as-dormant)
6276   (define-key gnus-summary-mark-map "b" 'gnus-summary-set-bookmark)
6277   (define-key gnus-summary-mark-map "B" 'gnus-summary-remove-bookmark)
6278   (define-key gnus-summary-mark-map "#" 'gnus-summary-mark-as-processable)
6279   (define-key gnus-summary-mark-map "\M-#" 'gnus-summary-unmark-as-processable)
6280   (define-key gnus-summary-mark-map "S" 'gnus-summary-limit-include-expunged)
6281   (define-key gnus-summary-mark-map "C" 'gnus-summary-catchup)
6282   (define-key gnus-summary-mark-map "H" 'gnus-summary-catchup-to-here)
6283   (define-key gnus-summary-mark-map "\C-c" 'gnus-summary-catchup-all)
6284   (define-key gnus-summary-mark-map 
6285     "k" 'gnus-summary-kill-same-subject-and-select)
6286   (define-key gnus-summary-mark-map "K" 'gnus-summary-kill-same-subject)
6287
6288   (define-prefix-command 'gnus-summary-mscore-map)
6289   (define-key gnus-summary-mark-map "V" 'gnus-summary-mscore-map)
6290   (define-key gnus-summary-mscore-map "c" 'gnus-summary-clear-above)
6291   (define-key gnus-summary-mscore-map "u" 'gnus-summary-tick-above)
6292   (define-key gnus-summary-mscore-map "m" 'gnus-summary-mark-above)
6293   (define-key gnus-summary-mscore-map "k" 'gnus-summary-kill-below)
6294
6295   (define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map)
6296   
6297   (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map)
6298
6299   (define-prefix-command 'gnus-summary-limit-map)
6300   (define-key gnus-summary-mode-map "/" 'gnus-summary-limit-map)
6301   (define-key gnus-summary-limit-map "/" 'gnus-summary-limit-to-subject)
6302   (define-key gnus-summary-limit-map "n" 'gnus-summary-limit-to-articles)
6303   (define-key gnus-summary-limit-map "w" 'gnus-summary-pop-limit)
6304   (define-key gnus-summary-limit-map "s" 'gnus-summary-limit-to-subject)
6305   (define-key gnus-summary-limit-map "u" 'gnus-summary-limit-to-unread)
6306   (define-key gnus-summary-limit-map "m" 'gnus-summary-limit-to-marks)
6307   (define-key gnus-summary-limit-map "v" 'gnus-summary-limit-to-score)
6308   (define-key gnus-summary-limit-map "D" 'gnus-summary-limit-include-dormant)
6309   (define-key gnus-summary-limit-map "d" 'gnus-summary-limit-exclude-dormant)
6310   (define-key gnus-summary-mark-map "E" 'gnus-summary-limit-include-expunged)
6311   (define-key gnus-summary-limit-map "c" 
6312     'gnus-summary-limit-exclude-childless-dormant)
6313
6314   (define-prefix-command 'gnus-summary-goto-map)
6315   (define-key gnus-summary-mode-map "G" 'gnus-summary-goto-map)
6316   (define-key gnus-summary-goto-map "n" 'gnus-summary-next-unread-article)
6317   (define-key gnus-summary-goto-map "p" 'gnus-summary-prev-unread-article)
6318   (define-key gnus-summary-goto-map "N" 'gnus-summary-next-article)
6319   (define-key gnus-summary-goto-map "P" 'gnus-summary-prev-article)
6320   (define-key gnus-summary-goto-map "\C-n" 'gnus-summary-next-same-subject)
6321   (define-key gnus-summary-goto-map "\C-p" 'gnus-summary-prev-same-subject)
6322   (define-key gnus-summary-goto-map "\M-n" 'gnus-summary-next-unread-subject)
6323   (define-key gnus-summary-goto-map "\M-p" 'gnus-summary-prev-unread-subject)
6324   (define-key gnus-summary-goto-map "f" 'gnus-summary-first-unread-article)
6325   (define-key gnus-summary-goto-map "b" 'gnus-summary-best-unread-article)
6326   (define-key gnus-summary-goto-map "g" 'gnus-summary-goto-subject)
6327   (define-key gnus-summary-goto-map "l" 'gnus-summary-goto-last-article)
6328   (define-key gnus-summary-goto-map "p" 'gnus-summary-pop-article)
6329
6330
6331   (define-prefix-command 'gnus-summary-thread-map)
6332   (define-key gnus-summary-mode-map "T" 'gnus-summary-thread-map)
6333   (define-key gnus-summary-thread-map "k" 'gnus-summary-kill-thread)
6334   (define-key gnus-summary-thread-map "l" 'gnus-summary-lower-thread)
6335   (define-key gnus-summary-thread-map "i" 'gnus-summary-raise-thread)
6336   (define-key gnus-summary-thread-map "T" 'gnus-summary-toggle-threads)
6337   (define-key gnus-summary-thread-map "s" 'gnus-summary-show-thread)
6338   (define-key gnus-summary-thread-map "S" 'gnus-summary-show-all-threads)
6339   (define-key gnus-summary-thread-map "h" 'gnus-summary-hide-thread)
6340   (define-key gnus-summary-thread-map "H" 'gnus-summary-hide-all-threads)
6341   (define-key gnus-summary-thread-map "n" 'gnus-summary-next-thread)
6342   (define-key gnus-summary-thread-map "p" 'gnus-summary-prev-thread)
6343   (define-key gnus-summary-thread-map "u" 'gnus-summary-up-thread)
6344   (define-key gnus-summary-thread-map "d" 'gnus-summary-down-thread)
6345   (define-key gnus-summary-thread-map "#" 'gnus-uu-mark-thread)
6346   (define-key gnus-summary-thread-map "\M-#" 'gnus-uu-unmark-thread)
6347
6348   
6349   (define-prefix-command 'gnus-summary-exit-map)
6350   (define-key gnus-summary-mode-map "Z" 'gnus-summary-exit-map)
6351   (define-key gnus-summary-exit-map "c" 'gnus-summary-catchup-and-exit)
6352   (define-key gnus-summary-exit-map "C" 'gnus-summary-catchup-all-and-exit)
6353   (define-key gnus-summary-exit-map "E" 'gnus-summary-exit-no-update)
6354   (define-key gnus-summary-exit-map "Q" 'gnus-summary-exit)
6355   (define-key gnus-summary-exit-map "Z" 'gnus-summary-exit)
6356   (define-key gnus-summary-exit-map 
6357     "n" 'gnus-summary-catchup-and-goto-next-group)
6358   (define-key gnus-summary-exit-map "R" 'gnus-summary-reselect-current-group)
6359   (define-key gnus-summary-exit-map "G" 'gnus-summary-rescan-group)
6360   (define-key gnus-summary-exit-map "N" 'gnus-summary-next-group)
6361   (define-key gnus-summary-exit-map "P" 'gnus-summary-prev-group)
6362
6363
6364   (define-prefix-command 'gnus-summary-article-map)
6365   (define-key gnus-summary-mode-map "A" 'gnus-summary-article-map)
6366   (define-key gnus-summary-article-map " " 'gnus-summary-next-page)
6367   (define-key gnus-summary-article-map "n" 'gnus-summary-next-page)
6368   (define-key gnus-summary-article-map "\177" 'gnus-summary-prev-page)
6369   (define-key gnus-summary-article-map "p" 'gnus-summary-prev-page)
6370   (define-key gnus-summary-article-map "\r" 'gnus-summary-scroll-up)
6371   (define-key gnus-summary-article-map "<" 'gnus-summary-beginning-of-article)
6372   (define-key gnus-summary-article-map ">" 'gnus-summary-end-of-article)
6373   (define-key gnus-summary-article-map "b" 'gnus-summary-beginning-of-article)
6374   (define-key gnus-summary-article-map "e" 'gnus-summary-end-of-article)
6375   (define-key gnus-summary-article-map "^" 'gnus-summary-refer-parent-article)
6376   (define-key gnus-summary-article-map "r" 'gnus-summary-refer-parent-article)
6377   (define-key gnus-summary-article-map "R" 'gnus-summary-refer-references)
6378   (define-key gnus-summary-article-map "g" 'gnus-summary-show-article)
6379   (define-key gnus-summary-article-map "s" 'gnus-summary-isearch-article)
6380
6381
6382
6383   (define-prefix-command 'gnus-summary-wash-map)
6384   (define-key gnus-summary-mode-map "W" 'gnus-summary-wash-map)
6385
6386   (define-prefix-command 'gnus-summary-wash-hide-map)
6387   (define-key gnus-summary-wash-map "W" 'gnus-summary-wash-hide-map)
6388   (define-key gnus-summary-wash-hide-map "a" 'gnus-article-hide)
6389   (define-key gnus-summary-wash-hide-map "h" 'gnus-article-hide-headers)
6390   (define-key gnus-summary-wash-hide-map "s" 'gnus-article-hide-signature)
6391   (define-key gnus-summary-wash-hide-map "c" 'gnus-article-hide-citation)
6392   (define-key gnus-summary-wash-hide-map "p" 'gnus-article-hide-pgp)
6393   (define-key gnus-summary-wash-hide-map 
6394     "\C-c" 'gnus-article-hide-citation-maybe)
6395
6396   (define-prefix-command 'gnus-summary-wash-highlight-map)
6397   (define-key gnus-summary-wash-map "H" 'gnus-summary-wash-highlight-map)
6398   (define-key gnus-summary-wash-highlight-map "a" 'gnus-article-highlight)
6399   (define-key gnus-summary-wash-highlight-map 
6400     "h" 'gnus-article-highlight-headers)
6401   (define-key gnus-summary-wash-highlight-map
6402     "c" 'gnus-article-highlight-citation)
6403   (define-key gnus-summary-wash-highlight-map
6404     "s" 'gnus-article-highlight-signature)
6405
6406   (define-prefix-command 'gnus-summary-wash-time-map)
6407   (define-key gnus-summary-wash-map "T" 'gnus-summary-wash-time-map)
6408   (define-key gnus-summary-wash-time-map "z" 'gnus-article-date-ut)
6409   (define-key gnus-summary-wash-time-map "u" 'gnus-article-date-ut)
6410   (define-key gnus-summary-wash-time-map "l" 'gnus-article-date-local)
6411   (define-key gnus-summary-wash-time-map "e" 'gnus-article-date-lapsed)
6412   (define-key gnus-summary-wash-time-map "o" 'gnus-article-date-original)
6413
6414   (define-key gnus-summary-wash-map "b" 'gnus-article-add-buttons)
6415   (define-key gnus-summary-wash-map "B" 'gnus-article-add-buttons-to-head)
6416   (define-key gnus-summary-wash-map "o" 'gnus-article-treat-overstrike)
6417   (define-key gnus-summary-wash-map "w" 'gnus-article-word-wrap)
6418   (define-key gnus-summary-wash-map "c" 'gnus-article-remove-cr)
6419   (define-key gnus-summary-wash-map "q" 'gnus-article-de-quoted-unreadable)
6420   (define-key gnus-summary-wash-map "f" 'gnus-article-display-x-face)
6421   (define-key gnus-summary-wash-map "l" 'gnus-summary-stop-page-breaking)
6422   (define-key gnus-summary-wash-map "r" 'gnus-summary-caesar-message)
6423   (define-key gnus-summary-wash-map "t" 'gnus-summary-toggle-header)
6424   (define-key gnus-summary-wash-map "m" 'gnus-summary-toggle-mime)
6425
6426
6427   (define-prefix-command 'gnus-summary-help-map)
6428   (define-key gnus-summary-mode-map "H" 'gnus-summary-help-map)
6429   (define-key gnus-summary-help-map "v" 'gnus-version)
6430   (define-key gnus-summary-help-map "f" 'gnus-summary-fetch-faq)
6431   (define-key gnus-summary-help-map "d" 'gnus-summary-describe-group)
6432   (define-key gnus-summary-help-map "h" 'gnus-summary-describe-briefly)
6433   (define-key gnus-summary-help-map "i" 'gnus-info-find-node)
6434
6435
6436   (define-prefix-command 'gnus-summary-backend-map)
6437   (define-key gnus-summary-mode-map "B" 'gnus-summary-backend-map)
6438   (define-key gnus-summary-backend-map "e" 'gnus-summary-expire-articles)
6439   (define-key gnus-summary-backend-map "\M-\C-e" 
6440     'gnus-summary-expire-articles-now)
6441   (define-key gnus-summary-backend-map "\177" 'gnus-summary-delete-article)
6442   (define-key gnus-summary-backend-map "m" 'gnus-summary-move-article)
6443   (define-key gnus-summary-backend-map "r" 'gnus-summary-respool-article)
6444   (define-key gnus-summary-backend-map "w" 'gnus-summary-edit-article)
6445   (define-key gnus-summary-backend-map "c" 'gnus-summary-copy-article)
6446   (define-key gnus-summary-backend-map "q" 'gnus-summary-respool-query)
6447   (define-key gnus-summary-backend-map "i" 'gnus-summary-import-article)
6448
6449
6450   (define-prefix-command 'gnus-summary-save-map)
6451   (define-key gnus-summary-mode-map "O" 'gnus-summary-save-map)
6452   (define-key gnus-summary-save-map "o" 'gnus-summary-save-article)
6453   (define-key gnus-summary-save-map "m" 'gnus-summary-save-article-mail)
6454   (define-key gnus-summary-save-map "r" 'gnus-summary-save-article-rmail)
6455   (define-key gnus-summary-save-map "f" 'gnus-summary-save-article-file)
6456   (define-key gnus-summary-save-map "b" 'gnus-summary-save-article-body-file)
6457   (define-key gnus-summary-save-map "h" 'gnus-summary-save-article-folder)
6458   (define-key gnus-summary-save-map "v" 'gnus-summary-save-article-vm)
6459   (define-key gnus-summary-save-map "p" 'gnus-summary-pipe-output)
6460   (define-key gnus-summary-save-map "s" 'gnus-soup-add-article)
6461
6462   (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
6463
6464   (define-key gnus-summary-mode-map "\M-&" 'gnus-summary-universal-argument)
6465   (define-key gnus-summary-article-map "D" 'gnus-summary-enter-digest-group)
6466
6467   (define-key gnus-summary-mode-map "V" 'gnus-summary-score-map)
6468
6469   (define-key gnus-summary-mode-map "I" 'gnus-summary-increase-score)
6470   (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-score)
6471   )
6472
6473
6474 \f
6475
6476 (defun gnus-summary-mode (&optional group)
6477   "Major mode for reading articles.
6478
6479 All normal editing commands are switched off.
6480 \\<gnus-summary-mode-map>
6481 Each line in this buffer represents one article.  To read an
6482 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
6483 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]', 
6484 respectively.
6485
6486 You can also post articles and send mail from this buffer.  To 
6487 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author 
6488 of an article, type `\\[gnus-summary-reply]'.
6489
6490 There are approx. one gazillion commands you can execute in this 
6491 buffer; read the info pages for more information (`\\[gnus-info-find-node]'). 
6492
6493 The following commands are available:
6494
6495 \\{gnus-summary-mode-map}"
6496   (interactive)
6497   (when (and menu-bar-mode
6498              (gnus-visual-p 'summary-menu 'menu))
6499     (gnus-summary-make-menu-bar))
6500   (kill-all-local-variables)
6501   (let ((locals gnus-summary-local-variables))
6502     (while locals
6503       (if (consp (car locals))
6504           (progn
6505             (make-local-variable (car (car locals)))
6506             (set (car (car locals)) (eval (cdr (car locals)))))
6507         (make-local-variable (car locals))
6508         (set (car locals) nil))
6509       (setq locals (cdr locals))))
6510   (gnus-make-thread-indent-array)
6511   (setq mode-line-modified "-- ")
6512   (make-local-variable 'mode-line-format)
6513   (setq mode-line-format (copy-sequence mode-line-format))
6514   (and (equal (nth 3 mode-line-format) "   ")
6515        (setcar (nthcdr 3 mode-line-format) ""))
6516   (setq major-mode 'gnus-summary-mode)
6517   (setq mode-name "Summary")
6518   (make-local-variable 'minor-mode-alist)
6519   (use-local-map gnus-summary-mode-map)
6520   (buffer-disable-undo (current-buffer))
6521   (setq buffer-read-only t)             ;Disable modification
6522   (setq truncate-lines t)
6523   (setq selective-display t)
6524   (setq selective-display-ellipses t)   ;Display `...'
6525   (setq buffer-display-table gnus-summary-display-table)
6526   (setq gnus-newsgroup-name group)
6527   (run-hooks 'gnus-summary-mode-hook))
6528
6529 (defun gnus-summary-make-display-table ()
6530   ;; Change the display table.  Odd characters have a tendency to mess
6531   ;; up nicely formatted displays - we make all possible glyphs
6532   ;; display only a single character.
6533
6534   ;; We start from the standard display table, if any.
6535   (setq gnus-summary-display-table 
6536         (or (copy-sequence standard-display-table)
6537             (make-display-table)))
6538   ;; Nix out all the control chars...
6539   (let ((i 32))
6540     (while (>= (setq i (1- i)) 0)
6541       (aset gnus-summary-display-table i [??])))
6542   ;; ... but not newline and cr, of course. (cr is necessary for the
6543   ;; selective display).  
6544   (aset gnus-summary-display-table ?\n nil)
6545   (aset gnus-summary-display-table ?\r nil)
6546   ;; We nix out any glyphs over 126 that are not set already.  
6547   (let ((i 256))
6548     (while (>= (setq i (1- i)) 127)
6549       ;; Only modify if the entry is nil.
6550       (or (aref gnus-summary-display-table i) 
6551           (aset gnus-summary-display-table i [??])))))
6552
6553 (defun gnus-summary-clear-local-variables ()
6554   (let ((locals gnus-summary-local-variables))
6555     (while locals
6556       (if (consp (car locals))
6557           (and (vectorp (car (car locals)))
6558                (set (car (car locals)) nil))
6559         (and (vectorp (car locals))
6560              (set (car locals) nil)))
6561       (setq locals (cdr locals)))))
6562
6563 ;; Summary data functions.
6564
6565 (defmacro gnus-data-number (data)
6566   `(car ,data))
6567
6568 (defmacro gnus-data-mark (data)
6569   `(nth 1 ,data))
6570
6571 (defmacro gnus-data-set-mark (data mark)
6572   `(setcar (nthcdr 1 ,data) ,mark))
6573
6574 (defmacro gnus-data-pos (data)
6575   `(nth 2 ,data))
6576
6577 (defmacro gnus-data-set-pos (data pos)
6578   `(setcar (nthcdr 2 ,data) ,pos))
6579
6580 (defmacro gnus-data-header (data)
6581   `(nth 3 ,data))
6582
6583 (defmacro gnus-data-level (data)
6584   `(nth 4 ,data))
6585
6586 (defmacro gnus-data-unread-p (data)
6587   `(= (nth 1 ,data) gnus-unread-mark))
6588
6589 (defmacro gnus-data-pseudo-p (data)
6590   `(consp (nth 3 ,data)))
6591
6592 (defmacro gnus-data-find (number)
6593   `(assq ,number gnus-newsgroup-data))
6594
6595 (defmacro gnus-data-find-list (number &optional data)
6596   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
6597      (memq (assq ,number bdata)
6598            bdata)))
6599
6600 (defmacro gnus-data-make (number mark pos header level)
6601   `(list ,number ,mark ,pos ,header ,level))
6602
6603 (defun gnus-data-enter (after-article number mark pos header level offset)
6604   (let ((data (gnus-data-find-list after-article)))
6605     (or data (error "No such article: %d" after-article))
6606     (setcdr data (cons (gnus-data-make number mark pos header level)
6607                        (cdr data)))
6608     (setq gnus-newsgroup-data-reverse nil)
6609     (gnus-data-update-list (cdr (cdr data)) offset)))
6610
6611 (defun gnus-data-enter-list (after-article list &optional offset)
6612   (when list
6613     (let ((data (and after-article (gnus-data-find-list after-article)))
6614           (ilist list))
6615       (or data (not after-article) (error "No such article: %d" after-article))
6616       ;; Find the last element in the list to be spliced into the main
6617       ;; list.  
6618       (while (cdr list)
6619         (setq list (cdr list)))
6620       (if (not data)
6621           (progn
6622             (setcdr list gnus-newsgroup-data)
6623             (setq gnus-newsgroup-data ilist)
6624             (and offset (gnus-data-update-list (cdr list) offset)))
6625         (setcdr list (cdr data))
6626         (setcdr data ilist)
6627         (and offset (gnus-data-update-list (cdr data) offset)))
6628       (setq gnus-newsgroup-data-reverse nil))))
6629
6630 (defun gnus-data-remove (article &optional offset)
6631   (let ((data gnus-newsgroup-data))
6632     (if (= (gnus-data-number (car data)) article)
6633         (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
6634               gnus-newsgroup-data-reverse nil)
6635       (while (cdr data)
6636         (and (= (gnus-data-number (car (cdr data))) article)
6637              (progn
6638                (setcdr data (cdr (cdr data)))
6639                (and offset (gnus-data-update-list (cdr data) offset))
6640                (setq data nil
6641                      gnus-newsgroup-data-reverse nil)))
6642         (setq data (cdr data))))))
6643
6644 (defmacro gnus-data-list (backward)
6645   `(if ,backward
6646        (or gnus-newsgroup-data-reverse
6647            (setq gnus-newsgroup-data-reverse
6648                  (reverse gnus-newsgroup-data)))
6649      gnus-newsgroup-data))
6650
6651 (defun gnus-data-update-list (data offset)
6652   "Add OFFSET to the POS of all data entries in DATA."
6653   (while data
6654     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
6655     (setq data (cdr data))))
6656
6657 (defun gnus-data-compute-positions ()
6658   "Compute the positions of all articles."
6659   (let ((data gnus-newsgroup-data)
6660         pos)
6661     (while data
6662       (when (setq pos (text-property-any 
6663                        (point-min) (point-max)
6664                        'gnus-number (gnus-data-number (car data))))
6665         (gnus-data-set-pos (car data) (+ pos 3)))
6666       (setq data (cdr data)))))
6667
6668 (defun gnus-summary-article-pseudo-p (article)
6669   "Say whether this article is a pseudo article or not."
6670   (not (vectorp (gnus-data-header (gnus-data-find article)))))
6671
6672 (defun gnus-article-parent-p (number)
6673   "Say whether this article is a parent or not."
6674   (let* ((data (gnus-data-find-list number)))
6675     (and (cdr data)                     ; There has to be an article after...
6676          (< (gnus-data-level (car data)) ; And it has to have a higher level.
6677             (gnus-data-level (nth 1 data))))))
6678     
6679 (defmacro gnus-summary-skip-intangible ()
6680   "If the current article is intangible, then jump to a different article."
6681   '(let ((to (get-text-property (point) 'gnus-intangible)))
6682     (when to
6683       (gnus-summary-goto-subject to))))
6684
6685 (defmacro gnus-summary-article-intangible-p ()
6686   "Say whether this article is intangible or not."
6687   '(get-text-property (point) 'gnus-intangible))
6688
6689 ;; Some summary mode macros.
6690
6691 (defmacro gnus-summary-article-number ()
6692   "The article number of the article on the current line.
6693 If there isn's an article number here, then we return the current
6694 article number."
6695   '(progn
6696      (gnus-summary-skip-intangible)
6697      (or (get-text-property (point) 'gnus-number) 
6698          (progn
6699            (forward-line -1)
6700            gnus-newsgroup-end))))
6701
6702 (defmacro gnus-summary-article-header (&optional number)
6703   `(gnus-data-header (gnus-data-find
6704                       ,(or number '(gnus-summary-article-number)))))
6705
6706 (defmacro gnus-summary-thread-level (&optional number)
6707   `(gnus-data-level (gnus-data-find
6708                      ,(or number '(gnus-summary-article-number)))))
6709
6710 (defmacro gnus-summary-article-mark (&optional number)
6711   `(gnus-data-mark (gnus-data-find
6712                     ,(or number '(gnus-summary-article-number)))))
6713
6714 (defmacro gnus-summary-article-pos (&optional number)
6715   `(gnus-data-pos (gnus-data-find
6716                    ,(or number '(gnus-summary-article-number)))))
6717
6718 (defmacro gnus-summary-article-subject (&optional number)
6719   "Return current subject string or nil if nothing."
6720   `(let ((headers 
6721           ,(if number
6722                `(gnus-data-header (assq ,number gnus-newsgroup-data))
6723              '(gnus-data-header (assq (gnus-summary-article-number)
6724                                       gnus-newsgroup-data)))))
6725      (and headers
6726           (vectorp headers)
6727           (mail-header-subject headers))))
6728
6729 (defmacro gnus-summary-article-score (&optional number)
6730   "Return current article score."
6731   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
6732                   gnus-newsgroup-scored))
6733        gnus-summary-default-score 0))
6734
6735 (defun gnus-summary-article-children (&optional number)
6736   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
6737          (level (gnus-data-level (car data)))
6738          l children)
6739     (while (and (setq data (cdr data))
6740                 (> (setq l (gnus-data-level (car data))) level))
6741       (and (= (1+ level) l)
6742            (setq children (cons (gnus-data-number (car data))
6743                                 children))))
6744     (nreverse children)))
6745
6746 (defun gnus-summary-article-parent (&optional number)
6747   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
6748                                     (gnus-data-list t)))
6749          (level (gnus-data-level (car data)))
6750          l)
6751     (if (zerop level)
6752         () ; This is a root.
6753       ;; We search until we find an article with a level less than
6754       ;; this one.  That function has to be the parent.
6755       (while (and (setq data (cdr data))
6756                   (not (< (gnus-data-level (car data)) level))))
6757       (and data (gnus-data-number (car data))))))
6758
6759
6760 ;; Various summary mode internalish functions.
6761
6762 (defun gnus-mouse-pick-article (e)
6763   (interactive "e")
6764   (mouse-set-point e)
6765   (gnus-summary-next-page nil t))
6766
6767 (defun gnus-summary-setup-buffer (group)
6768   "Initialize summary buffer."
6769   (let ((buffer (concat "*Summary " group "*")))
6770     (if (get-buffer buffer)
6771         (progn
6772           (set-buffer buffer)
6773           (not gnus-newsgroup-prepared))
6774       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
6775       (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer)))
6776       (gnus-add-current-to-buffer-list)
6777       (gnus-summary-mode group)
6778       (and gnus-carpal (gnus-carpal-setup-buffer 'summary))
6779       (setq gnus-newsgroup-name group)
6780       t)))
6781
6782 (defun gnus-set-global-variables ()
6783   ;; Set the global equivalents of the summary buffer-local variables
6784   ;; to the latest values they had.  These reflect the summary buffer
6785   ;; that was in action when the last article was fetched.
6786   (if (eq major-mode 'gnus-summary-mode) 
6787       (progn
6788         (setq gnus-summary-buffer (current-buffer))
6789         (let ((name gnus-newsgroup-name)
6790               (marked gnus-newsgroup-marked)
6791               (unread gnus-newsgroup-unreads)
6792               (headers gnus-current-headers)
6793               (data gnus-newsgroup-data)
6794               (score-file gnus-current-score-file))
6795           (save-excursion
6796             (set-buffer gnus-group-buffer)
6797             (setq gnus-newsgroup-name name)
6798             (setq gnus-newsgroup-marked marked)
6799             (setq gnus-newsgroup-unreads unread)
6800             (setq gnus-current-headers headers)
6801             (setq gnus-newsgroup-data data)
6802             (setq gnus-current-score-file score-file))))))
6803
6804 (defun gnus-summary-last-article-p (&optional article)
6805   "Return whether ARTICLE is the last article in the buffer."
6806   (if (not (setq article (or article (gnus-summary-article-number))))
6807       t ; All non-existant numbers are the last article. :-)
6808     (cdr (gnus-data-find-list article))))
6809     
6810 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
6811   "Insert a dummy root in the summary buffer."
6812   (beginning-of-line)
6813   (add-text-properties
6814    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
6815    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
6816
6817 (defvar gnus-thread-indent-array nil)
6818 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
6819 (defun gnus-make-thread-indent-array ()
6820   (let ((n 200))
6821     (if (and gnus-thread-indent-array
6822              (= gnus-thread-indent-level gnus-thread-indent-array-level))
6823         nil
6824       (setq gnus-thread-indent-array (make-vector 201 "")
6825             gnus-thread-indent-array-level gnus-thread-indent-level)
6826       (while (>= n 0)
6827         (aset gnus-thread-indent-array n
6828               (make-string (* n gnus-thread-indent-level) ? ))
6829         (setq n (1- n))))))
6830
6831 (defun gnus-summary-insert-line 
6832   (gnus-tmp-header gnus-tmp-level gnus-tmp-current gnus-tmp-unread 
6833                    gnus-tmp-replied gnus-tmp-expirable gnus-tmp-subject-or-nil
6834                    &optional gnus-tmp-dummy gnus-tmp-score gnus-tmp-process)
6835   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
6836          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
6837          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
6838          (gnus-tmp-score-char
6839           (if (or (null gnus-summary-default-score)
6840                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
6841                       gnus-summary-zcore-fuzz)) ? 
6842             (if (< gnus-tmp-score gnus-summary-default-score)
6843                 gnus-score-below-mark gnus-score-over-mark)))
6844          (gnus-tmp-replied (cond (gnus-tmp-process gnus-process-mark)
6845                                  (gnus-tmp-replied gnus-replied-mark)
6846                                  (t gnus-unread-mark)))
6847          (gnus-tmp-from (mail-header-from gnus-tmp-header))
6848          (gnus-tmp-name 
6849           (cond 
6850            ((string-match "(.+)" gnus-tmp-from)
6851             (substring gnus-tmp-from 
6852                        (1+ (match-beginning 0)) (1- (match-end 0))))
6853            ((string-match "<[^>]+> *$" gnus-tmp-from)
6854             (let ((beg (match-beginning 0)))
6855               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
6856                        (substring gnus-tmp-from (1+ (match-beginning 0))
6857                                   (1- (match-end 0))))
6858                   (substring gnus-tmp-from 0 beg))))
6859            (t gnus-tmp-from)))
6860          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
6861          (gnus-tmp-number (mail-header-number gnus-tmp-header))
6862          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
6863          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
6864          (buffer-read-only nil))
6865     (or (numberp gnus-tmp-lines) (setq gnus-tmp-lines 0))
6866     (put-text-property
6867      (point)
6868      (progn (eval gnus-summary-line-format-spec) (point))
6869      'gnus-number gnus-tmp-number)
6870     (when (gnus-visual-p 'summary-highlight 'highlight)
6871       (forward-line -1)
6872       (run-hooks 'gnus-summary-update-hook)
6873       (forward-line 1))))
6874
6875 (defun gnus-summary-update-line (&optional dont-update)
6876   ;; Update summary line after change.
6877   (when (and gnus-summary-default-score
6878              (not gnus-summary-inhibit-highlight))
6879     (let ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
6880           (article (gnus-summary-article-number)))
6881       (unless dont-update
6882         (if (and gnus-summary-mark-below
6883                  (< (gnus-summary-article-score)
6884                     gnus-summary-mark-below))
6885             ;; This article has a low score, so we mark it as read.
6886             (when (memq article gnus-newsgroup-unreads)
6887               (gnus-summary-mark-article-as-read gnus-low-score-mark))
6888           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
6889             ;; This article was previously marked as read on account
6890             ;; of a low score, but now it has risen, so we mark it as
6891             ;; unread. 
6892             (gnus-summary-mark-article-as-unread gnus-unread-mark))))
6893       ;; Do visual highlighting.
6894       (when (gnus-visual-p 'summary-highlight 'highlight)
6895         (run-hooks 'gnus-summary-update-hook)))))
6896
6897 (defvar gnus-tmp-new-adopts)
6898
6899 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
6900   ;; Sum up all elements (and sub-elements) in a list.
6901   (let* ((number
6902           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
6903           (cond ((and (consp thread) (cdr thread))
6904                  (apply
6905                   '+ 1 (mapcar
6906                         'gnus-summary-number-of-articles-in-thread 
6907                         (cdr thread))))
6908                 ((null thread)
6909                  1)
6910                 ((and level (zerop level) gnus-tmp-new-adopts)
6911                  (apply '+ 1 (mapcar 
6912                               'gnus-summary-number-of-articles-in-thread 
6913                               gnus-tmp-new-adopts)))
6914                 ((memq (mail-header-number (car thread))
6915                        gnus-newsgroup-limit)
6916                  1) 
6917                 (t 0))))
6918     (if char 
6919         (if (> number 1) gnus-not-empty-thread-mark
6920           gnus-empty-thread-mark)
6921       number)))
6922
6923 (defun gnus-summary-set-local-parameters (group)
6924  "Go through the local params of GROUP and set all variable specs in that list."
6925   (let ((params (gnus-info-params (gnus-get-info group)))
6926         elem)
6927     (while params
6928       (setq elem (car params)
6929             params (cdr params))
6930       (and (consp elem)                 ; Has to be a cons.
6931            (consp (cdr elem))           ; The cdr has to be a list.
6932            (symbolp (car elem))         ; Has to be a symbol in there.
6933            (progn                       ; So we set it.
6934              (make-local-variable (car elem))
6935              (set (car elem) (eval (nth 1 elem))))))))
6936
6937 (defun gnus-summary-read-group 
6938   (group &optional show-all no-article kill-buffer no-display)
6939   "Start reading news in newsgroup GROUP.
6940 If SHOW-ALL is non-nil, already read articles are also listed.
6941 If NO-ARTICLE is non-nil, no article is selected initially.
6942 If NO-DISPLAY, don't generate a summary buffer."
6943   (gnus-message 5 "Retrieving newsgroup: %s..." group)
6944   (let* ((new-group (gnus-summary-setup-buffer group))
6945          (quit-config (gnus-group-quit-config group))
6946          (did-select (and new-group (gnus-select-newsgroup group show-all))))
6947     (cond 
6948      ;; This summary buffer exists already, so we just select it. 
6949      ((not new-group)
6950       (gnus-set-global-variables)
6951       (gnus-kill-buffer kill-buffer)
6952       (gnus-configure-windows 'summary 'force)
6953       (gnus-set-mode-line 'summary)
6954       (gnus-summary-position-point)
6955       (message "")
6956       t)
6957      ;; We couldn't select this group.
6958      ((null did-select) 
6959       (when (and (eq major-mode 'gnus-summary-mode)
6960                  (not (equal (current-buffer) kill-buffer)))
6961         (kill-buffer (current-buffer))
6962         (if (not quit-config)
6963             (progn
6964               (set-buffer gnus-group-buffer)
6965               (gnus-group-jump-to-group group)
6966               (gnus-group-next-unread-group 1))
6967           (if (not (buffer-name (car quit-config)))
6968               (gnus-configure-windows 'group 'force)
6969             (set-buffer (car quit-config))
6970             (and (eq major-mode 'gnus-summary-mode)
6971                  (gnus-set-global-variables))
6972             (gnus-configure-windows (cdr quit-config)))))
6973       (message "Can't select group")
6974       nil)
6975      ;; The user did a `C-g' while prompting for number of articles,
6976      ;; so we exit this group.
6977      ((eq did-select 'quit)
6978       (and (eq major-mode 'gnus-summary-mode)
6979            (not (equal (current-buffer) kill-buffer))
6980            (kill-buffer (current-buffer)))
6981       (gnus-kill-buffer kill-buffer)
6982       (if (not quit-config)
6983           (progn
6984             (set-buffer gnus-group-buffer)
6985             (gnus-group-jump-to-group group)
6986             (gnus-group-next-unread-group 1)
6987             (gnus-configure-windows 'group 'force))
6988         (if (not (buffer-name (car quit-config)))
6989             (gnus-configure-windows 'group 'force)
6990           (set-buffer (car quit-config))
6991           (and (eq major-mode 'gnus-summary-mode)
6992                (gnus-set-global-variables))
6993           (gnus-configure-windows (cdr quit-config))))
6994       ;; Finallt signal the quit.
6995       (signal 'quit nil))
6996      ;; The group was successfully selected.
6997      (t
6998       (gnus-set-global-variables)
6999       ;; Save the active value in effect when the group was entered.
7000       (setq gnus-newsgroup-active 
7001             (gnus-copy-sequence
7002              (gnus-active gnus-newsgroup-name)))
7003       ;; You can change the summary buffer in some way with this hook.
7004       (run-hooks 'gnus-select-group-hook)
7005       ;; Set any local variables in the group parameters.
7006       (gnus-summary-set-local-parameters gnus-newsgroup-name)
7007       ;; Do score processing.
7008       (when gnus-use-scoring
7009         (gnus-possibly-score-headers))
7010       (gnus-update-format-specifications)
7011       ;; Find the initial limit.
7012       (gnus-summary-initial-limit)
7013       ;; Generate the summary buffer.
7014       (unless no-display
7015         (gnus-summary-prepare))
7016       ;; If the summary buffer is empty, but there are some low-scored
7017       ;; articles or some excluded dormants, we include these in the
7018       ;; buffer. 
7019       (when (zerop (buffer-size))
7020         (cond (gnus-newsgroup-dormant
7021                (gnus-summary-limit-include-dormant))
7022               ((and gnus-newsgroup-scored show-all)
7023                (gnus-summary-limit-include-expunged))))
7024       ;; Function `gnus-apply-kill-file' must be called in this hook.
7025       (run-hooks 'gnus-apply-kill-hook)
7026       (if (zerop (buffer-size))
7027           (progn
7028             ;; This newsgroup is empty.
7029             (gnus-summary-catchup-and-exit nil t) ;Without confirmations.
7030             (gnus-message 6 "No unread news")
7031             (gnus-kill-buffer kill-buffer)
7032             ;; Return nil from this function.
7033             nil)
7034         ;; Hide conversation thread subtrees.  We cannot do this in
7035         ;; gnus-summary-prepare-hook since kill processing may not
7036         ;; work with hidden articles.
7037         (and gnus-show-threads
7038              gnus-thread-hide-subtree
7039              (gnus-summary-hide-all-threads))
7040         ;; Show first unread article if requested.
7041         (if (and (not no-article)
7042                  gnus-newsgroup-unreads
7043                  gnus-auto-select-first)
7044             (progn
7045               (if (eq gnus-auto-select-first 'best)
7046                   (gnus-summary-best-unread-article)
7047                 (gnus-summary-first-unread-article)))
7048           ;; Don't select any articles, just move point to the first
7049           ;; article in the group.
7050           (goto-char (point-min))
7051           (gnus-summary-position-point)
7052           (gnus-set-mode-line 'summary)
7053           (gnus-configure-windows 'summary 'force))
7054         ;; If we are in async mode, we send some info to the backend.
7055         (when gnus-newsgroup-async
7056           (gnus-request-asynchronous gnus-newsgroup-name gnus-newsgroup-data))
7057         (gnus-kill-buffer kill-buffer)
7058         (when (get-buffer-window gnus-group-buffer)
7059           ;; Gotta use windows, because recenter does wierd stuff if
7060           ;; the current buffer ain't the displayed window.
7061           (let ((owin (selected-window))) 
7062             (select-window (get-buffer-window gnus-group-buffer))
7063             (when (gnus-group-goto-group group)
7064               (recenter))
7065             (select-window owin))))
7066       ;; Mark this buffer as "prepared".
7067       (setq gnus-newsgroup-prepared t)
7068       t))))
7069
7070 (defun gnus-summary-prepare ()
7071   "Generate the summary buffer."
7072   (let ((buffer-read-only nil))
7073     (erase-buffer)
7074     (setq gnus-newsgroup-data nil
7075           gnus-newsgroup-data-reverse nil)
7076     (run-hooks 'gnus-summary-generate-hook)
7077     ;; Generate the buffer, either with threads or without.
7078     (gnus-summary-prepare-threads 
7079      (if gnus-show-threads
7080          (gnus-gather-threads (gnus-sort-threads (gnus-make-threads)))
7081        gnus-newsgroup-headers))
7082     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
7083     ;; Call hooks for modifying summary buffer.
7084     (goto-char (point-min))
7085     (run-hooks 'gnus-summary-prepare-hook)))
7086
7087 (defun gnus-gather-threads (threads)
7088   "Gather threads that have lost their roots."
7089   (if (not gnus-summary-make-false-root)
7090       threads 
7091     (let ((hashtb (gnus-make-hashtable 1023))
7092           (prev threads)
7093           (result threads)
7094           subject hthread whole-subject)
7095       (while threads
7096         (setq whole-subject 
7097               (setq subject (mail-header-subject (car (car threads)))))
7098         (if (and gnus-summary-gather-exclude-subject
7099                  (string-match gnus-summary-gather-exclude-subject
7100                                subject))
7101             () ; We don't want to do anything with this.
7102           (if gnus-summary-gather-subject-limit
7103               (or (and (numberp gnus-summary-gather-subject-limit)
7104                        (> (length subject) gnus-summary-gather-subject-limit)
7105                        (setq subject
7106                              (substring subject 0 
7107                                         gnus-summary-gather-subject-limit)))
7108                   (and (eq 'fuzzy gnus-summary-gather-subject-limit)
7109                        (setq subject (gnus-simplify-subject-fuzzy subject))))
7110             (setq subject (gnus-simplify-subject-re subject)))
7111           (if (setq hthread 
7112                     (gnus-gethash subject hashtb))
7113               (progn
7114                 (or (stringp (car (car hthread)))
7115                     (setcar hthread (list whole-subject (car hthread))))
7116                 (setcdr (car hthread) (nconc (cdr (car hthread)) 
7117                                              (list (car threads))))
7118                 (setcdr prev (cdr threads))
7119                 (setq threads prev))
7120             (gnus-sethash subject threads hashtb)))
7121         (setq prev threads)
7122         (setq threads (cdr threads)))
7123       result)))
7124
7125 (defun gnus-make-threads ()
7126   "Go through the dependency hashtb and find the roots.  Return all threads."
7127   ;; Then we find all the roots and return all the threads.
7128   (let (threads)
7129     (mapatoms
7130      (lambda (refs)
7131        (or (car (symbol-value refs))
7132            (setq threads (append (cdr (symbol-value refs)) threads))))
7133      gnus-newsgroup-dependencies)
7134     threads))
7135   
7136 (defun gnus-build-old-threads ()
7137   ;; Look at all the articles that refer back to old articles, and
7138   ;; fetch the headers for the articles that aren't there.  This will
7139   ;; build complete threads - if the roots haven't been expired by the
7140   ;; server, that is.
7141   (let (id heads)
7142     (mapatoms
7143      (lambda (refs)
7144        (if (not (car (symbol-value refs)))
7145            (progn
7146              (setq heads (cdr (symbol-value refs)))
7147              (while heads
7148                (if (not (memq (mail-header-number (car (car heads)))
7149                               gnus-newsgroup-dormant))
7150                    (progn
7151                      (setq id (symbol-name refs))
7152                      (while (and (setq id (gnus-build-get-header id))
7153                                  (not (car (gnus-gethash 
7154                                             id gnus-newsgroup-dependencies)))))
7155                      (setq heads nil))
7156                  (setq heads (cdr heads)))))))
7157      gnus-newsgroup-dependencies)))
7158
7159 (defun gnus-build-get-header (id)
7160   ;; Look through the buffer of NOV lines and find the header to
7161   ;; ID.  Enter this line into the dependencies hash table, and return
7162   ;; the id of the parent article (if any).
7163   (let ((deps gnus-newsgroup-dependencies)
7164         found header)
7165     (prog1
7166         (save-excursion
7167           (set-buffer nntp-server-buffer)
7168           (goto-char (point-min))
7169           (while (and (not found) (search-forward id nil t))
7170             (beginning-of-line)
7171             (setq found (looking-at 
7172                          (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
7173                                  (regexp-quote id))))
7174             (or found (beginning-of-line 2)))
7175           (when found
7176             (let (ref)
7177               (beginning-of-line)
7178               (and
7179                (setq header (gnus-nov-parse-line 
7180                              (read (current-buffer)) deps))
7181                (gnus-parent-id (mail-header-references header))))))
7182       (when header
7183         (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers)
7184               gnus-newsgroup-ancient (cons (mail-header-number header)
7185                                            gnus-newsgroup-ancient))))))
7186
7187 (defun gnus-rebuild-thread (id)
7188   "Rebuild the thread containing ID."
7189   (let ((dep gnus-newsgroup-dependencies)
7190         (buffer-read-only nil)
7191         current headers refs thread art data)
7192     (if (not gnus-show-threads)
7193         (setq thread (list (car (gnus-gethash (downcase id) dep))))
7194       ;; Get the thread this article is part of.
7195       (setq thread (gnus-remove-thread id)))
7196     (setq current (save-excursion
7197                     (and (zerop (forward-line -1))
7198                          (gnus-summary-article-number))))
7199     ;; If this is a gathered thread, we have to go some re-gathering.
7200     (when (stringp (car thread))
7201       (let ((subject (car thread))
7202             roots thr)
7203         (setq thread (cdr thread))
7204         (while thread
7205           (unless (memq (setq thr (gnus-id-to-thread 
7206                                       (gnus-root-id
7207                                        (mail-header-id (car (car thread))))))
7208                         roots)
7209             (push thr roots))
7210           (setq thread (cdr thread)))
7211         ;; We now have all (unique) roots.
7212         (if (= (length roots) 1)
7213             ;; All the loose roots are now one solid root.
7214             (setq thread (car roots))
7215           (setq thread (cons subject (gnus-sort-threads roots))))))
7216     (let ((beg (point)) 
7217           threads)
7218       ;; We then insert this thread into the summary buffer.
7219       (let (gnus-newsgroup-data gnus-newsgroup-threads)
7220         (gnus-summary-prepare-threads (list thread))
7221         (setq data (nreverse gnus-newsgroup-data))
7222         (setq threads gnus-newsgroup-threads))
7223       ;; We splice the new data into the data structure.
7224       (gnus-data-enter-list current data)
7225       (gnus-data-compute-positions)
7226       (setq gnus-newsgroup-threads (nconc threads gnus-newsgroup-threads)))))
7227
7228 (defun gnus-id-to-thread (id)
7229   "Return the (sub-)thread where ID appears."
7230   (gnus-gethash (downcase id) gnus-newsgroup-dependencies))
7231
7232 (defun gnus-root-id (id)
7233   "Return the id of the root of the thread where ID appears."
7234   (let (last-id prev)
7235     (while (and id (setq prev (car (gnus-gethash 
7236                                     (downcase id)
7237                                     gnus-newsgroup-dependencies))))
7238       (setq last-id id
7239             id (gnus-parent-id (mail-header-references prev))))
7240     last-id))
7241
7242 (defun gnus-remove-thread (id)
7243   "Remove the thread that has ID in it."
7244   (let ((dep gnus-newsgroup-dependencies)
7245         headers thread prev last-id)
7246     ;; First go up in this thread until we find the root.
7247     (setq last-id (gnus-root-id id))
7248     (setq headers (list (car (gnus-id-to-thread last-id))
7249                         (car (car (cdr (gnus-id-to-thread last-id))))))
7250     ;; We have now found the real root of this thread.  It might have
7251     ;; been gathered into some loose thread, so we have to search
7252     ;; through the threads to find the thread we wanted.
7253     (let ((threads gnus-newsgroup-threads)
7254           sub)
7255       (while threads
7256         (setq sub (car threads))
7257         (if (stringp (car sub))
7258             ;; This is a gathered threads, so we look at the roots
7259             ;; below it to find whether this article in in this
7260             ;; gathered root.
7261             (progn
7262               (setq sub (cdr sub))
7263               (while sub
7264                 (when (member (car (car sub)) headers)
7265                   (setq thread (car threads)
7266                         threads nil
7267                         sub nil))
7268                 (setq sub (cdr sub))))
7269           ;; It's an ordinary thread, so we check it.
7270           (when (eq (car sub) (car headers))
7271             (setq thread sub
7272                   threads nil)))
7273         (setq threads (cdr threads)))
7274       ;; If this article is in no thread, then it's a root. 
7275       (if thread 
7276           (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads))
7277         (setq thread (gnus-gethash (downcase last-id) dep)))
7278       (when thread
7279         (prog1 
7280             thread ; We return this thread.
7281           (if (stringp (car thread))
7282               (progn
7283                 ;; If we use dummy roots, then we have to remove the
7284                 ;; dummy root as well.
7285                 (when (eq gnus-summary-make-false-root 'dummy)
7286                   ;; Uhm.
7287                   )
7288                 (setq thread (cdr thread))
7289                 (while thread
7290                   (gnus-remove-thread-1 (car thread))
7291                   (setq thread (cdr thread))))
7292             (gnus-remove-thread-1 thread)))))))
7293
7294 (defun gnus-remove-thread-1 (thread)
7295   "Remove the thread THREAD recursively."
7296   (let ((number (mail-header-number (car thread)))
7297         pos)
7298     (when (setq pos (text-property-any 
7299                      (point-min) (point-max) 'gnus-number number))
7300       (goto-char pos)
7301       (gnus-delete-line)
7302       (gnus-data-remove number))
7303     (setq thread (cdr thread))
7304     (while thread
7305       (gnus-remove-thread-1 (car thread))
7306       (setq thread (cdr thread)))))
7307
7308 (defun gnus-sort-threads (threads)
7309   "Sort THREADS as specified in `gnus-thread-sort-functions'."
7310   (let ((funs gnus-thread-sort-functions))
7311     (when funs
7312       (while funs
7313         (gnus-message 7 "Sorting with %S..." (car funs))
7314         (setq threads (sort threads (pop funs))))
7315       (gnus-message 7 "Sorting...done")))
7316   threads)
7317
7318 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
7319 (defmacro gnus-thread-header (thread)
7320   ;; Return header of first article in THREAD.
7321   ;; Note that THREAD must never, evr be anything else than a variable -
7322   ;; using some other form will lead to serious barfage.
7323   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
7324   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
7325   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ; 
7326         (vector thread) 2))
7327
7328 (defun gnus-thread-sort-by-number (h1 h2)
7329   "Sort threads by root article number."
7330   (< (mail-header-number (gnus-thread-header h1))
7331      (mail-header-number (gnus-thread-header h2))))
7332
7333 (defun gnus-thread-sort-by-author (h1 h2)
7334   "Sort threads by root author."
7335   (string-lessp
7336    (let ((extract (funcall 
7337                    gnus-extract-address-components
7338                    (mail-header-from (gnus-thread-header h1)))))
7339      (or (car extract) (cdr extract)))
7340    (let ((extract (funcall
7341                    gnus-extract-address-components 
7342                    (mail-header-from (gnus-thread-header h2)))))
7343      (or (car extract) (cdr extract)))))
7344
7345 (defun gnus-thread-sort-by-subject (h1 h2)
7346   "Sort threads by root subject."
7347   (string-lessp
7348    (downcase (gnus-simplify-subject-re
7349               (mail-header-subject (gnus-thread-header h1))))
7350    (downcase (gnus-simplify-subject-re 
7351               (mail-header-subject (gnus-thread-header h2))))))
7352
7353 (defun gnus-thread-sort-by-date (h1 h2)
7354   "Sort threads by root article date."
7355   (string-lessp
7356    (gnus-sortable-date (mail-header-date (gnus-thread-header h1)))
7357    (gnus-sortable-date (mail-header-date (gnus-thread-header h2)))))
7358
7359 (defun gnus-thread-sort-by-score (h1 h2)
7360   "Sort threads by root article score.
7361 Unscored articles will be counted as having a score of zero."
7362   (> (or (cdr (assq (mail-header-number (gnus-thread-header h1))
7363                     gnus-newsgroup-scored))
7364          gnus-summary-default-score 0)
7365      (or (cdr (assq (mail-header-number (gnus-thread-header h2))
7366                     gnus-newsgroup-scored))
7367          gnus-summary-default-score 0)))
7368
7369 (defun gnus-thread-sort-by-total-score (h1 h2)
7370   "Sort threads by the sum of all scores in the thread.
7371 Unscored articles will be counted as having a score of zero."
7372   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
7373
7374 (defun gnus-thread-total-score (thread)
7375   ;;  This function find the total score of THREAD.
7376   (if (consp thread)
7377       (if (stringp (car thread))
7378           (apply gnus-thread-score-function 0
7379                  (mapcar 'gnus-thread-total-score-1 (cdr thread)))
7380         (gnus-thread-total-score-1 thread))
7381     (gnus-thread-total-score-1 (list thread))))
7382
7383 (defun gnus-thread-total-score-1 (root)
7384   ;; This function find the total score of the thread below ROOT.
7385   (setq root (car root))
7386   (apply gnus-thread-score-function
7387          (or (cdr (assq (mail-header-number root) gnus-newsgroup-scored))
7388              gnus-summary-default-score 0)
7389          (mapcar 'gnus-thread-total-score
7390                  (cdr (gnus-gethash (downcase (mail-header-id root))
7391                                     gnus-newsgroup-dependencies)))))
7392
7393 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
7394 (defvar gnus-tmp-prev-subject nil)
7395 (defvar gnus-tmp-false-parent nil)
7396 (defvar gnus-tmp-root-expunged nil)
7397 (defvar gnus-tmp-dummy-line nil)
7398
7399 (defun gnus-summary-prepare-threads (threads)
7400   "Prepare summary buffer from THREADS and indentation LEVEL.  
7401 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'  
7402 or a straight list of headers."
7403   (message "Generating summary...")
7404
7405   (setq gnus-newsgroup-threads threads)
7406   (beginning-of-line)
7407
7408   (let ((gnus-tmp-level 0)
7409         (default-score (or gnus-summary-default-score 0))
7410         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
7411         thread number subject stack state gnus-tmp-gathered beg-match
7412         new-roots gnus-tmp-new-adopts thread-end
7413         gnus-tmp-header gnus-tmp-unread
7414         gnus-tmp-replied gnus-tmp-subject-or-nil
7415         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
7416         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
7417         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
7418
7419     (setq gnus-tmp-prev-subject nil)
7420
7421     (if (vectorp (car threads))
7422         ;; If this is a straight (sic) list of headers, then a
7423         ;; threaded summary display isn't required, so we just create
7424         ;; an unthreaded one.
7425         (gnus-summary-prepare-unthreaded threads)
7426
7427       ;; Do the threaded display.
7428
7429       (while (or threads stack gnus-tmp-new-adopts new-roots)
7430
7431         (if (and (= gnus-tmp-level 0)
7432                  (not (setq gnus-tmp-dummy-line nil))
7433                  (or (not stack)
7434                      (= (car (car stack)) 0))
7435                  (not gnus-tmp-false-parent)
7436                  (or gnus-tmp-new-adopts new-roots))
7437             (if gnus-tmp-new-adopts
7438                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
7439                       thread (list (car gnus-tmp-new-adopts))
7440                       gnus-tmp-header (car (car thread))
7441                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
7442               (if new-roots
7443                   (setq thread (list (car new-roots))
7444                         gnus-tmp-header (car (car thread))
7445                         new-roots (cdr new-roots))))
7446
7447           (if threads
7448               ;; If there are some threads, we do them before the
7449               ;; threads on the stack.
7450               (setq thread threads
7451                     gnus-tmp-header (car (car thread)))
7452             ;; There were no current threads, so we pop something off
7453             ;; the stack. 
7454             (setq state (car stack)
7455                   gnus-tmp-level (car state)
7456                   thread (cdr state)
7457                   stack (cdr stack)
7458                   gnus-tmp-header (car (car thread)))))
7459
7460         (setq gnus-tmp-false-parent nil)
7461         (setq gnus-tmp-root-expunged nil)
7462         (setq thread-end nil)
7463
7464         (if (stringp gnus-tmp-header)
7465             ;; The header is a dummy root.
7466             (cond 
7467              ((eq gnus-summary-make-false-root 'adopt)
7468               ;; We let the first article adopt the rest.
7469               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
7470                                                (cdr (cdr (car thread)))))
7471               (setq gnus-tmp-gathered 
7472                     (nconc (mapcar
7473                             (lambda (h) (mail-header-number (car h)))
7474                             (cdr (cdr (car thread))))
7475                            gnus-tmp-gathered))
7476               (setq thread (cons (list (car (car thread))
7477                                        (car (cdr (car thread))))
7478                                  (cdr thread)))
7479               (setq gnus-tmp-level -1
7480                     gnus-tmp-false-parent t))
7481              ((eq gnus-summary-make-false-root 'empty)
7482               ;; We print adopted articles with empty subject fields.
7483               (setq gnus-tmp-gathered 
7484                     (nconc (mapcar
7485                             (lambda (h) (mail-header-number (car h)))
7486                             (cdr (cdr (car thread))))
7487                            gnus-tmp-gathered))
7488               (setq gnus-tmp-level -1))
7489              ((eq gnus-summary-make-false-root 'dummy)
7490               ;; We remember that we probably want to output a dummy
7491               ;; root.   
7492               (setq gnus-tmp-dummy-line gnus-tmp-header)
7493               (setq gnus-tmp-prev-subject gnus-tmp-header))
7494              (t
7495               ;; We do not make a root for the gathered
7496               ;; sub-threads at all.  
7497               (setq gnus-tmp-level -1)))
7498       
7499           (setq number (mail-header-number gnus-tmp-header)
7500                 subject (mail-header-subject gnus-tmp-header))
7501
7502           (cond 
7503            ;; If the thread has changed subject, we might want to make 
7504            ;; this subthread into a root.
7505            ((and (null gnus-thread-ignore-subject)
7506                  (not (zerop gnus-tmp-level))
7507                  gnus-tmp-prev-subject
7508                  (not (inline
7509                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
7510             (setq new-roots (nconc new-roots (list (car thread)))
7511                   thread-end t
7512                   gnus-tmp-header nil))
7513            ;; If the article lies outside the current limit,
7514            ;; then we do not display it.
7515            ((not (memq number gnus-newsgroup-limit))
7516             (setq gnus-tmp-gathered 
7517                   (nconc (mapcar
7518                           (lambda (h) (mail-header-number (car h)))
7519                           (cdr (car thread)))
7520                          gnus-tmp-gathered))
7521             (setq gnus-tmp-new-adopts (if (cdr (car thread))
7522                                           (append gnus-tmp-new-adopts 
7523                                                   (cdr (car thread)))
7524                                         gnus-tmp-new-adopts)
7525                   thread-end t
7526                   gnus-tmp-header nil)
7527             (when (zerop gnus-tmp-level)
7528               (setq gnus-tmp-root-expunged t)))
7529            ;; Perhaps this article is to be marked as read?
7530            ((and gnus-summary-mark-below
7531                  (< (or (cdr (assq number gnus-newsgroup-scored))
7532                         default-score)
7533                     gnus-summary-mark-below))
7534             (setq gnus-newsgroup-unreads 
7535                   (delq number gnus-newsgroup-unreads)
7536                   gnus-newsgroup-reads
7537                   (cons (cons number gnus-low-score-mark)
7538                         gnus-newsgroup-reads))))
7539           
7540           (when gnus-tmp-header
7541             ;; We may have an old dummy line to output before this
7542             ;; article.  
7543             (when gnus-tmp-dummy-line
7544               (gnus-summary-insert-dummy-line 
7545                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header)))
7546
7547             ;; Compute the mark.
7548             (setq 
7549              gnus-tmp-unread
7550              (cond 
7551               ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
7552               ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
7553               ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
7554               ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
7555               (t (or (cdr (assq number gnus-newsgroup-reads))
7556                      gnus-ancient-mark))))
7557
7558             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
7559                                   gnus-tmp-header gnus-tmp-level)
7560                   gnus-newsgroup-data)
7561
7562             ;; Actually insert the line.
7563             (setq 
7564              gnus-tmp-subject-or-nil
7565              (cond
7566               ((and gnus-thread-ignore-subject
7567                     gnus-tmp-prev-subject
7568                     (not
7569                      (inline (gnus-subject-equal 
7570                               gnus-tmp-prev-subject subject))))
7571                subject)
7572               ((zerop gnus-tmp-level)
7573                (if (and (eq gnus-summary-make-false-root 'empty)
7574                         (memq number gnus-tmp-gathered))
7575                    gnus-summary-same-subject
7576                  subject))
7577               (t gnus-summary-same-subject)))
7578             (if (and (eq gnus-summary-make-false-root 'adopt)
7579                      (= gnus-tmp-level 1)
7580                      (memq number gnus-tmp-gathered))
7581                 (setq gnus-tmp-opening-bracket ?\<
7582                       gnus-tmp-closing-bracket ?\>)
7583               (setq gnus-tmp-opening-bracket ?\[
7584                     gnus-tmp-closing-bracket ?\]))
7585             (setq 
7586              gnus-tmp-indentation 
7587              (aref gnus-thread-indent-array gnus-tmp-level)
7588              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
7589              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
7590                                 gnus-summary-default-score 0)
7591              gnus-tmp-score-char
7592              (if (or (null gnus-summary-default-score)
7593                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
7594                          gnus-summary-zcore-fuzz)) ? 
7595                (if (< gnus-tmp-score gnus-summary-default-score)
7596                    gnus-score-below-mark gnus-score-over-mark))
7597              gnus-tmp-replied
7598              (cond ((memq number gnus-newsgroup-processable)
7599                     gnus-process-mark)
7600                    ((memq number gnus-newsgroup-replied)
7601                     gnus-replied-mark)
7602                    (t gnus-unread-mark))
7603              gnus-tmp-from (mail-header-from gnus-tmp-header)
7604              gnus-tmp-name 
7605              (cond 
7606               ((string-match "(.+)" gnus-tmp-from)
7607                (substring gnus-tmp-from 
7608                           (1+ (match-beginning 0)) (1- (match-end 0))))
7609               ((string-match "<[^>]+> *$" gnus-tmp-from)
7610                (setq beg-match (match-beginning 0))
7611                (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
7612                         (substring gnus-tmp-from (1+ (match-beginning 0))
7613                                    (1- (match-end 0))))
7614                    (substring gnus-tmp-from 0 beg-match)))
7615               (t gnus-tmp-from)))
7616             (or (numberp gnus-tmp-lines) (setq gnus-tmp-lines 0))
7617             (put-text-property
7618              (point)
7619              (progn (eval gnus-summary-line-format-spec) (point))
7620              'gnus-number number)
7621             (when gnus-visual-p
7622               (forward-line -1)
7623               (run-hooks 'gnus-summary-update-hook)
7624               (forward-line 1))
7625
7626             (setq gnus-tmp-prev-subject subject)))
7627
7628         (when (nth 1 thread) 
7629           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
7630         (incf gnus-tmp-level)
7631         (setq threads (if thread-end nil (cdr (car thread))))
7632         (unless threads
7633           (setq gnus-tmp-level 0)))))
7634   (message "Generating summary...done"))
7635
7636 (defun gnus-summary-prepare-unthreaded (headers)
7637   "Generate an unthreaded summary buffer based on HEADERS."
7638   (let (header number mark)
7639
7640     (while headers
7641       (setq header (car headers)
7642             headers (cdr headers)
7643             number (mail-header-number header))
7644
7645       ;; We may have to root out some bad articles...
7646       (when (memq number gnus-newsgroup-limit)
7647         (when (and gnus-summary-mark-below
7648                    (< (or (cdr (assq number gnus-newsgroup-scored))
7649                           gnus-summary-default-score 0)
7650                       gnus-summary-mark-below))
7651           (setq gnus-newsgroup-unreads 
7652                 (delq number gnus-newsgroup-unreads)
7653                 gnus-newsgroup-reads
7654                 (cons (cons number gnus-low-score-mark)
7655                       gnus-newsgroup-reads)))
7656           
7657         (setq mark
7658               (cond 
7659                ((memq number gnus-newsgroup-marked) gnus-ticked-mark)
7660                ((memq number gnus-newsgroup-dormant) gnus-dormant-mark)
7661                ((memq number gnus-newsgroup-unreads) gnus-unread-mark)
7662                ((memq number gnus-newsgroup-expirable) gnus-expirable-mark)
7663                (t (or (cdr (assq number gnus-newsgroup-reads))
7664                       gnus-ancient-mark))))
7665         (setq gnus-newsgroup-data 
7666               (cons (gnus-data-make number mark (1+ (point)) header 0)
7667                     gnus-newsgroup-data))
7668         (gnus-summary-insert-line
7669          header 0 nil mark (memq number gnus-newsgroup-replied)
7670          (memq number gnus-newsgroup-expirable)
7671          (mail-header-subject header) nil
7672          (cdr (assq number gnus-newsgroup-scored))
7673          (memq number gnus-newsgroup-processable))))))
7674
7675 (defun gnus-select-newsgroup (group &optional read-all)
7676   "Select newsgroup GROUP.
7677 If READ-ALL is non-nil, all articles in the group are selected."
7678   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
7679          (info (nth 2 entry))
7680          articles)
7681
7682     (or (gnus-check-server
7683          (setq gnus-current-select-method (gnus-find-method-for-group group)))
7684         (error "Couldn't open server"))
7685     
7686     (or (and entry (not (eq (car entry) t))) ; Either it's active...
7687         (gnus-activate-group group) ; Or we can activate it...
7688         (progn ; Or we bug out.
7689           (kill-buffer (current-buffer))
7690           (error "Couldn't request group %s: %s" 
7691                  group (gnus-status-message group))))
7692
7693     (setq gnus-newsgroup-name group)
7694     (setq gnus-newsgroup-unselected nil)
7695     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
7696
7697     (and gnus-asynchronous
7698          (gnus-check-backend-function 
7699           'request-asynchronous gnus-newsgroup-name)
7700          (setq gnus-newsgroup-async
7701                (gnus-request-asynchronous gnus-newsgroup-name)))
7702
7703     ;; Adjust and set lists of article marks.
7704     (when info
7705       (gnus-adjust-marked-articles info))
7706
7707     (setq gnus-newsgroup-unreads 
7708           (gnus-set-difference
7709            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
7710            gnus-newsgroup-dormant))
7711
7712     (setq gnus-newsgroup-processable nil)
7713     
7714     (setq articles (gnus-articles-to-read group read-all))
7715     
7716     (cond 
7717      ((null articles) 
7718       (gnus-message 3 "Couldn't select newsgroup")
7719       'quit)
7720      ((eq articles 0) nil)
7721      (t
7722       ;; Init the dependencies hash table.
7723       (setq gnus-newsgroup-dependencies 
7724             (gnus-make-hashtable (length articles)))
7725       ;; Retrieve the headers and read them in.
7726       (gnus-message 5 "Fetching headers...")
7727       (setq gnus-newsgroup-headers 
7728             (if (eq 'nov 
7729                     (setq gnus-headers-retrieved-by
7730                           (gnus-retrieve-headers 
7731                            articles gnus-newsgroup-name
7732                            ;; We might want to fetch old headers, but
7733                            ;; not if there is only 1 article.
7734                            (and gnus-fetch-old-headers
7735                                 (or (and 
7736                                      (not (eq gnus-fetch-old-headers 'some))
7737                                      (not (numberp gnus-fetch-old-headers)))
7738                                     (> (length articles) 1))))))
7739                 (gnus-get-newsgroup-headers-xover articles)
7740               (gnus-get-newsgroup-headers)))
7741       (gnus-message 5 "Fetching headers...done")      
7742       ;; Set the initial limit.
7743       (setq gnus-newsgroup-limit (copy-sequence articles))
7744       ;; Remove canceled articles from the list of unread articles.
7745       (setq gnus-newsgroup-unreads
7746             (gnus-set-sorted-intersection 
7747              gnus-newsgroup-unreads
7748              (mapcar (lambda (headers) (mail-header-number headers))
7749                      gnus-newsgroup-headers)))
7750       ;; We might want to build some more threads first.
7751       (and gnus-fetch-old-headers
7752            (eq gnus-headers-retrieved-by 'nov)
7753            (gnus-build-old-threads))
7754       ;; Check whether auto-expire is to be done in this group.
7755       (setq gnus-newsgroup-auto-expire
7756             (gnus-group-auto-expirable-p group))
7757       ;; First and last article in this newsgroup.
7758       (and gnus-newsgroup-headers
7759            (setq gnus-newsgroup-begin 
7760                  (mail-header-number (car gnus-newsgroup-headers)))
7761            (setq gnus-newsgroup-end
7762                  (mail-header-number
7763                   (gnus-last-element gnus-newsgroup-headers))))
7764       (setq gnus-reffed-article-number -1)
7765       ;; GROUP is successfully selected.
7766       (or gnus-newsgroup-headers t)))))
7767
7768 (defun gnus-articles-to-read (group read-all)
7769   ;; Find out what articles the user wants to read.
7770   (let* ((articles
7771           ;; Select all articles if `read-all' is non-nil, or if there
7772           ;; are no unread articles.
7773           (if (or read-all
7774                   (and (zerop (length gnus-newsgroup-marked))
7775                        (zerop (length gnus-newsgroup-unreads))))
7776               (gnus-uncompress-range (gnus-active group))
7777             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked 
7778                           (copy-sequence gnus-newsgroup-unreads))
7779                   '<)))
7780          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
7781          (scored (length scored-list))
7782          (number (length articles))
7783          (marked (+ (length gnus-newsgroup-marked)
7784                     (length gnus-newsgroup-dormant)))
7785          (select
7786           (cond 
7787            ((numberp read-all)
7788             read-all)
7789            (t
7790             (condition-case ()
7791                 (cond 
7792                  ((and (or (<= scored marked) (= scored number))
7793                        (numberp gnus-large-newsgroup)
7794                        (> number gnus-large-newsgroup))
7795                   (let ((input
7796                          (read-string
7797                           (format
7798                            "How many articles from %s (default %d): "
7799                            gnus-newsgroup-name number))))
7800                     (if (string-match "^[ \t]*$" input) number input)))
7801                  ((and (> scored marked) (< scored number))
7802                   (let ((input
7803                          (read-string
7804                           (format "%s %s (%d scored, %d total): "
7805                                   "How many articles from"
7806                                   group scored number))))
7807                     (if (string-match "^[ \t]*$" input)
7808                         number input)))
7809                  (t number))
7810               (quit nil))))))
7811     (setq select (if (stringp select) (string-to-number select) select))
7812     (if (or (null select) (zerop select))
7813         select
7814       (if (and (not (zerop scored)) (<= (abs select) scored))
7815           (progn
7816             (setq articles (sort scored-list '<))
7817             (setq number (length articles)))
7818         (setq articles (copy-sequence articles)))
7819
7820       (if (< (abs select) number)
7821           (if (< select 0) 
7822               ;; Select the N oldest articles.
7823               (setcdr (nthcdr (1- (abs select)) articles) nil)
7824             ;; Select the N most recent articles.
7825             (setq articles (nthcdr (- number select) articles))))
7826       (setq gnus-newsgroup-unselected
7827             (gnus-sorted-intersection
7828              gnus-newsgroup-unreads
7829              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
7830       articles)))
7831
7832 (defun gnus-killed-articles (killed articles)
7833   (let (out)
7834     (while articles
7835       (if (inline (gnus-member-of-range (car articles) killed))
7836           (setq out (cons (car articles) out)))
7837       (setq articles (cdr articles)))
7838     out))
7839
7840 (defun gnus-adjust-marked-articles (info)
7841   "Set all article lists and remove all marks that are no longer legal."
7842   (let* ((marked-lists (gnus-info-marks info))
7843          (active (gnus-active (gnus-info-group info)))
7844          (min (car active))
7845          (max (cdr active))
7846          (types '((marked . tick) (replied . reply) 
7847                   (expirable . expire) (killed . killed)
7848                   (bookmarks . bookmark) (dormant . dormant)
7849                   (scored . score)))
7850          (uncompressed '(score bookmark))
7851          marks var articles article mark)
7852
7853     (while marked-lists
7854       (setq marks (pop marked-lists))
7855       (set (setq var (intern (format "gnus-newsgroup-%s" 
7856                                      (car (rassq (setq mark (car marks)) 
7857                                                  types)))))
7858            (if (memq (car marks) uncompressed) (cdr marks)
7859              (gnus-uncompress-range (cdr marks))))
7860
7861       (setq articles (symbol-value var))
7862
7863       ;; All articles have to be subsets of the active articles.  
7864       (cond 
7865        ;; Adjust "simple" lists.
7866        ((memq mark '(tick dormant expirable reply killed))
7867         (while articles
7868           (when (or (< (setq article (pop articles)) min) (> article max))
7869             (set var (delq article (symbol-value var))))))
7870        ;; Adjust assocs.
7871        ((memq mark '(score bookmark))
7872         (while articles 
7873           (when (or (< (car (setq article (pop articles))) min) 
7874                     (> (car article) max))
7875             (set var (delq article (symbol-value var))))))))))
7876
7877 (defun gnus-update-marks ()
7878   "Enter the various lists of marked articles into the newsgroup info list."
7879   (let ((types '((marked . tick) (replied . reply) 
7880                  (expirable . expire) (killed . killed)
7881                  (bookmarks . bookmark) (dormant . dormant)
7882                  (scored . score)))
7883         (info (gnus-get-info gnus-newsgroup-name))
7884         (uncompressed '(score bookmark))
7885         var type list newmarked)
7886     ;; Add all marks lists that are non-nil to the list of marks lists. 
7887     (while types
7888       (setq type (pop types))
7889       (when (setq list (symbol-value (intern (format "gnus-newsgroup-%s" 
7890                                                      (car type)))))
7891         (push (cons (cdr type) 
7892                     (if (memq (cdr type) uncompressed) list
7893                       (gnus-compress-sequence list t)))
7894               newmarked)))
7895
7896     ;; Enter these new marks into the info of the group.
7897     (if (nthcdr 3 info)
7898         (progn
7899           (setcar (nthcdr 3 info) newmarked)
7900           ;; Cut off the end of the info if there's nothing else there. 
7901           (or newmarked (nthcdr 4 info)
7902               (setcdr (nthcdr 2 info) nil)))
7903       ;; Add the marks lists to the end of the info.
7904       (when newmarked
7905         (setcdr (nthcdr 2 info) (list newmarked))))))
7906
7907
7908 (defun gnus-add-marked-articles (group type articles &optional info force)
7909   ;; Add ARTICLES of TYPE to the info of GROUP.
7910   ;; If INFO is non-nil, use that info.  If FORCE is non-nil, don't
7911   ;; add, but replace marked articles of TYPE with ARTICLES.
7912   (let ((info (or info (gnus-get-info group)))
7913         (uncompressed '(score bookmark))
7914         marked m)
7915     (or (not info)
7916         (and (not (setq marked (nthcdr 3 info)))
7917              (setcdr (nthcdr 2 info)
7918                      (list (list (cons type (gnus-compress-sequence
7919                                              articles t))))))
7920         (and (not (setq m (assq type (car marked))))
7921              (setcar marked 
7922                      (cons (cons type (gnus-compress-sequence articles t) )
7923                            (car marked)))
7924         (if force
7925             (setcdr m (gnus-compress-sequence articles t))
7926           (setcdr m (gnus-compress-sequence
7927                      (sort (nconc (gnus-uncompress-range m) 
7928                                   (copy-sequence articles)) '<) t)))))))
7929          
7930 (defun gnus-set-mode-line (where)
7931   "This function sets the mode line of the article or summary buffers.
7932 If WHERE is `summary', the summary mode line format will be used."
7933   ;; Is this mode line one we keep updated?
7934   (when (memq where gnus-updated-mode-lines)
7935     (let (mode-string)
7936       (save-excursion
7937         ;; We evaluate this in the summary buffer since these
7938         ;; variables are buffer-local to that buffer.
7939         (set-buffer gnus-summary-buffer)
7940         ;; We bind all these variables that are used in the `eval' form
7941         ;; below. 
7942         (let* ((mformat (if (eq where 'article) 
7943                             gnus-article-mode-line-format-spec
7944                           gnus-summary-mode-line-format-spec))
7945                (gnus-tmp-group-name gnus-newsgroup-name)
7946                (gnus-tmp-article-number (or gnus-current-article 0))
7947                (gnus-tmp-unread gnus-newsgroup-unreads)
7948                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
7949                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
7950                (gnus-tmp-unread-and-unselected
7951                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
7952                             (zerop gnus-tmp-unselected)) "")
7953                       ((zerop gnus-tmp-unselected) 
7954                        (format "{%d more}" gnus-tmp-unread-and-unticked))
7955                       (t (format "{%d(+%d) more}"
7956                                  gnus-tmp-unread-and-unticked
7957                                  gnus-tmp-unselected))))
7958                (gnus-tmp-subject
7959                 (if gnus-current-headers
7960                     (mail-header-subject gnus-current-headers) ""))
7961                max-len 
7962                header);; passed as argument to any user-format-funcs
7963           (setq mode-string (eval mformat))
7964           (setq max-len (max 4 (if gnus-mode-non-string-length
7965                                    (- (frame-width) 
7966                                       gnus-mode-non-string-length)
7967                                  (length mode-string))))
7968           ;; We might have to chop a bit of the string off...
7969           (when (> (length mode-string) max-len)
7970             (setq mode-string 
7971                   (concat (gnus-truncate-string mode-string (- max-len 3))
7972                           "...")))
7973           ;; Pad the mode string a bit.
7974           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
7975       ;; Update the mode line.
7976       (setq mode-line-buffer-identification mode-string)
7977       (set-buffer-modified-p t))))
7978
7979 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
7980   "Go through the HEADERS list and add all Xrefs to a hash table.
7981 The resulting hash table is returned, or nil if no Xrefs were found."
7982   (let* ((from-method (gnus-find-method-for-group from-newsgroup))
7983          (prefix (gnus-group-real-prefix from-newsgroup))
7984          (xref-hashtb (make-vector 63 0))
7985          start group entry number xrefs header)
7986     (while headers
7987       (setq header (pop headers))
7988       (when (and (setq xrefs (mail-header-xref header))
7989                  (not (memq (setq number (mail-header-number header))
7990                             unreads)))
7991         (setq start 0)
7992         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
7993           (setq start (match-end 0))
7994           (setq group (concat prefix (substring xrefs (match-beginning 1) 
7995                                                 (match-end 1))))
7996           (setq number 
7997                 (string-to-int (substring xrefs (match-beginning 2) 
7998                                           (match-end 2))))
7999           (if (setq entry (gnus-gethash group xref-hashtb))
8000               (setcdr entry (cons number (cdr entry)))
8001             (gnus-sethash group (cons number nil) xref-hashtb)))))
8002     (and start xref-hashtb)))
8003
8004 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
8005   "Look through all the headers and mark the Xrefs as read."
8006   (let ((virtual (memq 'virtual 
8007                        (assoc (symbol-name (car (gnus-find-method-for-group 
8008                                                  from-newsgroup)))
8009                               gnus-valid-select-methods)))
8010         name entry info xref-hashtb idlist method
8011         nth4)
8012     (save-excursion
8013       (set-buffer gnus-group-buffer)
8014       (when (setq xref-hashtb 
8015                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
8016         (mapatoms 
8017          (lambda (group)
8018            (unless (string= from-newsgroup (setq name (symbol-name group)))
8019              (setq idlist (symbol-value group))
8020              ;; Dead groups are not updated.
8021              (and (prog1 
8022                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
8023                             info (nth 2 entry))
8024                     (if (stringp (setq nth4 (gnus-info-method info)))
8025                         (setq nth4 (gnus-server-to-method nth4))))
8026                   ;; Only do the xrefs if the group has the same
8027                   ;; select method as the group we have just read.
8028                   (or (gnus-methods-equal-p 
8029                        nth4 (gnus-find-method-for-group from-newsgroup))
8030                       virtual
8031                       (equal nth4 (setq method (gnus-find-method-for-group 
8032                                                 from-newsgroup)))
8033                       (and (equal (car nth4) (car method))
8034                            (equal (nth 1 nth4) (nth 1 method))))
8035                   gnus-use-cross-reference
8036                   (or (not (eq gnus-use-cross-reference t))
8037                       virtual
8038                       ;; Only do cross-references on subscribed
8039                       ;; groups, if that is what is wanted.  
8040                       (<= (gnus-info-level info) gnus-level-subscribed))
8041                   (gnus-group-make-articles-read name idlist))))
8042          xref-hashtb)))))
8043
8044 (defun gnus-group-make-articles-read (group articles)
8045   (let* ((num 0)
8046          (entry (gnus-gethash group gnus-newsrc-hashtb))
8047          (info (nth 2 entry))
8048          (active (gnus-active group))
8049          range)
8050     ;; First peel off all illegal article numbers.
8051     (if active
8052         (let ((ids articles)
8053               id first)
8054           (while ids
8055             (setq id (car ids))
8056             (if (and first (> id (cdr active)))
8057                 (progn
8058                   ;; We'll end up in this situation in one particular
8059                   ;; obscure situation.  If you re-scan a group and get
8060                   ;; a new article that is cross-posted to a different
8061                   ;; group that has not been re-scanned, you might get
8062                   ;; crossposted article that has a higher number than
8063                   ;; Gnus believes possible.  So we re-activate this
8064                   ;; group as well.  This might mean doing the
8065                   ;; crossposting thingie will *increase* the number
8066                   ;; of articles in some groups.  Tsk, tsk.
8067                   (setq active (or (gnus-activate-group group) active))))
8068             (if (or (> id (cdr active))
8069                     (< id (car active)))
8070                 (setq articles (delq id articles)))
8071             (setq ids (cdr ids)))))
8072     ;; If the read list is nil, we init it.
8073     (and active
8074          (null (gnus-info-read info))
8075          (> (car active) 1)
8076          (gnus-info-set-read info (cons 1 (1- (car active)))))
8077     ;; Then we add the read articles to the range.
8078     (gnus-info-set-read
8079      info
8080      (setq range
8081            (gnus-add-to-range 
8082             (gnus-info-read info) (setq articles (sort articles '<)))))
8083     ;; Then we have to re-compute how many unread
8084     ;; articles there are in this group.
8085     (if active
8086         (progn
8087           (cond 
8088            ((not range)
8089             (setq num (- (1+ (cdr active)) (car active))))
8090            ((not (listp (cdr range)))
8091             (setq num (- (cdr active) (- (1+ (cdr range)) 
8092                                          (car range)))))
8093            (t
8094             (while range
8095               (if (numberp (car range))
8096                   (setq num (1+ num))
8097                 (setq num (+ num (- (1+ (cdr (car range)))
8098                                     (car (car range))))))
8099               (setq range (cdr range)))
8100             (setq num (- (cdr active) num))))
8101           ;; Update the number of unread articles.
8102           (setcar entry num)
8103           ;; Update the group buffer.
8104           (gnus-group-update-group group t)))))
8105
8106 (defun gnus-methods-equal-p (m1 m2)
8107   (let ((m1 (or m1 gnus-select-method))
8108         (m2 (or m2 gnus-select-method)))
8109     (or (equal m1 m2)
8110         (and (eq (car m1) (car m2))
8111              (or (not (memq 'address (assoc (symbol-name (car m1))
8112                                             gnus-valid-select-methods)))
8113                  (equal (nth 1 m1) (nth 1 m2)))))))
8114
8115 (defsubst gnus-header-value ()
8116   (buffer-substring (match-end 0) (gnus-point-at-eol)))
8117
8118 (defvar gnus-newsgroup-none-id 0)
8119
8120 (defun gnus-get-newsgroup-headers ()
8121   (setq gnus-article-internal-prepare-hook nil)
8122   (let ((cur nntp-server-buffer)
8123         (dependencies (save-excursion (set-buffer gnus-summary-buffer)
8124                                       gnus-newsgroup-dependencies))
8125         headers id id-dep ref-dep end ref)
8126     (save-excursion
8127       (set-buffer nntp-server-buffer)
8128       (let ((case-fold-search t)
8129             in-reply-to header number p lines)
8130         (goto-char (point-min))
8131         ;; Search to the beginning of the next header.  Error messages
8132         ;; do not begin with 2 or 3.
8133         (while (re-search-forward "^[23][0-9]+ " nil t)
8134           (setq id nil
8135                 ref nil)
8136           ;; This implementation of this function, with nine
8137           ;; search-forwards instead of the one re-search-forward and
8138           ;; a case (which basically was the old function) is actually
8139           ;; about twice as fast, even though it looks messier.  You
8140           ;; can't have everything, I guess.  Speed and elegance
8141           ;; doesn't always go hand in hand.
8142           (setq 
8143            header
8144            (vector
8145             ;; Number.
8146             (prog1
8147                 (read cur)
8148               (end-of-line)
8149               (setq p (point))
8150               (narrow-to-region (point) 
8151                                 (or (and (search-forward "\n.\n" nil t)
8152                                          (- (point) 2))
8153                                     (point))))
8154             ;; Subject.
8155             (progn
8156               (goto-char p)
8157               (if (search-forward "\nsubject: " nil t)
8158                   (gnus-header-value) "(none)"))
8159             ;; From.
8160             (progn
8161               (goto-char p)
8162               (if (search-forward "\nfrom: " nil t)
8163                   (gnus-header-value) "(nobody)"))
8164             ;; Date.
8165             (progn
8166               (goto-char p)
8167               (if (search-forward "\ndate: " nil t)
8168                   (gnus-header-value) ""))
8169             ;; Message-ID.
8170             (progn
8171               (goto-char p)
8172               (if (search-forward "\nmessage-id: " nil t)
8173                   (setq id (gnus-header-value))
8174                 ;; If there was no message-id, we just fake one to make
8175                 ;; subsequent routines simpler.
8176                 (setq id (concat "none+" 
8177                                  (int-to-string 
8178                                   (setq gnus-newsgroup-none-id 
8179                                         (1+ gnus-newsgroup-none-id)))))))
8180             ;; References.
8181             (progn
8182               (goto-char p)
8183               (if (search-forward "\nreferences: " nil t)
8184                   (prog1
8185                       (gnus-header-value)
8186                     (setq end (match-end 0))
8187                     (save-excursion
8188                       (setq ref 
8189                             (downcase
8190                              (buffer-substring
8191                               (progn 
8192                                 (end-of-line)
8193                                 (search-backward ">" end t)
8194                                 (1+ (point)))
8195                               (progn
8196                                 (search-backward "<" end t)
8197                                 (point)))))))
8198                 ;; Get the references from the in-reply-to header if there
8199                 ;; were no references and the in-reply-to header looks
8200                 ;; promising. 
8201                 (if (and (search-forward "\nin-reply-to: " nil t)
8202                          (setq in-reply-to (gnus-header-value))
8203                          (string-match "<[^>]+>" in-reply-to))
8204                     (prog1
8205                         (setq ref (substring in-reply-to (match-beginning 0)
8206                                              (match-end 0)))
8207                       (setq ref (downcase ref))))
8208                 (setq ref "")))
8209             ;; Chars.
8210             0
8211             ;; Lines.
8212             (progn
8213               (goto-char p)
8214               (if (search-forward "\nlines: " nil t)
8215                   (if (numberp (setq lines (read cur)))
8216                       lines 0)
8217                 0))
8218             ;; Xref.
8219             (progn
8220               (goto-char p)
8221               (and (search-forward "\nxref: " nil t)
8222                    (gnus-header-value)))))
8223           (if (and gnus-nocem-hashtb
8224                    (gnus-gethash id gnus-nocem-hashtb))
8225               ;; Banned article.
8226               (setq header nil)
8227             ;; We do the threading while we read the headers.  The
8228             ;; message-id and the last reference are both entered into
8229             ;; the same hash table.  Some tippy-toeing around has to be
8230             ;; done in case an article has arrived before the article
8231             ;; which it refers to.
8232             (if (boundp (setq id-dep (intern (downcase id) dependencies)))
8233                 (if (car (symbol-value id-dep))
8234                     ;; An article with this Message-ID has already
8235                     ;; been seen, so we ignore this one, except we add
8236                     ;; any additional Xrefs (in case the two articles
8237                     ;; came from different servers).
8238                     (progn
8239                       (mail-header-set-xref 
8240                        (car (symbol-value id-dep))
8241                        (concat (or (mail-header-xref 
8242                                     (car (symbol-value id-dep))) "")
8243                                (or (mail-header-xref header) "")))
8244                       (setq header nil))
8245                   (setcar (symbol-value id-dep) header))
8246               (set id-dep (list header))))
8247           (if header
8248               (progn
8249                 (if (boundp (setq ref-dep (intern ref dependencies)))
8250                     (setcdr (symbol-value ref-dep) 
8251                             (nconc (cdr (symbol-value ref-dep))
8252                                    (list (symbol-value id-dep))))
8253                   (set ref-dep (list nil (symbol-value id-dep))))
8254                 (setq headers (cons header headers))))
8255           (goto-char (point-max))
8256           (widen))
8257         (nreverse headers)))))
8258
8259 ;; The following macros and functions were written by Felix Lee
8260 ;; <flee@cse.psu.edu>. 
8261
8262 (defmacro gnus-nov-read-integer ()
8263   '(prog1
8264        (if (= (following-char) ?\t)
8265            0
8266          (let ((num (condition-case nil (read buffer) (error nil))))
8267            (if (numberp num) num 0)))
8268      (or (eobp) (forward-char 1))))
8269
8270 (defmacro gnus-nov-skip-field ()
8271   '(search-forward "\t" eol 'move))
8272
8273 (defmacro gnus-nov-field ()
8274   '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol)))
8275
8276 ;; Goes through the xover lines and returns a list of vectors
8277 (defun gnus-get-newsgroup-headers-xover (sequence)
8278   "Parse the news overview data in the server buffer, and return a
8279 list of headers that match SEQUENCE (see `nntp-retrieve-headers')."
8280   ;; Get the Xref when the users reads the articles since most/some
8281   ;; NNTP servers do not include Xrefs when using XOVER.
8282   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
8283   (let ((cur nntp-server-buffer)
8284         (dependencies gnus-newsgroup-dependencies)
8285         number headers header)
8286     (save-excursion
8287       (set-buffer nntp-server-buffer)
8288       (goto-char (point-min))
8289       (while (and sequence (not (eobp)))
8290         (setq number (read cur))
8291         (while (and sequence (< (car sequence) number))
8292           (setq sequence (cdr sequence)))
8293         (and sequence 
8294              (eq number (car sequence))
8295              (progn
8296                (setq sequence (cdr sequence))
8297                (if (setq header 
8298                          (inline (gnus-nov-parse-line number dependencies)))
8299                    (setq headers (cons header headers)))))
8300         (forward-line 1))
8301       (setq headers (nreverse headers)))
8302     headers))
8303
8304 ;; This function has to be called with point after the article number
8305 ;; on the beginning of the line.
8306 (defun gnus-nov-parse-line (number dependencies)
8307   (let ((none 0)
8308         (eol (gnus-point-at-eol)) 
8309         (buffer (current-buffer))
8310         header ref id id-dep ref-dep)
8311
8312     ;; overview: [num subject from date id refs chars lines misc]
8313     (narrow-to-region (point) eol)
8314     (or (eobp) (forward-char))
8315
8316     (condition-case nil
8317         (setq header
8318               (vector 
8319                number                   ; number
8320                (gnus-nov-field)         ; subject
8321                (gnus-nov-field)         ; from
8322                (gnus-nov-field)         ; date
8323                (setq id (or (gnus-nov-field)
8324                             (concat "none+"
8325                                     (int-to-string 
8326                                      (setq none (1+ none)))))) ; id
8327                (progn
8328                  (save-excursion
8329                    (let ((beg (point)))
8330                      (search-forward "\t" eol)
8331                      (if (search-backward ">" beg t)
8332                          (setq ref 
8333                                (downcase 
8334                                 (buffer-substring 
8335                                  (1+ (point))
8336                                  (progn
8337                                    (search-backward "<" beg t)
8338                                    (point)))))
8339                        (setq ref nil))))
8340                  (gnus-nov-field))      ; refs
8341                (gnus-nov-read-integer)  ; chars
8342                (gnus-nov-read-integer)  ; lines
8343                (if (= (following-char) ?\n)
8344                    nil
8345                  (gnus-nov-field))      ; misc
8346                ))
8347       (error (progn 
8348                (ding)
8349                (message "Strange nov line.")
8350                (setq header nil)
8351                (goto-char eol))))
8352
8353     (widen)
8354
8355     ;; We build the thread tree.
8356     (and header
8357          (if (and gnus-nocem-hashtb
8358                   (gnus-gethash id gnus-nocem-hashtb))
8359              ;; Banned article.
8360              (setq header nil)
8361            (if (boundp (setq id-dep (intern (downcase id) dependencies)))
8362                (if (car (symbol-value id-dep))
8363                    ;; An article with this Message-ID has already been seen,
8364                    ;; so we ignore this one, except we add any additional
8365                    ;; Xrefs (in case the two articles came from different
8366                    ;; servers.
8367                    (progn
8368                      (mail-header-set-xref 
8369                       (car (symbol-value id-dep))
8370                       (concat (or (mail-header-xref 
8371                                    (car (symbol-value id-dep))) "")
8372                               (or (mail-header-xref header) "")))
8373                      (setq header nil))
8374                  (setcar (symbol-value id-dep) header))
8375              (set id-dep (list header)))))
8376     (if header
8377         (progn
8378           (if (boundp (setq ref-dep (intern (or ref "none") dependencies)))
8379               (setcdr (symbol-value ref-dep) 
8380                       (nconc (cdr (symbol-value ref-dep))
8381                              (list (symbol-value id-dep))))
8382             (set ref-dep (list nil (symbol-value id-dep))))))
8383     header))
8384
8385 (defun gnus-article-get-xrefs ()
8386   "Fill in the Xref value in `gnus-current-headers', if necessary.
8387 This is meant to be called in `gnus-article-internal-prepare-hook'."
8388   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
8389                                  gnus-current-headers)))
8390     (or (not gnus-use-cross-reference)
8391         (not headers)
8392         (and (mail-header-xref headers)
8393              (not (string= (mail-header-xref headers) "")))
8394         (let ((case-fold-search t)
8395               xref)
8396           (save-restriction
8397             (gnus-narrow-to-headers)
8398             (goto-char (point-min))
8399             (if (or (and (eq (downcase (following-char)) ?x)
8400                          (looking-at "Xref:"))
8401                     (search-forward "\nXref:" nil t))
8402                 (progn
8403                   (goto-char (1+ (match-end 0)))
8404                   (setq xref (buffer-substring (point) 
8405                                                (progn (end-of-line) (point))))
8406                   (mail-header-set-xref headers xref))))))))
8407
8408 (defun gnus-summary-insert-subject (id)
8409   "Find article ID and insert the summary line for that article."
8410   (let ((header (gnus-read-header id))
8411         number)
8412     (when header
8413       ;; Rebuild the thread that this article is part of and go to the
8414       ;; article we have fetched.
8415       (gnus-rebuild-thread (mail-header-id header))
8416       (gnus-summary-goto-subject (setq number (mail-header-number header)))
8417       (when (> number 0)
8418         ;; We have to update the boundaries, possibly.
8419         (and (> number gnus-newsgroup-end)
8420              (setq gnus-newsgroup-end number))
8421         (and (< number gnus-newsgroup-begin)
8422              (setq gnus-newsgroup-begin number))
8423         (setq gnus-newsgroup-unselected
8424               (delq number gnus-newsgroup-unselected)))
8425       ;; Report back a success.
8426       number)))
8427
8428 (defun gnus-summary-work-articles (n)
8429   "Return a list of articles to be worked upon.  The prefix argument,
8430 the list of process marked articles, and the current article will be
8431 taken into consideration."
8432   (cond
8433    ((and n (numberp n))
8434     ;; A numerical prefix has been given.
8435     (let ((backward (< n 0))
8436           (n (abs n))
8437           articles article)
8438       (save-excursion
8439         (while 
8440             (and (> n 0)
8441                  (push (setq article (gnus-summary-article-number))
8442                        articles)
8443                  (if backward
8444                      (gnus-summary-find-prev nil article)
8445                    (gnus-summary-find-next nil article)))
8446           (decf n)))
8447       (nreverse articles)))
8448    ((and (boundp 'transient-mark-mode)
8449          transient-mark-mode
8450          mark-active)
8451     ;; Work on the region between point and mark.
8452     (let ((max (max (point) (mark)))
8453           articles article)
8454       (save-excursion
8455         (goto-char (min (point) (mark)))
8456         (while 
8457             (and 
8458              (push (setq article (gnus-summary-article-number)) articles)
8459              (gnus-summary-find-next nil article)
8460              (< (point) max)))
8461         (nreverse articles))))
8462    (gnus-newsgroup-processable
8463     ;; There are process-marked articles present.
8464     (reverse gnus-newsgroup-processable))
8465    (t
8466     ;; Just return the current article.
8467     (list (gnus-summary-article-number)))))
8468
8469 (defun gnus-summary-search-group (&optional backward use-level)
8470   "Search for next unread newsgroup.
8471 If optional argument BACKWARD is non-nil, search backward instead."
8472   (save-excursion
8473     (set-buffer gnus-group-buffer)
8474     (if (gnus-group-search-forward 
8475          backward nil (if use-level (gnus-group-group-level) nil))
8476         (gnus-group-group-name))))
8477
8478 (defun gnus-summary-best-group (&optional exclude-group)
8479   "Find the name of the best unread group.
8480 If EXCLUDE-GROUP, do not go to this group."
8481   (save-excursion
8482     (set-buffer gnus-group-buffer)
8483     (save-excursion
8484       (gnus-group-best-unread-group exclude-group))))
8485
8486 (defun gnus-summary-find-next (&optional unread article backward)
8487   (if backward (gnus-summary-find-prev)
8488     (let* ((article (or article (gnus-summary-article-number)))
8489            (arts (gnus-data-find-list article))
8490            result)
8491       (unless gnus-summary-check-current
8492         (setq arts (cdr arts)))
8493       (when (setq result
8494                 (if unread
8495                     (progn
8496                       (while arts
8497                         (when (gnus-data-unread-p (car arts))
8498                           (setq result (car arts)
8499                                 arts nil))
8500                         (setq arts (cdr arts)))
8501                       result)
8502                   (car arts)))
8503         (goto-char (gnus-data-pos result))
8504         (gnus-data-number result)))))
8505
8506 (defun gnus-summary-find-prev (&optional unread article)
8507   (let* ((article (or article (gnus-summary-article-number)))
8508          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
8509          result)
8510     (unless gnus-summary-check-current
8511       (setq arts (cdr arts)))
8512     (if (setq result
8513               (if unread
8514                   (progn
8515                     (while arts
8516                       (and (gnus-data-unread-p (car arts))
8517                            (setq result (car arts)
8518                                  arts nil))
8519                       (setq arts (cdr arts)))
8520                     result)
8521                 (car arts)))
8522         (progn
8523           (goto-char (gnus-data-pos result))
8524           (gnus-data-number result)))))
8525
8526 (defun gnus-summary-find-subject (subject &optional unread backward article)
8527   (let* ((article (or article (gnus-summary-article-number)))
8528          (articles (gnus-data-list backward))
8529          (arts (gnus-data-find-list article articles))
8530          result)
8531     (unless gnus-summary-check-current
8532       (setq arts (cdr arts)))
8533     (while arts
8534       (and (or (not unread)
8535                (gnus-data-unread-p (car arts)))
8536            (vectorp (gnus-data-header (car arts)))
8537            (gnus-subject-equal 
8538             subject (mail-header-subject (gnus-data-header (car arts))))
8539            (setq result (car arts)
8540                  arts nil))
8541       (setq arts (cdr arts)))
8542     (and result
8543          (goto-char (gnus-data-pos result))
8544          (gnus-data-number result))))
8545
8546 (defun gnus-summary-search-forward (&optional unread subject backward)
8547   (cond (subject
8548          (gnus-summary-find-subject subject unread backward))
8549         (backward
8550          (gnus-summary-find-prev unread))
8551         (t
8552          (gnus-summary-find-next unread))))
8553
8554 (defun gnus-summary-recenter ()
8555   "Center point in the summary window.
8556 If `gnus-auto-center-summary' is nil, or the article buffer isn't
8557 displayed, no centering will be performed." 
8558   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
8559   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
8560   (let* ((top (cond ((< (window-height) 4) 0)
8561                     ((< (window-height) 7) 1)
8562                     (t 2)))
8563          (height (1- (window-height)))
8564          (bottom (save-excursion (goto-char (point-max))
8565                                  (forward-line (- height))
8566                                  (point)))
8567          (window (get-buffer-window (current-buffer))))
8568     (and 
8569      ;; The user has to want it,
8570      gnus-auto-center-summary 
8571      ;; the article buffer must be displayed,
8572      (get-buffer-window gnus-article-buffer)
8573      ;; Set the window start to either `bottom', which is the biggest
8574      ;; possible valid number, or the second line from the top,
8575      ;; whichever is the least.
8576      (set-window-start
8577       window (min bottom (save-excursion (forward-line (- top)) (point)))))))
8578
8579 ;; Function written by Stainless Steel Rat <ratinox@ccs.neu.edu>.
8580 (defun gnus-short-group-name (group &optional levels)
8581   "Collapse GROUP name LEVELS."
8582   (let* ((name "") (foreign "") (depth -1) (skip 1)
8583          (levels (or levels
8584                      (progn
8585                        (while (string-match "\\." group skip)
8586                          (setq skip (match-end 0)
8587                                depth (+ depth 1)))
8588                        depth))))
8589     (if (string-match ":" group)
8590         (setq foreign (substring group 0 (match-end 0))
8591               group (substring group (match-end 0))))
8592     (while group
8593       (if (and (string-match "\\." group) (> levels 0))
8594           (setq name (concat name (substring group 0 1))
8595                 group (substring group (match-end 0))
8596                 levels (- levels 1)
8597                 name (concat name "."))
8598         (setq name (concat foreign name group)
8599               group nil)))
8600     name))
8601
8602 (defun gnus-summary-jump-to-group (newsgroup)
8603   "Move point to NEWSGROUP in group mode buffer."
8604   ;; Keep update point of group mode buffer if visible.
8605   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
8606       (save-window-excursion
8607         ;; Take care of tree window mode.
8608         (if (get-buffer-window gnus-group-buffer)
8609             (pop-to-buffer gnus-group-buffer))
8610         (gnus-group-jump-to-group newsgroup))
8611     (save-excursion
8612       ;; Take care of tree window mode.
8613       (if (get-buffer-window gnus-group-buffer)
8614           (pop-to-buffer gnus-group-buffer)
8615         (set-buffer gnus-group-buffer))
8616       (gnus-group-jump-to-group newsgroup))))
8617
8618 ;; This function returns a list of article numbers based on the
8619 ;; difference between the ranges of read articles in this group and
8620 ;; the range of active articles.
8621 (defun gnus-list-of-unread-articles (group)
8622   (let* ((read (gnus-info-read (gnus-get-info group)))
8623          (active (gnus-active group))
8624          (last (cdr active))
8625          first nlast unread)
8626     ;; If none are read, then all are unread. 
8627     (if (not read)
8628         (setq first (car active))
8629       ;; If the range of read articles is a single range, then the
8630       ;; first unread article is the article after the last read
8631       ;; article.  Sounds logical, doesn't it?
8632       (if (not (listp (cdr read)))
8633           (setq first (1+ (cdr read)))
8634         ;; `read' is a list of ranges.
8635         (if (/= (setq nlast (or (and (numberp (car read)) (car read)) 
8636                                 (car (car read)))) 1)
8637             (setq first 1))
8638         (while read
8639           (if first 
8640               (while (< first nlast)
8641                 (setq unread (cons first unread))
8642                 (setq first (1+ first))))
8643           (setq first (1+ (if (atom (car read)) (car read) (cdr (car read)))))
8644           (setq nlast (if (atom (car (cdr read))) 
8645                           (car (cdr read))
8646                         (car (car (cdr read)))))
8647           (setq read (cdr read)))))
8648     ;; And add the last unread articles.
8649     (while (<= first last)
8650       (setq unread (cons first unread))
8651       (setq first (1+ first)))
8652     ;; Return the list of unread articles.
8653     (nreverse unread)))
8654
8655 (defun gnus-list-of-read-articles (group)
8656   "Return a list of unread, unticked and non-dormant articles."
8657   (let* ((info (gnus-get-info group))
8658          (marked (gnus-info-marks info))
8659          (active (gnus-active group)))
8660     (and info active
8661          (gnus-set-difference
8662           (gnus-sorted-complement 
8663            (gnus-uncompress-range active) 
8664            (gnus-list-of-unread-articles group))
8665           (append 
8666            (gnus-uncompress-range (cdr (assq 'dormant marked)))
8667            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
8668
8669 ;; Various summary commands
8670
8671 (defun gnus-summary-universal-argument ()
8672   "Perform any operation on all articles marked with the process mark."
8673   (interactive)
8674   (gnus-set-global-variables)
8675   (let ((articles (reverse gnus-newsgroup-processable))
8676         func)
8677     (or articles (error "No articles marked"))
8678     (or (setq func (key-binding (read-key-sequence "C-c C-u")))
8679         (error "Undefined key"))
8680     (while articles
8681       (gnus-summary-goto-subject (car articles))
8682       (command-execute func)
8683       (gnus-summary-remove-process-mark (car articles))
8684       (setq articles (cdr articles)))))
8685
8686 (defun gnus-summary-toggle-truncation (&optional arg)
8687   "Toggle truncation of summary lines.
8688 With arg, turn line truncation on iff arg is positive."
8689   (interactive "P")
8690   (setq truncate-lines
8691         (if (null arg) (not truncate-lines)
8692           (> (prefix-numeric-value arg) 0)))
8693   (redraw-display))
8694
8695 (defun gnus-summary-reselect-current-group (&optional all)
8696   "Once exit and then reselect the current newsgroup.
8697 The prefix argument ALL means to select all articles."
8698   (interactive "P")
8699   (gnus-set-global-variables)
8700   (let ((current-subject (gnus-summary-article-number))
8701         (group gnus-newsgroup-name))
8702     (setq gnus-newsgroup-begin nil)
8703     (gnus-summary-exit t)
8704     ;; We have to adjust the point of group mode buffer because the
8705     ;; current point was moved to the next unread newsgroup by
8706     ;; exiting.
8707     (gnus-summary-jump-to-group group)
8708     (gnus-group-read-group all t)
8709     (gnus-summary-goto-subject current-subject)))
8710
8711 (defun gnus-summary-rescan-group (&optional all)
8712   "Exit the newsgroup, ask for new articles, and select the newsgroup."
8713   (interactive "P")
8714   (gnus-set-global-variables)
8715   ;; Fix by Ilja Weis <kult@uni-paderborn.de>.
8716   (let ((group gnus-newsgroup-name))
8717     (gnus-summary-exit)
8718     (gnus-summary-jump-to-group group)
8719     (save-excursion
8720       (set-buffer gnus-group-buffer)
8721       (gnus-group-get-new-news-this-group 1))
8722     (gnus-summary-jump-to-group group)
8723     (gnus-group-read-group all)))
8724
8725 (defun gnus-summary-update-info ()
8726   (let* ((group gnus-newsgroup-name))
8727     (when gnus-newsgroup-kill-headers
8728       (setq gnus-newsgroup-killed
8729             (gnus-compress-sequence
8730              (nconc
8731               (gnus-set-sorted-intersection
8732                (gnus-uncompress-range gnus-newsgroup-killed)
8733                (setq gnus-newsgroup-unselected
8734                      (sort gnus-newsgroup-unselected '<)))
8735               (setq gnus-newsgroup-unreads
8736                     (sort gnus-newsgroup-unreads '<))) t)))
8737     (unless (listp (cdr gnus-newsgroup-killed))
8738       (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
8739     (let ((headers gnus-newsgroup-headers))
8740       (gnus-close-group group)
8741       (run-hooks 'gnus-exit-group-hook)
8742       (unless gnus-save-score
8743         (setq gnus-newsgroup-scored nil))
8744       ;; Set the new ranges of read articles.
8745       (gnus-update-read-articles
8746        group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
8747       ;; Set the current article marks.
8748       (gnus-update-marks)
8749       ;; Do the cross-ref thing.
8750       (when gnus-use-cross-reference
8751         (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
8752       ;; Do adaptive scoring, and possibly save score files.
8753       (when gnus-newsgroup-adaptive
8754         (gnus-score-adaptive))
8755       (when gnus-use-scoring 
8756         (gnus-score-save))
8757       ;; Do not switch windows but change the buffer to work.
8758       (set-buffer gnus-group-buffer)
8759       (or (gnus-ephemeral-group-p gnus-newsgroup-name)
8760           (gnus-group-update-group group)))))
8761   
8762 (defun gnus-summary-exit (&optional temporary)
8763   "Exit reading current newsgroup, and then return to group selection mode.
8764 gnus-exit-group-hook is called with no arguments if that value is non-nil."
8765   (interactive)
8766   (gnus-set-global-variables)
8767   (gnus-kill-save-kill-buffer)
8768   (let* ((group gnus-newsgroup-name)
8769          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
8770          (mode major-mode)
8771          (buf (current-buffer)))
8772     (run-hooks 'gnus-summary-prepare-exit-hook)
8773     ;; Make all changes in this group permanent.
8774     (gnus-summary-update-info)          
8775     (set-buffer buf)
8776     (and gnus-use-cache (gnus-cache-possibly-remove-articles))
8777     ;; Make sure where I was, and go to next newsgroup.
8778     (set-buffer gnus-group-buffer)
8779     (or quit-config
8780         (progn
8781           (gnus-group-jump-to-group group)
8782           (gnus-group-next-unread-group 1)))
8783     (if temporary
8784         nil                             ;Nothing to do.
8785       ;; We set all buffer-local variables to nil.  It is unclear why
8786       ;; this is needed, but if we don't, buffer-local variables are
8787       ;; not garbage-collected, it seems.  This would the lead to en
8788       ;; ever-growing Emacs.
8789       (set-buffer buf)
8790       (gnus-summary-clear-local-variables)
8791       ;; We clear the global counterparts of the buffer-local
8792       ;; variables as well, just to be on the safe side.
8793       (gnus-configure-windows 'group 'force)
8794       (gnus-summary-clear-local-variables)
8795       ;; Return to group mode buffer. 
8796       (if (eq mode 'gnus-summary-mode)
8797           (gnus-kill-buffer buf))
8798       (if (get-buffer gnus-article-buffer)
8799           (bury-buffer gnus-article-buffer))
8800       (setq gnus-current-select-method gnus-select-method)
8801       (pop-to-buffer gnus-group-buffer)
8802       (if (not quit-config)
8803           (progn
8804             (gnus-group-jump-to-group group)
8805             (gnus-group-next-unread-group 1))
8806         (if (not (buffer-name (car quit-config)))
8807             (gnus-configure-windows 'group 'force)
8808           (set-buffer (car quit-config))
8809           (and (eq major-mode 'gnus-summary-mode)
8810                (gnus-set-global-variables))
8811           (gnus-configure-windows (cdr quit-config))))
8812       (run-hooks 'gnus-summary-exit-hook))))
8813
8814 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
8815 (defun gnus-summary-exit-no-update (&optional no-questions)
8816   "Quit reading current newsgroup without updating read article info."
8817   (interactive)
8818   (gnus-set-global-variables)
8819   (let* ((group gnus-newsgroup-name)
8820          (quit-config (gnus-group-quit-config group)))
8821     (if (or no-questions
8822             gnus-expert-user
8823             (gnus-y-or-n-p "Do you really wanna quit reading this group? "))
8824         (progn
8825           (gnus-close-group group)
8826           (gnus-summary-clear-local-variables)
8827           (set-buffer gnus-group-buffer)
8828           (gnus-summary-clear-local-variables)
8829           ;; Return to group selection mode.
8830           (gnus-configure-windows 'group 'force)
8831           (if (get-buffer gnus-summary-buffer)
8832               (kill-buffer gnus-summary-buffer))
8833           (if (get-buffer gnus-article-buffer)
8834               (bury-buffer gnus-article-buffer))
8835           (if (equal (gnus-group-group-name) group)
8836               (gnus-group-next-unread-group 1))
8837           (if quit-config
8838               (progn
8839                 (if (not (buffer-name (car quit-config)))
8840                     (gnus-configure-windows 'group 'force)
8841                   (set-buffer (car quit-config))
8842                   (and (eq major-mode 'gnus-summary-mode)
8843                        (gnus-set-global-variables))
8844                   (gnus-configure-windows (cdr quit-config)))))))))
8845
8846 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
8847 (defun gnus-summary-fetch-faq (&optional faq-dir)
8848   "Fetch the FAQ for the current group.
8849 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
8850 in."
8851   (interactive 
8852    (list
8853     (if current-prefix-arg
8854         (completing-read 
8855          "Faq dir: " (and (listp gnus-group-faq-directory)
8856                           gnus-group-faq-directory)))))
8857   (let (gnus-faq-buffer)
8858     (and (setq gnus-faq-buffer 
8859                (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
8860          (gnus-configure-windows 'summary-faq))))
8861
8862 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
8863 (defun gnus-summary-describe-group (&optional force)
8864   "Describe the current newsgroup."
8865   (interactive "P")
8866   (gnus-group-describe-group force gnus-newsgroup-name))
8867
8868 (defun gnus-summary-describe-briefly ()
8869   "Describe summary mode commands briefly."
8870   (interactive)
8871   (gnus-message 6
8872                 (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")))
8873
8874 ;; Walking around group mode buffer from summary mode.
8875
8876 (defun gnus-summary-next-group (&optional no-article target-group backward)
8877   "Exit current newsgroup and then select next unread newsgroup.
8878 If prefix argument NO-ARTICLE is non-nil, no article is selected
8879 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
8880 previous group instead."
8881   (interactive "P")
8882   (gnus-set-global-variables)
8883   (let ((current-group gnus-newsgroup-name)
8884         (current-buffer (current-buffer))
8885         entered)
8886     ;; First we semi-exit this group to update Xrefs and all variables.
8887     ;; We can't do a real exit, because the window conf must remain
8888     ;; the same in case the user is prompted for info, and we don't
8889     ;; want the window conf to change before that...
8890     (gnus-summary-exit t)
8891     (while (not entered)
8892       ;; Then we find what group we are supposed to enter.
8893       (set-buffer gnus-group-buffer)
8894       (gnus-group-jump-to-group current-group)
8895       (setq target-group 
8896             (or target-group        
8897                 (if (eq gnus-keep-same-level 'best) 
8898                     (gnus-summary-best-group gnus-newsgroup-name)
8899                   (gnus-summary-search-group backward gnus-keep-same-level))))
8900       (if (not target-group)
8901           ;; There are no further groups, so we return to the group
8902           ;; buffer.
8903           (progn
8904             (gnus-message 5 "Returning to the group buffer")
8905             (setq entered t)
8906             (set-buffer current-buffer)
8907             (gnus-summary-exit))
8908         ;; We try to enter the target group.
8909         (gnus-group-jump-to-group target-group)
8910         (let ((unreads (gnus-group-group-unread)))
8911           (if (and (or (eq t unreads)
8912                        (and unreads (not (zerop unreads))))
8913                    (gnus-summary-read-group
8914                     target-group nil no-article current-buffer))
8915               (setq entered t)
8916             (setq current-group target-group
8917                   target-group nil)))))))
8918
8919 (defun gnus-summary-prev-group (&optional no-article)
8920   "Exit current newsgroup and then select previous unread newsgroup.
8921 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
8922   (interactive "P")
8923   (gnus-summary-next-group no-article nil t))
8924
8925 ;; Walking around summary lines.
8926
8927 (defun gnus-summary-first-subject (&optional unread)
8928   "Go to the first unread subject.
8929 If UNREAD is non-nil, go to the first unread article.
8930 Returns the article selected or nil if there are no unread articles."
8931   (interactive "P")
8932   (prog1
8933       (cond 
8934        ;; Empty summary.
8935        ((null gnus-newsgroup-data)
8936         (gnus-message 3 "No articles in the group")
8937         nil)
8938        ;; Pick the first article.
8939        ((not unread)
8940         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
8941         (gnus-data-number (car gnus-newsgroup-data)))
8942        ;; No unread articles.
8943        ((null gnus-newsgroup-unreads)
8944         (gnus-message 3 "No more unread articles")
8945         nil)
8946        ;; Find the first unread article.
8947        (t
8948         (let ((data gnus-newsgroup-data))
8949           (while (and data
8950                       (not (gnus-data-unread-p (car data))))
8951             (setq data (cdr data)))
8952           (if data
8953               (progn
8954                 (goto-char (gnus-data-pos (car data)))
8955                 (gnus-data-number (car data)))))))
8956     (gnus-summary-position-point)))
8957
8958 (defun gnus-summary-next-subject (n &optional unread dont-display)
8959   "Go to next N'th summary line.
8960 If N is negative, go to the previous N'th subject line.
8961 If UNREAD is non-nil, only unread articles are selected.
8962 The difference between N and the actual number of steps taken is
8963 returned."
8964   (interactive "p")
8965   (let ((backward (< n 0))
8966         (n (abs n)))
8967     (while (and (> n 0)
8968                 (if backward
8969                     (gnus-summary-find-prev unread)
8970                   (gnus-summary-find-next unread)))
8971       (setq n (1- n)))
8972     (if (/= 0 n) (gnus-message 7 "No more%s articles"
8973                                (if unread " unread" "")))
8974     (or dont-display
8975         (progn
8976           (gnus-summary-recenter)
8977           (gnus-summary-position-point)))
8978     n))
8979
8980 (defun gnus-summary-next-unread-subject (n)
8981   "Go to next N'th unread summary line."
8982   (interactive "p")
8983   (gnus-summary-next-subject n t))
8984
8985 (defun gnus-summary-prev-subject (n &optional unread)
8986   "Go to previous N'th summary line.
8987 If optional argument UNREAD is non-nil, only unread article is selected."
8988   (interactive "p")
8989   (gnus-summary-next-subject (- n) unread))
8990
8991 (defun gnus-summary-prev-unread-subject (n)
8992   "Go to previous N'th unread summary line."
8993   (interactive "p")
8994   (gnus-summary-next-subject (- n) t))
8995
8996 (defun gnus-summary-goto-subject (article &optional force silent)
8997   "Go the subject line of ARTICLE.
8998 If FORCE, also allow jumping to articles not currently shown."
8999   (let ((b (point))
9000         (data (gnus-data-find article)))
9001     ;; We read in the article if we have to.
9002     (and (not data) 
9003          force
9004          (gnus-summary-insert-subject article)
9005          (setq data (gnus-data-find article)))
9006     (goto-char b)
9007     (if (and (not silent) (not data))
9008         (progn
9009           (message "Can't find article %d" article)
9010           nil)
9011       (goto-char (gnus-data-pos data))
9012       article)))
9013
9014 ;; Walking around summary lines with displaying articles.
9015
9016 (defun gnus-summary-expand-window (&optional arg)
9017   "Make the summary buffer take up the entire Emacs frame.
9018 Given a prefix, will force an `article' buffer configuration."
9019   (interactive "P")
9020   (gnus-set-global-variables)
9021   (if arg
9022       (gnus-configure-windows 'article 'force)
9023     (gnus-configure-windows 'summary 'force)))
9024
9025 (defun gnus-summary-display-article (article &optional all-header)
9026   "Display ARTICLE in article buffer."
9027   (gnus-set-global-variables)
9028   (if (null article)
9029       nil
9030     (prog1
9031         (gnus-article-prepare article all-header)
9032       (gnus-summary-show-thread)
9033       (run-hooks 'gnus-select-article-hook)
9034       (gnus-summary-recenter)
9035       (gnus-summary-goto-subject article)
9036       ;; Successfully display article.
9037       (gnus-summary-update-line)
9038       (gnus-article-set-window-start 
9039        (cdr (assq article gnus-newsgroup-bookmarks)))
9040       t)))
9041
9042 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
9043   "Select the current article.
9044 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
9045 non-nil, the article will be re-fetched even if it already present in
9046 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
9047 be displayed."
9048   (let ((article (or article (gnus-summary-article-number)))
9049         (all-headers (not (not all-headers))) ;Must be T or NIL.
9050         did) 
9051     (and (not pseudo) 
9052          (gnus-summary-article-pseudo-p article)
9053          (error "This is a pseudo-article."))
9054     (prog1
9055         (save-excursion
9056           (set-buffer gnus-summary-buffer)
9057           (if (or (null gnus-current-article)
9058                   (null gnus-article-current)
9059                   (null (get-buffer gnus-article-buffer))
9060                   (not (eq article (cdr gnus-article-current)))
9061                   (not (equal (car gnus-article-current) gnus-newsgroup-name))
9062                   force)
9063               ;; The requested article is different from the current article.
9064               (progn
9065                 (gnus-summary-display-article article all-headers)
9066                 (setq did article))
9067             (if (or all-headers gnus-show-all-headers) 
9068                 (gnus-article-show-all-headers))
9069             nil))
9070       (if did 
9071           (gnus-article-set-window-start 
9072            (cdr (assq article gnus-newsgroup-bookmarks)))))))
9073
9074 (defun gnus-summary-set-current-mark (&optional current-mark)
9075   "Obsolete function."
9076   nil)
9077
9078 (defun gnus-summary-next-article (&optional unread subject backward)
9079   "Select the next article.
9080 If UNREAD, only unread articles are selected.
9081 If SUBJECT, only articles with SUBJECT are selected.
9082 If BACKWARD, the previous article is selected instead of the next."
9083   (interactive "P")
9084   (gnus-set-global-variables)
9085   (let (header)
9086     (cond
9087      ;; Is there such an article?
9088      ((and (gnus-summary-search-forward unread subject backward)
9089            (or (gnus-summary-display-article (gnus-summary-article-number))
9090                (eq (gnus-summary-article-mark) gnus-canceled-mark)))
9091       (gnus-summary-position-point))
9092      ;; If not, we try the first unread, if that is wanted.
9093      ((and subject
9094            gnus-auto-select-same
9095            (or (gnus-summary-first-unread-article)
9096                (eq (gnus-summary-article-mark) gnus-canceled-mark)))
9097       (gnus-summary-position-point)
9098       (gnus-message 6 "Wrapped"))
9099      ;; Try to get next/previous article not displayed in this group.
9100      ((and gnus-auto-extend-newsgroup
9101            (not unread) (not subject))
9102       (gnus-summary-goto-article 
9103        (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
9104        nil t))
9105      ;; Go to next/previous group.
9106      (t
9107       (or (gnus-ephemeral-group-p gnus-newsgroup-name)
9108           (gnus-summary-jump-to-group gnus-newsgroup-name))
9109       (let ((cmd last-command-char)
9110             (group 
9111              (if (eq gnus-keep-same-level 'best) 
9112                  (gnus-summary-best-group gnus-newsgroup-name)
9113                (gnus-summary-search-group backward gnus-keep-same-level))))
9114         ;; For some reason, the group window gets selected.  We change
9115         ;; it back.  
9116         (select-window (get-buffer-window (current-buffer)))
9117         ;; Keep just the event type of CMD.
9118                                         ;(and (listp cmd) (setq cmd (car cmd)))
9119         ;; Select next unread newsgroup automagically.
9120         (cond 
9121          ((not gnus-auto-select-next)
9122           (gnus-message 7 "No more%s articles" (if unread " unread" "")))
9123          ((or (eq gnus-auto-select-next 'quietly)
9124               (and (eq gnus-auto-select-next 'almost-quietly)
9125                    (gnus-summary-last-article-p)))
9126           ;; Select quietly.
9127           (if (gnus-ephemeral-group-p gnus-newsgroup-name)
9128               (gnus-summary-exit)
9129             (gnus-message 7 "No more%s articles (%s)..."
9130                           (if unread " unread" "") 
9131                           (if group (concat "selecting " group)
9132                             "exiting"))
9133             (gnus-summary-next-group nil group backward)))
9134          (t
9135           (let ((keystrokes '(?\C-n ?\C-p))
9136                 key)
9137             (while (or (null key) (memq key keystrokes))
9138               (gnus-message 
9139                7 "No more%s articles%s" (if unread " unread" "")
9140                (if (and group 
9141                         (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
9142                    (format " (Type %s for %s [%s])"
9143                            (single-key-description cmd) group
9144                            (car (gnus-gethash group gnus-newsrc-hashtb)))
9145                  (format " (Type %s to exit %s)"
9146                          (single-key-description cmd)
9147                          gnus-newsgroup-name)))
9148               ;; Confirm auto selection.
9149               (let* ((event (read-char-exclusive)))
9150                 (setq key (if (listp event) (car event) event))
9151                 (if (memq key keystrokes)
9152                     (let ((obuf (current-buffer)))
9153                       (switch-to-buffer gnus-group-buffer)
9154                       (and group
9155                            (gnus-group-jump-to-group group))
9156                       (condition-case ()
9157                           (cond ((= key ?\C-n)
9158                                  (gnus-group-next-unread-group 1))
9159                                 ((= key ?\C-p)
9160                                  (gnus-group-prev-unread-group 1)))
9161                         (error (ding) nil))
9162                       (setq group (gnus-group-group-name))
9163                       (switch-to-buffer obuf)))))
9164             (if (equal key cmd)
9165                 (if (or (not group)
9166                         (gnus-ephemeral-group-p gnus-newsgroup-name))
9167                     (gnus-summary-exit)
9168                   (gnus-summary-next-group nil group backward))
9169               (execute-kbd-macro (char-to-string key)))))))))))
9170
9171 (defun gnus-summary-next-unread-article ()
9172   "Select unread article after current one."
9173   (interactive)
9174   (gnus-summary-next-article t (and gnus-auto-select-same
9175                                     (gnus-summary-article-subject))))
9176
9177 (defun gnus-summary-prev-article (&optional unread subject)
9178   "Select the article after the current one.
9179 If UNREAD is non-nil, only unread articles are selected."
9180   (interactive "P")
9181   (gnus-summary-next-article unread subject t))
9182
9183 (defun gnus-summary-prev-unread-article ()
9184   "Select unred article before current one."
9185   (interactive)
9186   (gnus-summary-prev-article t (and gnus-auto-select-same
9187                                     (gnus-summary-article-subject))))
9188
9189 (defun gnus-summary-next-page (&optional lines circular)
9190   "Show next page of selected article.
9191 If end of article, select next article.
9192 Argument LINES specifies lines to be scrolled up.
9193 If CIRCULAR is non-nil, go to the start of the article instead of 
9194 instead of selecting the next article when reaching the end of the
9195 current article." 
9196   (interactive "P")
9197   (setq gnus-summary-buffer (current-buffer))
9198   (gnus-set-global-variables)
9199   (let ((article (gnus-summary-article-number))
9200         (endp nil))
9201     (gnus-configure-windows 'article)
9202     (if (or (null gnus-current-article)
9203             (null gnus-article-current)
9204             (/= article (cdr gnus-article-current))
9205             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
9206         ;; Selected subject is different from current article's.
9207         (gnus-summary-display-article article)
9208       (gnus-eval-in-buffer-window
9209        gnus-article-buffer
9210        (setq endp (gnus-article-next-page lines)))
9211       (if endp
9212           (cond (circular
9213                  (gnus-summary-beginning-of-article))
9214                 (lines
9215                  (gnus-message 3 "End of message"))
9216                 ((null lines)
9217                  (gnus-summary-next-unread-article)))))
9218     (gnus-summary-recenter)
9219     (gnus-summary-position-point)))
9220
9221 (defun gnus-summary-prev-page (&optional lines)
9222   "Show previous page of selected article.
9223 Argument LINES specifies lines to be scrolled down."
9224   (interactive "P")
9225   (gnus-set-global-variables)
9226   (let ((article (gnus-summary-article-number)))
9227     (gnus-configure-windows 'article)
9228     (if (or (null gnus-current-article)
9229             (null gnus-article-current)
9230             (/= article (cdr gnus-article-current))
9231             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
9232         ;; Selected subject is different from current article's.
9233         (gnus-summary-display-article article)
9234       (gnus-summary-recenter)
9235       (gnus-eval-in-buffer-window gnus-article-buffer
9236                                   (gnus-article-prev-page lines))))
9237   (gnus-summary-position-point))
9238
9239 (defun gnus-summary-scroll-up (lines)
9240   "Scroll up (or down) one line current article.
9241 Argument LINES specifies lines to be scrolled up (or down if negative)."
9242   (interactive "p")
9243   (gnus-set-global-variables)
9244   (gnus-configure-windows 'article)
9245   (or (gnus-summary-select-article nil nil 'pseudo)
9246       (gnus-eval-in-buffer-window 
9247        gnus-article-buffer
9248        (cond ((> lines 0)
9249               (if (gnus-article-next-page lines)
9250                   (gnus-message 3 "End of message")))
9251              ((< lines 0)
9252               (gnus-article-prev-page (- lines))))))
9253   (gnus-summary-recenter)
9254   (gnus-summary-position-point))
9255
9256 (defun gnus-summary-next-same-subject ()
9257   "Select next article which has the same subject as current one."
9258   (interactive)
9259   (gnus-set-global-variables)
9260   (gnus-summary-next-article nil (gnus-summary-article-subject)))
9261
9262 (defun gnus-summary-prev-same-subject ()
9263   "Select previous article which has the same subject as current one."
9264   (interactive)
9265   (gnus-set-global-variables)
9266   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
9267
9268 (defun gnus-summary-next-unread-same-subject ()
9269   "Select next unread article which has the same subject as current one."
9270   (interactive)
9271   (gnus-set-global-variables)
9272   (gnus-summary-next-article t (gnus-summary-article-subject)))
9273
9274 (defun gnus-summary-prev-unread-same-subject ()
9275   "Select previous unread article which has the same subject as current one."
9276   (interactive)
9277   (gnus-set-global-variables)
9278   (gnus-summary-prev-article t (gnus-summary-article-subject)))
9279
9280 (defun gnus-summary-first-unread-article ()
9281   "Select the first unread article. 
9282 Return nil if there are no unread articles."
9283   (interactive)
9284   (gnus-set-global-variables)
9285   (prog1
9286       (if (gnus-summary-first-subject t)
9287           (progn
9288             (gnus-summary-show-thread)
9289             (gnus-summary-first-subject t)
9290             (gnus-summary-display-article (gnus-summary-article-number))))
9291     (gnus-summary-position-point)))
9292
9293 (defun gnus-summary-best-unread-article ()
9294   "Select the unread article with the highest score."
9295   (interactive)
9296   (gnus-set-global-variables)
9297   (let ((best -1000000)
9298         (data gnus-newsgroup-data)
9299         article score)
9300     (while data
9301       (and (gnus-data-unread-p (car data))
9302            (> (setq score 
9303                     (gnus-summary-article-score (gnus-data-number (car data))))
9304               best)
9305            (setq best score
9306                  article (gnus-data-number (car data))))
9307       (setq data (cdr data)))
9308     (if article
9309         (gnus-summary-goto-article article)
9310       (error "No unread articles"))
9311     (gnus-summary-position-point)))
9312
9313 (defun gnus-summary-goto-article (article &optional all-headers force)
9314   "Fetch ARTICLE and display it if it exists.
9315 If ALL-HEADERS is non-nil, no header lines are hidden."
9316   (interactive
9317    (list
9318     (string-to-int
9319      (completing-read 
9320       "Article number: "
9321       (mapcar (lambda (number) (list (int-to-string number)))
9322               gnus-newsgroup-limit)))
9323     current-prefix-arg
9324     t))
9325   (prog1
9326       (if (gnus-summary-goto-subject article force)
9327           (gnus-summary-display-article article all-headers)
9328         (message "Couldn't go to article %s" article) nil)
9329     (gnus-summary-position-point)))
9330
9331 (defun gnus-summary-goto-last-article ()
9332   "Go to the previously read article."
9333   (interactive)
9334   (prog1
9335       (and gnus-last-article
9336            (gnus-summary-goto-article gnus-last-article))
9337     (gnus-summary-position-point)))
9338
9339 (defun gnus-summary-pop-article (number)
9340   "Pop one article off the history and go to the previous.
9341 NUMBER articles will be popped off."
9342   (interactive "p")
9343   (let (to)
9344     (setq gnus-newsgroup-history
9345           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
9346     (if to
9347         (gnus-summary-goto-article (car to))
9348       (error "Article history empty")))
9349   (gnus-summary-position-point))
9350
9351 ;; Summary commands and functions for limiting the summary buffer.
9352
9353 (defun gnus-summary-limit-to-articles (n)
9354   "Limit the summary buffer to the next N articles.
9355 If not given a prefix, use the process marked articles instead."
9356   (interactive "P")
9357   (gnus-set-global-variables)
9358   (prog1
9359       (let ((articles (gnus-summary-work-articles n)))
9360         (gnus-summary-limit articles))
9361     (gnus-summary-position-point)))
9362
9363 (defun gnus-summary-pop-limit (&optional total)
9364   "Restore the previous limit.
9365 If given a prefix, remove all limits."
9366   (interactive "P")
9367   (gnus-set-global-variables)
9368   (prog2
9369       (if total (setq gnus-newsgroup-limits 
9370                       (list (mapcar (lambda (h) (mail-header-number h))
9371                                     gnus-newsgroup-headers))))
9372       (gnus-summary-limit nil 'pop)
9373     (gnus-summary-position-point)))
9374
9375 (defun gnus-summary-limit-to-subject (subject)
9376   "Limit the summary buffer to articles that have subjects that match a regexp."
9377   (interactive "sRegexp: ")
9378   (when (not (equal "" subject))
9379     (prog1
9380         (let ((articles (gnus-summary-find-matching "subject" subject 'all)))
9381           (or articles (error "Found no matches for \"%s\"" subject))
9382           (gnus-summary-limit articles))
9383       (gnus-summary-position-point))))
9384
9385 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
9386 (make-obsolete 
9387  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
9388
9389 (defun gnus-summary-limit-to-unread (&optional all)
9390   "Limit the summary buffer to articles that are not marked as read.
9391 If ALL is non-nil, limit strictly to unread articles."
9392   (interactive "P")
9393   (if all
9394       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
9395     (gnus-summary-limit-to-marks
9396      ;; Concat all the marks that say that an article is read and have
9397      ;; those removed.  
9398      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
9399            gnus-killed-mark gnus-kill-file-mark
9400            gnus-low-score-mark gnus-expirable-mark
9401            gnus-canceled-mark gnus-catchup-mark)
9402      'reverse)))
9403
9404 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-to-marks)
9405 (make-obsolete 'gnus-summary-delete-marked-with 'gnus-summary-limit-to-marks)
9406
9407 (defun gnus-summary-limit-to-marks (marks &optional reverse)
9408   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
9409 If REVERSE, limit the summary buffer to articles that are not marked
9410 with MARKS.  MARKS can either be a string of marks or a list of marks. 
9411 Returns how many articles were removed."
9412   (interactive "sMarks: ")
9413   (gnus-set-global-variables)
9414   (prog1
9415       (let ((data gnus-newsgroup-data)
9416             (marks (if (listp marks) marks
9417                      (append marks nil))) ; Transform to list.
9418             articles)
9419         (while data
9420           (and (if reverse (not (memq (gnus-data-mark (car data)) marks))
9421                  (memq (gnus-data-mark (car data)) marks))
9422                (setq articles (cons (gnus-data-number (car data)) articles)))
9423           (setq data (cdr data)))
9424         (gnus-summary-limit articles))
9425     (gnus-summary-position-point)))
9426
9427 (defun gnus-summary-limit-to-score (&optional score)
9428   "Limit to articles with score at or above SCORE."
9429   (interactive "P")
9430   (gnus-set-global-variables)
9431   (setq score (if score
9432                   (prefix-numeric-value score)
9433                 (or gnus-summary-default-score 0)))
9434   (let ((data gnus-newsgroup-data)
9435         articles)
9436     (while data
9437       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
9438                 score)
9439         (push (gnus-data-number (car data)) articles))
9440       (setq data (cdr data)))
9441     (prog1
9442         (gnus-summary-limit articles)
9443       (gnus-summary-position-point))))
9444
9445 (defun gnus-summary-limit-include-dormant ()
9446   "Display all the hidden articles that are marked as dormant."
9447   (interactive)
9448   (gnus-set-global-variables)
9449   (or gnus-newsgroup-dormant 
9450       (error "There are no dormant articles in this group"))
9451   (prog1
9452       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
9453     (gnus-summary-position-point)))
9454
9455 (defun gnus-summary-limit-exclude-dormant ()
9456   "Hide all dormant articles."
9457   (interactive)
9458   (gnus-set-global-variables)
9459   (prog1
9460       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
9461     (gnus-summary-position-point)))
9462
9463 (defun gnus-summary-limit-exclude-childless-dormant ()
9464   "Hide all dormant articles that have no children."
9465   (interactive)
9466   (gnus-set-global-variables)
9467   (let ((data gnus-newsgroup-data)
9468         articles)
9469     ;; Find all articles that are either not dormant or have
9470     ;; children. 
9471     (while data
9472       (and (or (not (= (gnus-data-mark (car data)) gnus-dormant-mark))
9473                (gnus-article-parent-p (gnus-data-number (car data))))
9474            (setq articles (cons (gnus-data-number (car data))
9475                                 articles)))
9476       (setq data (cdr data)))
9477     ;; Do the limiting.
9478     (prog1
9479         (gnus-summary-limit articles)
9480       (gnus-summary-position-point))))
9481  
9482 (defun gnus-summary-limit (articles &optional pop)
9483   (if pop
9484       ;; We pop the previous limit off the stack and use that.
9485       (setq articles (car gnus-newsgroup-limits)
9486             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
9487     ;; We use the new limit, so we push the old limit on the stack. 
9488     (setq gnus-newsgroup-limits 
9489           (cons gnus-newsgroup-limit gnus-newsgroup-limits)))
9490   ;; Set the limit.
9491   (setq gnus-newsgroup-limit articles)
9492   (let ((total (length gnus-newsgroup-data))
9493         (data (gnus-data-find-list (gnus-summary-article-number)))
9494         found)
9495     ;; This will do all the work of generating the new summary buffer
9496     ;; according to the new limit.
9497     (gnus-summary-prepare)
9498     ;; Try to return to the article you were at, or on in the
9499     ;; neighborhood.  
9500     (if data
9501         ;; We try to find some article after the current one.
9502         (while data
9503           (and (gnus-summary-goto-subject (gnus-data-number (car data)))
9504                (setq data nil
9505                      found t))
9506           (setq data (cdr data))))
9507     (or found
9508         ;; If there is no data, that means that we were after the last
9509         ;; article.  The same goes when we can't find any articles
9510         ;; after the current one.
9511         (progn
9512           (goto-char (point-max))
9513           (gnus-summary-find-prev)))
9514     ;; We return how many articles were removed from the summary
9515     ;; buffer as a result of the new limit.
9516     (- total (length gnus-newsgroup-data))))
9517
9518 (defun gnus-summary-initial-limit ()
9519   "Figure out what the initial limit is supposed to be on group entry.
9520 This entails weeding out unwanted dormants, low-scored articles,
9521 fetch-old-headers verbiage, and so on."
9522   ;; Most groups have nothing to remove.
9523   (if (and (null gnus-newsgroup-dormant)
9524            (not (eq gnus-fetch-old-headers 'some))
9525            (null gnus-summary-expunge-below))
9526       () ; Do nothing.
9527     (setq gnus-newsgroup-limits 
9528           (cons gnus-newsgroup-limit gnus-newsgroup-limits))
9529     (setq gnus-newsgroup-limit nil)
9530     (mapatoms
9531      (lambda (node)
9532        (if (null (car (symbol-value node)))
9533            (let ((nodes (cdr (symbol-value node))))
9534              (while nodes
9535                (gnus-summary-limit-children (car nodes))
9536                (setq nodes (cdr nodes))))))
9537      gnus-newsgroup-dependencies)
9538     (when (not gnus-newsgroup-limit)
9539       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
9540     gnus-newsgroup-limit))
9541
9542 (defun gnus-summary-limit-children (thread)
9543   "Return 1 if this subthread is visible and 0 if it is not."
9544   ;; First we get the number of visible children to this thread.  This
9545   ;; is done by recursing down the thread using this function, so this
9546   ;; will really go down to a leaf article first, before slowly
9547   ;; working its way up towards the root.
9548   (let ((children 
9549          (if (cdr thread)
9550              (apply '+ (mapcar (lambda (th)
9551                                  (gnus-summary-limit-children th))
9552                                (cdr thread)))
9553            0))
9554         (number (mail-header-number (car thread)))
9555         score)
9556     (if (or 
9557          ;; If this article is dormant and has absolutely no visible
9558          ;; children, then this article isn't visible.
9559          (and (memq number gnus-newsgroup-dormant)
9560               (= children 0))
9561          ;; If this is a "fetch-old-headered" and there is only one
9562          ;; visible child (or less), then we don't want this article. 
9563          (and (eq gnus-fetch-old-headers 'some)
9564               (memq number gnus-newsgroup-ancient)
9565               (<= children 1))
9566          ;; If we use expunging, and this article is really
9567          ;; low-scored, then we don't want this article.
9568          (when (and gnus-summary-expunge-below
9569                     (< (setq score 
9570                              (or (cdr (assq number gnus-newsgroup-scored)) 
9571                                  gnus-summary-default-score))
9572                        gnus-summary-expunge-below))
9573            ;; We increase the expunge-tally here, but that has
9574            ;; nothing to do with the limits, really.
9575            (incf gnus-newsgroup-expunged-tally)
9576            ;; We also mark as read here, if that's wanted.
9577            (when (and gnus-summary-mark-below
9578                       (< score gnus-summary-mark-below))
9579              (setq gnus-newsgroup-unreads 
9580                    (delq number gnus-newsgroup-unreads))
9581              (push (cons number gnus-low-score-mark) gnus-newsgroup-reads))
9582            t))
9583         ;; Nope, invisible article.
9584         0
9585       ;; Ok, this article is to be visible, so we add it to the limit
9586       ;; and return 1.
9587       (setq gnus-newsgroup-limit (cons number gnus-newsgroup-limit))
9588       1)))
9589
9590 ;; Summary article oriented commands
9591
9592 (defun gnus-summary-refer-parent-article (n)
9593   "Refer parent article N times.
9594 The difference between N and the number of articles fetched is returned."
9595   (interactive "p")
9596   (gnus-set-global-variables)
9597   (while 
9598       (and 
9599        (> n 0)
9600        (let* ((header (gnus-summary-article-header))
9601               (ref 
9602                ;; If we try to find the parent of the currently
9603                ;; displayed article, then we take a look at the actual
9604                ;; References header, since this is slightly more
9605                ;; reliable than the References field we got from the
9606                ;; server. 
9607                (if (and (eq (mail-header-number header) 
9608                             (cdr gnus-article-current))
9609                         (equal gnus-newsgroup-name 
9610                                (car gnus-article-current)))
9611                    (save-excursion
9612                      (set-buffer gnus-original-article-buffer)
9613                      (gnus-narrow-to-headers)
9614                      (prog1
9615                          (mail-fetch-field "references")
9616                        (widen)))
9617                  ;; It's not the current article, so we take a bet on
9618                  ;; the value we got from the server. 
9619                  (mail-header-references header))))
9620          (if ref
9621              (or (gnus-summary-refer-article (gnus-parent-id ref))
9622                  (gnus-message 1 "Couldn't find parent"))
9623            (gnus-message 1 "No references in article %d"
9624                          (gnus-summary-article-number))
9625            nil)))
9626     (setq n (1- n)))
9627   (gnus-summary-position-point)
9628   n)
9629
9630 (defun gnus-summary-refer-references ()
9631   "Fetch all articles mentioned in the References header.
9632 Return how many articles were fetched."
9633   (interactive)
9634   (gnus-set-global-variables)
9635   (let ((ref (mail-header-references (gnus-summary-article-header)))
9636         (current (gnus-summary-article-number))
9637         (n 0))
9638     ;; For each Message-ID in the References header...
9639     (while (string-match "<[^>]*>" ref)
9640       (incf n)
9641       ;; ... fetch that article.
9642       (gnus-summary-refer-article 
9643        (prog1 (match-string 0 ref)
9644          (setq ref (substring ref (match-end 0))))))
9645     (gnus-summary-goto-subject current)
9646     (gnus-summary-position-point)
9647     n))
9648     
9649 (defun gnus-summary-refer-article (message-id)
9650   "Fetch an article specified by MESSAGE-ID."
9651   (interactive "sMessage-ID: ")
9652   (when (and (stringp message-id)
9653              (not (zerop (length message-id))))
9654     ;; Construct the correct Message-ID if necessary.
9655     ;; Suggested by tale@pawl.rpi.edu.
9656     (unless (string-match "^<" message-id)
9657       (setq message-id (concat "<" message-id)))
9658     (unless (string-match ">$" message-id)
9659       (setq message-id (concat message-id ">")))
9660     (let ((header (car (gnus-gethash (downcase message-id)
9661                                      gnus-newsgroup-dependencies))))
9662       (if header
9663           ;; The article is present in the buffer, to we just go to it.
9664           (gnus-summary-goto-article (mail-header-number header) nil t)
9665         ;; We fetch the article
9666         (let ((gnus-override-method gnus-refer-article-method)
9667               number)
9668           ;; Start the special refer-article method, if necessary.
9669           (when gnus-refer-article-method
9670             (gnus-check-server gnus-refer-article-method))
9671           ;; Fetch the header, and display the article.
9672           (when (setq number (gnus-summary-insert-subject message-id))
9673             (gnus-summary-select-article nil nil nil number)))))))
9674
9675 (defun gnus-summary-enter-digest-group (&optional force)
9676   "Enter a digest group based on the current article."
9677   (interactive "P")
9678   (gnus-set-global-variables)
9679   (gnus-summary-select-article)
9680   ;; We do not want a narrowed article.
9681   (gnus-summary-stop-page-breaking)
9682   (let ((name (format "%s-%d" 
9683                       (gnus-group-prefixed-name 
9684                        gnus-newsgroup-name (list 'nndoc "")) 
9685                       gnus-current-article))
9686         (ogroup gnus-newsgroup-name)
9687         (buf (current-buffer)))
9688     (if (gnus-group-read-ephemeral-group 
9689          name `(nndoc ,name (nndoc-address ,(get-buffer gnus-article-buffer))
9690                       (nndoc-article-type ,(if force 'digest 'guess))) t)
9691         ;; Make all postings to this group go to the parent group.
9692         (setcdr (nthcdr 4 (gnus-get-info name))
9693                 (list (list (cons 'to-group ogroup))))
9694       ;; Couldn't select this doc group.
9695       (switch-to-buffer buf)
9696       (gnus-set-global-variables)
9697       (gnus-configure-windows 'summary)
9698       (gnus-message 3 "Article not a digest?"))))
9699
9700 (defun gnus-summary-isearch-article (&optional regexp-p)
9701   "Do incremental search forward on the current article.
9702 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9703   (interactive "P")
9704   (gnus-set-global-variables)
9705   (gnus-summary-select-article)
9706   (gnus-eval-in-buffer-window 
9707    gnus-article-buffer
9708    (goto-char (point-min))
9709    (isearch-forward regexp-p)))
9710
9711 (defun gnus-summary-search-article-forward (regexp &optional backward)
9712   "Search for an article containing REGEXP forward.
9713 If BACKWARD, search backward instead."
9714   (interactive
9715    (list (read-string
9716           (format "Search article %s (regexp%s): "
9717                   (if current-prefix-arg "backward" "forward")
9718                   (if gnus-last-search-regexp
9719                       (concat ", default " gnus-last-search-regexp)
9720                     "")))
9721          current-prefix-arg))
9722   (gnus-set-global-variables)
9723   (if (string-equal regexp "")
9724       (setq regexp (or gnus-last-search-regexp ""))
9725     (setq gnus-last-search-regexp regexp))
9726   (if (gnus-summary-search-article regexp backward)
9727       (gnus-article-set-window-start 
9728        (cdr (assq (gnus-summary-article-number) gnus-newsgroup-bookmarks)))
9729     (error "Search failed: \"%s\"" regexp)))
9730
9731 (defun gnus-summary-search-article-backward (regexp)
9732   "Search for an article containing REGEXP backward."
9733   (interactive
9734    (list (read-string
9735           (format "Search article backward (regexp%s): "
9736                   (if gnus-last-search-regexp
9737                       (concat ", default " gnus-last-search-regexp)
9738                     "")))))
9739   (gnus-summary-search-article-forward regexp 'backward))
9740
9741 (defun gnus-summary-search-article (regexp &optional backward)
9742   "Search for an article containing REGEXP.
9743 Optional argument BACKWARD means do search for backward.
9744 gnus-select-article-hook is not called during the search."
9745   (let ((gnus-select-article-hook nil)  ;Disable hook.
9746         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9747         (re-search
9748          (if backward
9749              (function re-search-backward) (function re-search-forward)))
9750         (found nil)
9751         (last nil))
9752     ;; Hidden thread subtrees must be searched for ,too.
9753     (gnus-summary-show-all-threads)
9754     ;; First of all, search current article.
9755     ;; We don't want to read article again from NNTP server nor reset
9756     ;; current point.
9757     (gnus-summary-select-article)
9758     (gnus-message 9 "Searching article: %d..." gnus-current-article)
9759     (setq last gnus-current-article)
9760     (gnus-eval-in-buffer-window
9761      gnus-article-buffer
9762      (save-restriction
9763        (widen)
9764        ;; Begin search from current point.
9765        (setq found (funcall re-search regexp nil t))))
9766     ;; Then search next articles.
9767     (while (and (not found)
9768                 (gnus-summary-display-article 
9769                  (if backward (gnus-summary-find-prev)
9770                    (gnus-summary-find-next))))
9771       (gnus-message 9 "Searching article: %d..." gnus-current-article)
9772       (gnus-eval-in-buffer-window
9773        gnus-article-buffer
9774        (save-restriction
9775          (widen)
9776          (goto-char (if backward (point-max) (point-min)))
9777          (setq found (funcall re-search regexp nil t)))))
9778     (message "")
9779     ;; Adjust article pointer.
9780     (or (eq last gnus-current-article)
9781         (setq gnus-last-article last))
9782     ;; Return T if found such article.
9783     found))
9784
9785 (defun gnus-summary-find-matching (header regexp &optional backward unread
9786                                           not-case-fold)
9787   "Return a list of all articles that match REGEXP on HEADER.
9788 The search stars on the current article and goes forwards unless
9789 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9790 If UNREAD is non-nil, only unread articles will
9791 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9792 in the comparisons."
9793   (let ((data (if (eq backward 'all) gnus-newsgroup-data
9794                 (gnus-data-find-list 
9795                  (gnus-summary-article-number) (gnus-data-list backward))))
9796         (func (intern (concat "gnus-header-" header)))
9797         (case-fold-search (not not-case-fold))
9798         articles d)
9799     (or (fboundp func) (error "%s is not a valid header" header))
9800     (while data
9801       (setq d (car data))
9802       (and (or (not unread)             ; We want all articles...
9803                (gnus-data-unread-p d))  ; Or just unreads.
9804            (vectorp (gnus-data-header d)) ; It's not a pseudo.
9805            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
9806            (setq articles (cons (gnus-data-number d) articles))) ; Success!
9807       (setq data (cdr data)))
9808     (nreverse articles)))
9809     
9810 (defun gnus-summary-execute-command (header regexp command &optional backward)
9811   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9812 If HEADER is an empty string (or nil), the match is done on the entire
9813 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9814   (interactive
9815    (list (let ((completion-ignore-case t))
9816            (completing-read 
9817             "Header name: "
9818             (mapcar (lambda (string) (list string))
9819                     '("Number" "Subject" "From" "Lines" "Date"
9820                       "Message-ID" "Xref" "References"))
9821             nil 'require-match))
9822          (read-string "Regexp: ")
9823          (read-key-sequence "Command: ")
9824          current-prefix-arg))
9825   (gnus-set-global-variables)
9826   ;; Hidden thread subtrees must be searched as well.
9827   (gnus-summary-show-all-threads)
9828   ;; We don't want to change current point nor window configuration.
9829   (save-excursion
9830     (save-window-excursion
9831       (gnus-message 6 "Executing %s..." (key-description command))
9832       ;; We'd like to execute COMMAND interactively so as to give arguments.
9833       (gnus-execute header regexp
9834                     `(lambda () (call-interactively ',(key-binding command)))
9835                     backward)
9836       (gnus-message 6 "Executing %s...done" (key-description command)))))
9837
9838 (defun gnus-summary-beginning-of-article ()
9839   "Scroll the article back to the beginning."
9840   (interactive)
9841   (gnus-set-global-variables)
9842   (gnus-summary-select-article)
9843   (gnus-configure-windows 'article)
9844   (gnus-eval-in-buffer-window
9845    gnus-article-buffer
9846    (widen)
9847    (goto-char (point-min))
9848    (and gnus-break-pages (gnus-narrow-to-page))))
9849
9850 (defun gnus-summary-end-of-article ()
9851   "Scroll to the end of the article."
9852   (interactive)
9853   (gnus-set-global-variables)
9854   (gnus-summary-select-article)
9855   (gnus-configure-windows 'article)
9856   (gnus-eval-in-buffer-window 
9857    gnus-article-buffer
9858    (widen)
9859    (goto-char (point-max))
9860    (recenter -3)
9861    (and gnus-break-pages (gnus-narrow-to-page))))
9862
9863 (defun gnus-summary-show-article (&optional arg)
9864   "Force re-fetching of the current article.
9865 If ARG (the prefix) is non-nil, show the raw article without any
9866 article massaging functions being run."
9867   (interactive "P")
9868   (gnus-set-global-variables)
9869   (if (not arg)
9870       ;; Select the article the normal way.
9871       (gnus-summary-select-article nil 'force)
9872     ;; Bind the article treatment functions to nil.
9873     (let ((gnus-have-all-headers t)
9874           gnus-article-display-hook
9875           gnus-article-prepare-hook
9876           gnus-visual)
9877       (gnus-summary-select-article nil 'force)))
9878   (gnus-configure-windows 'article)
9879   (gnus-summary-position-point))
9880
9881 (defun gnus-summary-verbose-headers (&optional arg)
9882   "Toggle permanent full header display.
9883 If ARG is a positive number, turn header display on.
9884 If ARG is a negative number, turn header display off."
9885   (interactive "P")
9886   (gnus-set-global-variables)
9887   (gnus-summary-toggle-header arg)
9888   (setq gnus-show-all-headers
9889         (cond ((or (not (numberp arg))
9890                    (zerop arg))
9891                (not gnus-show-all-headers))
9892               ((natnump arg)
9893                t))))
9894
9895 (defun gnus-summary-toggle-header (&optional arg)
9896   "Show the headers if they are hidden, or hide them if they are shown.
9897 If ARG is a positive number, show the entire header.
9898 If ARG is a negative number, hide the unwanted header lines."
9899   (interactive "P")
9900   (gnus-set-global-variables)
9901   (save-excursion
9902     (set-buffer gnus-article-buffer)
9903     (let* ((buffer-read-only nil)
9904            (inhibit-point-motion-hooks t) 
9905            (hidden (text-property-any 
9906                     (goto-char (point-min)) (search-forward "\n\n")
9907                     'invisible t))
9908            e)
9909       (goto-char (point-min))
9910       (when (search-forward "\n\n" nil t)
9911         (delete-region (point-min) (1- (point))))
9912       (goto-char (point-min))
9913       (save-excursion 
9914         (set-buffer gnus-original-article-buffer)
9915         (goto-char (point-min))
9916         (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
9917       (insert-buffer-substring gnus-original-article-buffer 1 e)
9918       (let ((hook (delq 'gnus-article-hide-headers-if-wanted
9919                         (delq 'gnus-article-hide-headers
9920                               (copy-sequence gnus-article-display-hook))))
9921             (gnus-inhibit-hiding t))
9922         (run-hooks 'hook))
9923       (if (or (not hidden) (and (numberp arg) (< arg 0)))
9924           (gnus-article-hide-headers)))))
9925
9926 (defun gnus-summary-show-all-headers ()
9927   "Make all header lines visible."
9928   (interactive)
9929   (gnus-set-global-variables)
9930   (gnus-article-show-all-headers))
9931
9932 (defun gnus-summary-toggle-mime (&optional arg)
9933   "Toggle MIME processing.
9934 If ARG is a positive number, turn MIME processing on."
9935   (interactive "P")
9936   (gnus-set-global-variables)
9937   (setq gnus-show-mime
9938         (if (null arg) (not gnus-show-mime)
9939           (> (prefix-numeric-value arg) 0)))
9940   (gnus-summary-select-article t 'force))
9941
9942 (defun gnus-summary-caesar-message (&optional arg)
9943   "Caesar rotate the current article by 13.
9944 The numerical prefix specifies how manu places to rotate each letter
9945 forward."
9946   (interactive "P")
9947   (gnus-set-global-variables)
9948   (gnus-summary-select-article)
9949   (let ((mail-header-separator ""))
9950     (gnus-eval-in-buffer-window 
9951      gnus-article-buffer
9952      (save-restriction
9953        (widen)
9954        (let ((start (window-start)))
9955          (news-caesar-buffer-body arg)
9956          (set-window-start (get-buffer-window (current-buffer)) start))))))
9957
9958 (defun gnus-summary-stop-page-breaking ()
9959   "Stop page breaking in the current article."
9960   (interactive)
9961   (gnus-set-global-variables)
9962   (gnus-summary-select-article)
9963   (gnus-eval-in-buffer-window gnus-article-buffer (widen)))
9964
9965 ;; Suggested by Brian Edmonds <bedmonds@prodigy.bc.ca>.
9966
9967 (defun gnus-summary-move-article (&optional n to-newsgroup select-method)
9968   "Move the current article to a different newsgroup.
9969 If N is a positive number, move the N next articles.
9970 If N is a negative number, move the N previous articles.
9971 If N is nil and any articles have been marked with the process mark,
9972 move those articles instead.
9973 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. 
9974 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
9975 re-spool using this method.
9976 For this function to work, both the current newsgroup and the
9977 newsgroup that you want to move to have to support the `request-move'
9978 and `request-accept' functions. (Ie. mail newsgroups at present.)"
9979   (interactive "P")
9980   (gnus-set-global-variables)
9981   (or (gnus-check-backend-function 'request-move-article gnus-newsgroup-name)
9982       (error "The current newsgroup does not support article moving"))
9983   (let ((articles (gnus-summary-work-articles n))
9984         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
9985         art-group to-method sel-met)
9986     (if (and (not to-newsgroup) (not select-method))
9987         (setq to-newsgroup
9988               (completing-read 
9989                (format "Where do you want to move %s? %s"
9990                        (if (> (length articles) 1)
9991                            (format "these %d articles" (length articles))
9992                          "this article")
9993                        (if gnus-current-move-group
9994                            (format "(default %s) " gnus-current-move-group)
9995                          ""))
9996                gnus-active-hashtb nil nil prefix)))
9997     (if to-newsgroup
9998         (progn
9999           (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
10000               (setq to-newsgroup (or gnus-current-move-group "")))
10001           (or (gnus-active to-newsgroup)
10002               (gnus-activate-group to-newsgroup)
10003               (error "No such group: %s" to-newsgroup))
10004           (setq gnus-current-move-group to-newsgroup)))
10005     (setq to-method (if select-method (list select-method "")
10006                       (gnus-find-method-for-group to-newsgroup)))
10007     (or (gnus-check-backend-function 'request-accept-article (car to-method))
10008         (error "%s does not support article copying" (car to-method)))
10009     (or (gnus-check-server to-method)
10010         (error "Can't open server %s" (car to-method)))
10011     (gnus-message 6 "Moving to %s: %s..." 
10012                   (or select-method to-newsgroup) articles)
10013     (while articles
10014       (if (setq art-group
10015                 (gnus-request-move-article 
10016                  (car articles)         ; Article to move
10017                  gnus-newsgroup-name    ; From newsgrouo
10018                  (nth 1 (gnus-find-method-for-group 
10019                          gnus-newsgroup-name)) ; Server
10020                  (list 'gnus-request-accept-article 
10021                        (if select-method
10022                            (list 'quote select-method)
10023                          to-newsgroup)
10024                        (not (cdr articles))) ; Accept form
10025                  (not (cdr articles)))) ; Only save nov last time
10026           (let* ((buffer-read-only nil)
10027                  (entry 
10028                   (or
10029                    (gnus-gethash (car art-group) gnus-newsrc-hashtb)
10030                    (gnus-gethash 
10031                     (gnus-group-prefixed-name 
10032                      (car art-group) 
10033                      (if select-method (list select-method "")
10034                        (gnus-find-method-for-group to-newsgroup)))
10035                     gnus-newsrc-hashtb)))
10036                  (info (nth 2 entry))
10037                  (article (car articles)))
10038             (gnus-summary-goto-subject article)
10039             (gnus-summary-mark-article article gnus-canceled-mark)
10040             ;; Update the group that has been moved to.
10041             (if (not info)
10042                 ()                      ; This group does not exist yet.
10043               (if (not (memq article gnus-newsgroup-unreads))
10044                   (gnus-info-set-read 
10045                    info (gnus-add-to-range (gnus-info-read info) 
10046                                            (list (cdr art-group)))))
10047
10048               ;; Copy any marks over to the new group.
10049               (let ((marks '((tick . gnus-newsgroup-marked)
10050                              (dormant . gnus-newsgroup-dormant)
10051                              (expire . gnus-newsgroup-expirable)
10052                              (bookmark . gnus-newsgroup-bookmarks)
10053                              (reply . gnus-newsgroup-replied)))
10054                     (to-article (cdr art-group)))
10055
10056                 ;; See whether the article is to be put in the cache.
10057                 (when gnus-use-cache
10058                   (gnus-cache-possibly-enter-article 
10059                    (gnus-info-group info) to-article
10060                    (let ((header (copy-sequence
10061                                   (gnus-summary-article-header article))))
10062                      (mail-header-set-number header to-article)
10063                      header)
10064                    (memq article gnus-newsgroup-marked)
10065                    (memq article gnus-newsgroup-dormant)
10066                    (memq article gnus-newsgroup-unreads)))
10067
10068                 (while marks
10069                   (if (memq article (symbol-value (cdr (car marks))))
10070                       (gnus-add-marked-articles 
10071                        (gnus-info-group info) (car (car marks))
10072                        (list to-article) info))
10073                   (setq marks (cdr marks)))))
10074             ;; Update marks.
10075             (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10076             (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10077             (setq gnus-newsgroup-dormant
10078                   (delq article gnus-newsgroup-dormant))
10079             (setq gnus-newsgroup-reads
10080                   (cons (cons article gnus-canceled-mark)
10081                         gnus-newsgroup-reads)))
10082         (gnus-message 1 "Couldn't move article %s" (car articles)))
10083       (gnus-summary-remove-process-mark (car articles))
10084       (setq articles (cdr articles)))
10085     (gnus-set-mode-line 'summary)))
10086
10087 (defun gnus-summary-respool-article (&optional n respool-method)
10088   "Respool the current article.
10089 The article will be squeezed through the mail spooling process again,
10090 which means that it will be put in some mail newsgroup or other
10091 depending on `nnmail-split-methods'.
10092 If N is a positive number, respool the N next articles.
10093 If N is a negative number, respool the N previous articles.
10094 If N is nil and any articles have been marked with the process mark,
10095 respool those articles instead.
10096
10097 Respooling can be done both from mail groups and \"real\" newsgroups.
10098 In the former case, the articles in question will be moved from the
10099 current group into whatever groups they are destined to.  In the
10100 latter case, they will be copied into the relevant groups."
10101   (interactive "P")
10102   (gnus-set-global-variables)
10103   (let ((respool-methods (gnus-methods-using 'respool))
10104         (methname 
10105          (symbol-name (car (gnus-find-method-for-group gnus-newsgroup-name)))))
10106     (or respool-method
10107         (setq respool-method
10108               (completing-read
10109                "What method do you want to use when respooling? "
10110                respool-methods nil t methname)))
10111     (or (string= respool-method "")
10112         (if (assoc (symbol-name
10113                     (car (gnus-find-method-for-group gnus-newsgroup-name)))
10114                    respool-methods)
10115             (gnus-summary-move-article n nil (intern respool-method))
10116           (gnus-summary-copy-article n nil (intern respool-method))))))
10117
10118 ;; Suggested by gregj@unidata.com (Gregory J. Grubbs).
10119 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
10120   "Move the current article to a different newsgroup.
10121 If N is a positive number, move the N next articles.
10122 If N is a negative number, move the N previous articles.
10123 If N is nil and any articles have been marked with the process mark,
10124 move those articles instead.
10125 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. 
10126 If SELECT-METHOD is symbol, do not move to a specific newsgroup, but
10127 re-spool using this method.
10128 For this function to work, the newsgroup that you want to move to have
10129 to support the `request-move' and `request-accept'
10130 functions. (Ie. mail newsgroups at present.)"
10131   (interactive "P")
10132   (gnus-set-global-variables)
10133   (let ((articles (gnus-summary-work-articles n))
10134         (copy-buf (get-buffer-create "*copy work*"))
10135         (prefix (gnus-group-real-prefix gnus-newsgroup-name))
10136         art-group to-method)
10137     (buffer-disable-undo copy-buf)
10138     (if (and (not to-newsgroup) (not select-method))
10139         (setq to-newsgroup
10140               (completing-read 
10141                (format "Where do you want to copy %s? %s"
10142                        (if (> (length articles) 1)
10143                            (format "these %d articles" (length articles))
10144                          "this article")
10145                        (if gnus-current-move-group
10146                            (format "(default %s) " gnus-current-move-group)
10147                          ""))
10148                gnus-active-hashtb nil nil prefix)))
10149     (if to-newsgroup
10150         (progn
10151           (if (or (string= to-newsgroup "") (string= to-newsgroup prefix))
10152               (setq to-newsgroup (or gnus-current-move-group "")))
10153           (or (gnus-active to-newsgroup)
10154               (gnus-activate-group to-newsgroup)
10155               (error "No such group: %s" to-newsgroup))
10156           (setq gnus-current-move-group to-newsgroup)))
10157     (setq to-method (if select-method (list select-method "")
10158                       (gnus-find-method-for-group to-newsgroup)))
10159     (or (gnus-check-backend-function 'request-accept-article (car to-method))
10160         (error "%s does not support article copying" (car to-method)))
10161     (or (gnus-check-server to-method)
10162         (error "Can't open server %s" (car to-method)))
10163     (while articles
10164       (gnus-message 6 "Copying to %s: %s..." 
10165                     (or select-method to-newsgroup) articles)
10166       (if (setq art-group
10167                 (save-excursion
10168                   (set-buffer copy-buf)
10169                   (gnus-request-article-this-buffer
10170                    (car articles) gnus-newsgroup-name)
10171                   (gnus-request-accept-article
10172                    (if select-method select-method to-newsgroup)
10173                    (not (cdr articles)))))
10174           (let* ((entry 
10175                   (or
10176                    (gnus-gethash (car art-group) gnus-newsrc-hashtb)
10177                    (gnus-gethash 
10178                     (gnus-group-prefixed-name 
10179                      (car art-group) 
10180                      (if select-method (list select-method "")
10181                        (gnus-find-method-for-group to-newsgroup)))
10182                     gnus-newsrc-hashtb)))
10183                  (info (nth 2 entry))
10184                  (article (car articles)))
10185             ;; We copy the info over to the new group.
10186             (if (not info)
10187                 ()                      ; This group does not exist (yet).
10188               (if (not (memq article gnus-newsgroup-unreads))
10189                   (gnus-info-set-read 
10190                    info (gnus-add-to-range (gnus-info-read info) 
10191                                            (list (cdr art-group)))))
10192
10193               ;; Copy any marks over to the new group.
10194               (let ((marks '((tick . gnus-newsgroup-marked)
10195                              (dormant . gnus-newsgroup-dormant)
10196                              (expire . gnus-newsgroup-expirable)
10197                              (bookmark . gnus-newsgroup-bookmarks)
10198                              (reply . gnus-newsgroup-replied)))
10199                     (to-article (cdr art-group)))
10200
10201               ;; See whether the article is to be put in the cache.
10202               (when gnus-use-cache
10203                 (gnus-cache-possibly-enter-article 
10204                  (gnus-info-group info) to-article 
10205                  (let ((header (copy-sequence
10206                                 (gnus-summary-article-header article))))
10207                    (mail-header-set-number header to-article)
10208                    header)
10209                  (memq article gnus-newsgroup-marked)
10210                  (memq article gnus-newsgroup-dormant)
10211                  (memq article gnus-newsgroup-unreads)))
10212
10213               (while marks
10214                 (if (memq article (symbol-value (cdr (car marks))))
10215                     (gnus-add-marked-articles 
10216                      (gnus-info-group info) (car (car marks)) 
10217                      (list to-article) info))
10218                 (setq marks (cdr marks))))))
10219         (gnus-message 1 "Couldn't copy article %s" (car articles)))
10220       (gnus-summary-remove-process-mark (car articles))
10221       (setq articles (cdr articles)))
10222     (kill-buffer copy-buf)))
10223
10224 (defun gnus-summary-import-article (file)
10225   "Import a random file into a mail newsgroup."
10226   (interactive "fImport file: ")
10227   (gnus-set-global-variables)
10228   (let ((group gnus-newsgroup-name)
10229         atts lines)
10230     (or (gnus-check-backend-function 'request-accept-article group)
10231         (error "%s does not support article importing" group))
10232     (or (file-readable-p file)
10233         (not (file-regular-p file))
10234         (error "Can't read %s" file))
10235     (save-excursion
10236       (set-buffer (get-buffer-create " *import file*"))
10237       (buffer-disable-undo (current-buffer))
10238       (erase-buffer)
10239       (insert-file-contents file)
10240       (goto-char (point-min))
10241       (if (nnheader-article-p)
10242           ()
10243         (setq atts (file-attributes file)
10244               lines (count-lines (point-min) (point-max)))
10245         (insert "From: " (read-string "From: ") "\n"
10246                 "Subject: " (read-string "Subject: ") "\n"
10247                 "Date: " (current-time-string (nth 5 atts)) "\n"
10248                 "Message-ID: " (gnus-inews-message-id) "\n"
10249                 "Lines: " (int-to-string lines) "\n"
10250                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
10251       (gnus-request-accept-article group t)
10252       (kill-buffer (current-buffer)))))
10253
10254 (defun gnus-summary-expire-articles ()
10255   "Expire all articles that are marked as expirable in the current group."
10256   (interactive)
10257   (gnus-set-global-variables)
10258   (when (gnus-check-backend-function 
10259          'request-expire-articles gnus-newsgroup-name)
10260     ;; This backend supports expiry.
10261     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
10262            (expirable (if total
10263                           (gnus-list-of-read-articles gnus-newsgroup-name)
10264                         (setq gnus-newsgroup-expirable
10265                               (sort gnus-newsgroup-expirable '<))))
10266            es)
10267       (when expirable
10268         ;; There are expirable articles in this group, so we run them
10269         ;; through the expiry process.
10270         (gnus-message 6 "Expiring articles...")
10271         ;; The list of articles that weren't expired is returned.
10272         (setq es (gnus-request-expire-articles expirable gnus-newsgroup-name))
10273         (or total (setq gnus-newsgroup-expirable es))
10274         ;; We go through the old list of expirable, and mark all
10275         ;; really expired articles as non-existant.
10276         (unless (eq es expirable)       ;If nothing was expired, we don't mark.
10277           (let ((gnus-use-cache nil))
10278             (while expirable
10279               (unless (memq (car expirable) es)
10280                 (when (gnus-data-find (car expirable))
10281                   (gnus-summary-mark-article
10282                    (car expirable) gnus-canceled-mark)))
10283               (setq expirable (cdr expirable)))))
10284         (gnus-message 6 "Expiring articles...done")))))
10285
10286 (defun gnus-summary-expire-articles-now ()
10287   "Expunge all expirable articles in the current group.
10288 This means that *all* articles that are marked as expirable will be
10289 deleted forever, right now."
10290   (interactive)
10291   (gnus-set-global-variables)
10292   (or gnus-expert-user
10293       (gnus-y-or-n-p
10294        "Are you really, really, really sure you want to expunge? ")
10295       (error "Phew!"))
10296   (let ((nnmail-expiry-wait -1)
10297         (nnmail-expiry-wait-function nil))
10298     (gnus-summary-expire-articles)))
10299
10300 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10301 (defun gnus-summary-delete-article (&optional n)
10302   "Delete the N next (mail) articles.
10303 This command actually deletes articles.  This is not a marking
10304 command.  The article will disappear forever from your life, never to
10305 return. 
10306 If N is negative, delete backwards.
10307 If N is nil and articles have been marked with the process mark,
10308 delete these instead."
10309   (interactive "P")
10310   (gnus-set-global-variables)
10311   (or (gnus-check-backend-function 'request-expire-articles 
10312                                    gnus-newsgroup-name)
10313       (error "The current newsgroup does not support article deletion."))
10314   ;; Compute the list of articles to delete.
10315   (let ((articles (gnus-summary-work-articles n))
10316         not-deleted)
10317     (if (and gnus-novice-user
10318              (not (gnus-y-or-n-p 
10319                    (format "Do you really want to delete %s forever? "
10320                            (if (> (length articles) 1) "these articles"
10321                              "this article")))))
10322         ()
10323       ;; Delete the articles.
10324       (setq not-deleted (gnus-request-expire-articles 
10325                          articles gnus-newsgroup-name 'force))
10326       (while articles
10327         (gnus-summary-remove-process-mark (car articles))       
10328         ;; The backend might not have been able to delete the article
10329         ;; after all.  
10330         (or (memq (car articles) not-deleted)
10331             (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10332         (setq articles (cdr articles))))
10333     (gnus-summary-position-point)
10334     (gnus-set-mode-line 'summary)
10335     not-deleted))
10336
10337 (defun gnus-summary-edit-article (&optional force)
10338   "Enter into a buffer and edit the current article.
10339 This will have permanent effect only in mail groups.
10340 If FORCE is non-nil, allow editing of articles even in read-only
10341 groups."
10342   (interactive "P")
10343   (gnus-set-global-variables)
10344   (when (and (not force)
10345              (gnus-group-read-only-p))
10346     (error "The current newsgroup does not support article editing."))
10347   (gnus-summary-select-article t)
10348   (gnus-configure-windows 'article)
10349   (select-window (get-buffer-window gnus-article-buffer))
10350   (gnus-message 6 "C-c C-c to end edits")
10351   (setq buffer-read-only nil)
10352   (text-mode)
10353   (use-local-map (copy-keymap (current-local-map)))
10354   (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
10355   (buffer-enable-undo)
10356   (widen)
10357   (goto-char (point-min))
10358   (search-forward "\n\n" nil t))
10359
10360 (defun gnus-summary-edit-article-done ()
10361   "Make edits to the current article permanent."
10362   (interactive)
10363   (if (gnus-group-read-only-p)
10364       (progn
10365         (gnus-summary-edit-article-postpone)
10366         (message "The current newsgroup does not support article editing.")
10367         (ding))
10368     (let ((buf (buffer-substring-no-properties (point-min) (point-max))))
10369       (erase-buffer)
10370       (insert buf)
10371       (if (not (gnus-request-replace-article 
10372                 (cdr gnus-article-current) (car gnus-article-current) 
10373                 (current-buffer)))
10374           (error "Couldn't replace article.")
10375         (gnus-article-mode)
10376         (use-local-map gnus-article-mode-map)
10377         (setq buffer-read-only t)
10378         (buffer-disable-undo (current-buffer))
10379         (gnus-configure-windows 'summary))
10380       (and (gnus-visual-p 'summary-highlight 'highlight)
10381            (run-hooks 'gnus-visual-mark-article-hook)))))
10382
10383 (defun gnus-summary-edit-article-postpone ()
10384   "Postpone changes to the current article."
10385   (interactive)
10386   (gnus-article-mode)
10387   (use-local-map gnus-article-mode-map)
10388   (setq buffer-read-only t)
10389   (buffer-disable-undo (current-buffer))
10390   (gnus-configure-windows 'summary)
10391   (and (gnus-visual-p 'summary-highlight 'highlight)
10392        (run-hooks 'gnus-visual-mark-article-hook)))
10393
10394 (defun gnus-summary-respool-query ()
10395   "Query where the respool algorithm would put this article."
10396   (interactive)
10397   (gnus-set-global-variables)
10398   (gnus-summary-select-article)
10399   (save-excursion
10400     (set-buffer gnus-article-buffer)
10401     (save-restriction
10402       (goto-char (point-min))
10403       (search-forward "\n\n")
10404       (narrow-to-region (point-min) (point))
10405       (pp-eval-expression
10406        (list 'quote (mapcar 'car (nnmail-article-group 'identity)))))))
10407
10408 ;; Summary score commands.
10409
10410 ;; Suggested by boubaker@cenatls.cena.dgac.fr.
10411
10412 (defun gnus-summary-raise-score (n)
10413   "Raise the score of the current article by N."
10414   (interactive "p")
10415   (gnus-set-global-variables)
10416   (gnus-summary-set-score (+ (gnus-summary-article-score) n)))
10417
10418 (defun gnus-summary-set-score (n)
10419   "Set the score of the current article to N."
10420   (interactive "p")
10421   (gnus-set-global-variables)
10422   (save-excursion
10423     (gnus-summary-show-thread)
10424     (let ((buffer-read-only nil))
10425       ;; Set score.
10426       (gnus-summary-update-mark
10427        (if (= n (or gnus-summary-default-score 0)) ? 
10428          (if (< n (or gnus-summary-default-score 0)) 
10429              gnus-score-below-mark gnus-score-over-mark)) 'score))
10430     (let* ((article (gnus-summary-article-number))
10431            (score (assq article gnus-newsgroup-scored)))
10432       (if score (setcdr score n)
10433         (setq gnus-newsgroup-scored 
10434               (cons (cons article n) gnus-newsgroup-scored))))
10435     (gnus-summary-update-line)))
10436
10437 (defun gnus-summary-current-score ()
10438   "Return the score of the current article."
10439   (interactive)
10440   (gnus-set-global-variables)
10441   (message "%s" (gnus-summary-article-score)))
10442
10443 ;; Summary marking commands.
10444
10445 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10446   "Mark articles which has the same subject as read, and then select the next.
10447 If UNMARK is positive, remove any kind of mark.
10448 If UNMARK is negative, tick articles."
10449   (interactive "P")
10450   (gnus-set-global-variables)
10451   (if unmark
10452       (setq unmark (prefix-numeric-value unmark)))
10453   (let ((count
10454          (gnus-summary-mark-same-subject
10455           (gnus-summary-article-subject) unmark)))
10456     ;; Select next unread article.  If auto-select-same mode, should
10457     ;; select the first unread article.
10458     (gnus-summary-next-article t (and gnus-auto-select-same
10459                                       (gnus-summary-article-subject)))
10460     (gnus-message 7 "%d article%s marked as %s"
10461                   count (if (= count 1) " is" "s are")
10462                   (if unmark "unread" "read"))))
10463
10464 (defun gnus-summary-kill-same-subject (&optional unmark)
10465   "Mark articles which has the same subject as read. 
10466 If UNMARK is positive, remove any kind of mark.
10467 If UNMARK is negative, tick articles."
10468   (interactive "P")
10469   (gnus-set-global-variables)
10470   (if unmark
10471       (setq unmark (prefix-numeric-value unmark)))
10472   (let ((count
10473          (gnus-summary-mark-same-subject
10474           (gnus-summary-article-subject) unmark)))
10475     ;; If marked as read, go to next unread subject.
10476     (if (null unmark)
10477         ;; Go to next unread subject.
10478         (gnus-summary-next-subject 1 t))
10479     (gnus-message 7 "%d articles are marked as %s"
10480                   count (if unmark "unread" "read"))))
10481
10482 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10483   "Mark articles with same SUBJECT as read, and return marked number.
10484 If optional argument UNMARK is positive, remove any kinds of marks.
10485 If optional argument UNMARK is negative, mark articles as unread instead."
10486   (let ((count 1))
10487     (save-excursion
10488       (cond 
10489        ((null unmark)                   ; Mark as read.
10490         (while (and 
10491                 (progn
10492                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10493                   (gnus-summary-show-thread) t)
10494                 (gnus-summary-find-subject subject))
10495           (setq count (1+ count))))
10496        ((> unmark 0)                    ; Tick.
10497         (while (and
10498                 (progn
10499                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10500                   (gnus-summary-show-thread) t)
10501                 (gnus-summary-find-subject subject))
10502           (setq count (1+ count))))
10503        (t                               ; Mark as unread.
10504         (while (and
10505                 (progn
10506                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10507                   (gnus-summary-show-thread) t)
10508                 (gnus-summary-find-subject subject))
10509           (setq count (1+ count)))))
10510       (gnus-set-mode-line 'summary)
10511       ;; Return the number of marked articles.
10512       count)))
10513
10514 (defun gnus-summary-mark-as-processable (n &optional unmark)
10515   "Set the process mark on the next N articles.
10516 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10517 the process mark instead.  The difference between N and the actual
10518 number of articles marked is returned."
10519   (interactive "p")
10520   (gnus-set-global-variables)
10521   (let ((backward (< n 0))
10522         (n (abs n)))
10523     (while (and 
10524             (> n 0)
10525             (if unmark
10526                 (gnus-summary-remove-process-mark
10527                  (gnus-summary-article-number))
10528               (gnus-summary-set-process-mark (gnus-summary-article-number)))
10529             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10530       (setq n (1- n)))
10531     (if (/= 0 n) (gnus-message 7 "No more articles"))
10532     (gnus-summary-recenter)
10533     (gnus-summary-position-point)
10534     n))
10535
10536 (defun gnus-summary-unmark-as-processable (n)
10537   "Remove the process mark from the next N articles.
10538 If N is negative, mark backward instead.  The difference between N and
10539 the actual number of articles marked is returned."
10540   (interactive "p")
10541   (gnus-set-global-variables)
10542   (gnus-summary-mark-as-processable n t))
10543
10544 (defun gnus-summary-unmark-all-processable ()
10545   "Remove the process mark from all articles."
10546   (interactive)
10547   (gnus-set-global-variables)
10548   (save-excursion
10549     (while gnus-newsgroup-processable
10550       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10551   (gnus-summary-position-point))
10552
10553 (defun gnus-summary-mark-as-expirable (n)
10554   "Mark N articles forward as expirable.
10555 If N is negative, mark backward instead.  The difference between N and
10556 the actual number of articles marked is returned."
10557   (interactive "p")
10558   (gnus-set-global-variables)
10559   (gnus-summary-mark-forward n gnus-expirable-mark))
10560
10561 (defun gnus-summary-mark-article-as-replied (article)
10562   "Mark ARTICLE replied and update the summary line."
10563   (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied))
10564   (let ((buffer-read-only nil))
10565     (if (gnus-summary-goto-subject article)
10566         (progn
10567           (gnus-summary-update-mark gnus-replied-mark 'replied)
10568           t))))
10569
10570 (defun gnus-summary-set-bookmark (article)
10571   "Set a bookmark in current article."
10572   (interactive (list (gnus-summary-article-number)))
10573   (gnus-set-global-variables)
10574   (if (or (not (get-buffer gnus-article-buffer))
10575           (not gnus-current-article)
10576           (not gnus-article-current)
10577           (not (equal gnus-newsgroup-name (car gnus-article-current))))
10578       (error "No current article selected"))
10579   ;; Remove old bookmark, if one exists.
10580   (let ((old (assq article gnus-newsgroup-bookmarks)))
10581     (if old (setq gnus-newsgroup-bookmarks 
10582                   (delq old gnus-newsgroup-bookmarks))))
10583   ;; Set the new bookmark, which is on the form 
10584   ;; (article-number . line-number-in-body).
10585   (setq gnus-newsgroup-bookmarks 
10586         (cons 
10587          (cons article 
10588                (save-excursion
10589                  (set-buffer gnus-article-buffer)
10590                  (count-lines
10591                   (min (point)
10592                        (save-excursion
10593                          (goto-char (point-min))
10594                          (search-forward "\n\n" nil t)
10595                          (point)))
10596                   (point))))
10597          gnus-newsgroup-bookmarks))
10598   (gnus-message 6 "A bookmark has been added to the current article."))
10599
10600 (defun gnus-summary-remove-bookmark (article)
10601   "Remove the bookmark from the current article."
10602   (interactive (list (gnus-summary-article-number)))
10603   (gnus-set-global-variables)
10604   ;; Remove old bookmark, if one exists.
10605   (let ((old (assq article gnus-newsgroup-bookmarks)))
10606     (if old 
10607         (progn
10608           (setq gnus-newsgroup-bookmarks 
10609                 (delq old gnus-newsgroup-bookmarks))
10610           (gnus-message 6 "Removed bookmark."))
10611       (gnus-message 6 "No bookmark in current article."))))
10612
10613 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10614 (defun gnus-summary-mark-as-dormant (n)
10615   "Mark N articles forward as dormant.
10616 If N is negative, mark backward instead.  The difference between N and
10617 the actual number of articles marked is returned."
10618   (interactive "p")
10619   (gnus-set-global-variables)
10620   (gnus-summary-mark-forward n gnus-dormant-mark))
10621
10622 (defun gnus-summary-set-process-mark (article)
10623   "Set the process mark on ARTICLE and update the summary line."
10624   (setq gnus-newsgroup-processable (cons article gnus-newsgroup-processable))
10625   (let ((buffer-read-only nil))
10626     (if (gnus-summary-goto-subject article)
10627         (progn
10628           (gnus-summary-show-thread)
10629           (gnus-summary-update-mark gnus-process-mark 'replied)
10630           t))))
10631
10632 (defun gnus-summary-remove-process-mark (article)
10633   "Remove the process mark from ARTICLE and update the summary line."
10634   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10635   (let ((buffer-read-only nil))
10636     (if (gnus-summary-goto-subject article)
10637         (progn
10638           (gnus-summary-show-thread)
10639           (gnus-summary-update-mark ?  'replied)
10640           (if (memq article gnus-newsgroup-replied) 
10641               (gnus-summary-update-mark gnus-replied-mark 'replied))
10642           t))))
10643
10644 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10645   "Mark N articles as read forwards.
10646 If N is negative, mark backwards instead.
10647 Mark with MARK.  If MARK is ? , ?! or ??, articles will be
10648 marked as unread. 
10649 The difference between N and the actual number of articles marked is
10650 returned."
10651   (interactive "p")
10652   (gnus-set-global-variables)
10653   (let ((backward (< n 0))
10654         (gnus-summary-goto-unread
10655          (and gnus-summary-goto-unread
10656               (not (memq mark (list gnus-unread-mark
10657                                     gnus-ticked-mark gnus-dormant-mark)))))
10658         (n (abs n))
10659         (mark (or mark gnus-del-mark)))
10660     (while (and (> n 0)
10661                 (gnus-summary-mark-article nil mark no-expire)
10662                 (zerop (gnus-summary-next-subject 
10663                         (if backward -1 1) gnus-summary-goto-unread t)))
10664       (setq n (1- n)))
10665     (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10666     (gnus-summary-recenter)
10667     (gnus-summary-position-point)
10668     (gnus-set-mode-line 'summary)
10669     n))
10670
10671 (defun gnus-summary-mark-article-as-read (mark)
10672   "Mark the current article quickly as read with MARK."
10673   (let ((article (gnus-summary-article-number)))
10674     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10675     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10676     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10677     (setq gnus-newsgroup-reads
10678           (cons (cons article mark) gnus-newsgroup-reads))
10679     ;; Possibly remove from cache, if that is used. 
10680     (and gnus-use-cache (gnus-cache-enter-remove-article article))
10681     (and gnus-newsgroup-auto-expire 
10682          (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
10683              (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
10684              (= mark gnus-read-mark) (= mark gnus-souped-mark))
10685          (progn
10686            (setq mark gnus-expirable-mark)
10687            (setq gnus-newsgroup-expirable 
10688                  (cons article gnus-newsgroup-expirable))))
10689     ;; Fix the mark.
10690     (gnus-summary-update-mark mark 'unread)
10691     t))
10692
10693 (defun gnus-summary-mark-article-as-unread (mark)
10694   "Mark the current article quickly as unread with MARK."
10695   (let ((article (gnus-summary-article-number)))
10696     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10697     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10698     (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10699     (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10700     (cond ((= mark gnus-ticked-mark)
10701            (push article gnus-newsgroup-marked))
10702           ((= mark gnus-dormant-mark)
10703            (push article gnus-newsgroup-dormant))
10704           (t     
10705            (push article gnus-newsgroup-unreads)))
10706     (setq gnus-newsgroup-reads
10707           (delq (assq article gnus-newsgroup-reads)
10708                 gnus-newsgroup-reads))
10709
10710     ;; See whether the article is to be put in the cache.
10711     (and gnus-use-cache
10712          (vectorp (gnus-summary-article-header article))
10713          (save-excursion
10714            (gnus-cache-possibly-enter-article 
10715             gnus-newsgroup-name article 
10716             (gnus-summary-article-header article)
10717             (= mark gnus-ticked-mark)
10718             (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10719
10720     ;; Fix the mark.
10721     (gnus-summary-update-mark mark 'unread)
10722     t))
10723
10724 (defun gnus-summary-mark-article (&optional article mark no-expire)
10725   "Mark ARTICLE with MARK.  MARK can be any character.
10726 Four MARK strings are reserved: `? ' (unread), `?!' (ticked), `??'
10727 (dormant) and `?E' (expirable).
10728 If MARK is nil, then the default character `?D' is used.
10729 If ARTICLE is nil, then the article on the current line will be
10730 marked." 
10731   ;; The mark might be a string.
10732   (and (stringp mark)
10733        (setq mark (aref mark 0)))
10734   ;; If no mark is given, then we check auto-expiring.
10735   (and (not no-expire)
10736        gnus-newsgroup-auto-expire 
10737        (or (not mark)
10738            (and (numberp mark) 
10739                 (or (= mark gnus-killed-mark) (= mark gnus-del-mark)
10740                     (= mark gnus-catchup-mark) (= mark gnus-low-score-mark)
10741                     (= mark gnus-read-mark) (= mark gnus-souped-mark))))
10742        (setq mark gnus-expirable-mark))
10743   (let* ((mark (or mark gnus-del-mark))
10744          (article (or article (gnus-summary-article-number))))
10745     (or article (error "No article on current line"))
10746     (if (or (= mark gnus-unread-mark) 
10747             (= mark gnus-ticked-mark) 
10748             (= mark gnus-dormant-mark))
10749         (gnus-mark-article-as-unread article mark)
10750       (gnus-mark-article-as-read article mark))
10751
10752     ;; See whether the article is to be put in the cache.
10753     (and gnus-use-cache
10754          (not (= mark gnus-canceled-mark))
10755          (vectorp (gnus-summary-article-header article))
10756          (save-excursion
10757            (gnus-cache-possibly-enter-article 
10758             gnus-newsgroup-name article 
10759             (gnus-summary-article-header article)
10760             (= mark gnus-ticked-mark)
10761             (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10762
10763     (if (gnus-summary-goto-subject article nil t)
10764         (let ((buffer-read-only nil))
10765           (gnus-summary-show-thread)
10766           ;; Fix the mark.
10767           (gnus-summary-update-mark mark 'unread)
10768           t))))
10769
10770 (defun gnus-summary-update-mark (mark type)
10771   (beginning-of-line)
10772   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10773         (buffer-read-only nil))
10774     (when forward
10775       ;; Go to the right position on the line.
10776       (forward-char forward)
10777       ;; Replace the old mark with the new mark.
10778       (subst-char-in-region (point) (1+ (point)) (following-char) mark)
10779       ;; Optionally update the marks by some user rule.
10780       (when (eq type 'unread)
10781         (gnus-data-set-mark 
10782          (gnus-data-find (gnus-summary-article-number)) mark)
10783         (gnus-summary-update-line (eq mark gnus-unread-mark))))))
10784   
10785 (defun gnus-mark-article-as-read (article &optional mark)
10786   "Enter ARTICLE in the pertinent lists and remove it from others."
10787   ;; Make the article expirable.
10788   (let ((mark (or mark gnus-del-mark)))
10789     (if (= mark gnus-expirable-mark)
10790         (setq gnus-newsgroup-expirable (cons article gnus-newsgroup-expirable))
10791       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
10792     ;; Remove from unread and marked lists.
10793     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10794     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10795     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10796     (push (cons article mark) gnus-newsgroup-reads)
10797     ;; Possibly remove from cache, if that is used. 
10798     (when gnus-use-cache 
10799       (gnus-cache-enter-remove-article article))))
10800
10801 (defun gnus-mark-article-as-unread (article &optional mark)
10802   "Enter ARTICLE in the pertinent lists and remove it from others."
10803   (let ((mark (or mark gnus-ticked-mark)))
10804     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10805     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10806     (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10807     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10808     (cond ((= mark gnus-ticked-mark)
10809            (push article gnus-newsgroup-marked))
10810           ((= mark gnus-dormant-mark)
10811            (push article gnus-newsgroup-dormant))
10812           (t     
10813            (push article gnus-newsgroup-unreads)))
10814     (setq gnus-newsgroup-reads
10815           (delq (assq article gnus-newsgroup-reads)
10816                 gnus-newsgroup-reads))))
10817
10818 (defalias 'gnus-summary-mark-as-unread-forward 
10819   'gnus-summary-tick-article-forward)
10820 (make-obsolete 'gnus-summary-mark-as-unread-forward 
10821                'gnus-summary-tick-article-forward)
10822 (defun gnus-summary-tick-article-forward (n)
10823   "Tick N articles forwards.
10824 If N is negative, tick backwards instead.
10825 The difference between N and the number of articles ticked is returned."
10826   (interactive "p")
10827   (gnus-summary-mark-forward n gnus-ticked-mark))
10828
10829 (defalias 'gnus-summary-mark-as-unread-backward 
10830   'gnus-summary-tick-article-backward)
10831 (make-obsolete 'gnus-summary-mark-as-unread-backward 
10832                'gnus-summary-tick-article-backward)
10833 (defun gnus-summary-tick-article-backward (n)
10834   "Tick N articles backwards.
10835 The difference between N and the number of articles ticked is returned."
10836   (interactive "p")
10837   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10838
10839 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10840 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10841 (defun gnus-summary-tick-article (&optional article clear-mark)
10842   "Mark current article as unread.
10843 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10844 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10845   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10846                                        gnus-ticked-mark)))
10847
10848 (defun gnus-summary-mark-as-read-forward (n)
10849   "Mark N articles as read forwards.
10850 If N is negative, mark backwards instead.
10851 The difference between N and the actual number of articles marked is
10852 returned."
10853   (interactive "p")
10854   (gnus-summary-mark-forward n gnus-del-mark t))
10855
10856 (defun gnus-summary-mark-as-read-backward (n)
10857   "Mark the N articles as read backwards.
10858 The difference between N and the actual number of articles marked is
10859 returned."
10860   (interactive "p")
10861   (gnus-summary-mark-forward (- n) gnus-del-mark t))
10862
10863 (defun gnus-summary-mark-as-read (&optional article mark)
10864   "Mark current article as read.
10865 ARTICLE specifies the article to be marked as read.
10866 MARK specifies a string to be inserted at the beginning of the line."
10867   (gnus-summary-mark-article article mark))
10868
10869 (defun gnus-summary-clear-mark-forward (n)
10870   "Clear marks from N articles forward.
10871 If N is negative, clear backward instead.
10872 The difference between N and the number of marks cleared is returned."
10873   (interactive "p")
10874   (gnus-summary-mark-forward n gnus-unread-mark))
10875
10876 (defun gnus-summary-clear-mark-backward (n)
10877   "Clear marks from N articles backward.
10878 The difference between N and the number of marks cleared is returned."
10879   (interactive "p")
10880   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10881
10882 (defun gnus-summary-mark-unread-as-read ()
10883   "Intended to be used by `gnus-summary-mark-article-hook'."
10884   (when (memq gnus-current-article gnus-newsgroup-unreads)
10885     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10886
10887 (defun gnus-summary-mark-region-as-read (point mark all)
10888   "Mark all unread articles between point and mark as read.
10889 If given a prefix, mark all articles between point and mark as read,
10890 even ticked and dormant ones."
10891   (interactive "r\nP")
10892   (save-excursion
10893     (let (article)
10894       (goto-char point)
10895       (beginning-of-line)
10896       (while (and 
10897               (< (point) mark)
10898               (progn
10899                 (when (or all 
10900                           (memq (setq article (gnus-summary-article-number))
10901                                 gnus-newsgroup-unreads))
10902                   (gnus-summary-mark-article article gnus-del-mark))
10903                 t)
10904               (gnus-summary-find-next))))))
10905
10906 (defun gnus-summary-mark-below (score mark)
10907   "Mark articles with score less than SCORE with MARK."
10908   (interactive "P\ncMark: ")
10909   (gnus-set-global-variables)
10910   (setq score (if score
10911                   (prefix-numeric-value score)
10912                 (or gnus-summary-default-score 0)))
10913   (save-excursion
10914     (set-buffer gnus-summary-buffer)
10915     (goto-char (point-min))
10916     (while (not (eobp))
10917       (and (< (gnus-summary-article-score) score)
10918            (gnus-summary-mark-article nil mark))
10919       (gnus-summary-find-next))))
10920
10921 (defun gnus-summary-kill-below (&optional score)
10922   "Mark articles with score below SCORE as read."
10923   (interactive "P")
10924   (gnus-set-global-variables)
10925   (gnus-summary-mark-below score gnus-killed-mark))
10926
10927 (defun gnus-summary-clear-above (&optional score)
10928   "Clear all marks from articles with score above SCORE."
10929   (interactive "P")
10930   (gnus-set-global-variables)
10931   (gnus-summary-mark-above score gnus-unread-mark))
10932
10933 (defun gnus-summary-tick-above (&optional score)
10934   "Tick all articles with score above SCORE."
10935   (interactive "P")
10936   (gnus-set-global-variables)
10937   (gnus-summary-mark-above score gnus-ticked-mark))
10938
10939 (defun gnus-summary-mark-above (score mark)
10940   "Mark articles with score over SCORE with MARK."
10941   (interactive "P\ncMark: ")
10942   (gnus-set-global-variables)
10943   (setq score (if score
10944                   (prefix-numeric-value score)
10945                 (or gnus-summary-default-score 0)))
10946   (save-excursion
10947     (set-buffer gnus-summary-buffer)
10948     (goto-char (point-min))
10949     (while (and (progn
10950                   (if (> (gnus-summary-article-score) score)
10951                       (gnus-summary-mark-article nil mark))
10952                   t)
10953                 (gnus-summary-find-next)))))
10954
10955 ;; Suggested by Daniel Quinlan <quinlan@best.com>.  
10956 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10957 (defun gnus-summary-limit-include-expunged ()
10958   "Display all the hidden articles that were expunged for low scores."
10959   (interactive)
10960   (gnus-set-global-variables)
10961   (let ((buffer-read-only nil))
10962     (let ((scored gnus-newsgroup-scored)
10963           headers h)
10964       (while scored
10965         (or (gnus-summary-goto-subject (car (car scored)))
10966             (and (setq h (gnus-summary-article-header (car (car scored))))
10967                  (< (cdr (car scored)) gnus-summary-expunge-below)
10968                  (setq headers (cons h headers))))
10969         (setq scored (cdr scored)))
10970       (or headers (error "No expunged articles hidden."))
10971       (goto-char (point-min))
10972       (gnus-summary-prepare-unthreaded (nreverse headers)))
10973     (goto-char (point-min))
10974     (gnus-summary-position-point)))
10975
10976 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
10977   "Mark all articles not marked as unread in this newsgroup as read.
10978 If prefix argument ALL is non-nil, all articles are marked as read.
10979 If QUIETLY is non-nil, no questions will be asked.
10980 If TO-HERE is non-nil, it should be a point in the buffer.  All
10981 articles before this point will be marked as read.
10982 The number of articles marked as read is returned."
10983   (interactive "P")
10984   (gnus-set-global-variables)
10985   (prog1
10986       (if (or quietly
10987               (not gnus-interactive-catchup) ;Without confirmation?
10988               gnus-expert-user
10989               (gnus-y-or-n-p
10990                (if all
10991                    "Mark absolutely all articles as read? "
10992                  "Mark all unread articles as read? ")))
10993           (if (and not-mark 
10994                    (not gnus-newsgroup-adaptive)
10995                    (not gnus-newsgroup-auto-expire))
10996               (progn
10997                 (when all
10998                   (setq gnus-newsgroup-marked nil
10999                         gnus-newsgroup-dormant nil))
11000                 (setq gnus-newsgroup-unreads nil))
11001             ;; We actually mark all articles as canceled, which we
11002             ;; have to do when using auto-expiry or adaptive scoring. 
11003             (gnus-summary-show-all-threads)
11004             (if (gnus-summary-first-subject (not all))
11005                 (while (and 
11006                         (if to-here (< (point) to-here) t)
11007                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11008                         (gnus-summary-find-next (not all)))))
11009             (unless to-here
11010               (setq gnus-newsgroup-unreads nil))
11011             (gnus-set-mode-line 'summary)))
11012     (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
11013       (if (and (not to-here) (eq 'nnvirtual (car method)))
11014           (nnvirtual-catchup-group
11015            (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all)))
11016     (gnus-summary-position-point)))
11017
11018 (defun gnus-summary-catchup-to-here (&optional all)
11019   "Mark all unticked articles before the current one as read.
11020 If ALL is non-nil, also mark ticked and dormant articles as read."
11021   (interactive "P")
11022   (gnus-set-global-variables)
11023   (save-excursion
11024     (let ((beg (point)))
11025       ;; We check that there are unread articles.
11026       (when (or all (gnus-summary-find-prev))
11027         (gnus-summary-catchup all t beg))))
11028   (gnus-summary-position-point))
11029
11030 (defun gnus-summary-catchup-all (&optional quietly)
11031   "Mark all articles in this newsgroup as read."
11032   (interactive "P")
11033   (gnus-set-global-variables)
11034   (gnus-summary-catchup t quietly))
11035
11036 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11037   "Mark all articles not marked as unread in this newsgroup as read, then exit.
11038 If prefix argument ALL is non-nil, all articles are marked as read."
11039   (interactive "P")
11040   (gnus-set-global-variables)
11041   (gnus-summary-catchup all quietly nil 'fast)
11042   ;; Select next newsgroup or exit.
11043   (if (eq gnus-auto-select-next 'quietly)
11044       (gnus-summary-next-group nil)
11045     (gnus-summary-exit)))
11046
11047 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11048   "Mark all articles in this newsgroup as read, and then exit."
11049   (interactive "P")
11050   (gnus-set-global-variables)
11051   (gnus-summary-catchup-and-exit t quietly))
11052
11053 ;; Suggested by "Arne Eofsson" <arne@hodgkin.mbi.ucla.edu>.
11054 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11055   "Mark all articles in this group as read and select the next group.
11056 If given a prefix, mark all articles, unread as well as ticked, as
11057 read." 
11058   (interactive "P")
11059   (gnus-set-global-variables)
11060   (gnus-summary-catchup all)
11061   (gnus-summary-next-group))
11062
11063 ;; Thread-based commands.
11064
11065 (defun gnus-summary-articles-in-thread (&optional article)
11066   "Return a list of all articles in the current thread.
11067 If ARTICLE is non-nil, return all articles in the thread that starts
11068 with that article."
11069   (let* ((article (or article (gnus-summary-article-number)))
11070          (data (gnus-data-find-list article))
11071          (top-level (gnus-data-level (car data)))
11072          (top-subject 
11073           (cond ((null gnus-thread-operation-ignore-subject)
11074                  (gnus-simplify-subject-re
11075                   (mail-header-subject (gnus-data-header (car data)))))
11076                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11077                  (gnus-simplify-subject-fuzzy
11078                   (mail-header-subject (gnus-data-header (car data)))))
11079                 (t nil)))
11080          articles)
11081     (if (not data)
11082         ()                              ; This article doesn't exist.
11083       (while data
11084         (and (or (not top-subject)
11085                  (string= top-subject
11086                           (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11087                               (gnus-simplify-subject-fuzzy
11088                                (mail-header-subject 
11089                                 (gnus-data-header (car data))))
11090                             (gnus-simplify-subject-re
11091                              (mail-header-subject 
11092                               (gnus-data-header (car data)))))))
11093              (setq articles (cons (gnus-data-number (car data)) articles)))
11094         (if (and (setq data (cdr data))
11095                  (> (gnus-data-level (car data)) top-level))
11096             ()
11097           (setq data nil)))
11098       ;; Return the list of articles.
11099       (nreverse articles))))
11100
11101 (defun gnus-summary-toggle-threads (&optional arg)
11102   "Toggle showing conversation threads.
11103 If ARG is positive number, turn showing conversation threads on."
11104   (interactive "P")
11105   (gnus-set-global-variables)
11106   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11107     (setq gnus-show-threads
11108           (if (null arg) (not gnus-show-threads)
11109             (> (prefix-numeric-value arg) 0)))
11110     (gnus-summary-prepare)
11111     (gnus-summary-goto-subject current)
11112     (gnus-summary-position-point)))
11113
11114 (defun gnus-summary-show-all-threads ()
11115   "Show all threads."
11116   (interactive)
11117   (gnus-set-global-variables)
11118   (save-excursion
11119     (let ((buffer-read-only nil))
11120       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
11121   (gnus-summary-position-point))
11122
11123 (defun gnus-summary-show-thread ()
11124   "Show thread subtrees.
11125 Returns nil if no thread was there to be shown."
11126   (interactive)
11127   (gnus-set-global-variables)
11128   (let ((buffer-read-only nil)
11129         (orig (point))
11130         ;; first goto end then to beg, to have point at beg after let
11131         (end (progn (end-of-line) (point)))
11132         (beg (progn (beginning-of-line) (point))))
11133     (prog1
11134         ;; Any hidden lines here?
11135         (search-forward "\r" end t)
11136       (subst-char-in-region beg end ?\^M ?\n t)
11137       (goto-char orig)
11138       (gnus-summary-position-point))))
11139
11140 (defun gnus-summary-hide-all-threads ()
11141   "Hide all thread subtrees."
11142   (interactive)
11143   (gnus-set-global-variables)
11144   (save-excursion
11145     (goto-char (point-min))
11146     (gnus-summary-hide-thread)
11147     (while (zerop (gnus-summary-next-thread 1 t))
11148       (gnus-summary-hide-thread)))
11149   (gnus-summary-position-point))
11150
11151 (defun gnus-summary-hide-thread ()
11152   "Hide thread subtrees.
11153 Returns nil if no threads were there to be hidden."
11154   (interactive)
11155   (gnus-set-global-variables)
11156   (let ((buffer-read-only nil)
11157         (start (point))
11158         (article (gnus-summary-article-number))
11159         end)
11160     ;; Go forward until either the buffer ends or the subthread
11161     ;; ends. 
11162     (when (and (not (eobp))
11163                (or (and (zerop (gnus-summary-next-thread 1 t))
11164                         (gnus-summary-find-prev))
11165                    (gnus-summary-goto-subject gnus-newsgroup-end)))
11166       (setq end (point))
11167       (prog1
11168           (if (and (> (point) start)
11169                    (search-backward "\n" start t))
11170               (progn
11171                 (subst-char-in-region start end ?\n ?\^M)
11172                 (gnus-summary-goto-subject article))
11173             (goto-char start)
11174             nil)
11175         (gnus-summary-position-point)))))
11176
11177 (defun gnus-summary-go-to-next-thread (&optional previous)
11178   "Go to the same level (or less) next thread.
11179 If PREVIOUS is non-nil, go to previous thread instead.
11180 Return the article number moved to, or nil if moving was impossible."
11181   (let* ((level (gnus-summary-thread-level))
11182          (article (gnus-summary-article-number))
11183          (data (cdr (gnus-data-find-list article (gnus-data-list previous))))
11184          oart)
11185     (while data
11186       (if (<= (gnus-data-level (car data)) level)
11187           (setq oart (gnus-data-number (car data))
11188                 data nil)
11189         (setq data (cdr data))))
11190     (and oart 
11191          (gnus-summary-goto-subject oart))))
11192
11193 (defun gnus-summary-next-thread (n &optional silent)
11194   "Go to the same level next N'th thread.
11195 If N is negative, search backward instead.
11196 Returns the difference between N and the number of skips actually
11197 done.
11198
11199 If SILENT, don't output messages."
11200   (interactive "p")
11201   (gnus-set-global-variables)
11202   (let ((backward (< n 0))
11203         (n (abs n)))
11204     (while (and (> n 0)
11205                 (gnus-summary-go-to-next-thread backward))
11206       (decf n))
11207     (gnus-summary-position-point)
11208     (when (and (not silent) (/= 0 n))
11209       (gnus-message 7 "No more threads"))
11210     n))
11211
11212 (defun gnus-summary-prev-thread (n)
11213   "Go to the same level previous N'th thread.
11214 Returns the difference between N and the number of skips actually
11215 done."
11216   (interactive "p")
11217   (gnus-set-global-variables)
11218   (gnus-summary-next-thread (- n)))
11219
11220 (defun gnus-summary-go-down-thread ()
11221   "Go down one level in the current thread."
11222   (let ((children (gnus-summary-article-children)))
11223     (and children
11224          (gnus-summary-goto-subject (car children)))))
11225
11226 (defun gnus-summary-go-up-thread ()
11227   "Go up one level in the current thread."
11228   (let ((parent (gnus-summary-article-parent)))
11229     (and parent
11230          (gnus-summary-goto-subject parent))))
11231
11232 (defun gnus-summary-down-thread (n)
11233   "Go down thread N steps.
11234 If N is negative, go up instead.
11235 Returns the difference between N and how many steps down that were
11236 taken."
11237   (interactive "p")
11238   (gnus-set-global-variables)
11239   (let ((up (< n 0))
11240         (n (abs n)))
11241     (while (and (> n 0)
11242                 (if up (gnus-summary-go-up-thread)
11243                   (gnus-summary-go-down-thread)))
11244       (setq n (1- n)))
11245     (gnus-summary-position-point)
11246     (if (/= 0 n) (gnus-message 7 "Can't go further"))
11247     n))
11248
11249 (defun gnus-summary-up-thread (n)
11250   "Go up thread N steps.
11251 If N is negative, go up instead.
11252 Returns the difference between N and how many steps down that were
11253 taken."
11254   (interactive "p")
11255   (gnus-set-global-variables)
11256   (gnus-summary-down-thread (- n)))
11257
11258 (defun gnus-summary-kill-thread (&optional unmark)
11259   "Mark articles under current thread as read.
11260 If the prefix argument is positive, remove any kinds of marks.
11261 If the prefix argument is negative, tick articles instead."
11262   (interactive "P")
11263   (gnus-set-global-variables)
11264   (if unmark
11265       (setq unmark (prefix-numeric-value unmark)))
11266   (let ((articles (gnus-summary-articles-in-thread)))
11267     (save-excursion
11268       ;; Expand the thread.
11269       (gnus-summary-show-thread)
11270       ;; Mark all the articles.
11271       (while articles
11272         (gnus-summary-goto-subject (car articles))
11273         (cond ((null unmark) 
11274                (gnus-summary-mark-article-as-read gnus-killed-mark))
11275               ((> unmark 0) 
11276                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11277               (t 
11278                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11279         (setq articles (cdr articles))))
11280     ;; Hide killed subtrees.
11281     (and (null unmark)
11282          gnus-thread-hide-killed
11283          (gnus-summary-hide-thread))
11284     ;; If marked as read, go to next unread subject.
11285     (if (null unmark)
11286         ;; Go to next unread subject.
11287         (gnus-summary-next-subject 1 t)))
11288   (gnus-set-mode-line 'summary))
11289
11290 ;; Summary sorting commands
11291
11292 (defun gnus-summary-sort-by-number (&optional reverse)
11293   "Sort summary buffer by article number.
11294 Argument REVERSE means reverse order."
11295   (interactive "P")
11296   (gnus-set-global-variables)
11297   (gnus-summary-sort 
11298    ;; `gnus-summary-article-number' is a macro, and `sort-subr' wants
11299    ;; a function, so we wrap it.
11300    (cons (lambda () (gnus-summary-article-number))
11301          'gnus-thread-sort-by-number) reverse))
11302
11303 (defun gnus-summary-sort-by-author (&optional reverse)
11304   "Sort summary buffer by author name alphabetically.
11305 If case-fold-search is non-nil, case of letters is ignored.
11306 Argument REVERSE means reverse order."
11307   (interactive "P")
11308   (gnus-set-global-variables)
11309   (gnus-summary-sort
11310    (cons
11311     (lambda ()
11312       (let* ((header (gnus-summary-article-header))
11313              (extract (funcall
11314                        gnus-extract-address-components
11315                        (mail-header-from header))))
11316         (concat (or (car extract) (cdr extract))
11317                 "\r" (mail-header-subject header))))
11318     'gnus-thread-sort-by-author)
11319    reverse))
11320
11321 (defun gnus-summary-sort-by-subject (&optional reverse)
11322   "Sort summary buffer by subject alphabetically. `Re:'s are ignored.
11323 If case-fold-search is non-nil, case of letters is ignored.
11324 Argument REVERSE means reverse order."
11325   (interactive "P")
11326   (gnus-set-global-variables)
11327   (gnus-summary-sort
11328    (cons
11329     (lambda ()
11330       (let* ((header (gnus-summary-article-header))
11331              (extract (funcall
11332                        gnus-extract-address-components
11333                        (mail-header-from header))))
11334         (concat 
11335          (downcase (gnus-simplify-subject (gnus-summary-article-subject) t))
11336          "\r" (or (car extract) (cdr extract)))))
11337     'gnus-thread-sort-by-subject)
11338    reverse))
11339
11340 (defun gnus-summary-sort-by-date (&optional reverse)
11341   "Sort summary buffer by date.
11342 Argument REVERSE means reverse order."
11343   (interactive "P")
11344   (gnus-set-global-variables)
11345   (gnus-summary-sort
11346    (cons
11347     (lambda ()
11348       (gnus-sortable-date
11349        (mail-header-date 
11350         (gnus-summary-article-header))))
11351     'gnus-thread-sort-by-date)
11352    reverse))
11353
11354 (defun gnus-summary-sort-by-score (&optional reverse)
11355   "Sort summary buffer by score.
11356 Argument REVERSE means reverse order."
11357   (interactive "P")
11358   (gnus-set-global-variables)
11359   (gnus-summary-sort 
11360    (cons (lambda () (gnus-summary-article-score))
11361          'gnus-thread-sort-by-score)
11362    (not reverse)))
11363
11364 (defun gnus-summary-sort (predicate reverse)
11365   "Sort summary buffer by PREDICATE.  REVERSE means reverse order. 
11366 PREDICATE is a cons of `(unthreaded-func . threaded-func)'."
11367   (let (buffer-read-only)
11368     (if (not gnus-show-threads)
11369         ;; We do untreaded sorting...
11370         (progn
11371           (goto-char (point-min))
11372           (sort-subr reverse 'forward-line 'end-of-line (car predicate))
11373           (gnus-data-compute-positions))
11374       ;; ... or we do threaded sorting.
11375       (let ((gnus-thread-sort-functions (list (cdr predicate)))
11376             (gnus-summary-prepare-hook nil))
11377         ;; We do that by simply regenerating the threads.
11378         (gnus-summary-prepare)
11379         ;; Hide subthreads if needed.
11380         (when gnus-thread-hide-subtree
11381           (gnus-summary-hide-all-threads))))
11382     ;; If in async mode, we send some info to the backend.
11383     (when gnus-newsgroup-async
11384       (gnus-request-asynchronous 
11385        gnus-newsgroup-name gnus-newsgroup-data))))
11386   
11387 (defun gnus-sortable-date (date)
11388   "Make sortable string by string-lessp from DATE.
11389 Timezone package is used."
11390   (let* ((date (timezone-fix-time date nil nil)) ;[Y M D H M S]
11391          (year (aref date 0))
11392          (month (aref date 1))
11393          (day (aref date 2)))
11394     (timezone-make-sortable-date 
11395      year month day 
11396      (timezone-make-time-string
11397       (aref date 3) (aref date 4) (aref date 5)))))
11398
11399
11400 ;; Summary saving commands.
11401
11402 (defun gnus-summary-save-article (&optional n)
11403   "Save the current article using the default saver function.
11404 If N is a positive number, save the N next articles.
11405 If N is a negative number, save the N previous articles.
11406 If N is nil and any articles have been marked with the process mark,
11407 save those articles instead.
11408 The variable `gnus-default-article-saver' specifies the saver function."
11409   (interactive "P")
11410   (gnus-set-global-variables)
11411   (let ((articles (gnus-summary-work-articles n))
11412         file)
11413     (while articles
11414       (let ((header (gnus-summary-article-header (car articles))))
11415         (if (vectorp header)
11416             (progn
11417               (save-window-excursion
11418                 (gnus-summary-select-article t nil nil (car articles)))
11419               (or gnus-save-all-headers
11420                   ;; Remove headers accoring to `gnus-saved-headers'.
11421                   (let ((gnus-visible-headers 
11422                          (or gnus-saved-headers gnus-visible-headers)))
11423                     (gnus-article-hide-headers t)))
11424               ;; Remove any X-Gnus lines.
11425               (save-excursion
11426                 (save-restriction
11427                   (set-buffer gnus-article-buffer)
11428                   (let ((buffer-read-only nil))
11429                     (goto-char (point-min))
11430                     (narrow-to-region (point) (or (search-forward "\n\n" nil t)
11431                                                   (point-max)))
11432                     (while (re-search-forward "^X-Gnus" nil t)
11433                       (beginning-of-line)
11434                       (delete-region (point)
11435                                      (progn (forward-line 1) (point))))
11436                     (widen))))
11437               (save-window-excursion
11438                 (if gnus-default-article-saver
11439                     (setq file (funcall
11440                                 gnus-default-article-saver
11441                                 (cond
11442                                  ((not gnus-prompt-before-saving)
11443                                   'default)
11444                                  ((eq gnus-prompt-before-saving 'always)
11445                                   nil)
11446                                  (t file))))
11447                   (error "No default saver is defined."))))
11448           (if (assq 'name header)
11449               (gnus-copy-file (cdr (assq 'name header)))
11450             (gnus-message 1 "Article %d is unsaveable" (car articles)))))
11451       (gnus-summary-remove-process-mark (car articles))
11452       (setq articles (cdr articles)))
11453     (gnus-summary-position-point)
11454     n))
11455
11456 (defun gnus-summary-pipe-output (&optional arg)
11457   "Pipe the current article to a subprocess.
11458 If N is a positive number, pipe the N next articles.
11459 If N is a negative number, pipe the N previous articles.
11460 If N is nil and any articles have been marked with the process mark,
11461 pipe those articles instead."
11462   (interactive "P")
11463   (gnus-set-global-variables)
11464   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
11465     (gnus-summary-save-article arg))
11466   (gnus-configure-windows 'pipe))
11467
11468 (defun gnus-summary-save-article-mail (&optional arg)
11469   "Append the current article to an mail file.
11470 If N is a positive number, save the N next articles.
11471 If N is a negative number, save the N previous articles.
11472 If N is nil and any articles have been marked with the process mark,
11473 save those articles instead."
11474   (interactive "P")
11475   (gnus-set-global-variables)
11476   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11477     (gnus-summary-save-article arg)))
11478
11479 (defun gnus-summary-save-article-rmail (&optional arg)
11480   "Append the current article to an rmail file.
11481 If N is a positive number, save the N next articles.
11482 If N is a negative number, save the N previous articles.
11483 If N is nil and any articles have been marked with the process mark,
11484 save those articles instead."
11485   (interactive "P")
11486   (gnus-set-global-variables)
11487   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11488     (gnus-summary-save-article arg)))
11489
11490 (defun gnus-summary-save-article-file (&optional arg)
11491   "Append the current article to a file.
11492 If N is a positive number, save the N next articles.
11493 If N is a negative number, save the N previous articles.
11494 If N is nil and any articles have been marked with the process mark,
11495 save those articles instead."
11496   (interactive "P")
11497   (gnus-set-global-variables)
11498   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11499     (gnus-summary-save-article arg)))
11500
11501 (defun gnus-summary-save-article-body-file (&optional arg)
11502   "Append the current article body to a file.
11503 If N is a positive number, save the N next articles.
11504 If N is a negative number, save the N previous articles.
11505 If N is nil and any articles have been marked with the process mark,
11506 save those articles instead."
11507   (interactive "P")
11508   (gnus-set-global-variables)
11509   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11510     (gnus-summary-save-article arg)))
11511
11512 (defun gnus-read-save-file-name (prompt default-name)
11513   (let ((methods gnus-split-methods)
11514         split-name method)
11515     ;; Let the split methods have their say.
11516     (when gnus-split-methods
11517       (save-excursion
11518         (set-buffer gnus-original-article-buffer)
11519         (gnus-narrow-to-headers)
11520         (while methods
11521           (goto-char (point-min))
11522           (setq method (pop methods))
11523           (when (cond ((stringp (car method))
11524                        (condition-case () 
11525                            (re-search-forward (car method) nil t)
11526                          (error nil)))
11527                       ((and (symbolp (car method))
11528                             (fboundp (car method)))
11529                        (funcall (car method)))
11530                       ((consp (car method))
11531                        (eval (car method))))
11532             (setq split-name (cons (nth 1 methods) split-name))))
11533         (widen)))
11534     (cond
11535      ;; No split name was found
11536      ((null split-name)
11537       (read-file-name
11538        (concat prompt " (default " (file-name-nondirectory default-name) ") ")
11539        (file-name-directory default-name)
11540        default-name))
11541      ;; A single split name was found
11542      ((= 1 (length split-name))
11543       (read-file-name
11544        (concat prompt " (default " (car split-name) ") ")
11545        gnus-article-save-directory
11546        (concat gnus-article-save-directory (car split-name))))
11547      ;; A list of splits was found.
11548      (t
11549       (setq split-name (mapcar (lambda (el) (list el)) (nreverse split-name)))
11550       (let ((result (completing-read (concat prompt " ") split-name nil nil)))
11551         (concat gnus-article-save-directory
11552                 (if (string= result "")
11553                     (car (car split-name))
11554                   result)))))))
11555
11556 (defun gnus-summary-save-in-rmail (&optional filename)
11557   "Append this article to Rmail file.
11558 Optional argument FILENAME specifies file name.
11559 Directory to save to is default to `gnus-article-save-directory' which
11560 is initialized from the SAVEDIR environment variable."
11561   (interactive)
11562   (gnus-set-global-variables)
11563   (let ((default-name
11564           (funcall gnus-rmail-save-name gnus-newsgroup-name
11565                    gnus-current-headers gnus-newsgroup-last-rmail)))
11566     (setq filename
11567           (cond ((eq filename 'default)
11568                  default-name)
11569                 (filename filename)
11570                 (t (gnus-read-save-file-name 
11571                     "Save in rmail file:" default-name))))
11572     (gnus-make-directory (file-name-directory filename))
11573     (gnus-eval-in-buffer-window 
11574      gnus-original-article-buffer
11575      (save-excursion
11576        (save-restriction
11577          (widen)
11578          (gnus-output-to-rmail filename))))
11579     ;; Remember the directory name to save articles
11580     (setq gnus-newsgroup-last-rmail filename)))
11581
11582 (defun gnus-summary-save-in-mail (&optional filename)
11583   "Append this article to Unix mail file.
11584 Optional argument FILENAME specifies file name.
11585 Directory to save to is default to `gnus-article-save-directory' which
11586 is initialized from the SAVEDIR environment variable."
11587   (interactive)
11588   (gnus-set-global-variables)
11589   (let ((default-name
11590           (funcall gnus-mail-save-name gnus-newsgroup-name
11591                    gnus-current-headers gnus-newsgroup-last-mail)))
11592     (setq filename
11593           (cond ((eq filename 'default)
11594                  default-name)
11595                 (filename filename)
11596                 (t (gnus-read-save-file-name 
11597                     "Save in Unix mail file:" default-name))))
11598     (setq filename
11599           (expand-file-name filename
11600                             (and default-name
11601                                  (file-name-directory default-name))))
11602     (gnus-make-directory (file-name-directory filename))
11603     (gnus-eval-in-buffer-window 
11604      gnus-original-article-buffer
11605      (save-excursion
11606        (save-restriction
11607          (widen)
11608          (if (and (file-readable-p filename) (mail-file-babyl-p filename))
11609              (gnus-output-to-rmail filename)
11610            (rmail-output filename 1 t t)))))
11611     ;; Remember the directory name to save articles.
11612     (setq gnus-newsgroup-last-mail filename)))
11613
11614 (defun gnus-summary-save-in-file (&optional filename)
11615   "Append this article to file.
11616 Optional argument FILENAME specifies file name.
11617 Directory to save to is default to `gnus-article-save-directory' which
11618 is initialized from the SAVEDIR environment variable."
11619   (interactive)
11620   (gnus-set-global-variables)
11621   (let ((default-name
11622           (funcall gnus-file-save-name gnus-newsgroup-name
11623                    gnus-current-headers gnus-newsgroup-last-file)))
11624     (setq filename
11625           (cond ((eq filename 'default)
11626                  default-name)
11627                 (filename filename)
11628                 (t (gnus-read-save-file-name 
11629                     "Save in file:" default-name))))
11630     (gnus-make-directory (file-name-directory filename))
11631     (gnus-eval-in-buffer-window 
11632      gnus-article-buffer
11633      (save-excursion
11634        (save-restriction
11635          (widen)
11636          (gnus-output-to-file filename))))
11637     ;; Remember the directory name to save articles.
11638     (setq gnus-newsgroup-last-file filename)))
11639
11640 (defun gnus-summary-save-body-in-file (&optional filename)
11641   "Append this article body to a file.
11642 Optional argument FILENAME specifies file name.
11643 The directory to save in defaults to `gnus-article-save-directory' which
11644 is initialized from the SAVEDIR environment variable."
11645   (interactive)
11646   (gnus-set-global-variables)
11647   (let ((default-name
11648           (funcall gnus-file-save-name gnus-newsgroup-name
11649                    gnus-current-headers gnus-newsgroup-last-file)))
11650     (setq filename
11651           (cond ((eq filename 'default)
11652                  default-name)
11653                 (filename filename)
11654                 (t (gnus-read-save-file-name 
11655                     "Save body in file:" default-name))))
11656     (gnus-make-directory (file-name-directory filename))
11657     (gnus-eval-in-buffer-window 
11658      gnus-article-buffer
11659      (save-excursion
11660        (save-restriction
11661          (widen)
11662          (goto-char (point-min))
11663          (and (search-forward "\n\n" nil t)
11664               (narrow-to-region (point) (point-max)))
11665          (gnus-output-to-file filename))))
11666     ;; Remember the directory name to save articles.
11667     (setq gnus-newsgroup-last-file filename)))
11668
11669 (defun gnus-summary-save-in-pipe (&optional command)
11670   "Pipe this article to subprocess."
11671   (interactive)
11672   (gnus-set-global-variables)
11673   (setq command
11674         (cond ((eq command 'default)
11675                gnus-last-shell-command)
11676               (command command)
11677               (t (read-string "Shell command on article: "
11678                               gnus-last-shell-command))))
11679   (if (string-equal command "")
11680       (setq command gnus-last-shell-command))
11681   (gnus-eval-in-buffer-window 
11682    gnus-article-buffer
11683    (save-restriction
11684      (widen)
11685      (shell-command-on-region (point-min) (point-max) command nil)))
11686   (setq gnus-last-shell-command command))
11687
11688 ;; Summary extract commands
11689
11690 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11691   (let ((buffer-read-only nil)
11692         (article (gnus-summary-article-number))
11693         after-article b e)
11694     (or (gnus-summary-goto-subject article)
11695         (error (format "No such article: %d" article)))
11696     (gnus-summary-position-point)
11697     ;; If all commands are to be bunched up on one line, we collect
11698     ;; them here.  
11699     (if gnus-view-pseudos-separately
11700         ()
11701       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11702             files action)
11703         (while ps
11704           (setq action (cdr (assq 'action (car ps))))
11705           (setq files (list (cdr (assq 'name (car ps)))))
11706           (while (and ps (cdr ps)
11707                       (string= (or action "1")
11708                                (or (cdr (assq 'action (car (cdr ps)))) "2")))
11709             (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
11710             (setcdr ps (cdr (cdr ps))))
11711           (if (not files)
11712               ()
11713             (if (not (string-match "%s" action))
11714                 (setq files (cons " " files)))
11715             (setq files (cons " " files))
11716             (and (assq 'execute (car ps))
11717                  (setcdr (assq 'execute (car ps))
11718                          (funcall (if (string-match "%s" action)
11719                                       'format 'concat)
11720                                   action 
11721                                   (mapconcat (lambda (f) f) files " ")))))
11722           (setq ps (cdr ps)))))
11723     (if (and gnus-view-pseudos (not not-view))
11724         (while pslist
11725           (and (assq 'execute (car pslist))
11726                (gnus-execute-command (cdr (assq 'execute (car pslist)))
11727                                      (eq gnus-view-pseudos 'not-confirm)))
11728           (setq pslist (cdr pslist)))
11729       (save-excursion
11730         (while pslist
11731           (setq after-article (or (cdr (assq 'article (car pslist)))
11732                                   (gnus-summary-article-number)))
11733           (gnus-summary-goto-subject after-article)
11734           (forward-line 1)
11735           (setq b (point))
11736           (insert "          " (file-name-nondirectory
11737                                 (cdr (assq 'name (car pslist))))
11738                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11739           (setq e (point))
11740           (forward-line -1)             ; back to `b'
11741           (put-text-property b e 'gnus-number gnus-reffed-article-number)
11742           (gnus-data-enter after-article
11743                            gnus-reffed-article-number
11744                            gnus-unread-mark 
11745                            b
11746                            (car pslist) 
11747                            0 
11748                            (- e b))
11749           (setq gnus-newsgroup-unreads
11750                 (cons gnus-reffed-article-number gnus-newsgroup-unreads))
11751           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11752           (setq pslist (cdr pslist)))))))
11753
11754 (defun gnus-pseudos< (p1 p2)
11755   (let ((c1 (cdr (assq 'action p1)))
11756         (c2 (cdr (assq 'action p2))))
11757     (and c1 c2 (string< c1 c2))))
11758
11759 (defun gnus-request-pseudo-article (props)
11760   (cond ((assq 'execute props)
11761          (gnus-execute-command (cdr (assq 'execute props)))))
11762   (let ((gnus-current-article (gnus-summary-article-number)))
11763     (run-hooks 'gnus-mark-article-hook)))
11764
11765 (defun gnus-execute-command (command &optional automatic)
11766   (save-excursion
11767     (gnus-article-setup-buffer)
11768     (set-buffer gnus-article-buffer)
11769     (let ((command (if automatic command (read-string "Command: " command)))
11770           (buffer-read-only nil))
11771       (erase-buffer)
11772       (insert "$ " command "\n\n")
11773       (if gnus-view-pseudo-asynchronously
11774           (start-process "gnus-execute" nil "sh" "-c" command)
11775         (call-process "sh" nil t nil "-c" command)))))
11776
11777 (defun gnus-copy-file (file &optional to)
11778   "Copy FILE to TO."
11779   (interactive
11780    (list (read-file-name "Copy file: " default-directory)
11781          (read-file-name "Copy file to: " default-directory)))
11782   (gnus-set-global-variables)
11783   (or to (setq to (read-file-name "Copy file to: " default-directory)))
11784   (and (file-directory-p to) 
11785        (setq to (concat (file-name-as-directory to)
11786                         (file-name-nondirectory file))))
11787   (copy-file file to))
11788
11789 ;; Summary kill commands.
11790
11791 (defun gnus-summary-edit-global-kill (article)
11792   "Edit the \"global\" kill file."
11793   (interactive (list (gnus-summary-article-number)))
11794   (gnus-set-global-variables)
11795   (gnus-group-edit-global-kill article))
11796
11797 (defun gnus-summary-edit-local-kill ()
11798   "Edit a local kill file applied to the current newsgroup."
11799   (interactive)
11800   (gnus-set-global-variables)
11801   (setq gnus-current-headers (gnus-summary-article-header))
11802   (gnus-set-global-variables)
11803   (gnus-group-edit-local-kill 
11804    (gnus-summary-article-number) gnus-newsgroup-name))
11805
11806 \f
11807 ;;;
11808 ;;; Gnus article mode
11809 ;;;
11810
11811 (put 'gnus-article-mode 'mode-class 'special)
11812
11813 (if gnus-article-mode-map
11814     nil
11815   (setq gnus-article-mode-map (make-keymap))
11816   (suppress-keymap gnus-article-mode-map)
11817   (define-key gnus-article-mode-map " " 'gnus-article-next-page)
11818   (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page)
11819   (define-key gnus-article-mode-map "\C-c^" 'gnus-article-refer-article)
11820   (define-key gnus-article-mode-map "h" 'gnus-article-show-summary)
11821   (define-key gnus-article-mode-map "s" 'gnus-article-show-summary)
11822   (define-key gnus-article-mode-map "\C-c\C-m" 'gnus-article-mail)
11823   (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly)
11824   (define-key gnus-article-mode-map gnus-mouse-2 'gnus-article-push-button)
11825   (define-key gnus-article-mode-map "\r" 'gnus-article-press-button)
11826   (define-key gnus-article-mode-map "\t" 'gnus-article-next-button)
11827   (define-key gnus-article-mode-map "\C-c\C-b" 'gnus-bug)
11828   
11829   ;; Duplicate almost all summary keystrokes in the article mode map.
11830   (let ((commands 
11831          (list 
11832           "p" "N" "P" "\M-\C-n" "\M-\C-p"
11833           "\M-n" "\M-p" "." "," "\M-s" "\M-r" "<" ">" "j"
11834           "u" "!" "U" "d" "D" "E" "\M-u" "\M-U" "k" "\C-k" "\M-\C-k"
11835           "\M-\C-l" "e" "#" "\M-#" "\M-\C-t" "\M-\C-s" "\M-\C-h"
11836           "\M-\C-f" "\M-\C-b" "\M-\C-u" "\M-\C-d" "&" "\C-w"
11837           "\C-t" "?" "\C-c\M-\C-s" "\C-c\C-s\C-n" "\C-c\C-s\C-a"
11838           "\C-c\C-s\C-s" "\C-c\C-s\C-d" "\C-c\C-s\C-i" "\C-x\C-s"
11839           "\M-g" "w" "\C-c\C-r" "\M-t" "C"
11840           "o" "\C-o" "|" "\M-k" "\M-K" "V" "\C-c\C-d"
11841           "\C-c\C-i" "x" "X" "t" "g" "?" "l"
11842           "\C-c\C-v\C-v" "\C-d" "v" 
11843 ;;        "Mt" "M!" "Md" "Mr"
11844 ;;        "Mc" "M " "Me" "Mx" "M?" "Mb" "MB" "M#" "M\M-#" "M\M-r"
11845 ;;        "M\M-\C-r" "MD" "M\M-D" "MS" "MC" "MH" "M\C-c" "Mk" "MK"
11846 ;;        "Ms" "Mc" "Mu" "Mm" "Mk" "Gn" "Gp" "GN" "GP" "G\C-n" "G\C-p"
11847 ;;        "G\M-n" "G\M-p" "Gf" "Gb" "Gg" "Gl" "Gp" "Tk" "Tl" "Ti" "TT"
11848 ;;        "Ts" "TS" "Th" "TH" "Tn" "Tp" "Tu" "Td" "T#" "A " "An" "A\177" "Ap"
11849 ;;        "A\r" "A<" "A>" "Ab" "Ae" "A^" "Ar" "Aw" "Ac" "Ag" "At" "Am"
11850 ;;        "As" "Wh" "Ws" "Wc" "Wo" "Ww" "Wd" "Wq" "Wf" "Wt" "W\C-t"
11851 ;;        "WT" "WA" "Wa" "WH" "WC" "WS" "Wb" "Hv" "Hf" "Hd" "Hh" "Hi"
11852 ;;        "Be" "B\177" "Bm" "Br" "Bw" "Bc" "Bq" "Bi" "Oo" "Om" "Or"
11853 ;;        "Of" "Oh" "Ov" "Op" "Vu" "V\C-s" "V\C-r" "Vr" "V&" "VT" "Ve"
11854 ;;        "VD" "Vk" "VK" "Vsn" "Vsa" "Vss" "Vsd" "Vsi"
11855           )))
11856     (while commands
11857       (define-key gnus-article-mode-map (car commands) 
11858         'gnus-article-summary-command)
11859       (setq commands (cdr commands))))
11860
11861   (let ((commands (list "q" "Q"  "c" "r" "R" "\C-c\C-f" "m"  "a" "f" "F"
11862 ;;                      "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP" 
11863                          "=" "n"  "^" "\M-^")))
11864     (while commands
11865       (define-key gnus-article-mode-map (car commands) 
11866         'gnus-article-summary-command-nosave)
11867       (setq commands (cdr commands)))))
11868
11869
11870 (defun gnus-article-mode ()
11871   "Major mode for displaying an article.
11872
11873 All normal editing commands are switched off.
11874
11875 The following commands are available:
11876
11877 \\<gnus-article-mode-map>
11878 \\[gnus-article-next-page]\t Scroll the article one page forwards
11879 \\[gnus-article-prev-page]\t Scroll the article one page backwards
11880 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
11881 \\[gnus-article-show-summary]\t Display the summary buffer
11882 \\[gnus-article-mail]\t Send a reply to the address near point
11883 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
11884 \\[gnus-info-find-node]\t Go to the Gnus info node"
11885   (interactive)
11886   (when (and menu-bar-mode
11887              (gnus-visual-p 'article-menu 'menu))
11888     (gnus-article-make-menu-bar))
11889   (kill-all-local-variables)
11890   (setq mode-line-modified "-- ")
11891   (make-local-variable 'mode-line-format)
11892   (setq mode-line-format (copy-sequence mode-line-format))
11893   (and (equal (nth 3 mode-line-format) "   ")
11894        (setcar (nthcdr 3 mode-line-format) ""))
11895   (setq mode-name "Article")
11896   (setq major-mode 'gnus-article-mode)
11897   (make-local-variable 'minor-mode-alist)
11898   (or (assq 'gnus-show-mime minor-mode-alist)
11899       (setq minor-mode-alist
11900             (cons (list 'gnus-show-mime " MIME") minor-mode-alist)))
11901   (use-local-map gnus-article-mode-map)
11902   (make-local-variable 'page-delimiter)
11903   (setq page-delimiter gnus-page-delimiter)
11904   (buffer-disable-undo (current-buffer))
11905   (setq buffer-read-only t)             ;Disable modification
11906   (run-hooks 'gnus-article-mode-hook))
11907
11908 (defun gnus-article-setup-buffer ()
11909   "Initialize article mode buffer."
11910   ;; Returns the article buffer.
11911   (if (get-buffer gnus-article-buffer)
11912       (save-excursion
11913         (set-buffer gnus-article-buffer)
11914         (buffer-disable-undo (current-buffer))
11915         (setq buffer-read-only t)
11916         (gnus-add-current-to-buffer-list)
11917         (or (eq major-mode 'gnus-article-mode)
11918             (gnus-article-mode))
11919         (current-buffer))
11920     (save-excursion
11921       (set-buffer (get-buffer-create gnus-article-buffer))
11922       (gnus-add-current-to-buffer-list)
11923       (gnus-article-mode)
11924       (current-buffer))))
11925
11926 ;; Set article window start at LINE, where LINE is the number of lines
11927 ;; from the head of the article.
11928 (defun gnus-article-set-window-start (&optional line)
11929   (set-window-start 
11930    (get-buffer-window gnus-article-buffer)
11931    (save-excursion
11932      (set-buffer gnus-article-buffer)
11933      (goto-char (point-min))
11934      (if (not line)
11935          (point-min)
11936        (gnus-message 6 "Moved to bookmark")
11937        (search-forward "\n\n" nil t)
11938        (forward-line line)
11939        (point)))))
11940
11941 (defun gnus-request-article-this-buffer (article group)
11942   "Get an article and insert it into this buffer."
11943   (prog1
11944       (save-excursion
11945         (if (get-buffer gnus-original-article-buffer)
11946             (set-buffer (get-buffer gnus-original-article-buffer))
11947           (set-buffer (get-buffer-create gnus-original-article-buffer))
11948           (buffer-disable-undo (current-buffer))
11949           (setq major-mode 'gnus-original-article-mode)
11950           (setq buffer-read-only t)
11951           (gnus-add-current-to-buffer-list))
11952
11953         (setq group (or group gnus-newsgroup-name))
11954
11955         ;; Open server if it has closed.
11956         (gnus-check-server (gnus-find-method-for-group group))
11957
11958         ;; Using `gnus-request-article' directly will insert the article into
11959         ;; `nntp-server-buffer' - so we'll save some time by not having to
11960         ;; copy it from the server buffer into the article buffer.
11961
11962         ;; We only request an article by message-id when we do not have the
11963         ;; headers for it, so we'll have to get those.
11964         (and (stringp article) 
11965              (let ((gnus-override-method gnus-refer-article-method))
11966                (gnus-read-header article)))
11967
11968         ;; If the article number is negative, that means that this article
11969         ;; doesn't belong in this newsgroup (possibly), so we find its
11970         ;; message-id and request it by id instead of number.
11971         (if (not (numberp article))
11972             ()
11973           (save-excursion
11974             (set-buffer gnus-summary-buffer)
11975             (let ((header (gnus-summary-article-header article)))
11976               (if (< article 0)
11977                   (if (vectorp header)
11978                       ;; It's a real article.
11979                       (setq article (mail-header-id header))
11980                     ;; It is an extracted pseudo-article.
11981                     (setq article 'pseudo)
11982                     (gnus-request-pseudo-article header)))
11983
11984               (let ((method (gnus-find-method-for-group gnus-newsgroup-name)))
11985                 (if (not (eq (car method) 'nneething))
11986                     ()
11987                   (let ((dir (concat (file-name-as-directory (nth 1 method))
11988                                      (mail-header-subject header))))
11989                     (if (file-directory-p dir)
11990                         (progn
11991                           (setq article 'nneething)
11992                           (gnus-group-enter-directory dir)))))))))
11993
11994         (cond 
11995          ;; We first check `gnus-original-article-buffer'.
11996          ((and (equal (car gnus-original-article) group)
11997                (eq (cdr gnus-original-article) article))
11998           ;; We don't have to do anything, since it's already where we
11999           ;; want it.  
12000           'article)
12001          ;; Check the backlog.
12002          ((and gnus-keep-backlog
12003                (gnus-backlog-request-article group article (current-buffer)))
12004           'article)
12005          ;; Check the cache.
12006          ((and gnus-use-cache
12007                (numberp article)
12008                (gnus-cache-request-article article group))
12009           'article)
12010          ;; Get the article and put into the article buffer.
12011          ((or (stringp article) (numberp article))
12012           (let ((gnus-override-method 
12013                  (and (stringp article) gnus-refer-article-method))
12014                 (buffer-read-only nil))
12015             (erase-buffer)
12016             ;; There may be some overlays that we have to kill...
12017             (insert "i")
12018             (let ((overlays (and (fboundp 'overlays-at)
12019                                  (overlays-at (point-min)))))
12020               (while overlays
12021                 (delete-overlay (car overlays))
12022                 (setq overlays (cdr overlays))))
12023             (erase-buffer)        
12024             (if (gnus-request-article article group (current-buffer))
12025                 (progn
12026                   (and gnus-keep-backlog 
12027                        (gnus-backlog-enter-article 
12028                         group article (current-buffer)))
12029                   'article))))
12030          ;; It was a pseudo.
12031          (t article)))
12032     (setq gnus-original-article (cons group article))
12033     (let (buffer-read-only)
12034       (erase-buffer)
12035       ;; There may be some overlays that we have to kill...
12036       (insert "i")
12037       (let ((overlays (and (fboundp 'overlays-at)
12038                            (overlays-at (point-min)))))
12039         (while overlays
12040           (delete-overlay (pop overlays))))
12041       (erase-buffer)
12042       (insert-buffer-substring gnus-original-article-buffer))))
12043
12044 (defun gnus-read-header (id)
12045   "Read the headers of article ID and enter them into the Gnus system."
12046   (let ((group gnus-newsgroup-name)
12047         (headers gnus-newsgroup-headers)
12048         header where)
12049     ;; First we check to see whether the header in question is already
12050     ;; fetched. 
12051     (if (stringp id)
12052         ;; This is a Message-ID.
12053         (while headers
12054           (if (string= id (mail-header-id (car headers)))
12055               (setq header (car headers)
12056                     headers nil)
12057             (setq headers (cdr headers))))
12058       ;; This is an article number.
12059       (while headers
12060         (if (= id (mail-header-number (car headers)))
12061             (setq header (car headers)
12062                   headers nil)
12063           (setq headers (cdr headers)))))
12064     (if header
12065         ;; We have found the header.
12066         header
12067       ;; We have to really fetch the header to this article.
12068       (when (setq where
12069                   (if (gnus-check-backend-function 'request-head group)
12070                       (gnus-request-head id group)
12071                     (gnus-request-article id group)))
12072         (save-excursion
12073           (set-buffer nntp-server-buffer)
12074           (and (search-forward "\n\n" nil t)
12075                (delete-region (1- (point)) (point-max)))
12076           (goto-char (point-max))
12077           (insert ".\n")
12078           (goto-char (point-min))
12079           (insert "211 "
12080                   (int-to-string
12081                    (cond
12082                     ((numberp id)
12083                      id)
12084                     ((cdr where)
12085                      (cdr where))
12086                     (t
12087                      gnus-reffed-article-number)))
12088                   " Article retrieved.\n"))
12089         (if (not (setq header (car (gnus-get-newsgroup-headers))))
12090             () ; Malformed head.
12091           (if (and (stringp id)
12092                    (not (string= (gnus-group-real-name group)
12093                                  (car where))))
12094               ;; If we fetched by Message-ID and the article came
12095               ;; from a different group, we fudge some bogus article
12096               ;; numbers for this article.
12097               (mail-header-set-number header gnus-reffed-article-number))
12098           (decf gnus-reffed-article-number)
12099           (push header gnus-newsgroup-headers)
12100           (setq gnus-current-headers header)
12101           (push (mail-header-number header) gnus-newsgroup-limit)
12102           header)))))
12103
12104 (defun gnus-article-prepare (article &optional all-headers header)
12105   "Prepare ARTICLE in article mode buffer.
12106 ARTICLE should either be an article number or a Message-ID.
12107 If ARTICLE is an id, HEADER should be the article headers.
12108 If ALL-HEADERS is non-nil, no headers are hidden."
12109   (save-excursion
12110     ;; Make sure we start in a summary buffer.
12111     (or (eq major-mode 'gnus-summary-mode)
12112         (set-buffer gnus-summary-buffer))
12113     (setq gnus-summary-buffer (current-buffer))
12114     ;; Make sure the connection to the server is alive.
12115     (or (gnus-server-opened (gnus-find-method-for-group gnus-newsgroup-name))
12116         (progn
12117           (gnus-check-server 
12118            (gnus-find-method-for-group gnus-newsgroup-name))
12119           (gnus-request-group gnus-newsgroup-name t)))
12120     (let* ((article (if header (mail-header-number header) article))
12121            (summary-buffer (current-buffer))
12122            (internal-hook gnus-article-internal-prepare-hook)
12123            (group gnus-newsgroup-name)
12124            result)
12125       (save-excursion
12126         (gnus-article-setup-buffer)
12127         (set-buffer gnus-article-buffer)
12128         (if (not (setq result (let ((buffer-read-only nil))
12129                                 (gnus-request-article-this-buffer 
12130                                  article group))))
12131             ;; There is no such article.
12132             (save-excursion
12133               (if (not (numberp article))
12134                   ()
12135                 (setq gnus-article-current 
12136                       (cons gnus-newsgroup-name article))
12137                 (set-buffer gnus-summary-buffer)
12138                 (setq gnus-current-article article)
12139                 (gnus-summary-mark-article article gnus-canceled-mark))
12140               (gnus-message 
12141                1 "No such article (may have expired or been canceled)")
12142               (ding)
12143               nil)
12144           (if (or (eq result 'pseudo) (eq result 'nneething))
12145               (progn
12146                 (save-excursion
12147                   (set-buffer summary-buffer)
12148                   (setq gnus-last-article gnus-current-article
12149                         gnus-newsgroup-history (cons gnus-current-article
12150                                                      gnus-newsgroup-history)
12151                         gnus-current-article 0
12152                         gnus-current-headers nil
12153                         gnus-article-current nil)
12154                   (if (eq result 'nneething)
12155                       (gnus-configure-windows 'summary)
12156                     (gnus-configure-windows 'article))
12157                   (gnus-set-global-variables))
12158                 (gnus-set-mode-line 'article))
12159             ;; The result from the `request' was an actual article -
12160             ;; or at least some text that is now displayed in the
12161             ;; article buffer.
12162             (if (and (numberp article)
12163                      (not (eq article gnus-current-article)))
12164                 ;; Seems like a new article has been selected.
12165                 ;; `gnus-current-article' must be an article number.
12166                 (save-excursion
12167                   (set-buffer summary-buffer)
12168                   (setq gnus-last-article gnus-current-article
12169                         gnus-newsgroup-history (cons gnus-current-article
12170                                                      gnus-newsgroup-history)
12171                         gnus-current-article article
12172                         gnus-current-headers 
12173                         (gnus-summary-article-header gnus-current-article)
12174                         gnus-article-current 
12175                         (cons gnus-newsgroup-name gnus-current-article))
12176                   (gnus-summary-show-thread)
12177                   (run-hooks 'gnus-mark-article-hook)
12178                   (gnus-set-mode-line 'summary)
12179                   (and (gnus-visual-p 'article-highlight 'highlight)
12180                        (run-hooks 'gnus-visual-mark-article-hook))
12181                   ;; Set the global newsgroup variables here.
12182                   ;; Suggested by Jim Sisolak
12183                   ;; <sisolak@trans4.neep.wisc.edu>.
12184                   (gnus-set-global-variables)
12185                   (setq gnus-have-all-headers 
12186                         (or all-headers gnus-show-all-headers))
12187                   (and gnus-use-cache 
12188                        (vectorp (gnus-summary-article-header article))
12189                        (gnus-cache-possibly-enter-article
12190                         group article
12191                         (gnus-summary-article-header article)
12192                         (memq article gnus-newsgroup-marked)
12193                         (memq article gnus-newsgroup-dormant)
12194                         (memq article gnus-newsgroup-unreads)))))
12195             ;; Hooks for getting information from the article.
12196             ;; This hook must be called before being narrowed.
12197             (let (buffer-read-only)
12198               (run-hooks 'internal-hook)
12199               (run-hooks 'gnus-article-prepare-hook)
12200               ;; Decode MIME message.
12201               (if gnus-show-mime
12202                   (if (or (not gnus-strict-mime)
12203                           (gnus-fetch-field "Mime-Version"))
12204                       (funcall gnus-show-mime-method)
12205                     (funcall gnus-decode-encoded-word-method)))
12206               ;; Perform the article display hooks.
12207               (run-hooks 'gnus-article-display-hook))
12208             ;; Do page break.
12209             (goto-char (point-min))
12210             (and gnus-break-pages (gnus-narrow-to-page))
12211             (gnus-set-mode-line 'article)
12212             (gnus-configure-windows 'article)
12213             (goto-char (point-min))
12214             t))))))
12215
12216 (defun gnus-article-show-all-headers ()
12217   "Show all article headers in article mode buffer."
12218   (save-excursion 
12219     (gnus-article-setup-buffer)
12220     (set-buffer gnus-article-buffer)
12221     (let ((buffer-read-only nil))
12222       (remove-text-properties (point-min) (point-max) 
12223                               gnus-hidden-properties))))
12224
12225 (defun gnus-article-hide-headers-if-wanted ()
12226   "Hide unwanted headers if `gnus-have-all-headers' is nil.
12227 Provided for backwards compatability."
12228   (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers)
12229       gnus-inhibit-hiding
12230       (gnus-article-hide-headers)))
12231
12232 (defun gnus-article-hide-headers (&optional delete)
12233   "Hide unwanted headers and possibly sort them as well."
12234   (interactive "P")
12235   (unless gnus-inhibit-hiding
12236     (save-excursion
12237       (set-buffer gnus-article-buffer)
12238       (save-restriction
12239         (let ((sorted gnus-sorted-header-list)
12240               (buffer-read-only nil)
12241               want-list beg want-l)
12242           ;; First we narrow to just the headers.
12243           (widen)
12244           (goto-char (point-min))
12245           ;; Hide any "From " lines at the beginning of (mail) articles. 
12246           (while (looking-at "From ")
12247             (forward-line 1))
12248           (or (bobp) 
12249               (add-text-properties (point-min) (point) gnus-hidden-properties))
12250           ;; Then treat the rest of the header lines.
12251           (narrow-to-region 
12252            (point) 
12253            (progn (search-forward "\n\n" nil t) (forward-line -1) (point)))
12254           ;; Then we use the two regular expressions
12255           ;; `gnus-ignored-headers' and `gnus-visible-headers' to
12256           ;; select which header lines is to remain visible in the
12257           ;; article buffer.
12258           (goto-char (point-min))
12259           (while (re-search-forward "^[^ \t]*:" nil t)
12260             (beginning-of-line)
12261             ;; We add the headers we want to keep to a list and delete
12262             ;; them from the buffer.
12263             (if (or (and (stringp gnus-visible-headers)
12264                          (looking-at gnus-visible-headers))
12265                     (and (not (stringp gnus-visible-headers))
12266                          (stringp gnus-ignored-headers)
12267                          (not (looking-at gnus-ignored-headers))))
12268                 (progn
12269                   (setq beg (point))
12270                   (forward-line 1)
12271                   ;; Be sure to get multi-line headers...
12272                   (re-search-forward "^[^ \t]*:" nil t)
12273                   (beginning-of-line)
12274                   (setq want-list 
12275                         (cons (buffer-substring beg (point)) want-list))
12276                   (delete-region beg (point))
12277                   (goto-char beg))
12278               (forward-line 1)))
12279           ;; Next we perform the sorting by looking at
12280           ;; `gnus-sorted-header-list'. 
12281           (goto-char (point-min))
12282           (while (and sorted want-list)
12283             (setq want-l want-list)
12284             (while (and want-l
12285                         (not (string-match (car sorted) (car want-l))))
12286               (setq want-l (cdr want-l)))
12287             (if want-l 
12288                 (progn
12289                   (insert (car want-l))
12290                   (setq want-list (delq (car want-l) want-list))))
12291             (setq sorted (cdr sorted)))
12292           ;; Any headers that were not matched by the sorted list we
12293           ;; just tack on the end of the visible header list.
12294           (while want-list
12295             (insert (car want-list))
12296             (setq want-list (cdr want-list)))
12297           ;; And finally we make the unwanted headers invisible.
12298           (if delete
12299               (delete-region (point) (point-max))
12300             ;; Suggested by Sudish Joseph <joseph@cis.ohio-state.edu>.
12301             (add-text-properties 
12302              (point) (point-max) gnus-hidden-properties)))))))
12303
12304 ;; Written by Per Abrahamsen <amanda@iesd.auc.dk>.
12305 (defun gnus-article-treat-overstrike ()
12306   "Translate overstrikes into bold text."
12307   (interactive)
12308   (save-excursion
12309     (set-buffer gnus-article-buffer)
12310     (let ((buffer-read-only nil))
12311       (while (search-forward "\b" nil t)
12312         (let ((next (following-char))
12313               (previous (char-after (- (point) 2))))
12314           (cond ((eq next previous)
12315                  (put-text-property (- (point) 2) (point) 'invisible t)
12316                  (put-text-property (point) (1+ (point)) 'face 'bold))
12317                 ((eq next ?_)
12318                  (put-text-property (1- (point)) (1+ (point)) 'invisible t)
12319                  (put-text-property
12320                   (- (point) 2) (1- (point)) 'face 'underline))
12321                 ((eq previous ?_)
12322                  (put-text-property (- (point) 2) (point) 'invisible t)
12323                  (put-text-property 
12324                   (point) (1+ (point))  'face 'underline))))))))
12325
12326 (defun gnus-article-word-wrap ()
12327   "Format too long lines."
12328   (interactive)
12329   (save-excursion
12330     (set-buffer gnus-article-buffer)
12331     (let ((buffer-read-only nil)
12332           p)
12333       (widen)
12334       (goto-char (point-min))
12335       (search-forward "\n\n" nil t)
12336       (end-of-line 1)
12337       (let ((paragraph-start "^[>|#:<;* ]*[ \t]*$")
12338             (adaptive-fill-regexp "[ \t]*\\([|#:<;>*]+ *\\)?")
12339             (adaptive-fill-mode t))
12340         (while (not (eobp))
12341           (and (>= (current-column) (min fill-column (window-width)))
12342                (/= (preceding-char) ?:)
12343                (fill-paragraph nil))
12344           (end-of-line 2))))))
12345
12346 (defun gnus-article-remove-cr ()
12347   "Remove carriage returns from an article."
12348   (interactive)
12349   (save-excursion
12350     (set-buffer gnus-article-buffer)
12351     (let ((buffer-read-only nil))
12352       (goto-char (point-min))
12353       (while (search-forward "\r" nil t)
12354         (replace-match "" t t)))))
12355
12356 (defun gnus-article-display-x-face (&optional force)
12357   "Look for an X-Face header and display it if present."
12358   (interactive (list 'force))
12359   (save-excursion
12360     (set-buffer gnus-article-buffer)
12361     ;; Delete the old process, if any.
12362     (when (process-status "gnus-x-face")
12363       (delete-process "gnus-x-face"))
12364     (let ((inhibit-point-motion-hooks t)
12365           (case-fold-search nil)
12366           from)
12367       (save-restriction
12368         (gnus-narrow-to-headers)
12369         (setq from (mail-fetch-field "from"))
12370         (goto-char (point-min))
12371         (when (and gnus-article-x-face-command 
12372                    (or force
12373                        ;; Check whether this face is censored.
12374                        (not gnus-article-x-face-too-ugly)
12375                        (and gnus-article-x-face-too-ugly from
12376                             (not (string-match gnus-article-x-face-too-ugly 
12377                                                from))))
12378                    ;; Has to be present.
12379                    (re-search-forward "^X-Face: " nil t))
12380           ;; We now have the area of the buffer where the X-Face is stored.
12381           (let ((beg (point))
12382                 (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t))))
12383             ;; We display the face.
12384             (if (symbolp gnus-article-x-face-command)
12385                 ;; The command is a lisp function, so we call it.
12386                 (if (fboundp gnus-article-x-face-command)
12387                     (funcall gnus-article-x-face-command beg end)
12388                   (error "%s is not a function" gnus-article-x-face-command))
12389               ;; The command is a string, so we interpret the command
12390               ;; as a, well, command, and fork it off.
12391               (let ((process-connection-type nil))
12392                 (process-kill-without-query
12393                  (start-process 
12394                   "gnus-x-face" nil "sh" "-c" gnus-article-x-face-command))
12395                 (process-send-region "gnus-x-face" beg end)
12396                 (process-send-eof "gnus-x-face")))))))))
12397
12398 (defun gnus-headers-decode-quoted-printable ()
12399   "Hack to remove QP encoding from headers."
12400   (let ((case-fold-search t)
12401         (inhibit-point-motion-hooks t)
12402         string)
12403     (goto-char (point-min))
12404     (while (re-search-forward "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t)
12405       (setq string (match-string 1))
12406       (narrow-to-region (match-beginning 0) (match-end 0))
12407       (delete-region (point-min) (point-max))
12408       (insert string)
12409       (gnus-mime-decode-quoted-printable (goto-char (point-min)) (point-max))
12410       (subst-char-in-region (point-min) (point-max) ?_ ? )
12411       (widen)
12412       (goto-char (point-min)))))
12413        
12414 (defun gnus-article-de-quoted-unreadable (&optional force)
12415   "Do a naive translation of a quoted-printable-encoded article.
12416 This is in no way, shape or form meant as a replacement for real MIME
12417 processing, but is simply a stop-gap measure until MIME support is
12418 written.
12419 If FORCE, decode the article whether it is marked as quoted-printable
12420 or not." 
12421   (interactive (list 'force))
12422   (save-excursion
12423     (set-buffer gnus-article-buffer)
12424     (let ((case-fold-search t)
12425           (buffer-read-only nil)
12426           (type (gnus-fetch-field "content-transfer-encoding")))
12427       (when (or force
12428                 (and type (string-match "quoted-printable" type)))
12429         (goto-char (point-min))
12430         (search-forward "\n\n" nil 'move)
12431         (gnus-mime-decode-quoted-printable (point) (point-max))
12432         (gnus-headers-decode-quoted-printable)))))
12433
12434 (defun gnus-mime-decode-quoted-printable (from to)
12435   "Decode Quoted-Printable in the region between FROM and TO."
12436   (goto-char from)
12437   (while (search-forward "=" to t)
12438     (cond ((eq (following-char) ?\n)
12439            (delete-char -1)
12440            (delete-char 1))
12441           ((looking-at "[0-9A-F][0-9A-F]")
12442            (delete-char -1)
12443            (insert (hexl-hex-string-to-integer
12444                     (buffer-substring (point) (+ 2 (point)))))
12445            (delete-char 2))
12446           ((looking-at "=")
12447            (delete-char 1))
12448           ((gnus-message 3 "Malformed MIME quoted-printable message")))))
12449
12450 (defun gnus-article-hide-pgp ()
12451   "Hide any PGP headers and signatures in the current article."
12452   (interactive)
12453   (save-excursion
12454     (set-buffer gnus-article-buffer)
12455     (let (buffer-read-only beg end)
12456       (widen)
12457       (goto-char (point-min))
12458       ;; Hide the "header".
12459       (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t)
12460            (add-text-properties (match-beginning 0) (match-end 0)
12461                                 gnus-hidden-properties))
12462       (setq beg (point))
12463       ;; Hide the actual signature.
12464       (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t)
12465            (setq end (match-beginning 0))
12466            (add-text-properties 
12467             (match-beginning 0)
12468             (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t)
12469                 (match-end 0)
12470               ;; Perhaps we shouldn't hide to the end of the buffer
12471               ;; if there is no end to the signature?
12472               (point-max))
12473             gnus-hidden-properties))
12474       (when (and beg end)
12475         (narrow-to-region beg end)
12476         (goto-char (point-min))
12477         (while (re-search-forward "^- " nil t)
12478           (replace-match "" t t))
12479         (widen)))))
12480
12481 (defvar gnus-article-time-units
12482   `((year . ,(* 365.25 24 60 60))
12483     (week . ,(* 7 24 60 60))
12484     (day . ,(* 24 60 60))
12485     (hour . ,(* 60 60))
12486     (minute . 60)
12487     (second . 1))
12488   "Mapping from time units to seconds.")
12489
12490 (defun gnus-article-date-ut (&optional type highlight)
12491   "Convert DATE date to universal time in the current article.
12492 If TYPE is `local', convert to local time; if it is `lapsed', output
12493 how much time has lapsed since DATE."
12494   (interactive (list 'ut t))
12495   (let ((date (mail-header-date (or gnus-current-headers 
12496                                     (gnus-summary-article-header) "")))
12497         (date-regexp "^Date: \\|^X-Sent: ")
12498         (inhibit-point-motion-hooks t))
12499     (when (and date (not (string= date "")))
12500       (save-excursion
12501         (set-buffer gnus-article-buffer)
12502         (save-restriction
12503           (gnus-narrow-to-headers)
12504           (let ((buffer-read-only nil))
12505             ;; Delete any old Date headers.
12506             (if (zerop (nnheader-remove-header date-regexp t))
12507                 (beginning-of-line)
12508               (goto-char (point-max)))
12509             (insert
12510              (cond 
12511               ;; Convert to the local timezone.  We have to slap a
12512               ;; `condition-case' round the calls to the timezone
12513               ;; functions since they aren't particularly resistant to
12514               ;; buggy dates.
12515               ((eq type 'local)
12516                (concat "Date: " (condition-case ()
12517                                     (timezone-make-date-arpa-standard date)
12518                                   (error date))
12519                        "\n"))
12520               ;; Convert to Universal Time.
12521               ((eq type 'ut)
12522                (concat "Date: "
12523                        (condition-case ()
12524                            (timezone-make-date-arpa-standard date nil "UT")
12525                          (error date))
12526                        "\n"))
12527               ;; Get the original date from the article.
12528               ((eq type 'original)
12529                (concat "Date: " date "\n"))
12530               ;; Do an X-Sent lapsed format.
12531               ((eq type 'lapsed)
12532                ;; If the date is seriously mangled, the timezone
12533                ;; functions are liable to bug out, so we condition-case
12534                ;; the entire thing.  
12535                (let* ((real-sec (condition-case ()
12536                                     (- (gnus-seconds-since-epoch 
12537                                         (timezone-make-date-arpa-standard
12538                                          (current-time-string) 
12539                                          (current-time-zone) "UT"))
12540                                        (gnus-seconds-since-epoch 
12541                                         (timezone-make-date-arpa-standard 
12542                                          date nil "UT")))
12543                                   (error 0)))
12544                       (sec (abs real-sec))
12545                       num prev)
12546                  (if (zerop sec)
12547                      "X-Sent: Now\n"
12548                    (concat
12549                     "X-Sent: "
12550                     ;; This is a bit convoluted, but basically we go
12551                     ;; through the time units for years, weeks, etc,
12552                     ;; and divide things to see whether that results
12553                     ;; in positive answers.
12554                     (mapconcat 
12555                      (lambda (unit)
12556                        (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
12557                            ;; The (remaining) seconds are too few to
12558                            ;; be divided into this time unit.
12559                            "" 
12560                          ;; It's big enough, so we output it.
12561                          (setq sec (- sec (* num (cdr unit))))
12562                          (prog1
12563                              (concat (if prev ", " "") (int-to-string 
12564                                                         (floor num))
12565                                      " " (symbol-name (car unit))
12566                                      (if (> num 1) "s" ""))
12567                            (setq prev t))))
12568                      gnus-article-time-units "")
12569                     ;; If dates are odd, then it might appear like the
12570                     ;; article was sent in the future.
12571                     (if (> real-sec 0)
12572                         " ago\n"
12573                       " in the future\n")))))
12574               (t
12575                (error "Unknown conversion type: %s" type)))))
12576           ;; Do highlighting.
12577           (when (and highlight (gnus-visual-p 'article-highlight 'highlight))
12578             (gnus-article-highlight-headers)))))))
12579
12580 (defun gnus-article-date-local (&optional highlight)
12581   "Convert the current article date to the local timezone."
12582   (interactive (list t))
12583   (gnus-article-date-ut 'local highlight))
12584
12585 (defun gnus-article-date-original (&optional highlight)
12586   "Convert the current article date to what it was originally.
12587 This is only useful if you have used some other date conversion
12588 function and want to see what the date was before converting."
12589   (interactive (list t))
12590   (gnus-article-date-ut 'original highlight))
12591
12592 (defun gnus-article-date-lapsed (&optional highlight)
12593   "Convert the current article date to time lapsed since it was sent."
12594   (interactive (list t))
12595   (gnus-article-date-ut 'lapsed highlight))
12596
12597 (defun gnus-article-maybe-highlight ()
12598   "Do some article highlighting if `gnus-visual' is non-nil."
12599   (if (gnus-visual-p 'article-highlight 'highlight)
12600       (gnus-article-highlight-some)))
12601
12602 ;; Article savers.
12603
12604 (defun gnus-output-to-rmail (file-name)
12605   "Append the current article to an Rmail file named FILE-NAME."
12606   (require 'rmail)
12607   ;; Most of these codes are borrowed from rmailout.el.
12608   (setq file-name (expand-file-name file-name))
12609   (setq rmail-default-rmail-file file-name)
12610   (let ((artbuf (current-buffer))
12611         (tmpbuf (get-buffer-create " *Gnus-output*")))
12612     (save-excursion
12613       (or (get-file-buffer file-name)
12614           (file-exists-p file-name)
12615           (if (gnus-yes-or-no-p
12616                (concat "\"" file-name "\" does not exist, create it? "))
12617               (let ((file-buffer (create-file-buffer file-name)))
12618                 (save-excursion
12619                   (set-buffer file-buffer)
12620                   (rmail-insert-rmail-file-header)
12621                   (let ((require-final-newline nil))
12622                     (write-region (point-min) (point-max) file-name t 1)))
12623                 (kill-buffer file-buffer))
12624             (error "Output file does not exist")))
12625       (set-buffer tmpbuf)
12626       (buffer-disable-undo (current-buffer))
12627       (erase-buffer)
12628       (insert-buffer-substring artbuf)
12629       (gnus-convert-article-to-rmail)
12630       ;; Decide whether to append to a file or to an Emacs buffer.
12631       (let ((outbuf (get-file-buffer file-name)))
12632         (if (not outbuf)
12633             (append-to-file (point-min) (point-max) file-name)
12634           ;; File has been visited, in buffer OUTBUF.
12635           (set-buffer outbuf)
12636           (let ((buffer-read-only nil)
12637                 (msg (and (boundp 'rmail-current-message)
12638                           (symbol-value 'rmail-current-message))))
12639             ;; If MSG is non-nil, buffer is in RMAIL mode.
12640             (if msg
12641                 (progn (widen)
12642                        (narrow-to-region (point-max) (point-max))))
12643             (insert-buffer-substring tmpbuf)
12644             (if msg
12645                 (progn
12646                   (goto-char (point-min))
12647                   (widen)
12648                   (search-backward "\^_")
12649                   (narrow-to-region (point) (point-max))
12650                   (goto-char (1+ (point-min)))
12651                   (rmail-count-new-messages t)
12652                   (rmail-show-message msg)))))))
12653     (kill-buffer tmpbuf)))
12654
12655 (defun gnus-output-to-file (file-name)
12656   "Append the current article to a file named FILE-NAME."
12657   (setq file-name (expand-file-name file-name))
12658   (let ((artbuf (current-buffer))
12659         (tmpbuf (get-buffer-create " *Gnus-output*")))
12660     (save-excursion
12661       (set-buffer tmpbuf)
12662       (buffer-disable-undo (current-buffer))
12663       (erase-buffer)
12664       (insert-buffer-substring artbuf)
12665       ;; Append newline at end of the buffer as separator, and then
12666       ;; save it to file.
12667       (goto-char (point-max))
12668       (insert "\n")
12669       (append-to-file (point-min) (point-max) file-name))
12670     (kill-buffer tmpbuf)))
12671
12672 (defun gnus-convert-article-to-rmail ()
12673   "Convert article in current buffer to Rmail message format."
12674   (let ((buffer-read-only nil))
12675     ;; Convert article directly into Babyl format.
12676     ;; Suggested by Rob Austein <sra@lcs.mit.edu>
12677     (goto-char (point-min))
12678     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
12679     (while (search-forward "\n\^_" nil t) ;single char
12680       (replace-match "\n^_" t t))       ;2 chars: "^" and "_"
12681     (goto-char (point-max))
12682     (insert "\^_")))
12683
12684 (defun gnus-narrow-to-page (&optional arg)
12685   "Make text outside current page invisible except for page delimiter.
12686 A numeric arg specifies to move forward or backward by that many pages,
12687 thus showing a page other than the one point was originally in."
12688   (interactive "P")
12689   (setq arg (if arg (prefix-numeric-value arg) 0))
12690   (save-excursion
12691     (forward-page -1)                   ;Beginning of current page.
12692     (widen)
12693     (if (> arg 0)
12694         (forward-page arg)
12695       (if (< arg 0)
12696           (forward-page (1- arg))))
12697     ;; Find the end of the page.
12698     (forward-page)
12699     ;; If we stopped due to end of buffer, stay there.
12700     ;; If we stopped after a page delimiter, put end of restriction
12701     ;; at the beginning of that line.
12702     ;; These are commented out.
12703     ;;    (if (save-excursion (beginning-of-line)
12704     ;;                  (looking-at page-delimiter))
12705     ;;  (beginning-of-line))
12706     (narrow-to-region (point)
12707                       (progn
12708                         ;; Find the top of the page.
12709                         (forward-page -1)
12710                         ;; If we found beginning of buffer, stay there.
12711                         ;; If extra text follows page delimiter on same line,
12712                         ;; include it.
12713                         ;; Otherwise, show text starting with following line.
12714                         (if (and (eolp) (not (bobp)))
12715                             (forward-line 1))
12716                         (point)))))
12717
12718 (defun gnus-gmt-to-local ()
12719   "Rewrite Date header described in GMT to local in current buffer.
12720 Intended to be used with gnus-article-prepare-hook."
12721   (save-excursion
12722     (save-restriction
12723       (widen)
12724       (goto-char (point-min))
12725       (narrow-to-region (point-min)
12726                         (progn (search-forward "\n\n" nil 'move) (point)))
12727       (goto-char (point-min))
12728       (if (re-search-forward "^Date:[ \t]\\(.*\\)$" nil t)
12729           (let ((buffer-read-only nil)
12730                 (date (buffer-substring-no-properties
12731                        (match-beginning 1) (match-end 1))))
12732             (delete-region (match-beginning 1) (match-end 1))
12733             (insert
12734              (timezone-make-date-arpa-standard 
12735               date nil (current-time-zone))))))))
12736
12737 ;; Article mode commands
12738
12739 (defun gnus-article-next-page (&optional lines)
12740   "Show next page of current article.
12741 If end of article, return non-nil.  Otherwise return nil.
12742 Argument LINES specifies lines to be scrolled up."
12743   (interactive "P")
12744   (move-to-window-line -1)
12745   ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo)
12746   (if (save-excursion
12747         (end-of-line)
12748         (and (pos-visible-in-window-p)  ;Not continuation line.
12749              (eobp)))
12750       ;; Nothing in this page.
12751       (if (or (not gnus-break-pages)
12752               (save-excursion
12753                 (save-restriction
12754                   (widen) (forward-line 1) (eobp)))) ;Real end-of-buffer?
12755           t                             ;Nothing more.
12756         (gnus-narrow-to-page 1)         ;Go to next page.
12757         nil)
12758     ;; More in this page.
12759     (condition-case ()
12760         (scroll-up lines)
12761       (end-of-buffer
12762        ;; Long lines may cause an end-of-buffer error.
12763        (goto-char (point-max))))
12764     nil))
12765
12766 (defun gnus-article-prev-page (&optional lines)
12767   "Show previous page of current article.
12768 Argument LINES specifies lines to be scrolled down."
12769   (interactive "P")
12770   (move-to-window-line 0)
12771   (if (and gnus-break-pages
12772            (bobp)
12773            (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
12774       (progn
12775         (gnus-narrow-to-page -1)        ;Go to previous page.
12776         (goto-char (point-max))
12777         (recenter -1))
12778     (scroll-down lines)))
12779
12780 (defun gnus-article-refer-article ()
12781   "Read article specified by message-id around point."
12782   (interactive)
12783   (search-forward ">" nil t)            ;Move point to end of "<....>".
12784   (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t)
12785       (let ((message-id (match-string 1)))
12786         (set-buffer gnus-summary-buffer)
12787         (gnus-summary-refer-article message-id))
12788     (error "No references around point")))
12789
12790 (defun gnus-article-show-summary ()
12791   "Reconfigure windows to show summary buffer."
12792   (interactive)
12793   (gnus-configure-windows 'article)
12794   (gnus-summary-goto-subject gnus-current-article))
12795
12796 (defun gnus-article-describe-briefly ()
12797   "Describe article mode commands briefly."
12798   (interactive)
12799   (gnus-message 6
12800                 (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")))
12801
12802 (defun gnus-article-summary-command ()
12803   "Execute the last keystroke in the summary buffer."
12804   (interactive)
12805   (let ((obuf (current-buffer))
12806         (owin (current-window-configuration))
12807         func)
12808     (switch-to-buffer gnus-summary-buffer 'norecord)
12809     (setq func (lookup-key (current-local-map) (this-command-keys)))
12810     (call-interactively func)
12811     (set-buffer obuf)
12812     (set-window-configuration owin)
12813     (set-window-point (get-buffer-window (current-buffer)) (point))))
12814
12815 (defun gnus-article-summary-command-nosave ()
12816   "Execute the last keystroke in the summary buffer."
12817   (interactive)
12818   (let (func)
12819     (pop-to-buffer gnus-summary-buffer 'norecord)
12820     (setq func (lookup-key (current-local-map) (this-command-keys)))
12821     (call-interactively func)))
12822
12823 \f
12824 ;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti)
12825
12826 ;;;###autoload
12827 (defalias 'gnus-batch-kill 'gnus-batch-score)
12828 ;;;###autoload
12829 (defun gnus-batch-score ()
12830   "Run batched scoring.
12831 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
12832 Newsgroups is a list of strings in Bnews format.  If you want to score
12833 the comp hierarchy, you'd say \"comp.all\".  If you would not like to
12834 score the alt hierarchy, you'd say \"!alt.all\"."
12835   (interactive)
12836   (let* ((yes-and-no
12837           (gnus-newsrc-parse-options
12838            (apply (function concat)
12839                   (mapcar (lambda (g) (concat g " "))
12840                           command-line-args-left))))
12841          (gnus-expert-user t)
12842          (nnmail-spool-file nil)
12843          (gnus-use-dribble-file nil)
12844          (yes (car yes-and-no))
12845          (no (cdr yes-and-no))
12846          group newsrc entry
12847          ;; Disable verbose message.
12848          gnus-novice-user gnus-large-newsgroup)
12849     ;; Eat all arguments.
12850     (setq command-line-args-left nil)
12851     ;; Start Gnus.
12852     (gnus)
12853     ;; Apply kills to specified newsgroups in command line arguments.
12854     (setq newsrc (cdr gnus-newsrc-alist))
12855     (while newsrc
12856       (setq group (car (car newsrc)))
12857       (setq entry (gnus-gethash group gnus-newsrc-hashtb))
12858       (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed)
12859                (and (car entry)
12860                     (or (eq (car entry) t)
12861                         (not (zerop (car entry)))))
12862                (if yes (string-match yes group) t)
12863                (or (null no) (not (string-match no group))))
12864           (progn
12865             (gnus-summary-read-group group nil t nil t)
12866             (and (eq (current-buffer) (get-buffer gnus-summary-buffer))
12867                  (gnus-summary-exit))))
12868       (setq newsrc (cdr newsrc)))
12869     ;; Exit Emacs.
12870     (switch-to-buffer gnus-group-buffer)
12871     (gnus-group-save-newsrc)))
12872
12873 (defun gnus-apply-kill-file ()
12874   "Apply a kill file to the current newsgroup.
12875 Returns the number of articles marked as read."
12876   (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
12877           (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
12878       (gnus-apply-kill-file-internal)
12879     0))
12880
12881 (defun gnus-kill-save-kill-buffer ()
12882   (save-excursion
12883     (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
12884       (if (get-file-buffer file)
12885           (progn
12886             (set-buffer (get-file-buffer file))
12887             (and (buffer-modified-p) (save-buffer))
12888             (kill-buffer (current-buffer)))))))
12889
12890 (defvar gnus-kill-file-name "KILL"
12891   "Suffix of the kill files.")
12892
12893 (defun gnus-newsgroup-kill-file (newsgroup)
12894   "Return the name of a kill file name for NEWSGROUP.
12895 If NEWSGROUP is nil, return the global kill file name instead."
12896   (cond ((or (null newsgroup)
12897              (string-equal newsgroup ""))
12898          ;; The global KILL file is placed at top of the directory.
12899          (expand-file-name gnus-kill-file-name
12900                            (or gnus-kill-files-directory "~/News")))
12901         ((gnus-use-long-file-name 'not-kill)
12902          ;; Append ".KILL" to newsgroup name.
12903          (expand-file-name (concat (gnus-newsgroup-saveable-name newsgroup)
12904                                    "." gnus-kill-file-name)
12905                            (or gnus-kill-files-directory "~/News")))
12906         (t
12907          ;; Place "KILL" under the hierarchical directory.
12908          (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
12909                                    "/" gnus-kill-file-name)
12910                            (or gnus-kill-files-directory "~/News")))))
12911
12912 \f
12913 ;;;
12914 ;;; Dribble file
12915 ;;;
12916
12917 (defvar gnus-dribble-ignore nil)
12918 (defvar gnus-dribble-eval-file nil)
12919
12920 (defun gnus-dribble-file-name ()
12921   (concat 
12922    (if gnus-dribble-directory
12923        (concat (file-name-as-directory gnus-dribble-directory)
12924                (file-name-nondirectory gnus-current-startup-file))
12925      gnus-current-startup-file)
12926    "-dribble"))
12927
12928 (defun gnus-dribble-enter (string)
12929   (if (and (not gnus-dribble-ignore)
12930            (or gnus-dribble-buffer
12931                gnus-slave)
12932            (buffer-name gnus-dribble-buffer))
12933       (let ((obuf (current-buffer)))
12934         (set-buffer gnus-dribble-buffer)
12935         (insert string "\n")
12936         (set-window-point (get-buffer-window (current-buffer)) (point-max))
12937         (set-buffer obuf))))
12938
12939 (defun gnus-dribble-read-file ()
12940   (let ((dribble-file (gnus-dribble-file-name)))
12941     (save-excursion 
12942       (set-buffer (setq gnus-dribble-buffer 
12943                         (get-buffer-create 
12944                          (file-name-nondirectory dribble-file))))
12945       (gnus-add-current-to-buffer-list)
12946       (erase-buffer)
12947       (setq buffer-file-name dribble-file)
12948       (buffer-disable-undo (current-buffer))
12949       (bury-buffer (current-buffer))
12950       (set-buffer-modified-p nil)
12951       (let ((auto (make-auto-save-file-name))
12952             (gnus-dribble-ignore t))
12953         (if (or (file-exists-p auto) (file-exists-p dribble-file))
12954             (progn
12955               (if (file-newer-than-file-p auto dribble-file)
12956                   (setq dribble-file auto))
12957               (insert-file-contents dribble-file)
12958               (if (not (zerop (buffer-size)))
12959                   (set-buffer-modified-p t))
12960               (if (gnus-y-or-n-p 
12961                    "Auto-save file exists.  Do you want to read it? ")
12962                   (setq gnus-dribble-eval-file t))))))))
12963
12964 (defun gnus-dribble-eval-file ()
12965   (if (not gnus-dribble-eval-file)
12966       ()
12967     (setq gnus-dribble-eval-file nil)
12968     (save-excursion
12969       (let ((gnus-dribble-ignore t))
12970         (set-buffer gnus-dribble-buffer)
12971         (eval-buffer (current-buffer))))))
12972
12973 (defun gnus-dribble-delete-file ()
12974   (if (file-exists-p (gnus-dribble-file-name))
12975       (delete-file (gnus-dribble-file-name)))
12976   (if gnus-dribble-buffer
12977       (save-excursion
12978         (set-buffer gnus-dribble-buffer)
12979         (let ((auto (make-auto-save-file-name)))
12980           (if (file-exists-p auto)
12981               (delete-file auto))
12982           (erase-buffer)
12983           (set-buffer-modified-p nil)))))
12984
12985 (defun gnus-dribble-save ()
12986   (if (and gnus-dribble-buffer
12987            (buffer-name gnus-dribble-buffer))
12988       (save-excursion
12989         (set-buffer gnus-dribble-buffer)
12990         (save-buffer))))
12991
12992 (defun gnus-dribble-clear ()
12993   (save-excursion
12994     (if (gnus-buffer-exists-p gnus-dribble-buffer)
12995         (progn
12996           (set-buffer gnus-dribble-buffer)
12997           (erase-buffer)
12998           (set-buffer-modified-p nil)
12999           (setq buffer-saved-size (buffer-size))))))
13000
13001 ;;;
13002 ;;; Server Communication
13003 ;;;
13004
13005 (defun gnus-start-news-server (&optional confirm)
13006   "Open a method for getting news.
13007 If CONFIRM is non-nil, the user will be asked for an NNTP server."
13008   (let (how)
13009     (if gnus-current-select-method
13010         ;; Stream is already opened.
13011         nil
13012       ;; Open NNTP server.
13013       (if (null gnus-nntp-service) (setq gnus-nntp-server nil))
13014       (if confirm
13015           (progn
13016             ;; Read server name with completion.
13017             (setq gnus-nntp-server
13018                   (completing-read "NNTP server: "
13019                                    (mapcar (lambda (server) (list server))
13020                                            (cons (list gnus-nntp-server)
13021                                                  gnus-secondary-servers))
13022                                    nil nil gnus-nntp-server))))
13023
13024       (if (and gnus-nntp-server 
13025                (stringp gnus-nntp-server)
13026                (not (string= gnus-nntp-server "")))
13027           (setq gnus-select-method
13028                 (cond ((or (string= gnus-nntp-server "")
13029                            (string= gnus-nntp-server "::"))
13030                        (list 'nnspool (system-name)))
13031                       ((string-match "^:" gnus-nntp-server)
13032                        (list 'nnmh gnus-nntp-server 
13033                              (list 'nnmh-directory 
13034                                    (file-name-as-directory
13035                                     (expand-file-name
13036                                      (concat "~/" (substring
13037                                                    gnus-nntp-server 1)))))
13038                              (list 'nnmh-get-new-mail nil)))
13039                       (t
13040                        (list 'nntp gnus-nntp-server)))))
13041
13042       (setq how (car gnus-select-method))
13043       (cond ((eq how 'nnspool)
13044              (require 'nnspool)
13045              (gnus-message 5 "Looking up local news spool..."))
13046             ((eq how 'nnmh)
13047              (require 'nnmh)
13048              (gnus-message 5 "Looking up mh spool..."))
13049             (t
13050              (require 'nntp)))
13051       (setq gnus-current-select-method gnus-select-method)
13052       (run-hooks 'gnus-open-server-hook)
13053       (or 
13054        ;; gnus-open-server-hook might have opened it
13055        (gnus-server-opened gnus-select-method)  
13056        (gnus-open-server gnus-select-method)
13057        (gnus-y-or-n-p
13058         (format
13059          "%s open error: '%s'.  Continue? "
13060          (nth 1 gnus-select-method)
13061          (gnus-status-message gnus-select-method)))
13062        (progn
13063          (gnus-message 1 "Couldn't open server on %s" 
13064                        (nth 1 gnus-select-method))
13065          (ding)
13066          nil)))))
13067
13068 (defun gnus-check-server (&optional method)
13069   "Check whether the connection to METHOD is down.
13070 If METHOD is nil, use `gnus-select-method'.
13071 If it is down, start it up (again)."
13072   (let ((method (or method gnus-select-method)))
13073     ;; Transform virtual server names into select methods.
13074     (when (stringp method)
13075       (setq method (gnus-server-to-method method)))
13076     (if (gnus-server-opened method)
13077         ;; The stream is already opened.
13078         t
13079       ;; Open the server.
13080       (gnus-message 5 "Opening %s server on %s..." (car method) (nth 1 method))
13081       (run-hooks 'gnus-open-server-hook)
13082       (prog1
13083           (gnus-open-server method)
13084         (message "")))))
13085
13086 (defun gnus-get-function (method function)
13087   "Return a function symbol based on METHOD and FUNCTION."
13088   ;; Translate server names into methods.
13089   (when (stringp method)
13090     (setq method (gnus-server-to-method method)))
13091   (let ((func (intern (format "%s-%s" (car method) function))))
13092     ;; If the functions isn't bound, we require the backend in
13093     ;; question.  
13094     (unless (fboundp func)
13095       (require (car method))
13096       (unless (fboundp func)
13097         ;; This backend doesn't implement this function.
13098         (error "No such function: %s" func)))
13099     func))
13100
13101 ;;; Interface functions to the backends.
13102
13103 (defun gnus-open-server (method)
13104   "Open a connection to METHOD."
13105   (let ((elem (assoc method gnus-opened-servers)))
13106     ;; If this method was previously denied, we just return nil.
13107     (if (eq (nth 1 elem) 'denied)
13108         (progn
13109           (gnus-message 1 "Denied server")
13110           nil)
13111       ;; Open the server.
13112       (let ((result
13113              (funcall (gnus-get-function method 'open-server)
13114                       (nth 1 method) (nthcdr 2 method))))
13115         ;; If this hasn't been opened before, we add it to the list.
13116         (unless elem 
13117           (setq elem (list method nil)
13118                 gnus-opened-servers (cons elem gnus-opened-servers)))
13119         ;; Set the status of this server.
13120         (setcar (cdr elem) (if result 'ok 'denied))
13121         ;; Return the result from the "open" call.
13122         result))))
13123
13124 (defun gnus-close-server (method)
13125   "Close the connection to METHOD."
13126   (funcall (gnus-get-function method 'close-server) (nth 1 method)))
13127
13128 (defun gnus-request-list (method)
13129   "Request the active file from METHOD."
13130   (funcall (gnus-get-function method 'request-list) (nth 1 method)))
13131
13132 (defun gnus-request-list-newsgroups (method)
13133   "Request the newsgroups file from METHOD."
13134   (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method)))
13135
13136 (defun gnus-request-newgroups (date method)
13137   "Request all new groups since DATE from METHOD."
13138   (funcall (gnus-get-function method 'request-newgroups) 
13139            date (nth 1 method)))
13140
13141 (defun gnus-server-opened (method)
13142   "Check whether a connection to METHOD has been opened."
13143   (funcall (gnus-get-function method 'server-opened) (nth 1 method)))
13144
13145 (defun gnus-status-message (method)
13146   "Return the status message from METHOD.
13147 If METHOD is a string, it is interpreted as a group name.   The method
13148 this group uses will be queried."
13149   (let ((method (if (stringp method) (gnus-find-method-for-group method)
13150                   method)))
13151     (funcall (gnus-get-function method 'status-message) (nth 1 method))))
13152
13153 (defun gnus-request-group (group &optional dont-check)
13154   "Request GROUP.  If DONT-CHECK, no information is required."
13155   (let ((method (gnus-find-method-for-group group)))
13156     (funcall (gnus-get-function method 'request-group) 
13157              (gnus-group-real-name group) (nth 1 method) dont-check)))
13158
13159 (defun gnus-request-asynchronous (group &optional articles)
13160   "Request that GROUP behave asynchronously.
13161 ARTICLES is the `data' of the group."
13162   (let ((method (gnus-find-method-for-group group)))
13163     (funcall (gnus-get-function method 'request-asynchronous) 
13164              (gnus-group-real-name group) (nth 1 method) articles)))
13165
13166 (defun gnus-list-active-group (group)
13167   "Request active information on GROUP."
13168   (let ((method (gnus-find-method-for-group group))
13169         (func 'list-active-group))
13170     (when (gnus-check-backend-function func group)
13171       (funcall (gnus-get-function method func) 
13172                (gnus-group-real-name group) (nth 1 method)))))
13173
13174 (defun gnus-request-group-description (group)
13175   "Request a description of GROUP."
13176   (let ((method (gnus-find-method-for-group group))
13177         (func 'request-group-description))
13178     (when (gnus-check-backend-function func group)
13179       (funcall (gnus-get-function method func) 
13180                (gnus-group-real-name group) (nth 1 method)))))
13181
13182 (defun gnus-close-group (group)
13183   "Request the GROUP be closed."
13184   (let ((method (gnus-find-method-for-group group)))
13185     (funcall (gnus-get-function method 'close-group) 
13186              (gnus-group-real-name group) (nth 1 method))))
13187
13188 (defun gnus-retrieve-headers (articles group &optional fetch-old)
13189   "Request headers for ARTICLES in GROUP.
13190 If FETCH-OLD, retrieve all headers (or some subset thereof) in the group."
13191   (let ((method (gnus-find-method-for-group group)))
13192     (if (and gnus-use-cache (numberp (car articles)))
13193         (gnus-cache-retrieve-headers articles group)
13194       (funcall (gnus-get-function method 'retrieve-headers) 
13195                articles (gnus-group-real-name group) (nth 1 method)
13196                fetch-old))))
13197
13198 (defun gnus-retrieve-groups (groups method)
13199   "Request active information on GROUPS from METHOD."
13200   (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method)))
13201
13202 (defun gnus-request-article (article group &optional buffer)
13203   "Request the ARTICLE in GROUP.
13204 ARTICLE can either be an article number or an article Message-ID.
13205 If BUFFER, insert the article in that group."
13206   (let ((method (gnus-find-method-for-group group)))
13207     (funcall (gnus-get-function method 'request-article) 
13208              article (gnus-group-real-name group) (nth 1 method) buffer)))
13209
13210 (defun gnus-request-head (article group)
13211   "Request the head of ARTICLE in GROUP."
13212   (let ((method (gnus-find-method-for-group group)))
13213     (funcall (gnus-get-function method 'request-head) 
13214              article (gnus-group-real-name group) (nth 1 method))))
13215
13216 (defun gnus-request-body (article group)
13217   "Request the body of ARTICLE in GROUP."
13218   (let ((method (gnus-find-method-for-group group)))
13219     (funcall (gnus-get-function method 'request-body) 
13220              article (gnus-group-real-name group) (nth 1 method))))
13221
13222 (defun gnus-request-post (method)
13223   "Post the current buffer using METHOD."
13224   (funcall (gnus-get-function method 'request-post) (nth 1 method)))
13225
13226 (defun gnus-request-scan (group method)
13227   "Request a SCAN being performed in GROUP from METHOD.
13228 If GROUP is nil, all groups on METHOD are scanned."
13229   (let ((method (if group (gnus-find-method-for-group group) method)))
13230     (funcall (gnus-get-function method 'request-scan) 
13231              (and group (gnus-group-real-name group)) (nth 1 method))))
13232
13233 (defun gnus-request-update-info (info method)
13234   "Request that METHOD update INFO."
13235   (when (gnus-check-backend-function 'request-update-info method)
13236     (funcall (gnus-get-function method 'request-update-info) 
13237              (gnus-group-real-name (gnus-info-group info)) 
13238              info (nth 1 method))))
13239
13240 (defun gnus-request-expire-articles (articles group &optional force)
13241   (let ((method (gnus-find-method-for-group group)))
13242     (funcall (gnus-get-function method 'request-expire-articles) 
13243              articles (gnus-group-real-name group) (nth 1 method)
13244              force)))
13245
13246 (defun gnus-request-move-article 
13247   (article group server accept-function &optional last)
13248   (let ((method (gnus-find-method-for-group group)))
13249     (funcall (gnus-get-function method 'request-move-article) 
13250              article (gnus-group-real-name group) 
13251              (nth 1 method) accept-function last)))
13252
13253 (defun gnus-request-accept-article (group &optional last)
13254   (let ((func (if (symbolp group) group
13255                 (car (gnus-find-method-for-group group)))))
13256     (funcall (intern (format "%s-request-accept-article" func))
13257              (if (stringp group) (gnus-group-real-name group) group)
13258              last)))
13259
13260 (defun gnus-request-replace-article (article group buffer)
13261   (let ((func (car (gnus-find-method-for-group group))))
13262     (funcall (intern (format "%s-request-replace-article" func))
13263              article (gnus-group-real-name group) buffer)))
13264
13265 (defun gnus-request-create-group (group)
13266   (let ((method (gnus-find-method-for-group group)))
13267     (funcall (gnus-get-function method 'request-create-group) 
13268              (gnus-group-real-name group) (nth 1 method))))
13269
13270 (defun gnus-request-delete-group (group &optional force)
13271   (let ((method (gnus-find-method-for-group group)))
13272     (funcall (gnus-get-function method 'request-delete-group) 
13273              (gnus-group-real-name group) force (nth 1 method))))
13274
13275 (defun gnus-request-rename-group (group new-name)
13276   (let ((method (gnus-find-method-for-group group)))
13277     (funcall (gnus-get-function method 'request-rename-group) 
13278              (gnus-group-real-name group) 
13279              (gnus-group-real-name new-name) (nth 1 method))))
13280
13281 (defun gnus-post-method (group force-group-method)
13282   "Return the posting method based on GROUP and FORCE."
13283   (let ((group-method (if (stringp group)
13284                           (gnus-find-method-for-group group)
13285                         group)))
13286     (cond 
13287      ;; We want this group's method.
13288      (force-group-method group-method)
13289      ;; Override normal method.
13290      ((and gnus-post-method
13291            (gnus-method-option-p group-method 'post))
13292       gnus-post-method)
13293      ;; Perhaps this is a mail group?
13294      ((gnus-member-of-valid 'post group)
13295       group-method)
13296      ;; Use the normal select method.
13297      (t gnus-select-method))))
13298
13299 (defun gnus-member-of-valid (symbol group)
13300   "Find out if GROUP has SYMBOL as part of its \"valid\" spec."
13301   (memq symbol (assoc
13302                 (format "%s" (car (gnus-find-method-for-group group)))
13303                 gnus-valid-select-methods)))
13304
13305 (defun gnus-method-option-p (method option)
13306   "Return non-nil if select METHOD has OPTION as a parameter."
13307   (memq 'post (assoc (format "%s" (car method))
13308                      gnus-valid-select-methods)))
13309
13310
13311 (defmacro gnus-server-equal (ss1 ss2)
13312   "Say whether two servers are equal."
13313   `(let ((s1 ,ss1)
13314          (s2 ,ss2))
13315      (or (equal s1 s2)
13316          (and (= (length s1) (length s2))
13317               (progn
13318                 (while (and s1 (member (car s1) s2))
13319                   (setq s1 (cdr s1)))
13320                 (null s1))))))
13321
13322 (defun gnus-server-extend-method (group method)
13323   ;; This function "extends" a virtual server.  If the server is
13324   ;; "hello", and the select method is ("hello" (my-var "something")) 
13325   ;; in the group "alt.alt", this will result in a new virtual server
13326   ;; called "helly+alt.alt".
13327   (let ((entry
13328          (gnus-copy-sequence 
13329           (if (equal (car method) "native") gnus-select-method
13330             (cdr (assoc (car method) gnus-server-alist))))))
13331     (setcar (cdr entry) (concat (nth 1 entry) "+" group))
13332     (nconc entry (cdr method))))
13333
13334 (defun gnus-find-method-for-group (group &optional info)
13335   "Find the select method that GROUP uses."
13336   (or gnus-override-method
13337       (and (not group)
13338            gnus-select-method)
13339       (let ((info (or info (gnus-get-info group)))
13340             method)
13341         (if (or (not info)
13342                 (not (setq method (gnus-info-method info))))
13343             (setq method gnus-select-method)
13344           (setq method
13345                 (cond ((stringp method)
13346                        (gnus-server-to-method method))
13347                       ((stringp (car method))
13348                        (gnus-server-extend-method group method))
13349                       (t
13350                        method))))
13351         (gnus-server-add-address method))))
13352
13353 (defun gnus-check-backend-function (func group)
13354   "Check whether GROUP supports function FUNC."
13355   (let ((method (if (stringp group) (car (gnus-find-method-for-group group))
13356                   group)))
13357     (fboundp (intern (format "%s-%s" method func)))))
13358
13359 (defun gnus-methods-using (feature)
13360   "Find all methods that have FEATURE."
13361   (let ((valids gnus-valid-select-methods)
13362         outs)
13363     (while valids
13364       (if (memq feature (car valids)) 
13365           (setq outs (cons (car valids) outs)))
13366       (setq valids (cdr valids)))
13367     outs))
13368
13369 ;;; 
13370 ;;; Active & Newsrc File Handling
13371 ;;;
13372
13373 ;; Newsrc related functions.
13374 ;; Gnus internal format of gnus-newsrc-alist:
13375 ;; (("alt.general" 3 (1 . 1))
13376 ;;  ("alt.misc"    3 ((1 . 10) (12 . 15)))
13377 ;;  ("alt.test"    7 (1 . 99) (45 57 93)) ...)
13378 ;; The first item is the group name; the second is the subscription
13379 ;; level; the third is either a range of a list of ranges of read
13380 ;; articles, the optional fourth element is a list of marked articles,
13381 ;; the optional fifth element is the select method.
13382 ;;
13383 ;; Gnus internal format of gnus-newsrc-hashtb:
13384 ;; (95 ("alt.general" 3 (1 . 1)) ("alt.misc" 3 ((1 . 10) (12 . 15))) ...)
13385 ;; This is the entry for "alt.misc". The first element is the number
13386 ;; of unread articles in "alt.misc". The cdr of this entry is the
13387 ;; element *before* "alt.misc" in gnus-newsrc-alist, which makes is
13388 ;; trivial to remove or add new elements into gnus-newsrc-alist
13389 ;; without scanning the entire list.  So, to get the actual information
13390 ;; of "alt.misc", you'd say something like 
13391 ;; (nth 2 (gnus-gethash "alt.misc" gnus-newsrc-hashtb))
13392 ;;
13393 ;; Gnus internal format of gnus-active-hashtb:
13394 ;; ((1 . 1))
13395 ;;  (5 . 10))
13396 ;;  (67 . 99)) ...)
13397 ;; The only element in each entry in this hash table is a range of
13398 ;; (possibly) available articles. (Articles in this range may have
13399 ;; been expired or canceled.)
13400 ;;
13401 ;; Gnus internal format of gnus-killed-list and gnus-zombie-list:
13402 ;; ("alt.misc" "alt.test" "alt.general" ...)
13403
13404 (defun gnus-setup-news (&optional rawfile level)
13405   "Setup news information.
13406 If RAWFILE is non-nil, the .newsrc file will also be read.
13407 If LEVEL is non-nil, the news will be set up at level LEVEL."
13408   (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile)))))
13409     ;; Clear some variables to re-initialize news information.
13410     (if init (setq gnus-newsrc-alist nil 
13411                    gnus-active-hashtb nil))
13412
13413     ;; Read the newsrc file and create `gnus-newsrc-hashtb'.
13414     (if init (gnus-read-newsrc-file rawfile))
13415
13416     ;; If we don't read the complete active file, we fill in the
13417     ;; hashtb here. 
13418     (if (or (null gnus-read-active-file)
13419             (eq gnus-read-active-file 'some))
13420         (gnus-update-active-hashtb-from-killed))
13421
13422     ;; Read the active file and create `gnus-active-hashtb'.
13423     ;; If `gnus-read-active-file' is nil, then we just create an empty
13424     ;; hash table.  The partial filling out of the hash table will be
13425     ;; done in `gnus-get-unread-articles'.
13426     (and gnus-read-active-file 
13427          (not level)
13428          (gnus-read-active-file))
13429
13430     (or gnus-active-hashtb
13431         (setq gnus-active-hashtb (make-vector 4095 0)))
13432
13433     ;; Possibly eval the dribble file.
13434     (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file))
13435
13436     (gnus-update-format-specifications)
13437
13438     ;; Find new newsgroups and treat them.
13439     (if (and init gnus-check-new-newsgroups gnus-read-active-file (not level)
13440              (gnus-server-opened gnus-select-method))
13441         (gnus-find-new-newsgroups))
13442
13443     ;; Find the number of unread articles in each non-dead group.
13444     (let ((gnus-read-active-file (and (not level) gnus-read-active-file)))
13445       (gnus-get-unread-articles (or level (1+ gnus-level-subscribed))))
13446
13447     (if (and init gnus-check-bogus-newsgroups 
13448              gnus-read-active-file (not level)
13449              (gnus-server-opened gnus-select-method))
13450         (gnus-check-bogus-newsgroups))))
13451
13452 (defun gnus-find-new-newsgroups ()
13453   "Search for new newsgroups and add them.
13454 Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.'
13455 The `-n' option line from .newsrc is respected."
13456   (interactive)
13457   (or (gnus-check-first-time-used)
13458       (if (or (consp gnus-check-new-newsgroups)
13459               (eq gnus-check-new-newsgroups 'ask-server))
13460           (gnus-ask-server-for-new-groups)
13461         (let ((groups 0)
13462               group new-newsgroups)
13463           (gnus-message 5 "Looking for new newsgroups...")
13464           (or gnus-have-read-active-file (gnus-read-active-file))
13465           (setq gnus-newsrc-last-checked-date (current-time-string))
13466           (if (not gnus-killed-hashtb) (gnus-make-hashtable-from-killed))
13467           ;; Go though every newsgroup in `gnus-active-hashtb' and compare
13468           ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'.
13469           (mapatoms
13470            (lambda (sym)
13471              (if (or (null (setq group (symbol-name sym)))
13472                      (not (boundp sym))
13473                      (null (symbol-value sym))
13474                      (gnus-gethash group gnus-killed-hashtb)
13475                      (gnus-gethash group gnus-newsrc-hashtb))
13476                  ()
13477                (let ((do-sub (gnus-matches-options-n group)))
13478                  (cond 
13479                   ((eq do-sub 'subscribe)
13480                    (setq groups (1+ groups))
13481                    (gnus-sethash group group gnus-killed-hashtb)
13482                    (funcall gnus-subscribe-options-newsgroup-method group))
13483                   ((eq do-sub 'ignore)
13484                    nil)
13485                   (t
13486                    (setq groups (1+ groups))
13487                    (gnus-sethash group group gnus-killed-hashtb)
13488                    (if gnus-subscribe-hierarchical-interactive
13489                        (setq new-newsgroups (cons group new-newsgroups))
13490                      (funcall gnus-subscribe-newsgroup-method group)))))))
13491            gnus-active-hashtb)
13492           (if new-newsgroups 
13493               (gnus-subscribe-hierarchical-interactive new-newsgroups))
13494           ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
13495           (if (> groups 0)
13496               (gnus-message 6 "%d new newsgroup%s arrived." 
13497                             groups (if (> groups 1) "s have" " has"))
13498             (gnus-message 6 "No new newsgroups."))))))
13499
13500 (defun gnus-matches-options-n (group)
13501   ;; Returns `subscribe' if the group is to be uncoditionally
13502   ;; subscribed, `ignore' if it is to be ignored, and nil if there is
13503   ;; no match for the group.
13504
13505   ;; First we check the two user variables.
13506   (cond
13507    ((and gnus-options-subscribe
13508          (string-match gnus-options-subscribe group))
13509     'subscribe)
13510    ((and gnus-auto-subscribed-groups 
13511          (string-match gnus-auto-subscribed-groups group))
13512     'subscribe)
13513    ((and gnus-options-not-subscribe
13514          (string-match gnus-options-not-subscribe group))
13515     'ignore)
13516    ;; Then we go through the list that was retrieved from the .newsrc
13517    ;; file.  This list has elements on the form 
13518    ;; `(REGEXP . {ignore,subscribe})'.  The first match found (the list
13519    ;; is in the reverse order of the options line) is returned.
13520    (t
13521     (let ((regs gnus-newsrc-options-n))
13522       (while (and regs
13523                   (not (string-match (car (car regs)) group)))
13524         (setq regs (cdr regs)))
13525       (and regs (cdr (car regs)))))))
13526
13527 (defun gnus-ask-server-for-new-groups ()
13528   (let* ((date (or gnus-newsrc-last-checked-date (current-time-string)))
13529          (methods (cons gnus-select-method 
13530                         (append
13531                          (and (consp gnus-check-new-newsgroups)
13532                               gnus-check-new-newsgroups)
13533                          gnus-secondary-select-methods)))
13534          (groups 0)
13535          (new-date (current-time-string))
13536          (hashtb (gnus-make-hashtable 100))
13537          group new-newsgroups got-new method)
13538     ;; Go through both primary and secondary select methods and
13539     ;; request new newsgroups.  
13540     (while methods
13541       (setq method (gnus-server-get-method nil (car methods)))
13542       (and (gnus-check-server method)
13543            (gnus-request-newgroups date method)
13544            (save-excursion
13545              (setq got-new t)
13546              (set-buffer nntp-server-buffer)
13547              ;; Enter all the new groups in a hashtable.
13548              (gnus-active-to-gnus-format method hashtb 'ignore)))
13549       (setq methods (cdr methods)))
13550     (and got-new (setq gnus-newsrc-last-checked-date new-date))
13551     ;; Now all new groups from all select methods are in `hashtb'.
13552     (mapatoms
13553      (lambda (group-sym)
13554        (setq group (symbol-name group-sym))
13555        (if (or (null group)
13556                (null (symbol-value group-sym))
13557                (gnus-gethash group gnus-newsrc-hashtb)
13558                (member group gnus-zombie-list)
13559                (member group gnus-killed-list))
13560            ;; The group is already known.
13561            ()
13562          (and (symbol-value group-sym)
13563               (gnus-set-active group (symbol-value group-sym)))
13564          (let ((do-sub (gnus-matches-options-n group)))
13565            (cond ((eq do-sub 'subscribe)
13566                   (setq groups (1+ groups))
13567                   (gnus-sethash group group gnus-killed-hashtb)
13568                   (funcall 
13569                    gnus-subscribe-options-newsgroup-method group))
13570                  ((eq do-sub 'ignore)
13571                   nil)
13572                  (t
13573                   (setq groups (1+ groups))
13574                   (gnus-sethash group group gnus-killed-hashtb)
13575                   (if gnus-subscribe-hierarchical-interactive
13576                       (setq new-newsgroups (cons group new-newsgroups))
13577                     (funcall gnus-subscribe-newsgroup-method group)))))))
13578      hashtb)
13579     (if new-newsgroups 
13580         (gnus-subscribe-hierarchical-interactive new-newsgroups))
13581     ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
13582     (if (> groups 0)
13583         (gnus-message 6 "%d new newsgroup%s arrived." 
13584                       groups (if (> groups 1) "s have" " has")))
13585     got-new))
13586
13587 (defun gnus-check-first-time-used ()
13588   (if (or (> (length gnus-newsrc-alist) 1)
13589           (file-exists-p gnus-startup-file)
13590           (file-exists-p (concat gnus-startup-file ".el"))
13591           (file-exists-p (concat gnus-startup-file ".eld")))
13592       nil
13593     (gnus-message 6 "First time user; subscribing you to default groups")
13594     (or gnus-have-read-active-file (gnus-read-active-file))
13595     (setq gnus-newsrc-last-checked-date (current-time-string))
13596     (let ((groups gnus-default-subscribed-newsgroups)
13597           group)
13598       (if (eq groups t)
13599           nil
13600         (setq groups (or groups gnus-backup-default-subscribed-newsgroups))
13601         (mapatoms
13602          (lambda (sym)
13603            (if (null (setq group (symbol-name sym)))
13604                ()
13605              (let ((do-sub (gnus-matches-options-n group)))
13606                (cond 
13607                 ((eq do-sub 'subscribe)
13608                  (gnus-sethash group group gnus-killed-hashtb)
13609                  (funcall gnus-subscribe-options-newsgroup-method group))
13610                 ((eq do-sub 'ignore)
13611                  nil)
13612                 (t
13613                  (setq gnus-killed-list (cons group gnus-killed-list)))))))
13614          gnus-active-hashtb)
13615         (while groups
13616           (if (gnus-active (car groups))
13617               (gnus-group-change-level 
13618                (car groups) gnus-level-default-subscribed gnus-level-killed))
13619           (setq groups (cdr groups)))
13620         (gnus-group-make-help-group)
13621         (and gnus-novice-user
13622              (gnus-message 7 "`A k' to list killed groups"))))))
13623
13624 (defun gnus-subscribe-group (group previous &optional method)
13625   (gnus-group-change-level 
13626    (if method
13627        (list t group gnus-level-default-subscribed nil nil method)
13628      group) 
13629    gnus-level-default-subscribed gnus-level-killed previous t))
13630
13631 ;; `gnus-group-change-level' is the fundamental function for changing
13632 ;; subscription levels of newsgroups.  This might mean just changing
13633 ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back
13634 ;; again, which subscribes/unsubscribes a group, which is equally
13635 ;; trivial.  Changing from 1-7 to 8-9 means that you kill a group, and
13636 ;; from 8-9 to 1-7 means that you remove the group from the list of
13637 ;; killed (or zombie) groups and add them to the (kinda) subscribed
13638 ;; groups.  And last but not least, moving from 8 to 9 and 9 to 8,
13639 ;; which is trivial.
13640 ;; ENTRY can either be a string (newsgroup name) or a list (if
13641 ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST),
13642 ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb'
13643 ;; entries. 
13644 ;; LEVEL is the new level of the group, OLDLEVEL is the old level and
13645 ;; PREVIOUS is the group (in hashtb entry format) to insert this group
13646 ;; after. 
13647 (defun gnus-group-change-level (entry level &optional oldlevel
13648                                       previous fromkilled)
13649   (let (group info active num)
13650     ;; Glean what info we can from the arguments
13651     (if (consp entry)
13652         (if fromkilled (setq group (nth 1 entry))
13653           (setq group (car (nth 2 entry))))
13654       (setq group entry))
13655     (if (and (stringp entry)
13656              oldlevel 
13657              (< oldlevel gnus-level-zombie))
13658         (setq entry (gnus-gethash entry gnus-newsrc-hashtb)))
13659     (if (and (not oldlevel)
13660              (consp entry))
13661         (setq oldlevel (car (cdr (nth 2 entry)))))
13662     (if (stringp previous)
13663         (setq previous (gnus-gethash previous gnus-newsrc-hashtb)))
13664
13665     (if (and (>= oldlevel gnus-level-zombie)
13666              (gnus-gethash group gnus-newsrc-hashtb))
13667         ;; We are trying to subscribe a group that is already
13668         ;; subscribed. 
13669         ()                              ; Do nothing. 
13670
13671       (or (gnus-ephemeral-group-p group)
13672           (gnus-dribble-enter
13673            (format "(gnus-group-change-level %S %S %S %S %S)" 
13674                    group level oldlevel (car (nth 2 previous)) fromkilled)))
13675     
13676       ;; Then we remove the newgroup from any old structures, if needed.
13677       ;; If the group was killed, we remove it from the killed or zombie
13678       ;; list.  If not, and it is in fact going to be killed, we remove
13679       ;; it from the newsrc hash table and assoc.
13680       (cond ((>= oldlevel gnus-level-zombie)
13681              (if (= oldlevel gnus-level-zombie)
13682                  (setq gnus-zombie-list (delete group gnus-zombie-list))
13683                (setq gnus-killed-list (delete group gnus-killed-list))))
13684             (t
13685              (if (and (>= level gnus-level-zombie)
13686                       entry)
13687                  (progn
13688                    (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb)
13689                    (if (nth 3 entry)
13690                        (setcdr (gnus-gethash (car (nth 3 entry))
13691                                              gnus-newsrc-hashtb)
13692                                (cdr entry)))
13693                    (setcdr (cdr entry) (cdr (cdr (cdr entry))))))))
13694
13695       ;; Finally we enter (if needed) the list where it is supposed to
13696       ;; go, and change the subscription level.  If it is to be killed,
13697       ;; we enter it into the killed or zombie list.
13698       (cond ((>= level gnus-level-zombie)
13699              ;; Remove from the hash table.
13700              (gnus-sethash group nil gnus-newsrc-hashtb)
13701              ;; We do not enter foreign groups into the list of dead
13702              ;; groups.  
13703              (unless (gnus-group-foreign-p group)
13704                (if (= level gnus-level-zombie)
13705                    (setq gnus-zombie-list (cons group gnus-zombie-list))
13706                  (setq gnus-killed-list (cons group gnus-killed-list)))))
13707             (t
13708              ;; If the list is to be entered into the newsrc assoc, and
13709              ;; it was killed, we have to create an entry in the newsrc
13710              ;; hashtb format and fix the pointers in the newsrc assoc.
13711              (if (>= oldlevel gnus-level-zombie)
13712                  (progn
13713                    (if (listp entry)
13714                        (progn
13715                          (setq info (cdr entry))
13716                          (setq num (car entry)))
13717                      (setq active (gnus-active group))
13718                      (setq num 
13719                            (if active (- (1+ (cdr active)) (car active)) t))
13720                      ;; Check whether the group is foreign.  If so, the
13721                      ;; foreign select method has to be entered into the
13722                      ;; info. 
13723                      (let ((method (gnus-group-method-name group)))
13724                        (if (eq method gnus-select-method)
13725                            (setq info (list group level nil))
13726                          (setq info (list group level nil nil method)))))
13727                    (or previous 
13728                        (setq previous 
13729                              (let ((p gnus-newsrc-alist))
13730                                (while (cdr (cdr p))
13731                                  (setq p (cdr p)))
13732                                p)))
13733                    (setq entry (cons info (cdr (cdr previous))))
13734                    (if (cdr previous)
13735                        (progn
13736                          (setcdr (cdr previous) entry)
13737                          (gnus-sethash group (cons num (cdr previous)) 
13738                                        gnus-newsrc-hashtb))
13739                      (setcdr previous entry)
13740                      (gnus-sethash group (cons num previous)
13741                                    gnus-newsrc-hashtb))
13742                    (if (cdr entry)
13743                        (setcdr (gnus-gethash (car (car (cdr entry)))
13744                                              gnus-newsrc-hashtb)
13745                                entry)))
13746                ;; It was alive, and it is going to stay alive, so we
13747                ;; just change the level and don't change any pointers or
13748                ;; hash table entries.
13749                (setcar (cdr (car (cdr (cdr entry)))) level)))))))
13750
13751 (defun gnus-kill-newsgroup (newsgroup)
13752   "Obsolete function.  Kills a newsgroup."
13753   (gnus-group-change-level
13754    (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed))
13755
13756 (defun gnus-check-bogus-newsgroups (&optional confirm)
13757   "Remove bogus newsgroups.
13758 If CONFIRM is non-nil, the user has to confirm the deletion of every
13759 newsgroup." 
13760   (let ((newsrc (cdr gnus-newsrc-alist))
13761         bogus group entry)
13762     (gnus-message 5 "Checking bogus newsgroups...")
13763     (or gnus-have-read-active-file (gnus-read-active-file))
13764     ;; Find all bogus newsgroup that are subscribed.
13765     (while newsrc
13766       (setq group (car (car newsrc)))
13767       (if (or (gnus-active group) ; Active
13768               (nth 4 (car newsrc))      ; Foreign
13769               (and confirm
13770                    (not (gnus-y-or-n-p
13771                          (format "Remove bogus newsgroup: %s " group)))))
13772           ;; Don't remove.
13773           ()
13774         ;; Found a bogus newsgroup.
13775         (setq bogus (cons group bogus)))
13776       (setq newsrc (cdr newsrc)))
13777     ;; Remove all bogus subscribed groups by first killing them, and
13778     ;; then removing them from the list of killed groups.
13779     (while bogus
13780       (and (setq entry (gnus-gethash (car bogus) gnus-newsrc-hashtb))
13781            (progn
13782              (gnus-group-change-level entry gnus-level-killed)
13783              (setq gnus-killed-list (delete (car bogus) gnus-killed-list))))
13784       (setq bogus (cdr bogus)))
13785     ;; Then we remove all bogus groups from the list of killed and
13786     ;; zombie groups.  They are are removed without confirmation.
13787     (let ((dead-lists '(gnus-killed-list gnus-zombie-list))
13788           killed)
13789       (while dead-lists
13790         (setq killed (symbol-value (car dead-lists)))
13791         (while killed
13792           (setq group (car killed))
13793           (or (gnus-active group)
13794               ;; The group is bogus.
13795               (set (car dead-lists)
13796                    (delete group (symbol-value (car dead-lists)))))
13797           (setq killed (cdr killed)))
13798         (setq dead-lists (cdr dead-lists))))
13799     (gnus-message 5 "Checking bogus newsgroups...done")))
13800
13801 (defun gnus-check-duplicate-killed-groups ()
13802   "Remove duplicates from the list of killed groups."
13803   (interactive)
13804   (let ((killed gnus-killed-list))
13805     (while killed
13806       (gnus-message 9 "%d" (length killed))
13807       (setcdr killed (delete (car killed) (cdr killed)))
13808       (setq killed (cdr killed)))))
13809
13810 ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb'
13811 ;; and compute how many unread articles there are in each group.
13812 (defun gnus-get-unread-articles (&optional level) 
13813   (let* ((newsrc (cdr gnus-newsrc-alist))
13814          (level (or level (1+ gnus-level-subscribed)))
13815          (foreign-level
13816           (min 
13817            (cond ((and gnus-activate-foreign-newsgroups 
13818                        (not (numberp gnus-activate-foreign-newsgroups)))
13819                   (1+ gnus-level-subscribed))
13820                  ((numberp gnus-activate-foreign-newsgroups)
13821                   gnus-activate-foreign-newsgroups)
13822                  (t 0))
13823            level))
13824          (update
13825           (fboundp (intern (format "%s-request-update-info"
13826                                    (car gnus-select-method)))))
13827          info group active virtuals method fmethod)
13828     (gnus-message 5 "Checking new news...")
13829
13830     (while newsrc
13831       (setq info (car newsrc)
13832             group (gnus-info-group info)
13833             active (gnus-active group))
13834
13835       ;; Check newsgroups.  If the user doesn't want to check them, or
13836       ;; they can't be checked (for instance, if the news server can't
13837       ;; be reached) we just set the number of unread articles in this
13838       ;; newsgroup to t.  This means that Gnus thinks that there are
13839       ;; unread articles, but it has no idea how many.
13840       (if (and (setq method (gnus-info-method info))
13841                (not (gnus-server-equal
13842                      gnus-select-method
13843                      (prog1
13844                          (setq fmethod (gnus-server-get-method nil method))
13845                        ;; We do this here because it would be awkward
13846                        ;; to do it anywhere else.  Hell, it's pretty
13847                        ;; awkward here as well, but at least it's
13848                        ;; reasonably efficient. 
13849                        (and (<= (gnus-info-level info) foreign-level)
13850                             (gnus-request-update-info info method)))))
13851                (not (gnus-secondary-method-p method)))
13852           ;; These groups are foreign.  Check the level.
13853           (if (<= (gnus-info-level info) foreign-level)
13854               (setq active (gnus-activate-group (gnus-info-group info) 'scan)))
13855
13856         ;; These groups are native or secondary. 
13857         (if (<= (gnus-info-level info) level)
13858             (progn
13859               (if (and update (not method))
13860                   (progn
13861                     ;; Allow updating of native groups as well, even
13862                     ;; though that's pretty unlikely.
13863                     (gnus-request-update-info info gnus-select-method)
13864                     (setq active (gnus-activate-group 
13865                                   (gnus-info-group info) 'scan)))
13866                 (or gnus-read-active-file
13867                     (setq active (gnus-activate-group 
13868                                   (gnus-info-group info) 'scan)))))))
13869       
13870       (if active
13871           (gnus-get-unread-articles-in-group info active)
13872         ;; The group couldn't be reached, so we nix out the number of
13873         ;; unread articles and stuff.
13874         (gnus-set-active group nil)
13875         (setcar (gnus-gethash group gnus-newsrc-hashtb) t))
13876
13877       (setq newsrc (cdr newsrc)))
13878
13879     (gnus-message 5 "Checking new news...done")))
13880
13881 ;; Create a hash table out of the newsrc alist.  The `car's of the
13882 ;; alist elements are used as keys.
13883 (defun gnus-make-hashtable-from-newsrc-alist ()
13884   (let ((alist gnus-newsrc-alist)
13885         (ohashtb gnus-newsrc-hashtb)
13886         prev)
13887     (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist)))
13888     (setq alist 
13889           (setq prev (setq gnus-newsrc-alist 
13890                            (if (equal (car (car gnus-newsrc-alist))
13891                                       "dummy.group")
13892                                gnus-newsrc-alist
13893                              (cons (list "dummy.group" 0 nil) alist)))))
13894     (while alist
13895       (gnus-sethash (car (car alist)) 
13896                     (cons (and ohashtb (car (gnus-gethash 
13897                                              (car (car alist)) ohashtb))) 
13898                           prev) gnus-newsrc-hashtb)
13899       (setq prev alist
13900             alist (cdr alist)))))
13901
13902 (defun gnus-make-hashtable-from-killed ()
13903   "Create a hash table from the killed and zombie lists."
13904   (let ((lists '(gnus-killed-list gnus-zombie-list))
13905         list)
13906     (setq gnus-killed-hashtb 
13907           (gnus-make-hashtable 
13908            (+ (length gnus-killed-list) (length gnus-zombie-list))))
13909     (while lists
13910       (setq list (symbol-value (car lists)))
13911       (setq lists (cdr lists))
13912       (while list
13913         (gnus-sethash (car list) (car list) gnus-killed-hashtb)
13914         (setq list (cdr list))))))
13915
13916 (defun gnus-get-unread-articles-in-group (info active)
13917   (let* ((range (gnus-info-read info))
13918          (num 0)
13919          (marked (gnus-info-marks info)))
13920     ;; If a cache is present, we may have to alter the active info.
13921     (and gnus-use-cache
13922          (gnus-cache-possibly-alter-active (gnus-info-group info) active))
13923     ;; Modify the list of read articles according to what articles 
13924     ;; are available; then tally the unread articles and add the
13925     ;; number to the group hash table entry.
13926     (cond 
13927      ((zerop (cdr active))
13928       (setq num 0))
13929      ((not range)
13930       (setq num (- (1+ (cdr active)) (car active))))
13931      ((not (listp (cdr range)))
13932       ;; Fix a single (num . num) range according to the
13933       ;; active hash table.
13934       ;; Fix by Carsten Bormann <cabo@Informatik.Uni-Bremen.DE>.
13935       (and (< (cdr range) (car active)) (setcdr range (1- (car active))))
13936       (and (> (cdr range) (cdr active)) (setcdr range (cdr active)))
13937       ;; Compute number of unread articles.
13938       (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range))))))
13939      (t
13940       ;; The read list is a list of ranges.  Fix them according to
13941       ;; the active hash table.
13942       ;; First peel off any elements that are below the lower
13943       ;; active limit. 
13944       (while (and (cdr range) 
13945                   (>= (car active) 
13946                       (or (and (atom (car (cdr range))) (car (cdr range)))
13947                           (car (car (cdr range))))))
13948         (if (numberp (car range))
13949             (setcar range 
13950                     (cons (car range) 
13951                           (or (and (numberp (car (cdr range)))
13952                                    (car (cdr range))) 
13953                               (cdr (car (cdr range))))))
13954           (setcdr (car range) 
13955                   (or (and (numberp (nth 1 range)) (nth 1 range))
13956                       (cdr (car (cdr range))))))
13957         (setcdr range (cdr (cdr range))))
13958       ;; Adjust the first element to be the same as the lower limit. 
13959       (if (and (not (atom (car range))) 
13960                (< (cdr (car range)) (car active)))
13961           (setcdr (car range) (1- (car active))))
13962       ;; Then we want to peel off any elements that are higher
13963       ;; than the upper active limit.  
13964       (let ((srange range))
13965         ;; Go past all legal elements.
13966         (while (and (cdr srange) 
13967                     (<= (or (and (atom (car (cdr srange)))
13968                                  (car (cdr srange)))
13969                             (car (car (cdr srange)))) (cdr active)))
13970           (setq srange (cdr srange)))
13971         (if (cdr srange)
13972             ;; Nuke all remaining illegal elements.
13973             (setcdr srange nil))
13974
13975         ;; Adjust the final element.
13976         (if (and (not (atom (car srange)))
13977                  (> (cdr (car srange)) (cdr active)))
13978             (setcdr (car srange) (cdr active))))
13979       ;; Compute the number of unread articles.
13980       (while range
13981         (setq num (+ num (- (1+ (or (and (atom (car range)) (car range))
13982                                     (cdr (car range))))
13983                             (or (and (atom (car range)) (car range))
13984                                 (car (car range))))))
13985         (setq range (cdr range)))
13986       (setq num (max 0 (- (cdr active) num)))))
13987     ;; Set the number of unread articles.
13988     (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num)
13989     num))
13990
13991 (defun gnus-activate-group (group &optional scan)
13992   ;; Check whether a group has been activated or not.
13993   ;; If SCAN, request a scan of that group as well.
13994   (let ((method (gnus-find-method-for-group group))
13995         active)
13996     (and (gnus-check-server method)
13997          ;; We escape all bugs and quit here to make it possible to
13998          ;; continue if a group is so out-there that it reports bugs
13999          ;; and stuff.
14000          (progn
14001            (and scan
14002                 (gnus-check-backend-function 'request-scan (car method))
14003                 (gnus-request-scan group method))
14004            t)
14005          (condition-case ()
14006              (gnus-request-group group)
14007            (error nil)
14008            (quit nil))
14009          (save-excursion
14010            (set-buffer nntp-server-buffer)
14011            (goto-char (point-min))
14012            ;; Parse the result we got from `gnus-request-group'.
14013            (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+")
14014                 (progn
14015                   (goto-char (match-beginning 1))
14016                   (gnus-set-active 
14017                    group (setq active (cons (read (current-buffer))
14018                                             (read (current-buffer)))))
14019                   ;; Return the new active info.
14020                   active))))))
14021
14022 (defun gnus-update-read-articles (group unread)
14023   "Update the list of read and ticked articles in GROUP using the
14024 UNREAD and TICKED lists.
14025 Note: UNSELECTED has to be sorted over `<'.
14026 Returns whether the updating was successful."
14027   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
14028          (entry (gnus-gethash group gnus-newsrc-hashtb))
14029          (info (nth 2 entry))
14030          (marked (gnus-info-marks info))
14031          (prev 1)
14032          (unread (sort (copy-sequence unread) '<))
14033          read)
14034     (if (or (not info) (not active))
14035         ;; There is no info on this group if it was, in fact,
14036         ;; killed.  Gnus stores no information on killed groups, so
14037         ;; there's nothing to be done. 
14038         ;; One could store the information somewhere temporarily,
14039         ;; perhaps...  Hmmm... 
14040         ()
14041       ;; Remove any negative articles numbers.
14042       (while (and unread (< (car unread) 0))
14043         (setq unread (cdr unread)))
14044       ;; Remove any expired article numbers
14045       (while (and unread (< (car unread) (car active)))
14046         (setq unread (cdr unread)))
14047       ;; Compute the ranges of read articles by looking at the list of
14048       ;; unread articles.  
14049       (while unread
14050         (if (/= (car unread) prev)
14051             (setq read (cons (if (= prev (1- (car unread))) prev
14052                                (cons prev (1- (car unread)))) read)))
14053         (setq prev (1+ (car unread)))
14054         (setq unread (cdr unread)))
14055       (when (<= prev (cdr active))
14056         (setq read (cons (cons prev (cdr active)) read)))
14057       ;; Enter this list into the group info.
14058       (gnus-info-set-read 
14059        info (if (> (length read) 1) (nreverse read) read))
14060       ;; Set the number of unread articles in gnus-newsrc-hashtb.
14061       (gnus-get-unread-articles-in-group info (gnus-active group))
14062       t)))
14063
14064 (defun gnus-make-articles-unread (group articles)
14065   "Mark ARTICLES in GROUP as unread."
14066   (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb)
14067                           (gnus-gethash (gnus-group-real-name group)
14068                                         gnus-newsrc-hashtb))))
14069          (ranges (gnus-info-read info))
14070          news article)
14071     (while articles
14072       (when (gnus-member-of-range 
14073              (setq article (pop articles)) ranges)
14074         (setq news (cons article news))))
14075     (when news
14076       (gnus-info-set-read 
14077        info (gnus-remove-from-range (gnus-info-read info) (nreverse news)))
14078       (gnus-group-update-group group t))))
14079
14080 ;; Enter all dead groups into the hashtb.
14081 (defun gnus-update-active-hashtb-from-killed ()
14082   (let ((hashtb (setq gnus-active-hashtb (make-vector 4095 0)))
14083         (lists (list gnus-killed-list gnus-zombie-list))
14084         killed)
14085     (while lists
14086       (setq killed (car lists))
14087       (while killed
14088         (gnus-sethash (car killed) nil hashtb)
14089         (setq killed (cdr killed)))
14090       (setq lists (cdr lists)))))
14091
14092 ;; Get the active file(s) from the backend(s).
14093 (defun gnus-read-active-file ()
14094   (gnus-group-set-mode-line)
14095   (let ((methods (if (gnus-check-server gnus-select-method)
14096                      ;; The native server is available.
14097                      (cons gnus-select-method gnus-secondary-select-methods)
14098                    ;; The native server is down, so we just do the
14099                    ;; secondary ones.   
14100                    gnus-secondary-select-methods))
14101         list-type)
14102     (setq gnus-have-read-active-file nil)
14103     (save-excursion
14104       (set-buffer nntp-server-buffer)
14105       (while methods
14106         (let* ((method (gnus-server-get-method nil (car methods)))
14107                (where (nth 1 method))
14108                (mesg (format "Reading active file%s via %s..."
14109                              (if (and where (not (zerop (length where))))
14110                                  (concat " from " where) "")
14111                              (car method))))
14112           (gnus-message 5 mesg)
14113           (if (not (gnus-check-server method))
14114               ()
14115             ;; Request that the backend scan its incoming messages.
14116             (and (gnus-check-backend-function 'request-scan (car method))
14117                  (gnus-request-scan nil method))
14118             (cond 
14119              ((and (eq gnus-read-active-file 'some)
14120                    (gnus-check-backend-function 'retrieve-groups (car method)))
14121               (let ((newsrc (cdr gnus-newsrc-alist))
14122                     (gmethod (gnus-server-get-method nil method))
14123                     groups)
14124                 (while newsrc
14125                   (and (gnus-server-equal 
14126                         (gnus-find-method-for-group 
14127                          (car (car newsrc)) (car newsrc))
14128                         gmethod)
14129                        (setq groups (cons (gnus-group-real-name 
14130                                            (car (car newsrc))) groups)))
14131                   (setq newsrc (cdr newsrc)))
14132                 (gnus-check-server method)
14133                 (setq list-type (gnus-retrieve-groups groups method))
14134                 (cond 
14135                  ((not list-type)
14136                   (gnus-message 
14137                    1 "Cannot read partial active file from %s server." 
14138                    (car method))
14139                   (ding)
14140                   (sit-for 2))
14141                  ((eq list-type 'active)
14142                   (gnus-active-to-gnus-format method gnus-active-hashtb))
14143                  (t
14144                   (gnus-groups-to-gnus-format method gnus-active-hashtb)))))
14145              (t
14146               (if (not (gnus-request-list method))
14147                   (progn
14148                     (gnus-message 1 "Cannot read active file from %s server." 
14149                                   (car method))
14150                     (ding))
14151                 (gnus-active-to-gnus-format method)
14152                 ;; We mark this active file as read.
14153                 (setq gnus-have-read-active-file
14154                       (cons method gnus-have-read-active-file))
14155                 (gnus-message 5 "%sdone" mesg))))))
14156         (setq methods (cdr methods))))))
14157
14158 ;; Read an active file and place the results in `gnus-active-hashtb'.
14159 (defun gnus-active-to-gnus-format (method &optional hashtb ignore-errors)
14160   (let ((cur (current-buffer))
14161         (hashtb (or hashtb 
14162                     (if (and gnus-active-hashtb 
14163                              (not (equal method gnus-select-method)))
14164                         gnus-active-hashtb
14165                       (setq gnus-active-hashtb
14166                             (if (equal method gnus-select-method)
14167                                 (gnus-make-hashtable 
14168                                  (count-lines (point-min) (point-max)))
14169                               (gnus-make-hashtable 4096))))))
14170         (flag-hashtb (gnus-make-hashtable 60)))
14171     ;; Delete unnecessary lines.
14172     (goto-char (point-min))
14173     (while (search-forward "\nto." nil t)
14174       (delete-region (1+ (match-beginning 0)) 
14175                      (progn (forward-line 1) (point))))
14176     (or (string= gnus-ignored-newsgroups "")
14177         (progn
14178           (goto-char (point-min))
14179           (delete-matching-lines gnus-ignored-newsgroups)))
14180     ;; Make the group names readable as a lisp expression even if they
14181     ;; contain special characters.
14182     ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
14183     (goto-char (point-max))
14184     (while (re-search-backward "[][';?()#]" nil t)
14185       (insert ?\\))
14186     ;; If these are groups from a foreign select method, we insert the
14187     ;; group prefix in front of the group names. 
14188     (and method (not (gnus-server-equal
14189                       (gnus-server-get-method nil method)
14190                       (gnus-server-get-method nil gnus-select-method)))
14191          (let ((prefix (gnus-group-prefixed-name "" method)))
14192            (goto-char (point-min))
14193            (while (and (not (eobp))
14194                        (progn (insert prefix)
14195                               (zerop (forward-line 1)))))))
14196     ;; Store the active file in a hash table.
14197     (goto-char (point-min))
14198     (if (string-match "%[oO]" gnus-group-line-format)
14199         ;; Suggested by Brian Edmonds <edmonds@cs.ubc.ca>.
14200         ;; If we want information on moderated groups, we use this
14201         ;; loop...   
14202         (let* ((mod-hashtb (make-vector 7 0))
14203                (m (intern "m" mod-hashtb))
14204                group max min)
14205           (while (not (eobp))
14206             (condition-case nil
14207                 (progn
14208                   (narrow-to-region (point) (gnus-point-at-eol))
14209                   (setq group (let ((obarray hashtb)) (read cur)))
14210                   (if (and (numberp (setq max (read cur)))
14211                            (numberp (setq min (read cur)))
14212                            (progn 
14213                              (skip-chars-forward " \t")
14214                              (not
14215                               (or (= (following-char) ?=)
14216                                   (= (following-char) ?x)
14217                                   (= (following-char) ?j)))))
14218                       (set group (cons min max))
14219                     (set group nil))
14220                   ;; Enter moderated groups into a list.
14221                   (if (eq (let ((obarray mod-hashtb)) (read cur)) m)
14222                       (setq gnus-moderated-list 
14223                             (cons (symbol-name group) gnus-moderated-list))))
14224               (error 
14225                (and group
14226                     (symbolp group)
14227                     (set group nil))))
14228             (widen)
14229             (forward-line 1)))
14230       ;; And if we do not care about moderation, we use this loop,
14231       ;; which is faster.
14232       (let (group max min)
14233         (while (not (eobp))
14234           (condition-case ()
14235               (progn
14236                 (narrow-to-region (point) (gnus-point-at-eol))
14237                 ;; group gets set to a symbol interned in the hash table
14238                 ;; (what a hack!!) - jwz
14239                 (setq group (let ((obarray hashtb)) (read cur)))
14240                 (if (and (numberp (setq max (read cur)))
14241                          (numberp (setq min (read cur)))
14242                          (progn 
14243                            (skip-chars-forward " \t")
14244                            (not
14245                             (or (= (following-char) ?=)
14246                                 (= (following-char) ?x)
14247                                 (= (following-char) ?j)))))
14248                     (set group (cons min max))
14249                   (set group nil)))
14250             (error 
14251              (progn 
14252                (and group
14253                     (symbolp group)
14254                     (set group nil))
14255                (or ignore-errors
14256                    (gnus-message 3 "Warning - illegal active: %s"
14257                                  (buffer-substring 
14258                                   (gnus-point-at-bol) (gnus-point-at-eol)))))))
14259           (widen)
14260           (forward-line 1))))))
14261
14262 (defun gnus-groups-to-gnus-format (method &optional hashtb)
14263   ;; Parse a "groups" active file.
14264   (let ((cur (current-buffer))
14265         (hashtb (or hashtb 
14266                     (if (and method gnus-active-hashtb)
14267                         gnus-active-hashtb
14268                       (setq gnus-active-hashtb
14269                             (gnus-make-hashtable 
14270                              (count-lines (point-min) (point-max)))))))
14271         (prefix (and method 
14272                      (not (gnus-server-equal
14273                            (gnus-server-get-method nil method)
14274                            (gnus-server-get-method nil gnus-select-method)))
14275                      (gnus-group-prefixed-name "" method))))
14276
14277     (goto-char (point-min))
14278     ;; We split this into to separate loops, one with the prefix
14279     ;; and one without to speed the reading up somewhat.
14280     (if prefix
14281         (let (min max opoint group)
14282           (while (not (eobp))
14283             (condition-case ()
14284                 (progn
14285                   (read cur) (read cur)
14286                   (setq min (read cur)
14287                         max (read cur)
14288                         opoint (point))
14289                   (skip-chars-forward " \t")
14290                   (insert prefix)
14291                   (goto-char opoint)
14292                   (set (let ((obarray hashtb)) (read cur)) 
14293                        (cons min max)))
14294               (error (and group (symbolp group) (set group nil))))
14295             (forward-line 1)))
14296       (let (min max group)
14297         (while (not (eobp))
14298           (condition-case ()
14299               (if (= (following-char) ?2)
14300                   (progn
14301                     (read cur) (read cur)
14302                     (setq min (read cur)
14303                           max (read cur))
14304                     (set (setq group (let ((obarray hashtb)) (read cur)))
14305                          (cons min max))))
14306             (error (and group (symbolp group) (set group nil))))
14307           (forward-line 1))))))
14308
14309 (defun gnus-read-newsrc-file (&optional force)
14310   "Read startup file.
14311 If FORCE is non-nil, the .newsrc file is read."
14312   ;; Reset variables that might be defined in the .newsrc.eld file.
14313   (let ((variables gnus-variable-list))
14314     (while variables
14315       (set (car variables) nil)
14316       (setq variables (cdr variables))))
14317   (let* ((newsrc-file gnus-current-startup-file)
14318          (quick-file (concat newsrc-file ".el")))
14319     (save-excursion
14320       ;; We always load the .newsrc.eld file.  If always contains
14321       ;; much information that can not be gotten from the .newsrc
14322       ;; file (ticked articles, killed groups, foreign methods, etc.)
14323       (gnus-read-newsrc-el-file quick-file)
14324  
14325       (if (or force
14326               (and (file-newer-than-file-p newsrc-file quick-file)
14327                    (file-newer-than-file-p newsrc-file 
14328                                            (concat quick-file "d")))
14329               (not gnus-newsrc-alist))
14330           ;; We read the .newsrc file.  Note that if there if a
14331           ;; .newsrc.eld file exists, it has already been read, and
14332           ;; the `gnus-newsrc-hashtb' has been created.  While reading
14333           ;; the .newsrc file, Gnus will only use the information it
14334           ;; can find there for changing the data already read -
14335           ;; ie. reading the .newsrc file will not trash the data
14336           ;; already read (except for read articles).
14337           (save-excursion
14338             (gnus-message 5 "Reading %s..." newsrc-file)
14339             (set-buffer (find-file-noselect newsrc-file))
14340             (buffer-disable-undo (current-buffer))
14341             (gnus-newsrc-to-gnus-format)
14342             (kill-buffer (current-buffer))
14343             (gnus-message 5 "Reading %s...done" newsrc-file)))
14344
14345       ;; Read any slave files.
14346       (or gnus-slave
14347           (gnus-master-read-slave-newsrc)))))
14348
14349 (defun gnus-read-newsrc-el-file (file)
14350   (let ((ding-file (concat file "d")))
14351     ;; We always, always read the .eld file.
14352     (gnus-message 5 "Reading %s..." ding-file)
14353     (let (gnus-newsrc-assoc)
14354       (condition-case nil
14355           (load ding-file t t t)
14356         (error
14357          (gnus-message 1 "Error in %s" ding-file)
14358          (ding)))
14359       (when gnus-newsrc-assoc 
14360         (setq gnus-newsrc-alist gnus-newsrc-assoc)))
14361     (gnus-make-hashtable-from-newsrc-alist)
14362     (when (file-newer-than-file-p file ding-file)
14363       ;; Old format quick file
14364       (gnus-message 5 "Reading %s..." file)
14365       ;; The .el file is newer than the .eld file, so we read that one
14366       ;; as well. 
14367       (gnus-read-old-newsrc-el-file file))))
14368
14369 ;; Parse the old-style quick startup file
14370 (defun gnus-read-old-newsrc-el-file (file)
14371   (let (newsrc killed marked group m)
14372     (prog1
14373         (let ((gnus-killed-assoc nil)
14374               gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc)
14375           (prog1
14376               (condition-case nil
14377                   (load file t t t)
14378                 (error nil))
14379             (setq newsrc gnus-newsrc-assoc
14380                   killed gnus-killed-assoc
14381                   marked gnus-marked-assoc)))
14382       (setq gnus-newsrc-alist nil)
14383       (while newsrc
14384         (setq group (car newsrc))
14385         (let ((info (gnus-get-info (car group))))
14386           (if info
14387               (progn
14388                 (gnus-info-set-read info (cdr (cdr group)))
14389                 (gnus-info-set-level
14390                  info (if (nth 1 group) gnus-level-default-subscribed 
14391                         gnus-level-default-unsubscribed))
14392                 (setq gnus-newsrc-alist (cons info gnus-newsrc-alist)))
14393             (setq gnus-newsrc-alist
14394                   (cons 
14395                    (setq info
14396                          (list (car group)
14397                                (if (nth 1 group) gnus-level-default-subscribed
14398                                  gnus-level-default-unsubscribed) 
14399                                (cdr (cdr group))))
14400                    gnus-newsrc-alist)))
14401           (if (setq m (assoc (car group) marked))
14402               (gnus-info-set-marks 
14403                info (cons (list (cons 'tick (gnus-compress-sequence
14404                                              (sort (cdr m) '<) t)))
14405                           nil))))
14406         (setq newsrc (cdr newsrc)))
14407       (setq newsrc killed)
14408       (while newsrc
14409         (setcar newsrc (car (car newsrc)))
14410         (setq newsrc (cdr newsrc)))
14411       (setq gnus-killed-list killed))
14412     ;; The .el file version of this variable does not begin with
14413     ;; "options", while the .eld version does, so we just add it if it
14414     ;; isn't there.
14415     (and
14416      gnus-newsrc-options 
14417      (progn
14418        (and (not (string-match "^ *options" gnus-newsrc-options))
14419             (setq gnus-newsrc-options (concat "options " gnus-newsrc-options)))
14420        (and (not (string-match "\n$" gnus-newsrc-options))
14421             (setq gnus-newsrc-options (concat gnus-newsrc-options "\n")))
14422        ;; Finally, if we read some options lines, we parse them.
14423        (or (string= gnus-newsrc-options "")
14424            (gnus-newsrc-parse-options gnus-newsrc-options))))
14425
14426     (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))
14427     (gnus-make-hashtable-from-newsrc-alist)))
14428       
14429 (defun gnus-make-newsrc-file (file)
14430   "Make server dependent file name by catenating FILE and server host name."
14431   (let* ((file (expand-file-name file nil))
14432          (real-file (concat file "-" (nth 1 gnus-select-method))))
14433     (if (or (file-exists-p real-file)
14434             (file-exists-p (concat real-file ".el"))
14435             (file-exists-p (concat real-file ".eld")))
14436         real-file file)))
14437
14438 (defun gnus-newsrc-to-gnus-format ()
14439   (setq gnus-newsrc-options "")
14440   (setq gnus-newsrc-options-n nil)
14441
14442   (or gnus-active-hashtb
14443       (setq gnus-active-hashtb (make-vector 4095 0)))
14444   (let ((buf (current-buffer))
14445         (already-read (> (length gnus-newsrc-alist) 1))
14446         group subscribed options-symbol newsrc Options-symbol
14447         symbol reads num1)
14448     (goto-char (point-min))
14449     ;; We intern the symbol `options' in the active hashtb so that we
14450     ;; can `eq' against it later.
14451     (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil)
14452     (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil)
14453   
14454     (while (not (eobp))
14455       ;; We first read the first word on the line by narrowing and
14456       ;; then reading into `gnus-active-hashtb'.  Most groups will
14457       ;; already exist in that hashtb, so this will save some string
14458       ;; space.
14459       (narrow-to-region
14460        (point)
14461        (progn (skip-chars-forward "^ \t!:\n") (point)))
14462       (goto-char (point-min))
14463       (setq symbol 
14464             (and (/= (point-min) (point-max))
14465                  (let ((obarray gnus-active-hashtb)) (read buf))))
14466       (widen)
14467       ;; Now, the symbol we have read is either `options' or a group
14468       ;; name.  If it is an options line, we just add it to a string. 
14469       (cond 
14470        ((or (eq symbol options-symbol)
14471             (eq symbol Options-symbol))
14472         (setq gnus-newsrc-options
14473               ;; This concatting is quite inefficient, but since our
14474               ;; thorough studies show that approx 99.37% of all
14475               ;; .newsrc files only contain a single options line, we
14476               ;; don't give a damn, frankly, my dear.
14477               (concat gnus-newsrc-options
14478                       (buffer-substring 
14479                        (gnus-point-at-bol)
14480                        ;; Options may continue on the next line.
14481                        (or (and (re-search-forward "^[^ \t]" nil 'move)
14482                                 (progn (beginning-of-line) (point)))
14483                            (point)))))
14484         (forward-line -1))
14485        (symbol
14486         (or (boundp symbol) (set symbol nil))
14487         ;; It was a group name.
14488         (setq subscribed (= (following-char) ?:)
14489               group (symbol-name symbol)
14490               reads nil)
14491         (if (eolp)
14492             ;; If the line ends here, this is clearly a buggy line, so
14493             ;; we put point a the beginning of line and let the cond
14494             ;; below do the error handling.
14495             (beginning-of-line)
14496           ;; We skip to the beginning of the ranges.
14497           (skip-chars-forward "!: \t"))
14498         ;; We are now at the beginning of the list of read articles.
14499         ;; We read them range by range.
14500         (while
14501             (cond 
14502              ((looking-at "[0-9]+")
14503               ;; We narrow and read a number instead of buffer-substring/
14504               ;; string-to-int because it's faster.  narrow/widen is
14505               ;; faster than save-restriction/narrow, and save-restriction
14506               ;; produces a garbage object.
14507               (setq num1 (progn
14508                            (narrow-to-region (match-beginning 0) (match-end 0))
14509                            (read buf)))
14510               (widen)
14511               ;; If the next character is a dash, then this is a range.
14512               (if (= (following-char) ?-)
14513                   (progn
14514                     ;; We read the upper bound of the range.
14515                     (forward-char 1)
14516                     (if (not (looking-at "[0-9]+"))
14517                         ;; This is a buggy line, by we pretend that
14518                         ;; it's kinda OK.  Perhaps the user should be
14519                         ;; dinged? 
14520                         (setq reads (cons num1 reads))
14521                       (setq reads 
14522                             (cons 
14523                              (cons num1
14524                                    (progn
14525                                      (narrow-to-region (match-beginning 0) 
14526                                                        (match-end 0))
14527                                      (read buf)))
14528                              reads))
14529                       (widen)))
14530                 ;; It was just a simple number, so we add it to the
14531                 ;; list of ranges.
14532                 (setq reads (cons num1 reads)))
14533               ;; If the next char in ?\n, then we have reached the end
14534               ;; of the line and return nil.
14535               (/= (following-char) ?\n))
14536              ((= (following-char) ?\n)
14537               ;; End of line, so we end.
14538               nil)
14539              (t
14540               ;; Not numbers and not eol, so this might be a buggy
14541               ;; line... 
14542               (or (eobp)                
14543                   ;; If it was eob instead of ?\n, we allow it.
14544                   (progn
14545                     ;; The line was buggy.
14546                     (setq group nil)
14547                     (gnus-message 3 "Mangled line: %s" 
14548                                   (buffer-substring (gnus-point-at-bol) 
14549                                                     (gnus-point-at-eol)))
14550                     (ding)
14551                     (sit-for 1)))
14552               nil))
14553           ;; Skip past ", ".  Spaces are illegal in these ranges, but
14554           ;; we allow them, because it's a common mistake to put a
14555           ;; space after the comma.
14556           (skip-chars-forward ", "))
14557
14558         ;; We have already read .newsrc.eld, so we gently update the
14559         ;; data in the hash table with the information we have just
14560         ;; read. 
14561         (when group
14562           (let ((info (gnus-get-info group))
14563                 level)
14564             (if info
14565                 ;; There is an entry for this file in the alist.
14566                 (progn
14567                   (gnus-info-set-read info (nreverse reads))
14568                   ;; We update the level very gently.  In fact, we
14569                   ;; only change it if there's been a status change
14570                   ;; from subscribed to unsubscribed, or vice versa.
14571                   (setq level (gnus-info-level info))
14572                   (cond ((and (<= level gnus-level-subscribed)
14573                               (not subscribed))
14574                          (setq level (if reads
14575                                          gnus-level-default-unsubscribed 
14576                                        (1+ gnus-level-default-unsubscribed))))
14577                         ((and (> level gnus-level-subscribed) subscribed)
14578                          (setq level gnus-level-default-subscribed)))
14579                   (gnus-info-set-level info level))
14580               ;; This is a new group.
14581               (setq info (list group 
14582                                (if subscribed
14583                                    gnus-level-default-subscribed 
14584                                  (if reads
14585                                      (1+ gnus-level-subscribed)
14586                                    gnus-level-default-unsubscribed))
14587                                (nreverse reads))))
14588             (setq newsrc (cons info newsrc))))))
14589       (forward-line 1))
14590     
14591     (setq newsrc (nreverse newsrc))
14592
14593     (if (not already-read)
14594         ()
14595       ;; We now have two newsrc lists - `newsrc', which is what we
14596       ;; have read from .newsrc, and `gnus-newsrc-alist', which is
14597       ;; what we've read from .newsrc.eld.  We have to merge these
14598       ;; lists.  We do this by "attaching" any (foreign) groups in the
14599       ;; gnus-newsrc-alist to the (native) group that precedes them. 
14600       (let ((rc (cdr gnus-newsrc-alist))
14601             (prev gnus-newsrc-alist)
14602             entry mentry)
14603         (while rc
14604           (or (null (nth 4 (car rc)))   ; It's a native group.
14605               (assoc (car (car rc)) newsrc) ; It's already in the alist.
14606               (if (setq entry (assoc (car (car prev)) newsrc))
14607                   (setcdr (setq mentry (memq entry newsrc))
14608                           (cons (car rc) (cdr mentry)))
14609                 (setq newsrc (cons (car rc) newsrc))))
14610           (setq prev rc
14611                 rc (cdr rc)))))
14612
14613     (setq gnus-newsrc-alist newsrc)
14614     ;; We make the newsrc hashtb.
14615     (gnus-make-hashtable-from-newsrc-alist)
14616
14617     ;; Finally, if we read some options lines, we parse them.
14618     (or (string= gnus-newsrc-options "")
14619         (gnus-newsrc-parse-options gnus-newsrc-options))))
14620
14621 ;; Parse options lines to find "options -n !all rec.all" and stuff.
14622 ;; The return value will be a list on the form
14623 ;; ((regexp1 . ignore)
14624 ;;  (regexp2 . subscribe)...)
14625 ;; When handling new newsgroups, groups that match a `ignore' regexp
14626 ;; will be ignored, and groups that match a `subscribe' regexp will be
14627 ;; subscribed.  A line like
14628 ;; options -n !all rec.all
14629 ;; will lead to a list that looks like
14630 ;; (("^rec\\..+" . subscribe) 
14631 ;;  ("^.+" . ignore))
14632 ;; So all "rec.*" groups will be subscribed, while all the other
14633 ;; groups will be ignored.  Note that "options -n !all rec.all" is very
14634 ;; different from "options -n rec.all !all". 
14635 (defun gnus-newsrc-parse-options (options)
14636   (let (out eol)
14637     (save-excursion
14638       (gnus-set-work-buffer)
14639       (insert (regexp-quote options))
14640       ;; First we treat all continuation lines.
14641       (goto-char (point-min))
14642       (while (re-search-forward "\n[ \t]+" nil t)
14643         (replace-match " " t t))
14644       ;; Then we transform all "all"s into ".+"s.
14645       (goto-char (point-min))
14646       (while (re-search-forward "\\ball\\b" nil t)
14647         (replace-match ".+" t t))
14648       (goto-char (point-min))
14649       ;; We remove all other options than the "-n" ones.
14650       (while (re-search-forward "[ \t]-[^n][^-]*" nil t)
14651         (replace-match " ")
14652         (forward-char -1))
14653       (goto-char (point-min))
14654
14655       ;; We are only interested in "options -n" lines - we
14656       ;; ignore the other option lines.
14657       (while (re-search-forward "[ \t]-n" nil t)
14658         (setq eol 
14659               (or (save-excursion
14660                     (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t)
14661                          (- (point) 2)))
14662                   (gnus-point-at-eol)))
14663         ;; Search for all "words"...
14664         (while (re-search-forward "[^ \t,\n]+" eol t)
14665           (if (= (char-after (match-beginning 0)) ?!)
14666               ;; If the word begins with a bang (!), this is a "not"
14667               ;; spec.  We put this spec (minus the bang) and the
14668               ;; symbol `ignore' into the list.
14669               (setq out (cons (cons (concat 
14670                                      "^" (buffer-substring 
14671                                           (1+ (match-beginning 0))
14672                                           (match-end 0)))
14673                                     'ignore) out))
14674             ;; There was no bang, so this is a "yes" spec.
14675             (setq out (cons (cons (concat "^" (match-string 0))
14676                                   'subscribe) out)))))
14677     
14678       (setq gnus-newsrc-options-n out))))
14679
14680 (defun gnus-save-newsrc-file (&optional force)
14681   "Save .newsrc file."
14682   ;; Note: We cannot save .newsrc file if all newsgroups are removed
14683   ;; from the variable gnus-newsrc-alist.
14684   (when (and (or gnus-newsrc-alist gnus-killed-list)
14685              gnus-current-startup-file)
14686     (save-excursion
14687       (if (and (or gnus-use-dribble-file gnus-slave)
14688                (not force)
14689                (or (not gnus-dribble-buffer)
14690                    (not (buffer-name gnus-dribble-buffer))
14691                    (zerop (save-excursion
14692                             (set-buffer gnus-dribble-buffer)
14693                             (buffer-size)))))
14694           (gnus-message 4 "(No changes need to be saved)")
14695         (run-hooks 'gnus-save-newsrc-hook)
14696         (if gnus-slave
14697             (gnus-slave-save-newsrc)
14698           ;; Save .newsrc.
14699           (when gnus-save-newsrc-file
14700             (gnus-message 5 "Saving %s..." gnus-current-startup-file)
14701             (gnus-gnus-to-newsrc-format)
14702             (gnus-message 5 "Saving %s...done" gnus-current-startup-file))
14703           ;; Save .newsrc.eld.
14704           (set-buffer (get-buffer-create " *Gnus-newsrc*"))
14705           (make-local-variable 'version-control)
14706           (setq version-control 'never)
14707           (setq buffer-file-name 
14708                 (concat gnus-current-startup-file ".eld"))
14709           (gnus-add-current-to-buffer-list)
14710           (buffer-disable-undo (current-buffer))
14711           (erase-buffer)
14712           (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file)
14713           (gnus-gnus-to-quick-newsrc-format)
14714           (run-hooks 'gnus-save-quick-newsrc-hook)
14715           (save-buffer)
14716           (kill-buffer (current-buffer))
14717           (gnus-message 
14718            5 "Saving %s.eld...done" gnus-current-startup-file))
14719         (gnus-dribble-delete-file)))))
14720
14721 (defun gnus-gnus-to-quick-newsrc-format ()
14722   "Insert Gnus variables such as gnus-newsrc-alist in lisp format."
14723   (insert ";; Gnus startup file.\n")
14724   (insert ";; Never delete this file - touch .newsrc instead to force Gnus\n")
14725   (insert ";; to read .newsrc.\n")
14726   (insert "(setq gnus-newsrc-file-version "
14727           (prin1-to-string gnus-version) ")\n")
14728   (let ((variables 
14729          (if gnus-save-killed-list gnus-variable-list
14730            ;; Remove the `gnus-killed-list' from the list of variables
14731            ;; to be saved, if required.
14732            (delq 'gnus-killed-list (copy-sequence gnus-variable-list))))
14733         ;; Peel off the "dummy" group.
14734         (gnus-newsrc-alist (cdr gnus-newsrc-alist))
14735         variable)
14736     ;; Insert the variables into the file.
14737     (while variables
14738       (when (and (boundp (setq variable (pop variables)))
14739                  (symbol-value variable))
14740         (insert "(setq " (symbol-name variable) " '"
14741                 (prin1-to-string (symbol-value variable)) ")\n")))))
14742
14743 (defun gnus-gnus-to-newsrc-format ()
14744   ;; Generate and save the .newsrc file.
14745   (let ((newsrc (cdr gnus-newsrc-alist))
14746         info ranges range)
14747     (save-excursion
14748       (set-buffer (create-file-buffer gnus-current-startup-file))
14749       (setq buffer-file-name gnus-current-startup-file)
14750       (buffer-disable-undo (current-buffer))
14751       (erase-buffer)
14752       ;; Write options.
14753       (if gnus-newsrc-options (insert gnus-newsrc-options))
14754       ;; Write subscribed and unsubscribed.
14755       (while newsrc
14756         (setq info (car newsrc))
14757         (if (not (gnus-info-method info))
14758             ;; Don't write foreign groups to .newsrc.
14759             (progn
14760               (insert (gnus-info-group info)
14761                       (if (> (nth 1 info) gnus-level-subscribed)
14762                           "!" ":"))
14763               (if (setq ranges (gnus-info-read info))
14764                   (progn
14765                     (insert " ")
14766                     (if (not (listp (cdr ranges)))
14767                         (if (= (car ranges) (cdr ranges))
14768                             (insert (int-to-string (car ranges)))
14769                           (insert (int-to-string (car ranges)) "-" 
14770                                   (int-to-string (cdr ranges))))
14771                       (while ranges
14772                         (setq range (car ranges)
14773                               ranges (cdr ranges))
14774                         (if (or (atom range) (= (car range) (cdr range)))
14775                             (insert (int-to-string 
14776                                      (or (and (atom range) range) 
14777                                          (car range))))
14778                           (insert (int-to-string (car range)) "-"
14779                                   (int-to-string (cdr range))))
14780                         (if ranges (insert ","))))))
14781               (insert "\n")))
14782         (setq newsrc (cdr newsrc)))
14783       (make-local-variable 'version-control)
14784       (setq version-control 'never)
14785       ;; It has been reported that sometime the modtime on the .newsrc
14786       ;; file seems to be off.  We really do want to overwrite it, so
14787       ;; we clear the modtime here before saving.  It's a bit odd,
14788       ;; though... 
14789       ;; sometimes the modtime clear isn't sufficient.  most brute force:
14790       ;; delete the silly thing entirely first.  but this fails to provide
14791       ;; such niceties as .newsrc~ creation.
14792       (if gnus-modtime-botch
14793           (delete-file gnus-startup-file)
14794         (clear-visited-file-modtime))
14795       (run-hooks 'gnus-save-standard-newsrc-hook)
14796       (save-buffer)
14797       (kill-buffer (current-buffer)))))
14798
14799
14800 ;;; Slave functions.
14801
14802 (defun gnus-slave-save-newsrc ()
14803   (save-excursion
14804     (set-buffer gnus-dribble-buffer)
14805     (let ((slave-name 
14806            (make-temp-name (concat gnus-current-startup-file "-slave-"))))
14807       (write-region (point-min) (point-max) slave-name nil 'nomesg))))
14808
14809 (defun gnus-master-read-slave-newsrc ()
14810   (let ((slave-files 
14811          (directory-files 
14812           (file-name-directory gnus-current-startup-file)
14813           t (concat 
14814              "^" (regexp-quote
14815                   (concat
14816                    (file-name-nondirectory gnus-current-startup-file)
14817                    "-slave-")))
14818           t))
14819         file)
14820     (if (not slave-files)
14821         ()                              ; There are no slave files to read.
14822       (gnus-message 7 "Reading slave newsrcs...")
14823       (save-excursion
14824         (set-buffer (get-buffer-create " *gnus slave*"))
14825         (buffer-disable-undo (current-buffer))
14826         (setq slave-files 
14827               (sort (mapcar (lambda (file) 
14828                               (list (nth 5 (file-attributes file)) file))
14829                             slave-files)
14830                     (lambda (f1 f2)
14831                       (or (< (car (car f1)) (car (car f2)))
14832                           (< (nth 1 (car f1)) (nth 1 (car f2)))))))
14833         (while slave-files
14834           (erase-buffer)
14835           (setq file (nth 1 (car slave-files)))
14836           (insert-file-contents file)
14837           (if (condition-case ()
14838                   (progn
14839                     (eval-buffer (current-buffer))
14840                     t)
14841                 (error 
14842                  (message "Possible error in %s" file)
14843                  (ding)
14844                  (sit-for 2)
14845                  nil))
14846               (or gnus-slave ; Slaves shouldn't delete these files.
14847                   (condition-case ()
14848                       (delete-file file)
14849                     (error nil))))
14850           (setq slave-files (cdr slave-files))))
14851       (gnus-message 7 "Reading slave newsrcs...done"))))
14852
14853
14854 ;;; Group description.
14855
14856 (defun gnus-read-all-descriptions-files ()
14857   (let ((methods (cons gnus-select-method gnus-secondary-select-methods)))
14858     (while methods
14859       (gnus-read-descriptions-file (car methods))
14860       (setq methods (cdr methods)))
14861     t))
14862
14863 (defun gnus-read-descriptions-file (&optional method)
14864   (let ((method (or method gnus-select-method)))
14865     ;; We create the hashtable whether we manage to read the desc file
14866     ;; to avoid trying to re-read after a failed read.
14867     (or gnus-description-hashtb
14868         (setq gnus-description-hashtb 
14869               (gnus-make-hashtable (length gnus-active-hashtb))))
14870     ;; Mark this method's desc file as read.
14871     (gnus-sethash (gnus-group-prefixed-name "" method) "Has read"
14872                   gnus-description-hashtb)
14873
14874     (gnus-message 5 "Reading descriptions file via %s..." (car method))
14875     (cond 
14876      ((not (gnus-check-server method))
14877       (gnus-message 1 "Couldn't open server")
14878       nil)
14879      ((not (gnus-request-list-newsgroups method))
14880       (gnus-message 1 "Couldn't read newsgroups descriptions")
14881       nil)
14882      (t
14883       (let (group)
14884         (save-excursion
14885           (save-restriction
14886             (set-buffer nntp-server-buffer)
14887             (goto-char (point-min))
14888             (if (or (search-forward "\n.\n" nil t)
14889                     (goto-char (point-max)))
14890                 (progn
14891                   (beginning-of-line)
14892                   (narrow-to-region (point-min) (point))))
14893             (goto-char (point-min))
14894             (while (not (eobp))
14895               ;; If we get an error, we set group to 0, which is not a
14896               ;; symbol... 
14897               (setq group 
14898                     (condition-case ()
14899                         (let ((obarray gnus-description-hashtb))
14900                           ;; Group is set to a symbol interned in this
14901                           ;; hash table.
14902                           (read nntp-server-buffer))
14903                       (error 0)))
14904               (skip-chars-forward " \t")
14905               ;; ...  which leads to this line being effectively ignored.
14906               (and (symbolp group)
14907                    (set group (buffer-substring 
14908                                (point) (progn (end-of-line) (point)))))
14909               (forward-line 1))))
14910         (gnus-message 5 "Reading descriptions file...done")
14911         t)))))
14912
14913 (defun gnus-group-get-description (group)
14914   "Get the description of a group by sending XGTITLE to the server."
14915   (when (gnus-request-group-description group)
14916     (save-excursion
14917       (set-buffer nntp-server-buffer)
14918       (goto-char (point-min))
14919       (when (looking-at "[^ \t]+[ \t]+\\(.*\\)")
14920         (match-string 1)))))
14921
14922 ;;;
14923 ;;; Buffering of read articles.
14924 ;;;
14925
14926 (defvar gnus-backlog-buffer " *Gnus Backlog*")
14927 (defvar gnus-backlog-articles nil)
14928 (defvar gnus-backlog-hashtb nil)
14929
14930 (defun gnus-backlog-buffer ()
14931   "Return the backlog buffer."
14932   (or (get-buffer gnus-backlog-buffer)
14933       (save-excursion
14934         (set-buffer (get-buffer-create gnus-backlog-buffer))
14935         (buffer-disable-undo (current-buffer))
14936         (setq buffer-read-only t)
14937         (gnus-add-current-to-buffer-list))))
14938
14939 (defun gnus-backlog-setup ()
14940   "Initialize backlog variables."
14941   (unless gnus-backlog-hashtb
14942     (setq gnus-backlog-hashtb (make-vector 1023 0))))
14943
14944 (defun gnus-backlog-enter-article (group number buffer)
14945   (gnus-backlog-setup)
14946   (let ((ident (intern (concat group ":" (int-to-string number))
14947                        gnus-backlog-hashtb))
14948         b)
14949     (if (memq ident gnus-backlog-articles)
14950         () ; It's already kept.
14951       ;; Remove the oldest article, if necessary.
14952       (and (numberp gnus-keep-backlog)
14953            (>= (length gnus-backlog-articles) gnus-keep-backlog)
14954            (gnus-backlog-remove-oldest-article))
14955       (setq gnus-backlog-articles (cons ident gnus-backlog-articles))
14956       ;; Insert the new article.
14957       (save-excursion
14958         (set-buffer (gnus-backlog-buffer))
14959         (let (buffer-read-only)
14960           (goto-char (point-max))
14961           (or (bolp) (insert "\n"))
14962           (setq b (point))
14963           (insert-buffer-substring buffer)
14964           ;; Tag the beginning of the article with the ident.
14965           (put-text-property b (1+ b) 'gnus-backlog ident))))))
14966
14967 (defun gnus-backlog-remove-oldest-article ()
14968   (save-excursion
14969     (set-buffer (gnus-backlog-buffer))
14970     (goto-char (point-min))
14971     (if (zerop (buffer-size))
14972         () ; The buffer is empty.
14973       (let ((ident (get-text-property (point) 'gnus-backlog))
14974             buffer-read-only)
14975         ;; Remove the ident from the list of articles.
14976         (when ident
14977           (setq gnus-backlog-articles (delq ident gnus-backlog-articles)))
14978         ;; Delete the article itself.
14979         (delete-region 
14980          (point) (next-single-property-change
14981                   (1+ (point)) 'gnus-backlog nil (point-max)))))))
14982
14983 (defun gnus-backlog-request-article (group number buffer)
14984   (gnus-backlog-setup)
14985   (let ((ident (intern (concat group ":" (int-to-string number))
14986                        gnus-backlog-hashtb))
14987         beg end)
14988     (when (memq ident gnus-backlog-articles)
14989       ;; It was in the backlog.
14990       (save-excursion
14991         (set-buffer (gnus-backlog-buffer))
14992         (if (not (setq beg (text-property-any 
14993                             (point-min) (point-max) 'gnus-backlog
14994                             ident)))
14995             ;; It wasn't in the backlog after all.
14996             (progn
14997               (setq gnus-backlog-articles (delq ident gnus-backlog-articles))
14998               nil)
14999           ;; Find the end (i. e., the beginning of the next article).
15000           (setq end
15001                 (next-single-property-change 
15002                  (1+ beg) 'gnus-backlog (current-buffer) (point-max)))))
15003       (let ((buffer-read-only nil))
15004         (erase-buffer)
15005         (insert-buffer-substring gnus-backlog-buffer beg end)))))
15006
15007 ;; Allow redefinition of Gnus functions.
15008
15009 (gnus-ems-redefine)
15010
15011 (provide 'gnus)
15012
15013 ;;; gnus.el ends here