c9004f5b477bd3529fbc204f38dd45217f953830
[elisp/gnus.git-] / lisp / gnus.el
1 ;;; gnus.el --- a newsreader for GNU Emacs
2 ;; Copyright (C) 1987,88,89,90,93,94,95,96,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
5 ;;      Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, mail
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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval '(run-hooks 'gnus-load-hook))
30
31 (eval-when-compile (require 'cl))
32
33 (require 'custom)
34 (eval-and-compile
35   (if (< emacs-major-version 20)
36       (require 'gnus-load)))
37 (require 'message)
38
39 (defgroup gnus nil
40   "The coffee-brewing, all singing, all dancing, kitchen sink newsreader."
41   :group 'news
42   :group 'mail)
43
44 (defgroup gnus-cache nil
45   "Cache interface."
46   :group 'gnus)
47
48 (defgroup gnus-start nil
49   "Starting your favorite newsreader."
50   :group 'gnus)
51
52 (defgroup gnus-start-server nil
53   "Server options at startup."
54   :group 'gnus-start)
55
56 ;; These belong to gnus-group.el.
57 (defgroup gnus-group nil
58   "Group buffers."
59   :link '(custom-manual "(gnus)The Group Buffer")
60   :group 'gnus)
61
62 (defgroup gnus-group-foreign nil
63   "Foreign groups."
64   :link '(custom-manual "(gnus)Foreign Groups")
65   :group 'gnus-group)
66
67 (defgroup gnus-group-new nil
68   "Automatic subscription of new groups."
69   :group 'gnus-group)
70
71 (defgroup gnus-group-levels nil
72   "Group levels."
73   :link '(custom-manual "(gnus)Group Levels")
74   :group 'gnus-group)
75
76 (defgroup gnus-group-select nil
77   "Selecting a Group."
78   :link '(custom-manual "(gnus)Selecting a Group")
79   :group 'gnus-group)
80
81 (defgroup gnus-group-listing nil
82   "Showing slices of the group list."
83   :link '(custom-manual "(gnus)Listing Groups")
84   :group 'gnus-group)
85
86 (defgroup gnus-group-visual nil
87   "Sorting the group buffer."
88   :link '(custom-manual "(gnus)Group Buffer Format")
89   :group 'gnus-group
90   :group 'gnus-visual)
91
92 (defgroup gnus-group-various nil
93   "Various group options."
94   :link '(custom-manual "(gnus)Scanning New Messages")
95   :group 'gnus-group)
96
97 ;; These belong to gnus-sum.el.
98 (defgroup gnus-summary nil
99   "Summary buffers."
100   :link '(custom-manual "(gnus)The Summary Buffer")
101   :group 'gnus)
102
103 (defgroup gnus-summary-exit nil
104   "Leaving summary buffers."
105   :link '(custom-manual "(gnus)Exiting the Summary Buffer")
106   :group 'gnus-summary)
107
108 (defgroup gnus-summary-marks nil
109   "Marks used in summary buffers."
110   :link '(custom-manual "(gnus)Marking Articles")
111   :group 'gnus-summary)
112
113 (defgroup gnus-thread nil
114   "Ordering articles according to replies."
115   :link '(custom-manual "(gnus)Threading")
116   :group 'gnus-summary)
117
118 (defgroup gnus-summary-format nil
119   "Formatting of the summary buffer."
120   :link '(custom-manual "(gnus)Summary Buffer Format")
121   :group 'gnus-summary)
122
123 (defgroup gnus-summary-choose nil
124   "Choosing Articles."
125   :link '(custom-manual "(gnus)Choosing Articles")
126   :group 'gnus-summary)
127
128 (defgroup gnus-summary-maneuvering nil
129   "Summary movement commands."
130   :link '(custom-manual "(gnus)Summary Maneuvering")
131   :group 'gnus-summary)
132
133 (defgroup gnus-summary-mail nil
134   "Mail group commands."
135   :link '(custom-manual "(gnus)Mail Group Commands")
136   :group 'gnus-summary)
137
138 (defgroup gnus-summary-sort nil
139   "Sorting the summary buffer."
140   :link '(custom-manual "(gnus)Sorting")
141   :group 'gnus-summary)
142
143 (defgroup gnus-summary-visual nil
144   "Highlighting and menus in the summary buffer."
145   :link '(custom-manual "(gnus)Summary Highlighting")
146   :group 'gnus-visual
147   :group 'gnus-summary)
148
149 (defgroup gnus-summary-various nil
150   "Various summary buffer options."
151   :link '(custom-manual "(gnus)Various Summary Stuff")
152   :group 'gnus-summary)
153
154 (defgroup gnus-summary-pick nil
155   "Pick mode in the summary buffer."
156   :link '(custom-manual "(gnus)Pick and Read")
157   :prefix "gnus-pick-"
158   :group 'gnus-summary)
159
160 (defgroup gnus-summary-tree nil
161   "Tree display of threads in the summary buffer."
162   :link '(custom-manual "(gnus)Tree Display")
163   :prefix "gnus-tree-"
164   :group 'gnus-summary)
165
166 ;; Belongs to gnus-uu.el
167 (defgroup gnus-extract-view nil
168   "Viewing extracted files."
169   :link '(custom-manual "(gnus)Viewing Files")
170   :group 'gnus-extract)
171
172 ;; Belongs to gnus-score.el
173 (defgroup gnus-score nil
174   "Score and kill file handling."
175   :group 'gnus)
176
177 (defgroup gnus-score-kill nil
178   "Kill files."
179   :group 'gnus-score)
180
181 (defgroup gnus-score-adapt nil
182   "Adaptive score files."
183   :group 'gnus-score)
184
185 (defgroup gnus-score-default nil
186   "Default values for score files."
187   :group 'gnus-score)
188
189 (defgroup gnus-score-expire nil
190   "Expiring score rules."
191   :group 'gnus-score)
192
193 (defgroup gnus-score-decay nil
194   "Decaying score rules."
195   :group 'gnus-score)
196
197 (defgroup gnus-score-files nil
198   "Score and kill file names."
199   :group 'gnus-score
200   :group 'gnus-files)
201
202 (defgroup gnus-score-various nil
203   "Various scoring and killing options."
204   :group 'gnus-score)
205
206 ;; Other
207 (defgroup gnus-visual nil
208   "Options controling the visual fluff."
209   :group 'gnus
210   :group 'faces)
211
212 (defgroup gnus-agent nil
213   "Offline support for Gnus."
214   :group 'gnus)
215
216 (defgroup gnus-files nil
217   "Files used by Gnus."
218   :group 'gnus)
219
220 (defgroup gnus-dribble-file nil
221   "Auto save file."
222   :link '(custom-manual "(gnus)Auto Save")
223   :group 'gnus-files)
224
225 (defgroup gnus-newsrc nil
226   "Storing Gnus state."
227   :group 'gnus-files)
228
229 (defgroup gnus-server nil
230   "Options related to newsservers and other servers used by Gnus."
231   :group 'gnus)
232
233 (defgroup gnus-message '((message custom-group))
234   "Composing replies and followups in Gnus."
235   :group 'gnus)
236
237 (defgroup gnus-meta nil
238   "Meta variables controling major portions of Gnus.
239 In general, modifying these variables does not take affect until Gnus
240 is restarted, and sometimes reloaded."
241   :group 'gnus)
242
243 (defgroup gnus-various nil
244   "Other Gnus options."
245   :link '(custom-manual "(gnus)Various Various")
246   :group 'gnus)
247
248 (defgroup gnus-exit nil
249   "Exiting gnus."
250   :link '(custom-manual "(gnus)Exiting Gnus")
251   :group 'gnus)
252
253 (defconst gnus-product-name "T-gnus"
254   "Product name of this version of gnus.")
255
256 (defconst gnus-version-number "6.8.16"
257   "Version number for this version of gnus.")
258
259 (defconst gnus-version
260   (format "%s %s (based on Gnus 5.6.41; for SEMI 1.8, FLIM 1.8/1.9)"
261           gnus-product-name gnus-version-number)
262   "Version string for this version of gnus.")
263
264 (defcustom gnus-inhibit-startup-message nil
265   "If non-nil, the startup message will not be displayed.
266 This variable is used before `.gnus.el' is loaded, so it should
267 be set in `.emacs' instead."
268   :group 'gnus-start
269   :type 'boolean)
270
271 (defcustom gnus-play-startup-jingle nil
272   "If non-nil, play the Gnus jingle at startup."
273   :group 'gnus-start
274   :type 'boolean)
275
276 ;;; Kludges to help the transition from the old `custom.el'.
277
278 (unless (featurep 'gnus-xmas)
279   (defalias 'gnus-make-overlay 'make-overlay)
280   (defalias 'gnus-delete-overlay 'delete-overlay)
281   (defalias 'gnus-overlay-put 'overlay-put)
282   (defalias 'gnus-move-overlay 'move-overlay)
283   (defalias 'gnus-overlay-end 'overlay-end)
284   (defalias 'gnus-extent-detached-p 'ignore)
285   (defalias 'gnus-extent-start-open 'ignore)
286   (defalias 'gnus-set-text-properties 'set-text-properties)
287   (defalias 'gnus-group-remove-excess-properties 'ignore)
288   (defalias 'gnus-appt-select-lowest-window 'appt-select-lowest-window)
289   (defalias 'gnus-mail-strip-quoted-names 'mail-strip-quoted-names)
290   (defalias 'gnus-character-to-event 'identity)
291   (defalias 'gnus-add-text-properties 'add-text-properties)
292   (defalias 'gnus-put-text-property 'put-text-property)
293   (defalias 'gnus-mode-line-buffer-identification 'identity)
294   (defalias 'gnus-characterp 'numberp)
295   (defalias 'gnus-deactivate-mark 'deactivate-mark)
296   (defalias 'gnus-window-edges 'window-edges)
297   (defalias 'gnus-key-press-event-p 'numberp))
298
299 ;; We define these group faces here to avoid the display
300 ;; update forced when creating new faces.
301
302 (defface gnus-group-news-1-face
303   '((((class color)
304       (background dark))
305      (:foreground "PaleTurquoise" :bold t))
306     (((class color)
307       (background light))
308      (:foreground "ForestGreen" :bold t))
309     (t
310      ()))
311   "Level 1 newsgroup face.")
312
313 (defface gnus-group-news-1-empty-face
314   '((((class color)
315       (background dark))
316      (:foreground "PaleTurquoise"))
317     (((class color)
318       (background light))
319      (:foreground "ForestGreen"))
320     (t
321      ()))
322   "Level 1 empty newsgroup face.")
323
324 (defface gnus-group-news-2-face
325   '((((class color)
326       (background dark))
327      (:foreground "turquoise" :bold t))
328     (((class color)
329       (background light))
330      (:foreground "CadetBlue4" :bold t))
331     (t
332      ()))
333   "Level 2 newsgroup face.")
334
335 (defface gnus-group-news-2-empty-face
336   '((((class color)
337       (background dark))
338      (:foreground "turquoise"))
339     (((class color)
340       (background light))
341      (:foreground "CadetBlue4"))
342     (t
343      ()))
344   "Level 2 empty newsgroup face.")
345
346 (defface gnus-group-news-3-face
347   '((((class color)
348       (background dark))
349      (:bold t))
350     (((class color)
351       (background light))
352      (:bold t))
353     (t
354      ()))
355   "Level 3 newsgroup face.")
356
357 (defface gnus-group-news-3-empty-face
358   '((((class color)
359       (background dark))
360      ())
361     (((class color)
362       (background light))
363      ())
364     (t
365      ()))
366   "Level 3 empty newsgroup face.")
367
368 (defface gnus-group-news-low-face
369   '((((class color)
370       (background dark))
371      (:foreground "DarkTurquoise" :bold t))
372     (((class color)
373       (background light))
374      (:foreground "DarkGreen" :bold t))
375     (t
376      ()))
377   "Low level newsgroup face.")
378
379 (defface gnus-group-news-low-empty-face
380   '((((class color)
381       (background dark))
382      (:foreground "DarkTurquoise"))
383     (((class color)
384       (background light))
385      (:foreground "DarkGreen"))
386     (t
387      ()))
388   "Low level empty newsgroup face.")
389
390 (defface gnus-group-mail-1-face
391   '((((class color)
392       (background dark))
393      (:foreground "aquamarine1" :bold t))
394     (((class color)
395       (background light))
396      (:foreground "DeepPink3" :bold t))
397     (t
398      (:bold t)))
399   "Level 1 mailgroup face.")
400
401 (defface gnus-group-mail-1-empty-face
402   '((((class color)
403       (background dark))
404      (:foreground "aquamarine1"))
405     (((class color)
406       (background light))
407      (:foreground "DeepPink3"))
408     (t
409      (:italic t :bold t)))
410   "Level 1 empty mailgroup face.")
411
412 (defface gnus-group-mail-2-face
413   '((((class color)
414       (background dark))
415      (:foreground "aquamarine2" :bold t))
416     (((class color)
417       (background light))
418      (:foreground "HotPink3" :bold t))
419     (t
420      (:bold t)))
421   "Level 2 mailgroup face.")
422
423 (defface gnus-group-mail-2-empty-face
424   '((((class color)
425       (background dark))
426      (:foreground "aquamarine2"))
427     (((class color)
428       (background light))
429      (:foreground "HotPink3"))
430     (t
431      (:bold t)))
432   "Level 2 empty mailgroup face.")
433
434 (defface gnus-group-mail-3-face
435   '((((class color)
436       (background dark))
437      (:foreground "aquamarine3" :bold t))
438     (((class color)
439       (background light))
440      (:foreground "magenta4" :bold t))
441     (t
442      (:bold t)))
443   "Level 3 mailgroup face.")
444
445 (defface gnus-group-mail-3-empty-face
446   '((((class color)
447       (background dark))
448      (:foreground "aquamarine3"))
449     (((class color)
450       (background light))
451      (:foreground "magenta4"))
452     (t
453      ()))
454   "Level 3 empty mailgroup face.")
455
456 (defface gnus-group-mail-low-face
457   '((((class color)
458       (background dark))
459      (:foreground "aquamarine4" :bold t))
460     (((class color)
461       (background light))
462      (:foreground "DeepPink4" :bold t))
463     (t
464      (:bold t)))
465   "Low level mailgroup face.")
466
467 (defface gnus-group-mail-low-empty-face
468   '((((class color)
469       (background dark))
470      (:foreground "aquamarine4"))
471     (((class color)
472       (background light))
473      (:foreground "DeepPink4"))
474     (t
475      (:bold t)))
476   "Low level empty mailgroup face.")
477
478 ;; Summary mode faces.
479
480 (defface gnus-summary-selected-face '((t
481                                        (:underline t)))
482   "Face used for selected articles.")
483
484 (defface gnus-summary-cancelled-face
485   '((((class color))
486      (:foreground "yellow" :background "black")))
487   "Face used for cancelled articles.")
488
489 (defface gnus-summary-high-ticked-face
490   '((((class color)
491       (background dark))
492      (:foreground "pink" :bold t))
493     (((class color)
494       (background light))
495      (:foreground "firebrick" :bold t))
496     (t
497      (:bold t)))
498   "Face used for high interest ticked articles.")
499
500 (defface gnus-summary-low-ticked-face
501   '((((class color)
502       (background dark))
503      (:foreground "pink" :italic t))
504     (((class color)
505       (background light))
506      (:foreground "firebrick" :italic t))
507     (t
508      (:italic t)))
509   "Face used for low interest ticked articles.")
510
511 (defface gnus-summary-normal-ticked-face
512   '((((class color)
513       (background dark))
514      (:foreground "pink"))
515     (((class color)
516       (background light))
517      (:foreground "firebrick"))
518     (t
519      ()))
520   "Face used for normal interest ticked articles.")
521
522 (defface gnus-summary-high-ancient-face
523   '((((class color)
524       (background dark))
525      (:foreground "SkyBlue" :bold t))
526     (((class color)
527       (background light))
528      (:foreground "RoyalBlue" :bold t))
529     (t
530      (:bold t)))
531   "Face used for high interest ancient articles.")
532
533 (defface gnus-summary-low-ancient-face
534   '((((class color)
535       (background dark))
536      (:foreground "SkyBlue" :italic t))
537     (((class color)
538       (background light))
539      (:foreground "RoyalBlue" :italic t))
540     (t
541      (:italic t)))
542   "Face used for low interest ancient articles.")
543
544 (defface gnus-summary-normal-ancient-face
545   '((((class color)
546       (background dark))
547      (:foreground "SkyBlue"))
548     (((class color)
549       (background light))
550      (:foreground "RoyalBlue"))
551     (t
552      ()))
553   "Face used for normal interest ancient articles.")
554
555 (defface gnus-summary-high-unread-face
556   '((t
557      (:bold t)))
558   "Face used for high interest unread articles.")
559
560 (defface gnus-summary-low-unread-face
561   '((t
562      (:italic t)))
563   "Face used for low interest unread articles.")
564
565 (defface gnus-summary-normal-unread-face
566   '((t
567      ()))
568   "Face used for normal interest unread articles.")
569
570 (defface gnus-summary-high-read-face
571   '((((class color)
572       (background dark))
573      (:foreground "PaleGreen"
574                   :bold t))
575     (((class color)
576       (background light))
577      (:foreground "DarkGreen"
578                   :bold t))
579     (t
580      (:bold t)))
581   "Face used for high interest read articles.")
582
583 (defface gnus-summary-low-read-face
584   '((((class color)
585       (background dark))
586      (:foreground "PaleGreen"
587                   :italic t))
588     (((class color)
589       (background light))
590      (:foreground "DarkGreen"
591                   :italic t))
592     (t
593      (:italic t)))
594   "Face used for low interest read articles.")
595
596 (defface gnus-summary-normal-read-face
597   '((((class color)
598       (background dark))
599      (:foreground "PaleGreen"))
600     (((class color)
601       (background light))
602      (:foreground "DarkGreen"))
603     (t
604      ()))
605   "Face used for normal interest read articles.")
606
607
608 ;;;
609 ;;; Gnus buffers
610 ;;;
611
612 (defvar gnus-buffers nil)
613
614 (defun gnus-get-buffer-create (name)
615   "Do the same as `get-buffer-create', but store the created buffer."
616   (or (get-buffer name)
617       (car (push (get-buffer-create name) gnus-buffers))))
618
619 (defun gnus-add-buffer ()
620   "Add the current buffer to the list of Gnus buffers."
621   (push (current-buffer) gnus-buffers))
622
623 (defun gnus-buffers ()
624   "Return a list of live Gnus buffers."
625   (while (and gnus-buffers
626               (not (buffer-name (car gnus-buffers))))
627     (pop gnus-buffers))
628   (let ((buffers gnus-buffers))
629     (while (cdr buffers)
630       (if (buffer-name (cadr buffers))
631           (pop buffers)
632         (setcdr buffers (cddr buffers)))))
633   gnus-buffers)
634
635 ;;; Splash screen.
636
637 (defvar gnus-group-buffer "*Group*")
638
639 (eval-and-compile
640   (autoload 'gnus-play-jingle "gnus-audio"))
641
642 (defface gnus-splash-face
643   '((((class color)
644       (background dark))
645      (:foreground "ForestGreen"))
646     (((class color)
647       (background light))
648      (:foreground "ForestGreen"))
649     (t
650      ()))
651   "Level 1 newsgroup face.")
652
653 (defun gnus-splash ()
654   (save-excursion
655     (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
656     (let ((buffer-read-only nil))
657       (erase-buffer)
658       (unless gnus-inhibit-startup-message
659         (gnus-group-startup-message)
660         (sit-for 0)
661         (when gnus-play-startup-jingle
662           (gnus-play-jingle))))))
663
664 (defun gnus-indent-rigidly (start end arg)
665   "Indent rigidly using only spaces and no tabs."
666   (save-excursion
667     (save-restriction
668       (narrow-to-region start end)
669       (let ((tab-width 8))
670         (indent-rigidly start end arg)
671         ;; We translate tabs into spaces -- not everybody uses
672         ;; an 8-character tab.
673         (goto-char (point-min))
674         (while (search-forward "\t" nil t)
675           (replace-match "        " t t))))))
676
677 (defvar gnus-simple-splash nil)
678
679 (defun gnus-group-startup-message (&optional x y)
680   "Insert startup message in current buffer."
681   ;; Insert the message.
682   (erase-buffer)
683   (insert
684    (format "              %s
685           _    ___ _             _
686           _ ___ __ ___  __    _ ___
687           __   _     ___    __  ___
688               _           ___     _
689              _  _ __             _
690              ___   __            _
691                    __           _
692                     _      _   _
693                    _      _    _
694                       _  _    _
695                   __  ___
696                  _   _ _     _
697                 _   _
698               _    _
699              _    _
700             _
701           __
702
703 "
704            ""))
705   ;; And then hack it.
706   (gnus-indent-rigidly (point-min) (point-max)
707                        (/ (max (- (window-width) (or x 46)) 0) 2))
708   (goto-char (point-min))
709   (forward-line 1)
710   (let* ((pheight (count-lines (point-min) (point-max)))
711          (wheight (window-height))
712          (rest (- wheight pheight)))
713     (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
714   ;; Fontify some.
715   (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)
716   (goto-char (point-min))
717   (setq mode-line-buffer-identification (concat " " gnus-version))
718   (setq gnus-simple-splash t)
719   (set-buffer-modified-p t))
720
721 (eval-when (load)
722   (let ((command (format "%s" this-command)))
723     (if (and (string-match "gnus" command)
724              (not (string-match "gnus-other-frame" command)))
725         (gnus-splash)
726       (gnus-get-buffer-create gnus-group-buffer))))
727
728 ;;; Do the rest.
729
730 (require 'custom)
731 (require 'gnus-util)
732 (require 'nnheader)
733
734 (defcustom gnus-home-directory "~/"
735   "Directory variable that specifies the \"home\" directory.
736 All other Gnus path variables are initialized from this variable."
737   :group 'gnus-files
738   :type 'directory)
739
740 (defcustom gnus-directory (or (getenv "SAVEDIR")
741                               (nnheader-concat gnus-home-directory "News/"))
742   "*Directory variable from which all other Gnus file variables are derived.
743
744 Note that Gnus is mostly loaded when the `.gnus.el' file is read.
745 This means that other directory variables that are initialized from
746 this variable won't be set properly if you set this variable in `.gnus.el'.
747 Set this variable in `.emacs' instead."
748   :group 'gnus-files
749   :type 'directory)
750
751 (defcustom gnus-default-directory nil
752   "*Default directory for all Gnus buffers."
753   :group 'gnus-files
754   :type '(choice (const :tag "current" nil)
755                  directory))
756
757 ;; Site dependent variables.  These variables should be defined in
758 ;; paths.el.
759
760 (defvar gnus-default-nntp-server nil
761   "Specify a default NNTP server.
762 This variable should be defined in paths.el, and should never be set
763 by the user.
764 If you want to change servers, you should use `gnus-select-method'.
765 See the documentation to that variable.")
766
767 ;; Don't touch this variable.
768 (defvar gnus-nntp-service "nntp"
769   "NNTP service name (\"nntp\" or 119).
770 This is an obsolete variable, which is scarcely used.  If you use an
771 nntp server for your newsgroup and want to change the port number
772 used to 899, you would say something along these lines:
773
774  (setq gnus-select-method '(nntp \"my.nntp.server\" (nntp-port-number 899)))")
775
776 (defcustom gnus-nntpserver-file "/etc/nntpserver"
777   "A file with only the name of the nntp server in it."
778   :group 'gnus-files
779   :group 'gnus-server
780   :type 'file)
781
782 ;; This function is used to check both the environment variable
783 ;; NNTPSERVER and the /etc/nntpserver file to see whether one can find
784 ;; an nntp server name default.
785 (defun gnus-getenv-nntpserver ()
786   (or (getenv "NNTPSERVER")
787       (and (file-readable-p gnus-nntpserver-file)
788            (save-excursion
789              (set-buffer (gnus-get-buffer-create " *gnus nntp*"))
790              (buffer-disable-undo (current-buffer))
791              (insert-file-contents gnus-nntpserver-file)
792              (let ((name (buffer-string)))
793                (prog1
794                    (if (string-match "^[ \t\n]*$" name)
795                        nil
796                      name)
797                  (kill-buffer (current-buffer))))))))
798
799 (defcustom gnus-select-method
800   (condition-case nil
801     (nconc
802      (list 'nntp (or (condition-case nil
803                          (gnus-getenv-nntpserver)
804                        (error nil))
805                      (when (and gnus-default-nntp-server
806                                 (not (string= gnus-default-nntp-server "")))
807                        gnus-default-nntp-server)
808                      "news"))
809      (if (or (null gnus-nntp-service)
810              (equal gnus-nntp-service "nntp"))
811          nil
812        (list gnus-nntp-service)))
813     (error nil))
814   "*Default method for selecting a newsgroup.
815 This variable should be a list, where the first element is how the
816 news is to be fetched, the second is the address.
817
818 For instance, if you want to get your news via NNTP from
819 \"flab.flab.edu\", you could say:
820
821 \(setq gnus-select-method '(nntp \"flab.flab.edu\"))
822
823 If you want to use your local spool, say:
824
825 \(setq gnus-select-method (list 'nnspool (system-name)))
826
827 If you use this variable, you must set `gnus-nntp-server' to nil.
828
829 There is a lot more to know about select methods and virtual servers -
830 see the manual for details."
831   :group 'gnus-server
832   :type 'gnus-select-method)
833
834 (defcustom gnus-message-archive-method
835   `(nnfolder
836     "archive"
837     (nnfolder-directory ,(nnheader-concat message-directory "archive"))
838     (nnfolder-active-file
839      ,(nnheader-concat message-directory "archive/active"))
840     (nnfolder-get-new-mail nil)
841     (nnfolder-inhibit-expiry t))
842   "*Method used for archiving messages you've sent.
843 This should be a mail method.
844
845 It's probably not a very effective to change this variable once you've
846 run Gnus once.  After doing that, you must edit this server from the
847 server buffer."
848   :group 'gnus-server
849   :group 'gnus-message
850   :type 'gnus-select-method)
851
852 (defcustom gnus-message-archive-group nil
853   "*Name of the group in which to save the messages you've written.
854 This can either be a string; a list of strings; or an alist
855 of regexps/functions/forms to be evaluated to return a string (or a list
856 of strings).  The functions are called with the name of the current
857 group (or nil) as a parameter.
858
859 If you want to save your mail in one group and the news articles you
860 write in another group, you could say something like:
861
862  \(setq gnus-message-archive-group
863         '((if (message-news-p)
864               \"misc-news\"
865             \"misc-mail\")))
866
867 Normally the group names returned by this variable should be
868 unprefixed -- which implicitly means \"store on the archive server\".
869 However, you may wish to store the message on some other server.  In
870 that case, just return a fully prefixed name of the group --
871 \"nnml+private:mail.misc\", for instance."
872   :group 'gnus-message
873   :type '(choice (const :tag "none" nil)
874                  string))
875
876 (defcustom gnus-secondary-servers nil
877   "List of NNTP servers that the user can choose between interactively.
878 To make Gnus query you for a server, you have to give `gnus' a
879 non-numeric prefix - `C-u M-x gnus', in short."
880   :group 'gnus-server
881   :type '(repeat string))
882
883 (defcustom gnus-nntp-server nil
884   "*The name of the host running the NNTP server.
885 This variable is semi-obsolete.  Use the `gnus-select-method'
886 variable instead."
887   :group 'gnus-server
888   :type '(choice (const :tag "disable" nil)
889                  string))
890
891 (defcustom gnus-secondary-select-methods nil
892   "A list of secondary methods that will be used for reading news.
893 This is a list where each element is a complete select method (see
894 `gnus-select-method').
895
896 If, for instance, you want to read your mail with the nnml backend,
897 you could set this variable:
898
899 \(setq gnus-secondary-select-methods '((nnml \"\")))"
900 :group 'gnus-server
901 :type '(repeat gnus-select-method))
902
903 (defvar gnus-backup-default-subscribed-newsgroups
904   '("news.announce.newusers" "news.groups.questions" "gnu.emacs.gnus")
905   "Default default new newsgroups the first time Gnus is run.
906 Should be set in paths.el, and shouldn't be touched by the user.")
907
908 (defcustom gnus-local-domain nil
909   "Local domain name without a host name.
910 The DOMAINNAME environment variable is used instead if it is defined.
911 If the `system-name' function returns the full Internet name, there is
912 no need to set this variable."
913   :group 'gnus-message
914   :type '(choice (const :tag "default" nil)
915                  string))
916
917 (defvar gnus-local-organization nil
918   "String with a description of what organization (if any) the user belongs to.
919 Obsolete variable; use `message-user-organization' instead.")
920
921 ;; Customization variables
922
923 (defcustom gnus-refer-article-method nil
924   "Preferred method for fetching an article by Message-ID.
925 If you are reading news from the local spool (with nnspool), fetching
926 articles by Message-ID is painfully slow.  By setting this method to an
927 nntp method, you might get acceptable results.
928
929 The value of this variable must be a valid select method as discussed
930 in the documentation of `gnus-select-method'."
931   :group 'gnus-server
932   :type '(choice (const :tag "default" nil)
933                  gnus-select-method))
934
935 (defcustom gnus-group-faq-directory
936   '("/ftp@mirrors.aol.com:/pub/rtfm/usenet/"
937     "/ftp@sunsite.auc.dk:/pub/usenet/"
938     "/ftp@sunsite.doc.ic.ac.uk:/pub/usenet/news-faqs/"
939     "/ftp@src.doc.ic.ac.uk:/usenet/news-FAQS/"
940     "/ftp@ftp.seas.gwu.edu:/pub/rtfm/"
941     "/ftp@rtfm.mit.edu:/pub/usenet/"
942     "/ftp@ftp.uni-paderborn.de:/pub/FAQ/"
943     "/ftp@ftp.sunet.se:/pub/usenet/"
944     "/ftp@nctuccca.edu.tw:/USENET/FAQ/"
945     "/ftp@hwarang.postech.ac.kr:/pub/usenet/"
946     "/ftp@ftp.hk.super.net:/mirror/faqs/")
947   "*Directory where the group FAQs are stored.
948 This will most commonly be on a remote machine, and the file will be
949 fetched by ange-ftp.
950
951 This variable can also be a list of directories.  In that case, the
952 first element in the list will be used by default.  The others can
953 be used when being prompted for a site.
954
955 Note that Gnus uses an aol machine as the default directory.  If this
956 feels fundamentally unclean, just think of it as a way to finally get
957 something of value back from them.
958
959 If the default site is too slow, try one of these:
960
961    North America: mirrors.aol.com                /pub/rtfm/usenet
962                   ftp.seas.gwu.edu               /pub/rtfm
963                   rtfm.mit.edu                   /pub/usenet
964    Europe:        ftp.uni-paderborn.de           /pub/FAQ
965                   src.doc.ic.ac.uk               /usenet/news-FAQS
966                   ftp.sunet.se                   /pub/usenet
967                   sunsite.auc.dk                 /pub/usenet
968    Asia:          nctuccca.edu.tw                /USENET/FAQ
969                   hwarang.postech.ac.kr          /pub/usenet
970                   ftp.hk.super.net               /mirror/faqs"
971   :group 'gnus-group-various
972   :type '(choice directory
973                  (repeat directory)))
974
975 (defcustom gnus-use-cross-reference t
976   "*Non-nil means that cross referenced articles will be marked as read.
977 If nil, ignore cross references.  If t, mark articles as read in
978 subscribed newsgroups.  If neither t nor nil, mark as read in all
979 newsgroups."
980   :group 'gnus-server
981   :type '(choice (const :tag "off" nil)
982                  (const :tag "subscribed" t)
983                  (sexp :format "all"
984                        :value always)))
985
986 (defcustom gnus-process-mark ?#
987   "*Process mark."
988   :group 'gnus-group-visual
989   :group 'gnus-summary-marks
990   :type 'character)
991
992 (defcustom gnus-asynchronous nil
993   "*If non-nil, Gnus will supply backends with data needed for async article fetching."
994   :group 'gnus-asynchronous
995   :type 'boolean)
996
997 (defcustom gnus-large-newsgroup 200
998   "*The number of articles which indicates a large newsgroup.
999 If the number of articles in a newsgroup is greater than this value,
1000 confirmation is required for selecting the newsgroup."
1001   :group 'gnus-group-select
1002   :type 'integer)
1003
1004 (defcustom gnus-use-long-file-name (not (memq system-type '(usg-unix-v xenix)))
1005   "*Non-nil means that the default name of a file to save articles in is the group name.
1006 If it's nil, the directory form of the group name is used instead.
1007
1008 If this variable is a list, and the list contains the element
1009 `not-score', long file names will not be used for score files; if it
1010 contains the element `not-save', long file names will not be used for
1011 saving; and if it contains the element `not-kill', long file names
1012 will not be used for kill files.
1013
1014 Note that the default for this variable varies according to what system
1015 type you're using.  On `usg-unix-v' and `xenix' this variable defaults
1016 to nil while on all other systems it defaults to t."
1017   :group 'gnus-start
1018   :type 'boolean)
1019
1020 (defcustom gnus-kill-files-directory gnus-directory
1021   "*Name of the directory where kill files will be stored (default \"~/News\")."
1022   :group 'gnus-score-files
1023   :group 'gnus-score-kill
1024   :type 'directory)
1025
1026 (defcustom gnus-save-score nil
1027   "*If non-nil, save group scoring info."
1028   :group 'gnus-score-various
1029   :group 'gnus-start
1030   :type 'boolean)
1031
1032 (defcustom gnus-use-undo t
1033   "*If non-nil, allow undoing in Gnus group mode buffers."
1034   :group 'gnus-meta
1035   :type 'boolean)
1036
1037 (defcustom gnus-use-adaptive-scoring nil
1038   "*If non-nil, use some adaptive scoring scheme.
1039 If a list, then the values `word' and `line' are meaningful.  The
1040 former will perform adaption on individual words in the subject
1041 header while `line' will perform adaption on several headers."
1042   :group 'gnus-meta
1043   :group 'gnus-score-adapt
1044   :type '(set (const word) (const line)))
1045
1046 (defcustom gnus-use-cache 'passive
1047   "*If nil, Gnus will ignore the article cache.
1048 If `passive', it will allow entering (and reading) articles
1049 explicitly entered into the cache.  If anything else, use the
1050 cache to the full extent of the law."
1051   :group 'gnus-meta
1052   :group 'gnus-cache
1053   :type '(choice (const :tag "off" nil)
1054                  (const :tag "passive" passive)
1055                  (const :tag "active" t)))
1056
1057 (defcustom gnus-use-trees nil
1058   "*If non-nil, display a thread tree buffer."
1059   :group 'gnus-meta
1060   :type 'boolean)
1061
1062 (defcustom gnus-use-grouplens nil
1063   "*If non-nil, use GroupLens ratings."
1064   :group 'gnus-meta
1065   :type 'boolean)
1066
1067 (defcustom gnus-keep-backlog nil
1068   "*If non-nil, Gnus will keep read articles for later re-retrieval.
1069 If it is a number N, then Gnus will only keep the last N articles
1070 read.  If it is neither nil nor a number, Gnus will keep all read
1071 articles.  This is not a good idea."
1072   :group 'gnus-meta
1073   :type '(choice (const :tag "off" nil)
1074                  integer
1075                  (sexp :format "all"
1076                        :value t)))
1077
1078 (defcustom gnus-use-nocem nil
1079   "*If non-nil, Gnus will read NoCeM cancel messages."
1080   :group 'gnus-meta
1081   :type 'boolean)
1082
1083 (defcustom gnus-suppress-duplicates nil
1084   "*If non-nil, Gnus will mark duplicate copies of the same article as read."
1085   :group 'gnus-meta
1086   :type 'boolean)
1087
1088 (defcustom gnus-use-demon nil
1089   "If non-nil, Gnus might use some demons."
1090   :group 'gnus-meta
1091   :type 'boolean)
1092
1093 (defcustom gnus-use-scoring t
1094   "*If non-nil, enable scoring."
1095   :group 'gnus-meta
1096   :type 'boolean)
1097
1098 (defcustom gnus-use-picons nil
1099   "*If non-nil, display picons."
1100   :group 'gnus-meta
1101   :type 'boolean)
1102
1103 (defcustom gnus-summary-prepare-exit-hook
1104   '(gnus-summary-expire-articles)
1105   "*A hook called when preparing to exit from the summary buffer.
1106 It calls `gnus-summary-expire-articles' by default."
1107   :group 'gnus-summary-exit
1108   :type 'hook)
1109
1110 (defcustom gnus-novice-user t
1111   "*Non-nil means that you are a usenet novice.
1112 If non-nil, verbose messages may be displayed and confirmations may be
1113 required."
1114   :group 'gnus-meta
1115   :type 'boolean)
1116
1117 (defcustom gnus-expert-user nil
1118   "*Non-nil means that you will never be asked for confirmation about anything.
1119 That doesn't mean *anything* anything; particularly destructive
1120 commands will still require prompting."
1121   :group 'gnus-meta
1122   :type 'boolean)
1123
1124 (defcustom gnus-interactive-catchup t
1125   "*If non-nil, require your confirmation when catching up a group."
1126   :group 'gnus-group-select
1127   :type 'boolean)
1128
1129 (defcustom gnus-interactive-exit t
1130   "*If non-nil, require your confirmation when exiting Gnus."
1131   :group 'gnus-exit
1132   :type 'boolean)
1133
1134 (defcustom gnus-extract-address-components 'gnus-extract-address-components
1135   "*Function for extracting address components from a From header.
1136
1137 `gnus-extract-address-components' is a quite fast, and too simplistic.
1138 `mail-extract-address-components' works much better, but is slower.
1139 `std11-extract-address-components' also works better, and less slower."
1140   :group 'gnus-summary-format
1141   :type '(radio (function-item gnus-extract-address-components)
1142                 (function-item mail-extract-address-components)
1143                 (function-item std11-extract-address-components)
1144                 (function :tag "Other")))
1145
1146 (defcustom gnus-carpal nil
1147   "*If non-nil, display clickable icons."
1148   :group 'gnus-meta
1149   :type 'boolean)
1150
1151 (defcustom gnus-shell-command-separator ";"
1152   "String used to separate to shell commands."
1153   :group 'gnus-files
1154   :type 'string)
1155
1156 (defcustom gnus-valid-select-methods
1157   '(("nntp" post address prompt-address physical-address)
1158     ("nnspool" post address)
1159     ("nnvirtual" post-mail virtual prompt-address)
1160     ("nnmbox" mail respool address)
1161     ("nnml" mail respool address)
1162     ("nnmh" mail respool address)
1163     ("nndir" post-mail prompt-address physical-address)
1164     ("nneething" none address prompt-address physical-address)
1165     ("nndoc" none address prompt-address)
1166     ("nnbabyl" mail address respool)
1167     ("nnkiboze" post virtual)
1168     ("nnsoup" post-mail address)
1169     ("nndraft" post-mail)
1170     ("nnfolder" mail respool address)
1171     ("nngateway" post-mail address prompt-address physical-address)
1172     ("nnweb" none)
1173     ("nnlistserv" none)
1174     ("nnagent" post-mail))
1175   "*An alist of valid select methods.
1176 The first element of each list lists should be a string with the name
1177 of the select method.  The other elements may be the category of
1178 this method (i. e., `post', `mail', `none' or whatever) or other
1179 properties that this method has (like being respoolable).
1180 If you implement a new select method, all you should have to change is
1181 this variable.  I think."
1182   :group 'gnus-server
1183   :type '(repeat (group (string :tag "Name")
1184                         (radio-button-choice (const :format "%v " post)
1185                                              (const :format "%v " mail)
1186                                              (const :format "%v " none)
1187                                              (const post-mail))
1188                         (checklist :inline t
1189                                    (const :format "%v " address)
1190                                    (const :format "%v " prompt-address)
1191                                    (const :format "%v " physical-address)
1192                                    (const :format "%v " virtual)
1193                                    (const respool)))))
1194
1195 (define-widget 'gnus-select-method 'list
1196   "Widget for entering a select method."
1197   :args `((choice :tag "Method"
1198                   ,@(mapcar (lambda (entry)
1199                               (list 'const :format "%v\n"
1200                                     (intern (car entry))))
1201                             gnus-valid-select-methods))
1202           (string :tag "Address")
1203           (editable-list  :inline t
1204                           (list :format "%v"
1205                                 variable
1206                                 (sexp :tag "Value")))))
1207
1208 (defcustom gnus-updated-mode-lines '(group article summary tree)
1209   "List of buffers that should update their mode lines.
1210 The list may contain the symbols `group', `article', `tree' and
1211 `summary'.  If the corresponding symbol is present, Gnus will keep
1212 that mode line updated with information that may be pertinent.
1213 If this variable is nil, screen refresh may be quicker."
1214   :group 'gnus-various
1215   :type '(set (const group)
1216               (const article)
1217               (const summary)
1218               (const tree)))
1219
1220 ;; Added by Keinonen Kari <kk85613@cs.tut.fi>.
1221 (defcustom gnus-mode-non-string-length nil
1222   "*Max length of mode-line non-string contents.
1223 If this is nil, Gnus will take space as is needed, leaving the rest
1224 of the modeline intact.  Note that the default of nil is unlikely
1225 to be desirable; see the manual for further details."
1226   :group 'gnus-various
1227   :type '(choice (const nil)
1228                  integer))
1229
1230 (defcustom gnus-auto-expirable-newsgroups nil
1231   "*Groups in which to automatically mark read articles as expirable.
1232 If non-nil, this should be a regexp that should match all groups in
1233 which to perform auto-expiry.  This only makes sense for mail groups."
1234   :group 'nnmail-expire
1235   :type '(choice (const nil)
1236                  regexp))
1237
1238 (defcustom gnus-total-expirable-newsgroups nil
1239   "*Groups in which to perform expiry of all read articles.
1240 Use with extreme caution.  All groups that match this regexp will be
1241 expiring - which means that all read articles will be deleted after
1242 \(say) one week.         (This only goes for mail groups and the like, of
1243 course.)"
1244   :group 'nnmail-expire
1245   :type '(choice (const nil)
1246                  regexp))
1247
1248 (defcustom gnus-group-uncollapsed-levels 1
1249   "Number of group name elements to leave alone when making a short group name."
1250   :group 'gnus-group-visual
1251   :type 'integer)
1252
1253 (defcustom gnus-group-use-permanent-levels nil
1254   "*If non-nil, once you set a level, Gnus will use this level."
1255   :group 'gnus-group-levels
1256   :type 'boolean)
1257
1258 ;; Hooks.
1259
1260 (defcustom gnus-load-hook nil
1261   "A hook run while Gnus is loaded."
1262   :group 'gnus-start
1263   :type 'hook)
1264
1265 (defcustom gnus-apply-kill-hook '(gnus-apply-kill-file)
1266   "A hook called to apply kill files to a group.
1267 This hook is intended to apply a kill file to the selected newsgroup.
1268 The function `gnus-apply-kill-file' is called by default.
1269
1270 Since a general kill file is too heavy to use only for a few
1271 newsgroups, I recommend you to use a lighter hook function.  For
1272 example, if you'd like to apply a kill file to articles which contains
1273 a string `rmgroup' in subject in newsgroup `control', you can use the
1274 following hook:
1275
1276  (setq gnus-apply-kill-hook
1277       (list
1278         (lambda ()
1279           (cond ((string-match \"control\" gnus-newsgroup-name)
1280                  (gnus-kill \"Subject\" \"rmgroup\")
1281                  (gnus-expunge \"X\"))))))"
1282   :group 'gnus-score-kill
1283   :options '(gnus-apply-kill-file)
1284   :type 'hook)
1285
1286 (defcustom gnus-group-change-level-function nil
1287   "Function run when a group level is changed.
1288 It is called with three parameters -- GROUP, LEVEL and OLDLEVEL."
1289   :group 'gnus-group-level
1290   :type 'function)
1291
1292 ;;; Face thingies.
1293
1294 (defcustom gnus-visual
1295   '(summary-highlight group-highlight article-highlight
1296                       mouse-face
1297                       summary-menu group-menu article-menu
1298                       tree-highlight menu highlight
1299                       browse-menu server-menu
1300                       page-marker tree-menu binary-menu pick-menu
1301                       grouplens-menu)
1302   "*Enable visual features.
1303 If `visual' is disabled, there will be no menus and few faces.  Most of
1304 the visual customization options below will be ignored.  Gnus will use
1305 less space and be faster as a result.
1306
1307 This variable can also be a list of visual elements to switch on.  For
1308 instance, to switch off all visual things except menus, you can say:
1309
1310    (setq gnus-visual '(menu))
1311
1312 Valid elements include `summary-highlight', `group-highlight',
1313 `article-highlight', `mouse-face', `summary-menu', `group-menu',
1314 `article-menu', `tree-highlight', `menu', `highlight', `browse-menu',
1315 `server-menu', `page-marker', `tree-menu', `binary-menu', `pick-menu',
1316 and `grouplens-menu'."
1317   :group 'gnus-meta
1318   :group 'gnus-visual
1319   :type '(set (const summary-highlight)
1320               (const group-highlight)
1321               (const article-highlight)
1322               (const mouse-face)
1323               (const summary-menu)
1324               (const group-menu)
1325               (const article-menu)
1326               (const tree-highlight)
1327               (const menu)
1328               (const highlight)
1329               (const browse-menu)
1330               (const server-menu)
1331               (const page-marker)
1332               (const tree-menu)
1333               (const binary-menu)
1334               (const pick-menu)
1335               (const grouplens-menu)))
1336
1337 (defcustom gnus-mouse-face
1338   (condition-case ()
1339       (if (gnus-visual-p 'mouse-face 'highlight)
1340           (if (boundp 'gnus-mouse-face)
1341               (or gnus-mouse-face 'highlight)
1342             'highlight)
1343         'default)
1344     (error 'highlight))
1345   "*Face used for group or summary buffer mouse highlighting.
1346 The line beneath the mouse pointer will be highlighted with this
1347 face."
1348   :group 'gnus-visual
1349   :type 'face)
1350
1351 (defcustom gnus-article-display-hook
1352   (if (and (string-match "XEmacs" emacs-version)
1353            (featurep 'xface))
1354       '(gnus-article-hide-headers-if-wanted
1355         gnus-article-hide-boring-headers
1356         gnus-article-treat-overstrike
1357         gnus-article-maybe-highlight
1358         gnus-article-display-x-face)
1359     '(gnus-article-hide-headers-if-wanted
1360       gnus-article-hide-boring-headers
1361       gnus-article-treat-overstrike
1362       gnus-article-maybe-highlight))
1363   "*Controls how the article buffer will look.
1364
1365 If you leave the list empty, the article will appear exactly as it is
1366 stored on the disk.  The list entries will hide or highlight various
1367 parts of the article, making it easier to find the information you
1368 want."
1369   :group 'gnus-article-highlight
1370   :group 'gnus-visual
1371   :type 'hook
1372   :options '(gnus-article-add-buttons
1373              gnus-article-add-buttons-to-head
1374              gnus-article-emphasize
1375              gnus-article-fill-cited-article
1376              gnus-article-remove-cr
1377              gnus-summary-stop-page-breaking
1378              ;; gnus-summary-caesar-message
1379              ;; gnus-summary-verbose-headers
1380              gnus-summary-toggle-mime
1381              gnus-article-hide
1382              gnus-article-hide-headers
1383              gnus-article-hide-boring-headers
1384              gnus-article-hide-signature
1385              gnus-article-hide-citation
1386              gnus-article-hide-pgp
1387              gnus-article-hide-pem
1388              gnus-article-highlight
1389              gnus-article-highlight-headers
1390              gnus-article-highlight-citation
1391              gnus-article-highlight-signature
1392              gnus-article-date-ut
1393              gnus-article-date-local
1394              gnus-article-date-lapsed
1395              gnus-article-date-original
1396              gnus-article-remove-trailing-blank-lines
1397              gnus-article-strip-leading-blank-lines
1398              gnus-article-strip-multiple-blank-lines
1399              gnus-article-strip-blank-lines
1400              gnus-article-treat-overstrike
1401              gnus-article-display-x-face
1402              gnus-smiley-display))
1403
1404 (defcustom gnus-article-save-directory gnus-directory
1405   "*Name of the directory articles will be saved in (default \"~/News\")."
1406   :group 'gnus-article-saving
1407   :type 'directory)
1408
1409 (defvar gnus-plugged t
1410   "Whether Gnus is plugged or not.")
1411
1412 \f
1413 ;;; Internal variables
1414
1415 (defvar gnus-group-get-parameter-function 'gnus-group-get-parameter)
1416 (defvar gnus-original-article-buffer " *Original Article*")
1417 (defvar gnus-newsgroup-name nil)
1418 (defvar gnus-ephemeral-servers nil)
1419
1420 (defvar gnus-agent nil
1421   "Whether we want to use the Gnus agent or not.")
1422
1423 (defvar gnus-command-method nil
1424   "Dynamically bound variable that says what the current backend is.")
1425
1426 (defvar gnus-current-select-method nil
1427   "The current method for selecting a newsgroup.")
1428
1429 (defvar gnus-tree-buffer "*Tree*"
1430   "Buffer where Gnus thread trees are displayed.")
1431
1432 ;; Dummy variable.
1433 (defvar gnus-use-generic-from nil)
1434
1435 ;; Variable holding the user answers to all method prompts.
1436 (defvar gnus-method-history nil)
1437
1438 ;; Variable holding the user answers to all mail method prompts.
1439 (defvar gnus-mail-method-history nil)
1440
1441 ;; Variable holding the user answers to all group prompts.
1442 (defvar gnus-group-history nil)
1443
1444 (defvar gnus-server-alist nil
1445   "List of available servers.")
1446
1447 (defcustom gnus-cache-directory
1448   (nnheader-concat gnus-directory "cache/")
1449   "*The directory where cached articles will be stored."
1450   :group 'gnus-cache
1451   :type 'directory)
1452
1453 (defvar gnus-predefined-server-alist
1454   `(("cache"
1455      nnspool "cache"
1456      (nnspool-spool-directory ,gnus-cache-directory)
1457      (nnspool-nov-directory ,gnus-cache-directory)
1458      (nnspool-active-file
1459       ,(nnheader-concat gnus-cache-directory "active"))))
1460   "List of predefined (convenience) servers.")
1461
1462 (defvar gnus-topic-indentation "") ;; Obsolete variable.
1463
1464 (defconst gnus-article-mark-lists
1465   '((marked . tick) (replied . reply)
1466     (expirable . expire) (killed . killed)
1467     (bookmarks . bookmark) (dormant . dormant)
1468     (scored . score) (saved . save)
1469     (cached . cache) (downloadable . download)
1470     (unsendable . unsend)))
1471
1472 (defvar gnus-headers-retrieved-by nil)
1473 (defvar gnus-article-reply nil)
1474 (defvar gnus-override-method nil)
1475 (defvar gnus-article-check-size nil)
1476 (defvar gnus-opened-servers nil)
1477
1478 (defvar gnus-current-kill-article nil)
1479
1480 (defvar gnus-have-read-active-file nil)
1481
1482 (defconst gnus-maintainer
1483   "bugs@gnus.org (The Gnus Bugfixing Girls + Boys)"
1484   "The mail address of the Gnus maintainers.")
1485
1486 (defvar gnus-info-nodes
1487   '((gnus-group-mode "(gnus)The Group Buffer")
1488     (gnus-summary-mode "(gnus)The Summary Buffer")
1489     (gnus-article-mode "(gnus)The Article Buffer")
1490     (mime/viewer-mode "(gnus)The Article Buffer")
1491     (gnus-server-mode "(gnus)The Server Buffer")
1492     (gnus-browse-mode "(gnus)Browse Foreign Server")
1493     (gnus-tree-mode "(gnus)Tree Display"))
1494   "Alist of major modes and related Info nodes.")
1495
1496 (defvar gnus-group-buffer "*Group*")
1497 (defvar gnus-summary-buffer "*Summary*")
1498 (defvar gnus-article-buffer "*Article*")
1499 (defvar gnus-server-buffer "*Server*")
1500
1501 (defvar gnus-slave nil
1502   "Whether this Gnus is a slave or not.")
1503
1504 (defvar gnus-batch-mode nil
1505   "Whether this Gnus is running in batch mode or not.")
1506
1507 (defvar gnus-variable-list
1508   '(gnus-newsrc-options gnus-newsrc-options-n
1509     gnus-newsrc-last-checked-date
1510     gnus-newsrc-alist gnus-server-alist
1511     gnus-killed-list gnus-zombie-list
1512     gnus-topic-topology gnus-topic-alist
1513     gnus-format-specs)
1514   "Gnus variables saved in the quick startup file.")
1515
1516 (defvar gnus-newsrc-alist nil
1517   "Assoc list of read articles.
1518 gnus-newsrc-hashtb should be kept so that both hold the same information.")
1519
1520 (defvar gnus-newsrc-hashtb nil
1521   "Hashtable of gnus-newsrc-alist.")
1522
1523 (defvar gnus-killed-list nil
1524   "List of killed newsgroups.")
1525
1526 (defvar gnus-killed-hashtb nil
1527   "Hash table equivalent of gnus-killed-list.")
1528
1529 (defvar gnus-zombie-list nil
1530   "List of almost dead newsgroups.")
1531
1532 (defvar gnus-description-hashtb nil
1533   "Descriptions of newsgroups.")
1534
1535 (defvar gnus-list-of-killed-groups nil
1536   "List of newsgroups that have recently been killed by the user.")
1537
1538 (defvar gnus-active-hashtb nil
1539   "Hashtable of active articles.")
1540
1541 (defvar gnus-moderated-hashtb nil
1542   "Hashtable of moderated newsgroups.")
1543
1544 ;; Save window configuration.
1545 (defvar gnus-prev-winconf nil)
1546
1547 (defvar gnus-reffed-article-number nil)
1548
1549 ;;; Let the byte-compiler know that we know about this variable.
1550 (defvar rmail-default-rmail-file)
1551
1552 (defvar gnus-dead-summary nil)
1553
1554 ;;; End of variables.
1555
1556 ;; Define some autoload functions Gnus might use.
1557 (eval-and-compile
1558
1559   ;; This little mapcar goes through the list below and marks the
1560   ;; symbols in question as autoloaded functions.
1561   (mapcar
1562    (lambda (package)
1563      (let ((interactive (nth 1 (memq ':interactive package))))
1564        (mapcar
1565         (lambda (function)
1566           (let (keymap)
1567             (when (consp function)
1568               (setq keymap (car (memq 'keymap function)))
1569               (setq function (car function)))
1570             (autoload function (car package) nil interactive keymap)))
1571         (if (eq (nth 1 package) ':interactive)
1572             (cdddr package)
1573           (cdr package)))))
1574    '(("info" Info-goto-node)
1575      ("hexl" hexl-hex-string-to-integer)
1576      ("pp" pp pp-to-string pp-eval-expression)
1577      ("ps-print" ps-print-preprint)
1578      ("mail-extr" mail-extract-address-components)
1579      ("browse-url" browse-url)
1580      ("message" :interactive t
1581       message-send-and-exit message-yank-original)
1582      ("nnmail" nnmail-split-fancy nnmail-article-group nnmail-date-to-time)
1583      ("nnvirtual" nnvirtual-catchup-group nnvirtual-convert-headers)
1584      ("timezone" timezone-make-date-arpa-standard timezone-fix-time
1585       timezone-make-sortable-date timezone-make-time-string)
1586      ("rmailout" rmail-output)
1587      ("rmail" rmail-insert-rmail-file-header rmail-count-new-messages
1588       rmail-show-message)
1589      ("gnus-audio" :interactive t gnus-audio-play)
1590      ("gnus-xmas" gnus-xmas-splash)
1591      ("gnus-soup" :interactive t
1592       gnus-group-brew-soup gnus-brew-soup gnus-soup-add-article
1593       gnus-soup-send-replies gnus-soup-save-areas gnus-soup-pack-packet)
1594      ("nnsoup" nnsoup-pack-replies)
1595      ("score-mode" :interactive t gnus-score-mode)
1596      ("gnus-mh" gnus-summary-save-article-folder
1597       gnus-Folder-save-name gnus-folder-save-name)
1598      ("gnus-mh" :interactive t gnus-summary-save-in-folder)
1599      ("gnus-demon" gnus-demon-add-nocem gnus-demon-add-scanmail
1600       gnus-demon-add-rescan gnus-demon-add-scan-timestamps
1601       gnus-demon-add-disconnection gnus-demon-add-handler
1602       gnus-demon-remove-handler)
1603      ("gnus-demon" :interactive t
1604       gnus-demon-init gnus-demon-cancel)
1605      ("gnus-salt" gnus-highlight-selected-tree gnus-possibly-generate-tree
1606       gnus-tree-open gnus-tree-close gnus-carpal-setup-buffer)
1607      ("gnus-nocem" gnus-nocem-scan-groups gnus-nocem-close
1608       gnus-nocem-unwanted-article-p)
1609      ("gnus-srvr" gnus-enter-server-buffer gnus-server-set-info
1610       gnus-server-server-name)
1611      ("gnus-srvr" gnus-browse-foreign-server)
1612      ("gnus-cite" :interactive t
1613       gnus-article-highlight-citation gnus-article-hide-citation-maybe
1614       gnus-article-hide-citation gnus-article-fill-cited-article
1615       gnus-article-hide-citation-in-followups)
1616      ("gnus-kill" gnus-kill gnus-apply-kill-file-internal
1617       gnus-kill-file-edit-file gnus-kill-file-raise-followups-to-author
1618       gnus-execute gnus-expunge)
1619      ("gnus-cache" gnus-cache-possibly-enter-article gnus-cache-save-buffers
1620       gnus-cache-possibly-remove-articles gnus-cache-request-article
1621       gnus-cache-retrieve-headers gnus-cache-possibly-alter-active
1622       gnus-cache-enter-remove-article gnus-cached-article-p
1623       gnus-cache-open gnus-cache-close gnus-cache-update-article)
1624       ("gnus-cache" :interactive t gnus-jog-cache gnus-cache-enter-article
1625        gnus-cache-remove-article gnus-summary-insert-cached-articles)
1626       ("gnus-score" :interactive t
1627        gnus-summary-increase-score gnus-summary-set-score
1628        gnus-summary-raise-thread gnus-summary-raise-same-subject
1629        gnus-summary-raise-score gnus-summary-raise-same-subject-and-select
1630        gnus-summary-lower-thread gnus-summary-lower-same-subject
1631        gnus-summary-lower-score gnus-summary-lower-same-subject-and-select
1632        gnus-summary-current-score gnus-score-default
1633        gnus-score-flush-cache gnus-score-close
1634        gnus-possibly-score-headers gnus-score-followup-article
1635        gnus-score-followup-thread)
1636       ("gnus-score"
1637        (gnus-summary-score-map keymap) gnus-score-save gnus-score-headers
1638       gnus-current-score-file-nondirectory gnus-score-adaptive
1639       gnus-score-find-trace gnus-score-file-name)
1640      ("gnus-cus" :interactive t gnus-group-customize gnus-score-customize)
1641      ("gnus-topic" :interactive t gnus-topic-mode)
1642      ("gnus-topic" gnus-topic-remove-group gnus-topic-set-parameters)
1643      ("gnus-salt" :interactive t gnus-pick-mode gnus-binary-mode)
1644      ("gnus-uu" (gnus-uu-extract-map keymap) (gnus-uu-mark-map keymap))
1645      ("gnus-uu" :interactive t
1646       gnus-uu-digest-mail-forward gnus-uu-digest-post-forward
1647       gnus-uu-mark-series gnus-uu-mark-region gnus-uu-mark-buffer
1648       gnus-uu-mark-by-regexp gnus-uu-mark-all
1649       gnus-uu-mark-sparse gnus-uu-mark-thread gnus-uu-decode-uu
1650       gnus-uu-decode-uu-and-save gnus-uu-decode-unshar
1651       gnus-uu-decode-unshar-and-save gnus-uu-decode-save
1652       gnus-uu-decode-binhex gnus-uu-decode-uu-view
1653       gnus-uu-decode-uu-and-save-view gnus-uu-decode-unshar-view
1654       gnus-uu-decode-unshar-and-save-view gnus-uu-decode-save-view
1655       gnus-uu-decode-binhex-view gnus-uu-unmark-thread
1656       gnus-uu-mark-over)
1657      ("gnus-uu" gnus-uu-delete-work-dir gnus-quote-arg-for-sh-or-csh
1658       gnus-uu-unmark-thread)
1659      ("gnus-msg" (gnus-summary-send-map keymap)
1660       gnus-article-mail gnus-copy-article-buffer gnus-extended-version)
1661      ("gnus-msg" :interactive t
1662       gnus-group-post-news gnus-group-mail gnus-summary-post-news
1663       gnus-summary-followup gnus-summary-followup-with-original
1664       gnus-summary-cancel-article gnus-summary-supersede-article
1665       gnus-post-news gnus-summary-reply gnus-summary-reply-with-original
1666       gnus-summary-mail-forward gnus-summary-mail-other-window
1667       gnus-summary-resend-message gnus-summary-resend-bounced-mail
1668       gnus-summary-wide-reply
1669       gnus-bug)
1670      ("gnus-picon" :interactive t gnus-article-display-picons
1671       gnus-group-display-picons gnus-picons-article-display-x-face
1672       gnus-picons-display-x-face)
1673      ("gnus-gl" bbb-login bbb-logout bbb-grouplens-group-p
1674       gnus-grouplens-mode)
1675      ("smiley" :interactive t gnus-smiley-display)
1676      ("gnus-win" gnus-configure-windows gnus-add-configuration)
1677      ("gnus-sum" gnus-summary-insert-line gnus-summary-read-group
1678       gnus-list-of-unread-articles gnus-list-of-read-articles
1679       gnus-offer-save-summaries gnus-make-thread-indent-array
1680       gnus-summary-exit gnus-update-read-articles gnus-summary-last-subject
1681       gnus-summary-skip-intangible gnus-summary-article-number
1682       gnus-data-header gnus-data-find)
1683      ("gnus-group" gnus-group-insert-group-line gnus-group-quit
1684       gnus-group-list-groups gnus-group-first-unread-group
1685       gnus-group-set-mode-line gnus-group-set-info gnus-group-save-newsrc
1686       gnus-group-setup-buffer gnus-group-get-new-news
1687       gnus-group-make-help-group gnus-group-update-group
1688       gnus-clear-inboxes-moved gnus-group-iterate
1689       gnus-group-group-name)
1690      ("gnus-bcklg" gnus-backlog-request-article gnus-backlog-enter-article
1691       gnus-backlog-remove-article)
1692      ("gnus-art" gnus-article-read-summary-keys gnus-article-save
1693       gnus-article-prepare gnus-article-set-window-start
1694       gnus-article-next-page gnus-article-prev-page
1695       gnus-request-article-this-buffer gnus-article-mode
1696       gnus-article-setup-buffer gnus-narrow-to-page
1697       gnus-article-delete-invisible-text gnus-hack-decode-rfc1522)
1698      ("gnus-art" :interactive t
1699       gnus-article-hide-headers gnus-article-hide-boring-headers
1700       gnus-article-treat-overstrike gnus-article-word-wrap
1701       gnus-article-remove-cr gnus-article-remove-trailing-blank-lines
1702       gnus-article-display-x-face
1703       gnus-article-mime-decode-quoted-printable gnus-article-hide-pgp
1704       gnus-article-hide-pem gnus-article-hide-signature
1705       gnus-article-strip-leading-blank-lines gnus-article-date-local
1706       gnus-article-date-original gnus-article-date-lapsed
1707       gnus-article-show-all-headers
1708       gnus-article-edit-mode gnus-article-edit-article
1709       gnus-article-edit-done gnus-decode-rfc1522 article-decode-rfc1522
1710       gnus-start-date-timer gnus-stop-date-timer)
1711      ("gnus-int" gnus-request-type)
1712      ("gnus-start" gnus-newsrc-parse-options gnus-1 gnus-no-server-1
1713       gnus-dribble-enter gnus-read-init-file gnus-dribble-touch)
1714      ("gnus-dup" gnus-dup-suppress-articles gnus-dup-unsuppress-article
1715       gnus-dup-enter-articles)
1716      ("gnus-range" gnus-copy-sequence)
1717      ("gnus-eform" gnus-edit-form)
1718      ("gnus-move" :interactive t
1719       gnus-group-move-group-to-server gnus-change-server)
1720      ("gnus-logic" gnus-score-advanced)
1721      ("gnus-undo" gnus-undo-mode gnus-undo-register)
1722      ("gnus-async" gnus-async-request-fetched-article gnus-async-prefetch-next
1723       gnus-async-prefetch-article gnus-async-prefetch-remove-group
1724       gnus-async-halt-prefetch)
1725      ("gnus-agent" gnus-open-agent gnus-agent-get-function
1726       gnus-agent-save-groups gnus-agent-save-active gnus-agent-method-p
1727       gnus-agent-get-undownloaded-list gnus-agent-fetch-session
1728       gnus-summary-set-agent-mark gnus-agent-save-group-info)
1729      ("gnus-agent" :interactive t
1730       gnus-unplugged gnus-agentize gnus-agent-batch)
1731      ("gnus-vm" :interactive t gnus-summary-save-in-vm
1732       gnus-summary-save-article-vm)
1733      ("gnus-draft" :interactive t gnus-draft-mode gnus-group-send-drafts))))
1734
1735 ;;; gnus-sum.el thingies
1736
1737
1738 (defcustom gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n"
1739   "*The format specification of the lines in the summary buffer.
1740
1741 It works along the same lines as a normal formatting string,
1742 with some simple extensions.
1743
1744 %N   Article number, left padded with spaces (string)
1745 %S   Subject (string)
1746 %s   Subject if it is at the root of a thread, and \"\" otherwise (string)
1747 %n   Name of the poster (string)
1748 %a   Extracted name of the poster (string)
1749 %A   Extracted address of the poster (string)
1750 %F   Contents of the From: header (string)
1751 %x   Contents of the Xref: header (string)
1752 %D   Date of the article (string)
1753 %d   Date of the article (string) in DD-MMM format
1754 %M   Message-id of the article (string)
1755 %r   References of the article (string)
1756 %c   Number of characters in the article (integer)
1757 %L   Number of lines in the article (integer)
1758 %I   Indentation based on thread level (a string of spaces)
1759 %T   A string with two possible values: 80 spaces if the article
1760      is on thread level two or larger and 0 spaces on level one
1761 %R   \"A\" if this article has been replied to, \" \" otherwise (character)
1762 %U   Status of this article (character, \"R\", \"K\", \"-\" or \" \")
1763 %[   Opening bracket (character, \"[\" or \"<\")
1764 %]   Closing bracket (character, \"]\" or \">\")
1765 %>   Spaces of length thread-level (string)
1766 %<   Spaces of length (- 20 thread-level) (string)
1767 %i   Article score (number)
1768 %z   Article zcore (character)
1769 %t   Number of articles under the current thread (number).
1770 %e   Whether the thread is empty or not (character).
1771 %l   GroupLens score (string).
1772 %V   Total thread score (number).
1773 %P   The line number (number).
1774 %O   Download mark (character).
1775 %u   User defined specifier.  The next character in the format string should
1776      be a letter.  Gnus will call the function gnus-user-format-function-X,
1777      where X is the letter following %u.  The function will be passed the
1778      current header as argument.  The function should return a string, which
1779      will be inserted into the summary just like information from any other
1780      summary specifier.
1781
1782 Text between %( and %) will be highlighted with `gnus-mouse-face'
1783 when the mouse point is placed inside the area.  There can only be one
1784 such area.
1785
1786 The %U (status), %R (replied) and %z (zcore) specs have to be handled
1787 with care.  For reasons of efficiency, Gnus will compute what column
1788 these characters will end up in, and \"hard-code\" that.  This means that
1789 it is illegal to have these specs after a variable-length spec.  Well,
1790 you might not be arrested, but your summary buffer will look strange,
1791 which is bad enough.
1792
1793 The smart choice is to have these specs as for to the left as
1794 possible.
1795
1796 This restriction may disappear in later versions of Gnus."
1797   :type 'string
1798   :group 'gnus-summary-format)
1799
1800 ;;;
1801 ;;; Skeleton keymaps
1802 ;;;
1803
1804 (defun gnus-suppress-keymap (keymap)
1805   (suppress-keymap keymap)
1806   (let ((keys `([backspace] [delete] "\177" "\M-u"))) ;gnus-mouse-2
1807     (while keys
1808       (define-key keymap (pop keys) 'undefined))))
1809
1810 (defvar gnus-article-mode-map
1811   (let ((keymap (make-keymap)))
1812     (gnus-suppress-keymap keymap)
1813     keymap))
1814 (defvar gnus-summary-mode-map
1815   (let ((keymap (make-keymap)))
1816     (gnus-suppress-keymap keymap)
1817     keymap))
1818 (defvar gnus-group-mode-map
1819   (let ((keymap (make-keymap)))
1820     (gnus-suppress-keymap keymap)
1821     keymap))
1822
1823 \f
1824
1825 ;; Fix by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
1826 ;; If you want the cursor to go somewhere else, set these two
1827 ;; functions in some startup hook to whatever you want.
1828 (defalias 'gnus-summary-position-point 'gnus-goto-colon)
1829 (defalias 'gnus-group-position-point 'gnus-goto-colon)
1830
1831 ;;; Various macros and substs.
1832
1833 (defun gnus-header-from (header)
1834   (mail-header-from header))
1835
1836 (defmacro gnus-gethash (string hashtable)
1837   "Get hash value of STRING in HASHTABLE."
1838   `(symbol-value (intern-soft ,string ,hashtable)))
1839
1840 (defmacro gnus-sethash (string value hashtable)
1841   "Set hash value.  Arguments are STRING, VALUE, and HASHTABLE."
1842   `(set (intern ,string ,hashtable) ,value))
1843 (put 'gnus-sethash 'edebug-form-spec '(form form form))
1844
1845 (defmacro gnus-group-unread (group)
1846   "Get the currently computed number of unread articles in GROUP."
1847   `(car (gnus-gethash ,group gnus-newsrc-hashtb)))
1848
1849 (defmacro gnus-group-entry (group)
1850   "Get the newsrc entry for GROUP."
1851   `(gnus-gethash ,group gnus-newsrc-hashtb))
1852
1853 (defmacro gnus-active (group)
1854   "Get active info on GROUP."
1855   `(gnus-gethash ,group gnus-active-hashtb))
1856
1857 (defmacro gnus-set-active (group active)
1858   "Set GROUP's active info."
1859   `(gnus-sethash ,group ,active gnus-active-hashtb))
1860
1861 ;; Info access macros.
1862
1863 (defmacro gnus-info-group (info)
1864   `(nth 0 ,info))
1865 (defmacro gnus-info-rank (info)
1866   `(nth 1 ,info))
1867 (defmacro gnus-info-read (info)
1868   `(nth 2 ,info))
1869 (defmacro gnus-info-marks (info)
1870   `(nth 3 ,info))
1871 (defmacro gnus-info-method (info)
1872   `(nth 4 ,info))
1873 (defmacro gnus-info-params (info)
1874   `(nth 5 ,info))
1875
1876 (defmacro gnus-info-level (info)
1877   `(let ((rank (gnus-info-rank ,info)))
1878      (if (consp rank)
1879          (car rank)
1880        rank)))
1881 (defmacro gnus-info-score (info)
1882   `(let ((rank (gnus-info-rank ,info)))
1883      (or (and (consp rank) (cdr rank)) 0)))
1884
1885 (defmacro gnus-info-set-group (info group)
1886   `(setcar ,info ,group))
1887 (defmacro gnus-info-set-rank (info rank)
1888   `(setcar (nthcdr 1 ,info) ,rank))
1889 (defmacro gnus-info-set-read (info read)
1890   `(setcar (nthcdr 2 ,info) ,read))
1891 (defmacro gnus-info-set-marks (info marks &optional extend)
1892   (if extend
1893       `(gnus-info-set-entry ,info ,marks 3)
1894     `(setcar (nthcdr 3 ,info) ,marks)))
1895 (defmacro gnus-info-set-method (info method &optional extend)
1896   (if extend
1897       `(gnus-info-set-entry ,info ,method 4)
1898     `(setcar (nthcdr 4 ,info) ,method)))
1899 (defmacro gnus-info-set-params (info params &optional extend)
1900   (if extend
1901       `(gnus-info-set-entry ,info ,params 5)
1902     `(setcar (nthcdr 5 ,info) ,params)))
1903
1904 (defun gnus-info-set-entry (info entry number)
1905   ;; Extend the info until we have enough elements.
1906   (while (<= (length info) number)
1907     (nconc info (list nil)))
1908   ;; Set the entry.
1909   (setcar (nthcdr number info) entry))
1910
1911 (defmacro gnus-info-set-level (info level)
1912   `(let ((rank (cdr ,info)))
1913      (if (consp (car rank))
1914          (setcar (car rank) ,level)
1915        (setcar rank ,level))))
1916 (defmacro gnus-info-set-score (info score)
1917   `(let ((rank (cdr ,info)))
1918      (if (consp (car rank))
1919          (setcdr (car rank) ,score)
1920        (setcar rank (cons (car rank) ,score)))))
1921
1922 (defmacro gnus-get-info (group)
1923   `(nth 2 (gnus-gethash ,group gnus-newsrc-hashtb)))
1924
1925 ;; Byte-compiler warning.
1926 (defvar gnus-visual)
1927 ;; Find out whether the gnus-visual TYPE is wanted.
1928 (defun gnus-visual-p (&optional type class)
1929   (and gnus-visual                      ; Has to be non-nil, at least.
1930        (if (not type)                   ; We don't care about type.
1931            gnus-visual
1932          (if (listp gnus-visual)        ; It's a list, so we check it.
1933              (or (memq type gnus-visual)
1934                  (memq class gnus-visual))
1935            t))))
1936
1937 ;;; Load the compatability functions.
1938
1939 (require 'gnus-ems)
1940
1941 \f
1942 ;;;
1943 ;;; Shutdown
1944 ;;;
1945
1946 (defvar gnus-shutdown-alist nil)
1947
1948 (defun gnus-add-shutdown (function &rest symbols)
1949   "Run FUNCTION whenever one of SYMBOLS is shut down."
1950   (push (cons function symbols) gnus-shutdown-alist))
1951
1952 (defun gnus-shutdown (symbol)
1953   "Shut down everything that waits for SYMBOL."
1954   (let ((alist gnus-shutdown-alist)
1955         entry)
1956     (while (setq entry (pop alist))
1957       (when (memq symbol (cdr entry))
1958         (funcall (car entry))))))
1959
1960 \f
1961 ;;;
1962 ;;; Gnus Utility Functions
1963 ;;;
1964
1965
1966 (defmacro gnus-string-or (&rest strings)
1967   "Return the first element of STRINGS that is a non-blank string.
1968 STRINGS will be evaluated in normal `or' order."
1969   `(gnus-string-or-1 ',strings))
1970
1971 (defun gnus-string-or-1 (strings)
1972   (let (string)
1973     (while strings
1974       (setq string (eval (pop strings)))
1975       (if (string-match "^[ \t]*$" string)
1976           (setq string nil)
1977         (setq strings nil)))
1978     string))
1979
1980 (defun gnus-version (&optional arg)
1981   "Version number of this version of Gnus.
1982 If ARG, insert string at point."
1983   (interactive "P")
1984   (if arg
1985       (insert (message gnus-version))
1986     (message gnus-version)))
1987
1988 (defun gnus-continuum-version (version)
1989   "Return VERSION as a floating point number."
1990   (when (or (string-match "^\\([^ ]+\\)? ?Gnus v?\\([0-9.]+\\)$" version)
1991             (string-match "^\\(.?\\)gnus-\\([0-9.]+\\)$" version))
1992     (let ((alpha (and (match-beginning 1) (match-string 1 version)))
1993           (number (match-string 2 version))
1994           major minor least)
1995       (unless (string-match
1996                "\\([0-9]\\)\\.\\([0-9]+\\)\\.?\\([0-9]+\\)?" number)
1997         (error "Invalid version string: %s" version))
1998       (setq major (string-to-number (match-string 1 number))
1999             minor (string-to-number (match-string 2 number))
2000             least (if (match-beginning 3)
2001                       (string-to-number (match-string 3 number))
2002                     0))
2003       (string-to-number
2004        (if (zerop major)
2005            (format "%s00%02d%02d"
2006                    (cond
2007                     ((member alpha '("(ding)" "d")) "4.99")
2008                     ((member alpha '("September" "s")) "5.01")
2009                     ((member alpha '("Red" "r")) "5.03")
2010                     ((member alpha '("Quassia" "q")) "5.05")
2011                     ((member alpha '("p")) "5.07")
2012                     ((member alpha '("o")) "5.09")
2013                     ((member alpha '("n")) "5.11"))
2014                    minor least)
2015          (format "%d.%02d%02d" major minor least))))))
2016
2017 (defun gnus-info-find-node ()
2018   "Find Info documentation of Gnus."
2019   (interactive)
2020   ;; Enlarge info window if needed.
2021   (let (gnus-info-buffer)
2022     (Info-goto-node (cadr (assq major-mode gnus-info-nodes)))
2023     (setq gnus-info-buffer (current-buffer))
2024     (gnus-configure-windows 'info)))
2025
2026 ;;;
2027 ;;; gnus-interactive
2028 ;;;
2029
2030 (defvar gnus-current-prefix-symbol nil
2031   "Current prefix symbol.")
2032
2033 (defvar gnus-current-prefix-symbols nil
2034   "List of current prefix symbols.")
2035
2036 (defun gnus-interactive (string &optional params)
2037   "Return a list that can be fed to `interactive'.
2038 See `interactive' for full documentation.
2039
2040 Adds the following specs:
2041
2042 y -- The current symbolic prefix.
2043 Y -- A list of the current symbolic prefix(es).
2044 A -- Article number.
2045 H -- Article header.
2046 g -- Group name."
2047   (let ((i 0)
2048         out c prompt)
2049     (while (< i (length string))
2050       (string-match ".\\([^\n]*\\)\n?" string i)
2051       (setq c (aref string i))
2052       (when (match-end 1)
2053         (setq prompt (match-string 1 string)))
2054       (setq i (match-end 0))
2055       ;; We basically emulate just about everything that
2056       ;; `interactive' does, but add the specs listed above.
2057       (push
2058        (cond
2059         ((= c ?a)
2060          (completing-read prompt obarray 'fboundp t))
2061         ((= c ?b)
2062          (read-buffer prompt (current-buffer) t))
2063         ((= c ?B)
2064          (read-buffer prompt (other-buffer (current-buffer))))
2065         ((= c ?c)
2066          (read-char))
2067         ((= c ?C)
2068          (completing-read prompt obarray 'commandp t))
2069         ((= c ?d)
2070          (point))
2071         ((= c ?D)
2072          (read-file-name prompt nil default-directory 'lambda))
2073         ((= c ?f)
2074          (read-file-name prompt nil nil 'lambda))
2075         ((= c ?F)
2076          (read-file-name prompt))
2077         ((= c ?k)
2078          (read-key-sequence prompt))
2079         ((= c ?K)
2080          (error "Not implemented spec"))
2081         ((= c ?e)
2082          (error "Not implemented spec"))
2083         ((= c ?m)
2084          (mark))
2085         ((= c ?N)
2086          (error "Not implemented spec"))
2087         ((= c ?n)
2088          (string-to-number (read-from-minibuffer prompt)))
2089         ((= c ?p)
2090          (prefix-numeric-value current-prefix-arg))
2091         ((= c ?P)
2092          current-prefix-arg)
2093         ((= c ?r)
2094          'gnus-prefix-nil)
2095         ((= c ?s)
2096          (read-string prompt))
2097         ((= c ?S)
2098          (intern (read-string prompt)))
2099         ((= c ?v)
2100          (read-variable prompt))
2101         ((= c ?x)
2102          (read-minibuffer prompt))
2103         ((= c ?x)
2104          (eval-minibuffer prompt))
2105         ;; And here the new specs come.
2106         ((= c ?y)
2107          gnus-current-prefix-symbol)
2108         ((= c ?Y)
2109          gnus-current-prefix-symbols)
2110         ((= c ?g)
2111          (gnus-group-group-name))
2112         ((= c ?A)
2113          (gnus-summary-skip-intangible)
2114          (or (get-text-property (point) 'gnus-number)
2115              (gnus-summary-last-subject)))
2116         ((= c ?H)
2117          (gnus-data-header (gnus-data-find (gnus-summary-article-number))))
2118         (t
2119          (error "Non-implemented spec")))
2120        out)
2121       (cond
2122        ((= c ?r)
2123         (push (if (< (point) (mark) (point) (mark))) out)
2124         (push (if (> (point) (mark) (point) (mark))) out))))
2125     (setq out (delq 'gnus-prefix-nil out))
2126     (nreverse out)))
2127
2128 (defun gnus-symbolic-argument (&optional arg)
2129   "Read a symbolic argument and a command, and then execute command."
2130   (interactive "P")
2131   (let* ((in-command (this-command-keys))
2132          (command in-command)
2133          gnus-current-prefix-symbols
2134          gnus-current-prefix-symbol
2135          syms)
2136     (while (equal in-command command)
2137       (message "%s-" (key-description (this-command-keys)))
2138       (push (intern (char-to-string (read-char))) syms)
2139       (setq command (read-key-sequence nil t)))
2140     (setq gnus-current-prefix-symbols (nreverse syms)
2141           gnus-current-prefix-symbol (car gnus-current-prefix-symbols))
2142     (call-interactively (key-binding command t))))
2143
2144 ;;; More various functions.
2145
2146 (defsubst gnus-check-backend-function (func group)
2147   "Check whether GROUP supports function FUNC.
2148 GROUP can either be a string (a group name) or a select method."
2149   (ignore-errors
2150     (let ((method (if (stringp group)
2151                       (car (gnus-find-method-for-group group))
2152                     group)))
2153       (unless (featurep method)
2154         (require method))
2155       (fboundp (intern (format "%s-%s" method func))))))
2156
2157 (defun gnus-group-read-only-p (&optional group)
2158   "Check whether GROUP supports editing or not.
2159 If GROUP is nil, `gnus-newsgroup-name' will be checked instead.  Note
2160 that that variable is buffer-local to the summary buffers."
2161   (let ((group (or group gnus-newsgroup-name)))
2162     (not (gnus-check-backend-function 'request-replace-article group))))
2163
2164 (defun gnus-group-total-expirable-p (group)
2165   "Check whether GROUP is total-expirable or not."
2166   (let ((params (gnus-group-find-parameter group))
2167         val)
2168     (cond
2169      ((memq 'total-expire params)
2170       t)
2171      ((setq val (assq 'total-expire params)) ; (auto-expire . t)
2172       (cdr val))
2173      (gnus-total-expirable-newsgroups   ; Check var.
2174       (string-match gnus-total-expirable-newsgroups group)))))
2175
2176 (defun gnus-group-auto-expirable-p (group)
2177   "Check whether GROUP is auto-expirable or not."
2178   (let ((params (gnus-group-find-parameter group))
2179         val)
2180     (cond
2181      ((memq 'auto-expire params)
2182       t)
2183      ((setq val (assq 'auto-expire params)) ; (auto-expire . t)
2184       (cdr val))
2185      (gnus-auto-expirable-newsgroups    ; Check var.
2186       (string-match gnus-auto-expirable-newsgroups group)))))
2187
2188 (defun gnus-virtual-group-p (group)
2189   "Say whether GROUP is virtual or not."
2190   (memq 'virtual (assoc (symbol-name (car (gnus-find-method-for-group group)))
2191                         gnus-valid-select-methods)))
2192
2193 (defun gnus-news-group-p (group &optional article)
2194   "Return non-nil if GROUP (and ARTICLE) come from a news server."
2195   (or (gnus-member-of-valid 'post group) ; Ordinary news group.
2196       (and (gnus-member-of-valid 'post-mail group) ; Combined group.
2197            (eq (gnus-request-type group article) 'news))))
2198
2199 ;; Returns a list of writable groups.
2200 (defun gnus-writable-groups ()
2201   (let ((alist gnus-newsrc-alist)
2202         groups group)
2203     (while (setq group (car (pop alist)))
2204       (unless (gnus-group-read-only-p group)
2205         (push group groups)))
2206     (nreverse groups)))
2207
2208 ;; Check whether to use long file names.
2209 (defun gnus-use-long-file-name (symbol)
2210   ;; The variable has to be set...
2211   (and gnus-use-long-file-name
2212        ;; If it isn't a list, then we return t.
2213        (or (not (listp gnus-use-long-file-name))
2214            ;; If it is a list, and the list contains `symbol', we
2215            ;; return nil.
2216            (not (memq symbol gnus-use-long-file-name)))))
2217
2218 ;; Generate a unique new group name.
2219 (defun gnus-generate-new-group-name (leaf)
2220   (let ((name leaf)
2221         (num 0))
2222     (while (gnus-gethash name gnus-newsrc-hashtb)
2223       (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">")))
2224     name))
2225
2226 (defun gnus-ephemeral-group-p (group)
2227   "Say whether GROUP is ephemeral or not."
2228   (gnus-group-get-parameter group 'quit-config t))
2229
2230 (defun gnus-group-quit-config (group)
2231   "Return the quit-config of GROUP."
2232   (gnus-group-get-parameter group 'quit-config t))
2233
2234 (defun gnus-kill-ephemeral-group (group)
2235   "Remove ephemeral GROUP from relevant structures."
2236   (gnus-sethash group nil gnus-newsrc-hashtb))
2237
2238 (defun gnus-simplify-mode-line ()
2239   "Make mode lines a bit simpler."
2240   (setq mode-line-modified (cdr gnus-mode-line-modified))
2241   (when (listp mode-line-format)
2242     (make-local-variable 'mode-line-format)
2243     (setq mode-line-format (copy-sequence mode-line-format))
2244     (when (equal (nth 3 mode-line-format) "   ")
2245       (setcar (nthcdr 3 mode-line-format) " "))))
2246
2247 ;;; Servers and groups.
2248
2249 (defsubst gnus-server-add-address (method)
2250   (let ((method-name (symbol-name (car method))))
2251     (if (and (memq 'address (assoc method-name gnus-valid-select-methods))
2252              (not (assq (intern (concat method-name "-address")) method))
2253              (memq 'physical-address (assq (car method)
2254                                            gnus-valid-select-methods)))
2255         (append method (list (list (intern (concat method-name "-address"))
2256                                    (nth 1 method))))
2257       method)))
2258
2259 (defsubst gnus-server-get-method (group method)
2260   ;; Input either a server name, and extended server name, or a
2261   ;; select method, and return a select method.
2262   (cond ((stringp method)
2263          (gnus-server-to-method method))
2264         ((equal method gnus-select-method)
2265          gnus-select-method)
2266         ((and (stringp (car method))
2267               group)
2268          (gnus-server-extend-method group method))
2269         ((and method
2270               (not group)
2271               (equal (cadr method) ""))
2272          method)
2273         (t
2274          (gnus-server-add-address method))))
2275
2276 (defun gnus-server-to-method (server)
2277   "Map virtual server names to select methods."
2278   (or
2279    ;; Is this a method, perhaps?
2280    (and server (listp server) server)
2281    ;; Perhaps this is the native server?
2282    (and (equal server "native") gnus-select-method)
2283    ;; It should be in the server alist.
2284    (cdr (assoc server gnus-server-alist))
2285    ;; It could be in the predefined server alist.
2286    (cdr (assoc server gnus-predefined-server-alist))
2287    ;; If not, we look through all the opened server
2288    ;; to see whether we can find it there.
2289    (let ((opened gnus-opened-servers))
2290      (while (and opened
2291                  (not (equal server (format "%s:%s" (caaar opened)
2292                                             (cadaar opened)))))
2293        (pop opened))
2294      (caar opened))))
2295
2296 (defmacro gnus-method-equal (ss1 ss2)
2297   "Say whether two servers are equal."
2298   `(let ((s1 ,ss1)
2299          (s2 ,ss2))
2300      (or (equal s1 s2)
2301          (and (= (length s1) (length s2))
2302               (progn
2303                 (while (and s1 (member (car s1) s2))
2304                   (setq s1 (cdr s1)))
2305                 (null s1))))))
2306
2307 (defun gnus-server-equal (m1 m2)
2308   "Say whether two methods are equal."
2309   (let ((m1 (cond ((null m1) gnus-select-method)
2310                   ((stringp m1) (gnus-server-to-method m1))
2311                   (t m1)))
2312         (m2 (cond ((null m2) gnus-select-method)
2313                   ((stringp m2) (gnus-server-to-method m2))
2314                   (t m2))))
2315     (gnus-method-equal m1 m2)))
2316
2317 (defun gnus-servers-using-backend (backend)
2318   "Return a list of known servers using BACKEND."
2319   (let ((opened gnus-opened-servers)
2320         out)
2321     (while opened
2322       (when (eq backend (caaar opened))
2323         (push (caar opened) out))
2324       (pop opened))
2325     out))
2326
2327 (defun gnus-archive-server-wanted-p ()
2328   "Say whether the user wants to use the archive server."
2329   (cond
2330    ((or (not gnus-message-archive-method)
2331         (not gnus-message-archive-group))
2332     nil)
2333    ((and gnus-message-archive-method gnus-message-archive-group)
2334     t)
2335    (t
2336     (let ((active (cadr (assq 'nnfolder-active-file
2337                               gnus-message-archive-method))))
2338       (and active
2339            (file-exists-p active))))))
2340
2341 (defun gnus-group-prefixed-name (group method)
2342   "Return the whole name from GROUP and METHOD."
2343   (and (stringp method) (setq method (gnus-server-to-method method)))
2344   (if (or (not method)
2345           (gnus-server-equal method "native"))
2346       group
2347     (concat (format "%s" (car method))
2348             (when (and
2349                    (or (assoc (format "%s" (car method))
2350                               (gnus-methods-using 'address))
2351                        (gnus-server-equal method gnus-message-archive-method))
2352                    (nth 1 method)
2353                    (not (string= (nth 1 method) "")))
2354               (concat "+" (nth 1 method)))
2355             ":" group)))
2356
2357 (defun gnus-group-real-prefix (group)
2358   "Return the prefix of the current group name."
2359   (if (string-match "^[^:]+:" group)
2360       (substring group 0 (match-end 0))
2361     ""))
2362
2363 (defun gnus-group-method (group)
2364   "Return the server or method used for selecting GROUP.
2365 You should probably use `gnus-find-method-for-group' instead."
2366   (let ((prefix (gnus-group-real-prefix group)))
2367     (if (equal prefix "")
2368         gnus-select-method
2369       (let ((servers gnus-opened-servers)
2370             (server "")
2371             backend possible found)
2372         (if (string-match "^[^\\+]+\\+" prefix)
2373             (setq backend (intern (substring prefix 0 (1- (match-end 0))))
2374                   server (substring prefix (match-end 0) (1- (length prefix))))
2375           (setq backend (intern (substring prefix 0 (1- (length prefix))))))
2376         (while servers
2377           (when (eq (caaar servers) backend)
2378             (setq possible (caar servers))
2379             (when (equal (cadaar servers) server)
2380               (setq found (caar servers))))
2381           (pop servers))
2382         (or (car (rassoc found gnus-server-alist))
2383             found
2384             (car (rassoc possible gnus-server-alist))
2385             possible
2386             (list backend server))))))
2387
2388 (defsubst gnus-secondary-method-p (method)
2389   "Return whether METHOD is a secondary select method."
2390   (let ((methods gnus-secondary-select-methods)
2391         (gmethod (gnus-server-get-method nil method)))
2392     (while (and methods
2393                 (not (equal (gnus-server-get-method nil (car methods))
2394                             gmethod)))
2395       (setq methods (cdr methods)))
2396     methods))
2397
2398 (defun gnus-groups-from-server (server)
2399   "Return a list of all groups that are fetched from SERVER."
2400   (let ((alist (cdr gnus-newsrc-alist))
2401         info groups)
2402     (while (setq info (pop alist))
2403       (when (gnus-server-equal (gnus-info-method info) server)
2404         (push (gnus-info-group info) groups)))
2405     (sort groups 'string<)))
2406
2407 (defun gnus-group-foreign-p (group)
2408   "Say whether a group is foreign or not."
2409   (and (not (gnus-group-native-p group))
2410        (not (gnus-group-secondary-p group))))
2411
2412 (defun gnus-group-native-p (group)
2413   "Say whether the group is native or not."
2414   (not (string-match ":" group)))
2415
2416 (defun gnus-group-secondary-p (group)
2417   "Say whether the group is secondary or not."
2418   (gnus-secondary-method-p (gnus-find-method-for-group group)))
2419
2420 (defun gnus-group-find-parameter (group &optional symbol allow-list)
2421   "Return the group parameters for GROUP.
2422 If SYMBOL, return the value of that symbol in the group parameters."
2423   (save-excursion
2424     (set-buffer gnus-group-buffer)
2425     (let ((parameters (funcall gnus-group-get-parameter-function group)))
2426       (if symbol
2427           (gnus-group-parameter-value parameters symbol allow-list)
2428         parameters))))
2429
2430 (defun gnus-group-get-parameter (group &optional symbol allow-list)
2431   "Return the group parameters for GROUP.
2432 If SYMBOL, return the value of that symbol in the group parameters.
2433 Most functions should use `gnus-group-find-parameter', which
2434 also examines the topic parameters."
2435   (let ((params (gnus-info-params (gnus-get-info group))))
2436     (if symbol
2437         (gnus-group-parameter-value params symbol allow-list)
2438       params)))
2439
2440 (defun gnus-group-parameter-value (params symbol &optional allow-list)
2441   "Return the value of SYMBOL in group PARAMS."
2442   ;; We only wish to return group parameters (dotted lists) and
2443   ;; not local variables, which may have the same names.
2444   ;; But first we handle single elements...
2445   (or (car (memq symbol params))
2446       ;; Handle alist.
2447       (let (elem)
2448         (catch 'found
2449           (while (setq elem (pop params))
2450             (when (and (consp elem)
2451                        (eq (car elem) symbol)
2452                        (or allow-list
2453                            (atom (cdr elem))))
2454               (throw 'found (cdr elem))))))))
2455
2456 (defun gnus-group-add-parameter (group param)
2457   "Add parameter PARAM to GROUP."
2458   (let ((info (gnus-get-info group)))
2459     (when info
2460       (gnus-group-remove-parameter group (if (consp param) (car param) param))
2461       ;; Cons the new param to the old one and update.
2462       (gnus-group-set-info (cons param (gnus-info-params info))
2463                            group 'params))))
2464
2465 (defun gnus-group-set-parameter (group name value)
2466   "Set parameter NAME to VALUE in GROUP."
2467   (let ((info (gnus-get-info group)))
2468     (when info
2469       (gnus-group-remove-parameter group name)
2470       (let ((old-params (gnus-info-params info))
2471             (new-params (list (cons name value))))
2472         (while old-params
2473           (when (or (not (listp (car old-params)))
2474                     (not (eq (caar old-params) name)))
2475             (setq new-params (append new-params (list (car old-params)))))
2476           (setq old-params (cdr old-params)))
2477         (gnus-group-set-info new-params group 'params)))))
2478
2479 (defun gnus-group-remove-parameter (group name)
2480   "Remove parameter NAME from GROUP."
2481   (let ((info (gnus-get-info group)))
2482     (when info
2483       (let ((params (gnus-info-params info)))
2484         (when params
2485           (setq params (delq name params))
2486           (while (assq name params)
2487             (gnus-pull name params))
2488           (gnus-info-set-params info params))))))
2489
2490 (defun gnus-group-add-score (group &optional score)
2491   "Add SCORE to the GROUP score.
2492 If SCORE is nil, add 1 to the score of GROUP."
2493   (let ((info (gnus-get-info group)))
2494     (when info
2495       (gnus-info-set-score info (+ (gnus-info-score info) (or score 1))))))
2496
2497 ;; Function written by Stainless Steel Rat <ratinox@peorth.gweep.net>
2498 (defun gnus-short-group-name (group &optional levels)
2499   "Collapse GROUP name LEVELS.
2500 Select methods are stripped and any remote host name is stripped down to
2501 just the host name."
2502   (let* ((name "")
2503          (foreign "")
2504          (depth 0)
2505          (skip 1)
2506          (levels (or levels
2507                      (progn
2508                        (while (string-match "\\." group skip)
2509                          (setq skip (match-end 0)
2510                                depth (+ depth 1)))
2511                        depth))))
2512     ;; separate foreign select method from group name and collapse.
2513     ;; if method contains a server, collapse to non-domain server name,
2514     ;; otherwise collapse to select method
2515     (when (string-match ":" group)
2516       (cond ((string-match "+" group)
2517              (let* ((plus (string-match "+" group))
2518                     (colon (string-match ":" group (or plus 0)))
2519                     (dot (string-match "\\." group)))
2520                (setq foreign (concat
2521                               (substring group (+ 1 plus)
2522                                          (cond ((null dot) colon)
2523                                                ((< colon dot) colon)
2524                                                ((< dot colon) dot)))
2525                               ":")
2526                      group (substring group (+ 1 colon)))))
2527             (t
2528              (let* ((colon (string-match ":" group)))
2529                (setq foreign (concat (substring group 0 (+ 1 colon)))
2530                      group (substring group (+ 1 colon)))))))
2531     ;; collapse group name leaving LEVELS uncollapsed elements
2532     (while group
2533       (if (and (string-match "\\." group) (> levels 0))
2534           (setq name (concat name (substring group 0 1))
2535                 group (substring group (match-end 0))
2536                 levels (- levels 1)
2537                 name (concat name "."))
2538         (setq name (concat foreign name group)
2539               group nil)))
2540     name))
2541
2542 (defun gnus-narrow-to-body ()
2543   "Narrow to the body of an article."
2544   (narrow-to-region
2545    (progn
2546      (goto-char (point-min))
2547      (or (search-forward "\n\n" nil t)
2548          (point-max)))
2549    (point-max)))
2550
2551 \f
2552 ;;;
2553 ;;; Kill file handling.
2554 ;;;
2555
2556 (defun gnus-apply-kill-file ()
2557   "Apply a kill file to the current newsgroup.
2558 Returns the number of articles marked as read."
2559   (if (or (file-exists-p (gnus-newsgroup-kill-file nil))
2560           (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)))
2561       (gnus-apply-kill-file-internal)
2562     0))
2563
2564 (defun gnus-kill-save-kill-buffer ()
2565   (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)))
2566     (when (get-file-buffer file)
2567       (save-excursion
2568         (set-buffer (get-file-buffer file))
2569         (when (buffer-modified-p)
2570           (save-buffer))
2571         (kill-buffer (current-buffer))))))
2572
2573 (defcustom gnus-kill-file-name "KILL"
2574   "Suffix of the kill files."
2575   :group 'gnus-score-kill
2576   :group 'gnus-score-files
2577   :type 'string)
2578
2579 (defun gnus-newsgroup-kill-file (newsgroup)
2580   "Return the name of a kill file name for NEWSGROUP.
2581 If NEWSGROUP is nil, return the global kill file name instead."
2582   (cond
2583    ;; The global KILL file is placed at top of the directory.
2584    ((or (null newsgroup)
2585         (string-equal newsgroup ""))
2586     (expand-file-name gnus-kill-file-name
2587                       gnus-kill-files-directory))
2588    ;; Append ".KILL" to newsgroup name.
2589    ((gnus-use-long-file-name 'not-kill)
2590     (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup)
2591                               "." gnus-kill-file-name)
2592                       gnus-kill-files-directory))
2593    ;; Place "KILL" under the hierarchical directory.
2594    (t
2595     (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup)
2596                               "/" gnus-kill-file-name)
2597                       gnus-kill-files-directory))))
2598
2599 ;;; Server things.
2600
2601 (defun gnus-member-of-valid (symbol group)
2602   "Find out if GROUP has SYMBOL as part of its \"valid\" spec."
2603   (memq symbol (assoc
2604                 (symbol-name (car (gnus-find-method-for-group group)))
2605                 gnus-valid-select-methods)))
2606
2607 (defun gnus-method-option-p (method option)
2608   "Return non-nil if select METHOD has OPTION as a parameter."
2609   (when (stringp method)
2610     (setq method (gnus-server-to-method method)))
2611   (memq option (assoc (format "%s" (car method))
2612                       gnus-valid-select-methods)))
2613
2614 (defun gnus-similar-server-opened (method)
2615   (let ((opened gnus-opened-servers))
2616     (while (and method opened)
2617       (when (and (equal (cadr method) (cadaar opened))
2618                  (not (equal method (caar opened))))
2619         (setq method nil))
2620       (pop opened))
2621     (not method)))
2622
2623 (defun gnus-server-extend-method (group method)
2624   ;; This function "extends" a virtual server.  If the server is
2625   ;; "hello", and the select method is ("hello" (my-var "something"))
2626   ;; in the group "alt.alt", this will result in a new virtual server
2627   ;; called "hello+alt.alt".
2628   (if (or (not (inline (gnus-similar-server-opened method)))
2629           (not (cddr method)))
2630       method
2631     `(,(car method) ,(concat (cadr method) "+" group)
2632       (,(intern (format "%s-address" (car method))) ,(cadr method))
2633       ,@(cddr method))))
2634
2635 (defun gnus-server-status (method)
2636   "Return the status of METHOD."
2637   (nth 1 (assoc method gnus-opened-servers)))
2638
2639 (defun gnus-group-name-to-method (group)
2640   "Guess a select method based on GROUP."
2641   (if (string-match ":" group)
2642       (let ((server (substring group 0 (match-beginning 0))))
2643         (if (string-match "\\+" server)
2644             (list (intern (substring server 0 (match-beginning 0)))
2645                   (substring server (match-end 0)))
2646           (list (intern server) "")))
2647     gnus-select-method))
2648
2649 (defun gnus-find-method-for-group (group &optional info)
2650   "Find the select method that GROUP uses."
2651   (or gnus-override-method
2652       (and (not group)
2653            gnus-select-method)
2654       (let ((info (or info (gnus-get-info group)))
2655             method)
2656         (if (or (not info)
2657                 (not (setq method (gnus-info-method info)))
2658                 (equal method "native"))
2659             gnus-select-method
2660           (setq method
2661                 (cond ((stringp method)
2662                        (inline (gnus-server-to-method method)))
2663                       ((stringp (cadr method))
2664                        (inline (gnus-server-extend-method group method)))
2665                       (t
2666                        method)))
2667           (cond ((equal (cadr method) "")
2668                  method)
2669                 ((null (cadr method))
2670                  (list (car method) ""))
2671                 (t
2672                  (gnus-server-add-address method)))))))
2673
2674 (defun gnus-methods-using (feature)
2675   "Find all methods that have FEATURE."
2676   (let ((valids gnus-valid-select-methods)
2677         outs)
2678     (while valids
2679       (when (memq feature (car valids))
2680         (push (car valids) outs))
2681       (setq valids (cdr valids)))
2682     outs))
2683
2684 (defun gnus-read-group (prompt &optional default)
2685   "Prompt the user for a group name.
2686 Disallow illegal group names."
2687   (let ((prefix "")
2688         group)
2689     (while (not group)
2690       (when (string-match
2691              "[: `'\"/]\\|^$"
2692              (setq group (read-string (concat prefix prompt)
2693                                       (cons (or default "") 0)
2694                                       'gnus-group-history)))
2695         (setq prefix (format "Illegal group name: \"%s\".  " group)
2696               group nil)))
2697     group))
2698
2699 (defun gnus-read-method (prompt)
2700   "Prompt the user for a method.
2701 Allow completion over sensible values."
2702   (let* ((servers
2703           (append gnus-valid-select-methods
2704                   gnus-predefined-server-alist
2705                   gnus-server-alist))
2706          (method
2707           (completing-read
2708            prompt servers
2709            nil t nil 'gnus-method-history)))
2710     (cond
2711      ((equal method "")
2712       (setq method gnus-select-method))
2713      ((assoc method gnus-valid-select-methods)
2714       (list (intern method)
2715             (if (memq 'prompt-address
2716                       (assoc method gnus-valid-select-methods))
2717                 (read-string "Address: ")
2718               "")))
2719      ((assoc method servers)
2720       method)
2721      (t
2722       (list (intern method) "")))))
2723
2724 ;;; User-level commands.
2725
2726 ;;;###autoload
2727 (defun gnus-slave-no-server (&optional arg)
2728   "Read network news as a slave, without connecting to local server."
2729   (interactive "P")
2730   (gnus-no-server arg t))
2731
2732 ;;;###autoload
2733 (defun gnus-no-server (&optional arg slave)
2734   "Read network news.
2735 If ARG is a positive number, Gnus will use that as the
2736 startup level.  If ARG is nil, Gnus will be started at level 2.
2737 If ARG is non-nil and not a positive number, Gnus will
2738 prompt the user for the name of an NNTP server to use.
2739 As opposed to `gnus', this command will not connect to the local server."
2740   (interactive "P")
2741   (gnus-no-server-1 arg slave))
2742
2743 ;;;###autoload
2744 (defun gnus-slave (&optional arg)
2745   "Read news as a slave."
2746   (interactive "P")
2747   (gnus arg nil 'slave))
2748
2749 ;;;###autoload
2750 (defun gnus-other-frame (&optional arg)
2751   "Pop up a frame to read news."
2752   (interactive "P")
2753   (let ((window (get-buffer-window gnus-group-buffer)))
2754     (cond (window
2755            (select-frame (window-frame window)))
2756           ((= (length (frame-list)) 1)
2757            (select-frame (make-frame)))
2758           (t
2759            (other-frame 1))))
2760   (gnus arg))
2761
2762 ;;;###autoload
2763 (defun gnus (&optional arg dont-connect slave)
2764   "Read network news.
2765 If ARG is non-nil and a positive number, Gnus will use that as the
2766 startup level.  If ARG is non-nil and not a positive number, Gnus will
2767 prompt the user for the name of an NNTP server to use."
2768   (interactive "P")
2769   (gnus-1 arg dont-connect slave))
2770
2771 ;; Allow redefinition of Gnus functions.
2772
2773 (gnus-ems-redefine)
2774
2775 (provide 'gnus)
2776
2777 ;;; gnus.el ends here