Importing Oort Gnus v0.05.
[elisp/gnus.git-] / lisp / gnus-util.el
1 ;;; gnus-util.el --- utility functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; Nothing in this file depends on any other parts of Gnus -- all
28 ;; functions and macros in this file are utility functions that are
29 ;; used by Gnus and may be used by any other package without loading
30 ;; Gnus first.
31
32 ;;; Code:
33
34 (require 'custom)
35 (eval-when-compile
36   (require 'cl)
37   ;; Fixme: this should be a gnus variable, not nnmail-.
38   (defvar nnmail-pathname-coding-system))
39 (require 'nnheader)
40 (require 'time-date)
41
42 (eval-and-compile
43   (autoload 'message-fetch-field "message")
44   (autoload 'gnus-get-buffer-window "gnus-win")
45   (autoload 'rmail-insert-rmail-file-header "rmail")
46   (autoload 'rmail-count-new-messages "rmail")
47   (autoload 'rmail-show-message "rmail"))
48
49 (eval-and-compile
50   (cond
51    ((fboundp 'replace-in-string)
52     (defalias 'gnus-replace-in-string 'replace-in-string))
53    ((fboundp 'replace-regexp-in-string)
54     (defun gnus-replace-in-string  (string regexp newtext &optional literal)
55       (replace-regexp-in-string regexp newtext string nil literal)))
56    (t
57     (defun gnus-replace-in-string (string regexp newtext &optional literal)
58       (let ((start 0) tail)
59         (while (string-match regexp string start)
60           (setq tail (- (length string) (match-end 0)))
61           (setq string (replace-match newtext nil literal string))
62           (setq start (- (length string) tail))))
63       string))))
64
65 (defun gnus-boundp (variable)
66   "Return non-nil if VARIABLE is bound and non-nil."
67   (and (boundp variable)
68        (symbol-value variable)))
69
70 (defmacro gnus-eval-in-buffer-window (buffer &rest forms)
71   "Pop to BUFFER, evaluate FORMS, and then return to the original window."
72   (let ((tempvar (make-symbol "GnusStartBufferWindow"))
73         (w (make-symbol "w"))
74         (buf (make-symbol "buf")))
75     `(let* ((,tempvar (selected-window))
76             (,buf ,buffer)
77             (,w (gnus-get-buffer-window ,buf 'visible)))
78        (unwind-protect
79            (progn
80              (if ,w
81                  (progn
82                    (select-window ,w)
83                    (set-buffer (window-buffer ,w)))
84                (pop-to-buffer ,buf))
85              ,@forms)
86          (select-window ,tempvar)))))
87
88 (put 'gnus-eval-in-buffer-window 'lisp-indent-function 1)
89 (put 'gnus-eval-in-buffer-window 'edebug-form-spec '(form body))
90
91 (defmacro gnus-intern-safe (string hashtable)
92   "Set hash value.  Arguments are STRING, VALUE, and HASHTABLE."
93   `(let ((symbol (intern ,string ,hashtable)))
94      (or (boundp symbol)
95          (set symbol nil))
96      symbol))
97
98 ;; Added by Geoffrey T. Dairiki <dairiki@u.washington.edu>.  A safe way
99 ;; to limit the length of a string.  This function is necessary since
100 ;; `(substr "abc" 0 30)' pukes with "Args out of range".
101 (defsubst gnus-limit-string (str width)
102   (if (> (length str) width)
103       (substring str 0 width)
104     str))
105
106 (defsubst gnus-functionp (form)
107   "Return non-nil if FORM is funcallable."
108   (or (and (symbolp form) (fboundp form))
109       (and (listp form) (eq (car form) 'lambda))
110       (byte-code-function-p form)))
111
112 (defsubst gnus-goto-char (point)
113   (and point (goto-char point)))
114
115 (defmacro gnus-buffer-exists-p (buffer)
116   `(let ((buffer ,buffer))
117      (when buffer
118        (funcall (if (stringp buffer) 'get-buffer 'buffer-name)
119                 buffer))))
120
121 (defmacro gnus-kill-buffer (buffer)
122   `(let ((buf ,buffer))
123      (when (gnus-buffer-exists-p buf)
124        (kill-buffer buf))))
125
126 (defalias 'gnus-point-at-bol
127   (if (fboundp 'point-at-bol)
128       'point-at-bol
129     'line-beginning-position))
130
131 (defalias 'gnus-point-at-eol
132   (if (fboundp 'point-at-eol)
133       'point-at-eol
134     'line-end-position))
135
136 (defun gnus-delete-first (elt list)
137   "Delete by side effect the first occurrence of ELT as a member of LIST."
138   (if (equal (car list) elt)
139       (cdr list)
140     (let ((total list))
141       (while (and (cdr list)
142                   (not (equal (cadr list) elt)))
143         (setq list (cdr list)))
144       (when (cdr list)
145         (setcdr list (cddr list)))
146       total)))
147
148 ;; Delete the current line (and the next N lines).
149 (defmacro gnus-delete-line (&optional n)
150   `(delete-region (progn (beginning-of-line) (point))
151                   (progn (forward-line ,(or n 1)) (point))))
152
153 (defun gnus-byte-code (func)
154   "Return a form that can be `eval'ed based on FUNC."
155   (let ((fval (indirect-function func)))
156     (if (byte-code-function-p fval)
157         (let ((flist (append fval nil)))
158           (setcar flist 'byte-code)
159           flist)
160       (cons 'progn (cddr fval)))))
161
162 (defun gnus-extract-address-components (from)
163   (let (name address)
164     ;; First find the address - the thing with the @ in it.  This may
165     ;; not be accurate in mail addresses, but does the trick most of
166     ;; the time in news messages.
167     (when (string-match "\\b[^@ \t<>]+[!@][^@ \t<>]+\\b" from)
168       (setq address (substring from (match-beginning 0) (match-end 0))))
169     ;; Then we check whether the "name <address>" format is used.
170     (and address
171          ;; Linear white space is not required.
172          (string-match (concat "[ \t]*<" (regexp-quote address) ">") from)
173          (and (setq name (substring from 0 (match-beginning 0)))
174               ;; Strip any quotes from the name.
175               (string-match "\".*\"" name)
176               (setq name (substring name 1 (1- (match-end 0))))))
177     ;; If not, then "address (name)" is used.
178     (or name
179         (and (string-match "(.+)" from)
180              (setq name (substring from (1+ (match-beginning 0))
181                                    (1- (match-end 0)))))
182         (and (string-match "()" from)
183              (setq name address))
184         ;; XOVER might not support folded From headers.
185         (and (string-match "(.*" from)
186              (setq name (substring from (1+ (match-beginning 0))
187                                    (match-end 0)))))
188     (list (if (string= name "") nil name) (or address from))))
189
190
191 (defun gnus-fetch-field (field)
192   "Return the value of the header FIELD of current article."
193   (save-excursion
194     (save-restriction
195       (let ((case-fold-search t)
196             (inhibit-point-motion-hooks t))
197         (nnheader-narrow-to-headers)
198         (message-fetch-field field)))))
199
200 (defun gnus-goto-colon ()
201   (beginning-of-line)
202   (let ((eol (gnus-point-at-eol)))
203     (goto-char (or (text-property-any (point) eol 'gnus-position t)
204                    (search-forward ":" eol t)
205                    (point)))))
206
207 (defun gnus-decode-newsgroups (newsgroups group &optional method)
208   (let ((method (or method (gnus-find-method-for-group group))))
209     (mapconcat (lambda (group)
210                  (gnus-group-name-decode group (gnus-group-name-charset
211                                                 method group)))
212                (message-tokenize-header newsgroups)
213                ",")))
214
215 (defun gnus-remove-text-with-property (prop)
216   "Delete all text in the current buffer with text property PROP."
217   (save-excursion
218     (goto-char (point-min))
219     (while (not (eobp))
220       (while (get-text-property (point) prop)
221         (delete-char 1))
222       (goto-char (next-single-property-change (point) prop nil (point-max))))))
223
224 (require 'nnheader)
225 (defun gnus-newsgroup-directory-form (newsgroup)
226   "Make hierarchical directory name from NEWSGROUP name."
227   (let* ((newsgroup (gnus-newsgroup-savable-name newsgroup))
228          (idx (string-match ":" newsgroup)))
229     (concat
230      (if idx (substring newsgroup 0 idx))
231      (if idx "/")
232      (nnheader-replace-chars-in-string
233       (if idx (substring newsgroup (1+ idx)) newsgroup)
234       ?. ?/))))
235
236 (defun gnus-newsgroup-savable-name (group)
237   ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group)
238   ;; with dots.
239   (nnheader-replace-chars-in-string group ?/ ?.))
240
241 (defun gnus-string> (s1 s2)
242   (not (or (string< s1 s2)
243            (string= s1 s2))))
244
245 ;;; Time functions.
246
247 (defun gnus-file-newer-than (file date)
248   (let ((fdate (nth 5 (file-attributes file))))
249     (or (> (car fdate) (car date))
250         (and (= (car fdate) (car date))
251              (> (nth 1 fdate) (nth 1 date))))))
252
253 ;;; Keymap macros.
254
255 (defmacro gnus-local-set-keys (&rest plist)
256   "Set the keys in PLIST in the current keymap."
257   `(gnus-define-keys-1 (current-local-map) ',plist))
258
259 (defmacro gnus-define-keys (keymap &rest plist)
260   "Define all keys in PLIST in KEYMAP."
261   `(gnus-define-keys-1 (quote ,keymap) (quote ,plist)))
262
263 (defmacro gnus-define-keys-safe (keymap &rest plist)
264   "Define all keys in PLIST in KEYMAP without overwriting previous definitions."
265   `(gnus-define-keys-1 (quote ,keymap) (quote ,plist) t))
266
267 (put 'gnus-define-keys 'lisp-indent-function 1)
268 (put 'gnus-define-keys-safe 'lisp-indent-function 1)
269 (put 'gnus-local-set-keys 'lisp-indent-function 1)
270
271 (defmacro gnus-define-keymap (keymap &rest plist)
272   "Define all keys in PLIST in KEYMAP."
273   `(gnus-define-keys-1 ,keymap (quote ,plist)))
274
275 (put 'gnus-define-keymap 'lisp-indent-function 1)
276
277 (defun gnus-define-keys-1 (keymap plist &optional safe)
278   (when (null keymap)
279     (error "Can't set keys in a null keymap"))
280   (cond ((symbolp keymap)
281          (setq keymap (symbol-value keymap)))
282         ((keymapp keymap))
283         ((listp keymap)
284          (set (car keymap) nil)
285          (define-prefix-command (car keymap))
286          (define-key (symbol-value (caddr keymap)) (cadr keymap) (car keymap))
287          (setq keymap (symbol-value (car keymap)))))
288   (let (key)
289     (while plist
290       (when (symbolp (setq key (pop plist)))
291         (setq key (symbol-value key)))
292       (if (or (not safe)
293               (eq (lookup-key keymap key) 'undefined))
294           (define-key keymap key (pop plist))
295         (pop plist)))))
296
297 (defun gnus-completing-read-with-default (default prompt &rest args)
298   ;; Like `completing-read', except that DEFAULT is the default argument.
299   (let* ((prompt (if default
300                      (concat prompt " (default " default ") ")
301                    (concat prompt " ")))
302          (answer (apply 'completing-read prompt args)))
303     (if (or (null answer) (zerop (length answer)))
304         default
305       answer)))
306
307 ;; Two silly functions to ensure that all `y-or-n-p' questions clear
308 ;; the echo area.
309 (defun gnus-y-or-n-p (prompt)
310   (prog1
311       (y-or-n-p prompt)
312     (message "")))
313
314 (defun gnus-yes-or-no-p (prompt)
315   (prog1
316       (yes-or-no-p prompt)
317     (message "")))
318
319 ;; By Frank Schmitt <ich@Frank-Schmitt.net>. Allows to have
320 ;; age-depending date representations. (e.g. just the time if it's
321 ;; from today, the day of the week if it's within the last 7 days and
322 ;; the full date if it's older)
323 (defun gnus-seconds-today ()
324   "Returns the number of seconds passed today"
325   (let ((now (decode-time (current-time))))
326     (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600))))
327
328 (defun gnus-seconds-month ()
329   "Returns the number of seconds passed this month"
330   (let ((now (decode-time (current-time))))
331     (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600)
332        (* (- (car (nthcdr 3 now)) 1) 3600 24))))
333
334 (defun gnus-seconds-year ()
335   "Returns the number of seconds passed this year"
336   (let ((now (decode-time (current-time)))
337         (days (format-time-string "%j" (current-time))))
338     (+ (car now) (* (car (cdr now)) 60) (* (car (nthcdr 2 now)) 3600)
339        (* (- (string-to-number days) 1) 3600 24))))
340
341 (defvar gnus-user-date-format-alist
342   '(((gnus-seconds-today) . "%k:%M")
343     (604800 . "%a %k:%M")                   ;;that's one week
344     ((gnus-seconds-month) . "%a %d")
345     ((gnus-seconds-year) . "%b %d")
346     (t . "%b %d '%y"))                      ;;this one is used when no
347                                             ;;other does match
348   "Alist of time in seconds and format specification used to display dates not older.
349 The first element must be a number or a function returning a
350 number. The second element is a format-specification as described in
351 the documentation for format-time-string.  The list must be ordered
352 smallest number up. When there is an element, which is not a number,
353 the corresponding format-specification will be used, disregarding any
354 following elements.  You can use the functions gnus-seconds-today,
355 gnus-seconds-month, gnus-seconds-year which will return the number of
356 seconds which passed today/this month/this year.")
357
358 (defun gnus-user-date (messy-date)
359   "Format the messy-date acording to gnus-user-date-format-alist.
360 Returns \"  ?  \" if there's bad input or if an other error occurs.
361 Input should look like this: \"Sun, 14 Oct 2001 13:34:39 +0200\"."
362   (condition-case ()
363       (let* ((messy-date (safe-date-to-time messy-date))
364              (now (current-time))
365              ;;If we don't find something suitable we'll use this one
366              (my-format "%b %m '%y")
367              (high (lsh (- (car now) (car messy-date)) 16)))
368         (if (and (> high -1) (= (logand high 65535) 0))
369             ;;overflow and bad input
370             (let* ((difference (+ high (- (car (cdr now))
371                                           (car (cdr messy-date)))))
372                    (templist gnus-user-date-format-alist)
373                    (top (eval (caar templist))))
374               (while (if (numberp top) (< top difference) (not top))
375                 (progn
376                   (setq templist (cdr templist))
377                   (setq top (eval (caar templist)))))
378               (if (stringp (cdr (car templist)))
379                   (setq my-format (cdr (car templist))))))
380         (format-time-string (eval my-format) messy-date))
381     (error "  ?   ")))
382 ;;end of Frank's code
383
384 (defun gnus-dd-mmm (messy-date)
385   "Return a string like DD-MMM from a big messy string."
386   (condition-case ()
387       (format-time-string "%d-%b" (safe-date-to-time messy-date))
388     (error "  -   ")))
389
390 (defmacro gnus-date-get-time (date)
391   "Convert DATE string to Emacs time.
392 Cache the result as a text property stored in DATE."
393   ;; Either return the cached value...
394   `(let ((d ,date))
395      (if (equal "" d)
396          '(0 0)
397        (or (get-text-property 0 'gnus-time d)
398            ;; or compute the value...
399            (let ((time (safe-date-to-time d)))
400              ;; and store it back in the string.
401              (put-text-property 0 1 'gnus-time time d)
402              time)))))
403
404 (defsubst gnus-time-iso8601 (time)
405   "Return a string of TIME in YYYYMMDDTHHMMSS format."
406   (format-time-string "%Y%m%dT%H%M%S" time))
407
408 (defun gnus-date-iso8601 (date)
409   "Convert the DATE to YYYYMMDDTHHMMSS."
410   (condition-case ()
411       (gnus-time-iso8601 (gnus-date-get-time date))
412     (error "")))
413
414 (defun gnus-mode-string-quote (string)
415   "Quote all \"%\"'s in STRING."
416   (gnus-replace-in-string string "%" "%%"))
417
418 ;; Make a hash table (default and minimum size is 256).
419 ;; Optional argument HASHSIZE specifies the table size.
420 (defun gnus-make-hashtable (&optional hashsize)
421   (make-vector (if hashsize (max (gnus-create-hash-size hashsize) 256) 256) 0))
422
423 ;; Make a number that is suitable for hashing; bigger than MIN and
424 ;; equal to some 2^x.  Many machines (such as sparcs) do not have a
425 ;; hardware modulo operation, so they implement it in software.  On
426 ;; many sparcs over 50% of the time to intern is spent in the modulo.
427 ;; Yes, it's slower than actually computing the hash from the string!
428 ;; So we use powers of 2 so people can optimize the modulo to a mask.
429 (defun gnus-create-hash-size (min)
430   (let ((i 1))
431     (while (< i min)
432       (setq i (* 2 i)))
433     i))
434
435 (defcustom gnus-verbose 7
436   "*Integer that says how verbose Gnus should be.
437 The higher the number, the more messages Gnus will flash to say what
438 it's doing.  At zero, Gnus will be totally mute; at five, Gnus will
439 display most important messages; and at ten, Gnus will keep on
440 jabbering all the time."
441   :group 'gnus-start
442   :type 'integer)
443
444 ;; Show message if message has a lower level than `gnus-verbose'.
445 ;; Guideline for numbers:
446 ;; 1 - error messages, 3 - non-serious error messages, 5 - messages
447 ;; for things that take a long time, 7 - not very important messages
448 ;; on stuff, 9 - messages inside loops.
449 (defun gnus-message (level &rest args)
450   (if (<= level gnus-verbose)
451       (apply 'message args)
452     ;; We have to do this format thingy here even if the result isn't
453     ;; shown - the return value has to be the same as the return value
454     ;; from `message'.
455     (apply 'format args)))
456
457 (defun gnus-error (level &rest args)
458   "Beep an error if LEVEL is equal to or less than `gnus-verbose'."
459   (when (<= (floor level) gnus-verbose)
460     (apply 'message args)
461     (ding)
462     (let (duration)
463       (when (and (floatp level)
464                  (not (zerop (setq duration (* 10 (- level (floor level)))))))
465         (sit-for duration))))
466   nil)
467
468 (defun gnus-split-references (references)
469   "Return a list of Message-IDs in REFERENCES."
470   (let ((beg 0)
471         ids)
472     (while (string-match "<[^> \t]+>" references beg)
473       (push (substring references (match-beginning 0) (setq beg (match-end 0)))
474             ids))
475     (nreverse ids)))
476
477 (defsubst gnus-parent-id (references &optional n)
478   "Return the last Message-ID in REFERENCES.
479 If N, return the Nth ancestor instead."
480   (when (and references
481              (not (zerop (length references))))
482     (if n
483         (let ((ids (inline (gnus-split-references references))))
484           (while (nthcdr n ids)
485             (setq ids (cdr ids)))
486           (car ids))
487       (when (string-match "<[^> \t]+>\\'" references)
488         (match-string 0 references)))))
489
490 (defun gnus-buffer-live-p (buffer)
491   "Say whether BUFFER is alive or not."
492   (and buffer
493        (get-buffer buffer)
494        (buffer-name (get-buffer buffer))))
495
496 (defun gnus-horizontal-recenter ()
497   "Recenter the current buffer horizontally."
498   (if (< (current-column) (/ (window-width) 2))
499       (set-window-hscroll (gnus-get-buffer-window (current-buffer) t) 0)
500     (let* ((orig (point))
501            (end (window-end (gnus-get-buffer-window (current-buffer) t)))
502            (max 0))
503       (when end
504         ;; Find the longest line currently displayed in the window.
505         (goto-char (window-start))
506         (while (and (not (eobp))
507                     (< (point) end))
508           (end-of-line)
509           (setq max (max max (current-column)))
510           (forward-line 1))
511         (goto-char orig)
512         ;; Scroll horizontally to center (sort of) the point.
513         (if (> max (window-width))
514             (set-window-hscroll
515              (gnus-get-buffer-window (current-buffer) t)
516              (min (- (current-column) (/ (window-width) 3))
517                   (+ 2 (- max (window-width)))))
518           (set-window-hscroll (gnus-get-buffer-window (current-buffer) t) 0))
519         max))))
520
521 (defun gnus-read-event-char ()
522   "Get the next event."
523   (let ((event (read-event)))
524     ;; should be gnus-characterp, but this can't be called in XEmacs anyway
525     (cons (and (numberp event) event) event)))
526
527 (defun gnus-sortable-date (date)
528   "Make string suitable for sorting from DATE."
529   (gnus-time-iso8601 (date-to-time date)))
530
531 (defun gnus-copy-file (file &optional to)
532   "Copy FILE to TO."
533   (interactive
534    (list (read-file-name "Copy file: " default-directory)
535          (read-file-name "Copy file to: " default-directory)))
536   (unless to
537     (setq to (read-file-name "Copy file to: " default-directory)))
538   (when (file-directory-p to)
539     (setq to (concat (file-name-as-directory to)
540                      (file-name-nondirectory file))))
541   (copy-file file to))
542
543 (defvar gnus-work-buffer " *gnus work*")
544
545 (defun gnus-set-work-buffer ()
546   "Put point in the empty Gnus work buffer."
547   (if (get-buffer gnus-work-buffer)
548       (progn
549         (set-buffer gnus-work-buffer)
550         (erase-buffer))
551     (set-buffer (gnus-get-buffer-create gnus-work-buffer))
552     (kill-all-local-variables)
553     (mm-enable-multibyte)))
554
555 (defmacro gnus-group-real-name (group)
556   "Find the real name of a foreign newsgroup."
557   `(let ((gname ,group))
558      (if (string-match "^[^:]+:" gname)
559          (substring gname (match-end 0))
560        gname)))
561
562 (defun gnus-make-sort-function (funs)
563   "Return a composite sort condition based on the functions in FUNC."
564   (cond
565    ;; Just a simple function.
566    ((gnus-functionp funs) funs)
567    ;; No functions at all.
568    ((null funs) funs)
569    ;; A list of functions.
570    ((or (cdr funs)
571         (listp (car funs)))
572     (gnus-byte-compile
573      `(lambda (t1 t2)
574         ,(gnus-make-sort-function-1 (reverse funs)))))
575    ;; A list containing just one function.
576    (t
577     (car funs))))
578
579 (defun gnus-make-sort-function-1 (funs)
580   "Return a composite sort condition based on the functions in FUNC."
581   (let ((function (car funs))
582         (first 't1)
583         (last 't2))
584     (when (consp function)
585       (cond
586        ;; Reversed spec.
587        ((eq (car function) 'not)
588         (setq function (cadr function)
589               first 't2
590               last 't1))
591        ((gnus-functionp function)
592         ;; Do nothing.
593         )
594        (t
595         (error "Invalid sort spec: %s" function))))
596     (if (cdr funs)
597         `(or (,function ,first ,last)
598              (and (not (,function ,last ,first))
599                   ,(gnus-make-sort-function-1 (cdr funs))))
600       `(,function ,first ,last))))
601
602 (defun gnus-turn-off-edit-menu (type)
603   "Turn off edit menu in `gnus-TYPE-mode-map'."
604   (define-key (symbol-value (intern (format "gnus-%s-mode-map" type)))
605     [menu-bar edit] 'undefined))
606
607 (defun gnus-prin1 (form)
608   "Use `prin1' on FORM in the current buffer.
609 Bind `print-quoted' and `print-readably' to t while printing."
610   (let ((print-quoted t)
611         (print-readably t)
612         (print-escape-multibyte nil)
613         print-level print-length)
614     (prin1 form (current-buffer))))
615
616 (defun gnus-prin1-to-string (form)
617   "The same as `prin1', but bind `print-quoted' and `print-readably' to t."
618   (let ((print-quoted t)
619         (print-readably t))
620     (prin1-to-string form)))
621
622 (defun gnus-make-directory (directory)
623   "Make DIRECTORY (and all its parents) if it doesn't exist."
624   (require 'nnmail)
625   (let ((file-name-coding-system nnmail-pathname-coding-system))
626     (when (and directory
627                (not (file-exists-p directory)))
628       (make-directory directory t)))
629   t)
630
631 (defun gnus-write-buffer (file)
632   "Write the current buffer's contents to FILE."
633   ;; Make sure the directory exists.
634   (gnus-make-directory (file-name-directory file))
635   (let ((file-name-coding-system nnmail-pathname-coding-system))
636     ;; Write the buffer.
637     (write-region (point-min) (point-max) file nil 'quietly)))
638
639 (defun gnus-delete-file (file)
640   "Delete FILE if it exists."
641   (when (file-exists-p file)
642     (delete-file file)))
643
644 (defun gnus-strip-whitespace (string)
645   "Return STRING stripped of all whitespace."
646   (while (string-match "[\r\n\t ]+" string)
647     (setq string (replace-match "" t t string)))
648   string)
649
650 (defsubst gnus-put-text-property-excluding-newlines (beg end prop val)
651   "The same as `put-text-property', but don't put this prop on any newlines in the region."
652   (save-match-data
653     (save-excursion
654       (save-restriction
655         (goto-char beg)
656         (while (re-search-forward gnus-emphasize-whitespace-regexp end 'move)
657           (gnus-put-text-property beg (match-beginning 0) prop val)
658           (setq beg (point)))
659         (gnus-put-text-property beg (point) prop val)))))
660
661 (defsubst gnus-put-overlay-excluding-newlines (beg end prop val)
662   "The same as `put-text-property', but don't put this prop on any newlines in the region."
663   (save-match-data
664     (save-excursion
665       (save-restriction
666         (goto-char beg)
667         (while (re-search-forward gnus-emphasize-whitespace-regexp end 'move)
668           (gnus-overlay-put
669            (gnus-make-overlay beg (match-beginning 0))
670            prop val)
671           (setq beg (point)))
672         (gnus-overlay-put (gnus-make-overlay beg (point)) prop val)))))
673
674 (defun gnus-put-text-property-excluding-characters-with-faces (beg end
675                                                                    prop val)
676   "The same as `put-text-property', but don't put props on characters with the `gnus-face' property."
677   (let ((b beg))
678     (while (/= b end)
679       (when (get-text-property b 'gnus-face)
680         (setq b (next-single-property-change b 'gnus-face nil end)))
681       (when (/= b end)
682         (inline
683           (gnus-put-text-property
684            b (setq b (next-single-property-change b 'gnus-face nil end))
685            prop val))))))
686
687 ;;; Protected and atomic operations.  dmoore@ucsd.edu 21.11.1996
688 ;;; The primary idea here is to try to protect internal datastructures
689 ;;; from becoming corrupted when the user hits C-g, or if a hook or
690 ;;; similar blows up.  Often in Gnus multiple tables/lists need to be
691 ;;; updated at the same time, or information can be lost.
692
693 (defvar gnus-atomic-be-safe t
694   "If t, certain operations will be protected from interruption by C-g.")
695
696 (defmacro gnus-atomic-progn (&rest forms)
697   "Evaluate FORMS atomically, which means to protect the evaluation
698 from being interrupted by the user.  An error from the forms themselves
699 will return without finishing the operation.  Since interrupts from
700 the user are disabled, it is recommended that only the most minimal
701 operations are performed by FORMS.  If you wish to assign many
702 complicated values atomically, compute the results into temporary
703 variables and then do only the assignment atomically."
704   `(let ((inhibit-quit gnus-atomic-be-safe))
705      ,@forms))
706
707 (put 'gnus-atomic-progn 'lisp-indent-function 0)
708
709 (defmacro gnus-atomic-progn-assign (protect &rest forms)
710   "Evaluate FORMS, but insure that the variables listed in PROTECT
711 are not changed if anything in FORMS signals an error or otherwise
712 non-locally exits.  The variables listed in PROTECT are updated atomically.
713 It is safe to use gnus-atomic-progn-assign with long computations.
714
715 Note that if any of the symbols in PROTECT were unbound, they will be
716 set to nil on a sucessful assignment.  In case of an error or other
717 non-local exit, it will still be unbound."
718   (let* ((temp-sym-map (mapcar (lambda (x) (list (make-symbol
719                                                   (concat (symbol-name x)
720                                                           "-tmp"))
721                                                  x))
722                                protect))
723          (sym-temp-map (mapcar (lambda (x) (list (cadr x) (car x)))
724                                temp-sym-map))
725          (temp-sym-let (mapcar (lambda (x) (list (car x)
726                                                  `(and (boundp ',(cadr x))
727                                                        ,(cadr x))))
728                                temp-sym-map))
729          (sym-temp-let sym-temp-map)
730          (temp-sym-assign (apply 'append temp-sym-map))
731          (sym-temp-assign (apply 'append sym-temp-map))
732          (result (make-symbol "result-tmp")))
733     `(let (,@temp-sym-let
734            ,result)
735        (let ,sym-temp-let
736          (setq ,result (progn ,@forms))
737          (setq ,@temp-sym-assign))
738        (let ((inhibit-quit gnus-atomic-be-safe))
739          (setq ,@sym-temp-assign))
740        ,result)))
741
742 (put 'gnus-atomic-progn-assign 'lisp-indent-function 1)
743 ;(put 'gnus-atomic-progn-assign 'edebug-form-spec '(sexp body))
744
745 (defmacro gnus-atomic-setq (&rest pairs)
746   "Similar to setq, except that the real symbols are only assigned when
747 there are no errors.  And when the real symbols are assigned, they are
748 done so atomically.  If other variables might be changed via side-effect,
749 see gnus-atomic-progn-assign.  It is safe to use gnus-atomic-setq
750 with potentially long computations."
751   (let ((tpairs pairs)
752         syms)
753     (while tpairs
754       (push (car tpairs) syms)
755       (setq tpairs (cddr tpairs)))
756     `(gnus-atomic-progn-assign ,syms
757        (setq ,@pairs))))
758
759 ;(put 'gnus-atomic-setq 'edebug-form-spec '(body))
760
761
762 ;;; Functions for saving to babyl/mail files.
763
764 (defvar rmail-default-rmail-file)
765 (defun gnus-output-to-rmail (filename &optional ask)
766   "Append the current article to an Rmail file named FILENAME."
767   (require 'rmail)
768   ;; Most of these codes are borrowed from rmailout.el.
769   (setq filename (expand-file-name filename))
770   (setq rmail-default-rmail-file filename)
771   (let ((artbuf (current-buffer))
772         (tmpbuf (get-buffer-create " *Gnus-output*")))
773     (save-excursion
774       (or (get-file-buffer filename)
775           (file-exists-p filename)
776           (if (or (not ask)
777                   (gnus-yes-or-no-p
778                    (concat "\"" filename "\" does not exist, create it? ")))
779               (let ((file-buffer (create-file-buffer filename)))
780                 (save-excursion
781                   (set-buffer file-buffer)
782                   (rmail-insert-rmail-file-header)
783                   (let ((require-final-newline nil)
784                         (coding-system-for-write mm-text-coding-system))
785                     (gnus-write-buffer filename)))
786                 (kill-buffer file-buffer))
787             (error "Output file does not exist")))
788       (set-buffer tmpbuf)
789       (erase-buffer)
790       (insert-buffer-substring artbuf)
791       (gnus-convert-article-to-rmail)
792       ;; Decide whether to append to a file or to an Emacs buffer.
793       (let ((outbuf (get-file-buffer filename)))
794         (if (not outbuf)
795             (let ((file-name-coding-system nnmail-pathname-coding-system))
796               (mm-append-to-file (point-min) (point-max) filename))
797           ;; File has been visited, in buffer OUTBUF.
798           (set-buffer outbuf)
799           (let ((buffer-read-only nil)
800                 (msg (and (boundp 'rmail-current-message)
801                           (symbol-value 'rmail-current-message))))
802             ;; If MSG is non-nil, buffer is in RMAIL mode.
803             (when msg
804               (widen)
805               (narrow-to-region (point-max) (point-max)))
806             (insert-buffer-substring tmpbuf)
807             (when msg
808               (goto-char (point-min))
809               (widen)
810               (search-backward "\n\^_")
811               (narrow-to-region (point) (point-max))
812               (rmail-count-new-messages t)
813               (when (rmail-summary-exists)
814                 (rmail-select-summary
815                  (rmail-update-summary)))
816               (rmail-count-new-messages t)
817               (rmail-show-message msg))
818             (save-buffer)))))
819     (kill-buffer tmpbuf)))
820
821 (defun gnus-output-to-mail (filename &optional ask)
822   "Append the current article to a mail file named FILENAME."
823   (setq filename (expand-file-name filename))
824   (let ((artbuf (current-buffer))
825         (tmpbuf (get-buffer-create " *Gnus-output*")))
826     (save-excursion
827       ;; Create the file, if it doesn't exist.
828       (when (and (not (get-file-buffer filename))
829                  (not (file-exists-p filename)))
830         (if (or (not ask)
831                 (gnus-y-or-n-p
832                  (concat "\"" filename "\" does not exist, create it? ")))
833             (let ((file-buffer (create-file-buffer filename)))
834               (save-excursion
835                 (set-buffer file-buffer)
836                 (let ((require-final-newline nil)
837                       (coding-system-for-write mm-text-coding-system))
838                   (gnus-write-buffer filename)))
839               (kill-buffer file-buffer))
840           (error "Output file does not exist")))
841       (set-buffer tmpbuf)
842       (erase-buffer)
843       (insert-buffer-substring artbuf)
844       (goto-char (point-min))
845       (if (looking-at "From ")
846           (forward-line 1)
847         (insert "From nobody " (current-time-string) "\n"))
848       (let (case-fold-search)
849         (while (re-search-forward "^From " nil t)
850           (beginning-of-line)
851           (insert ">")))
852       ;; Decide whether to append to a file or to an Emacs buffer.
853       (let ((outbuf (get-file-buffer filename)))
854         (if (not outbuf)
855             (let ((buffer-read-only nil))
856               (save-excursion
857                 (goto-char (point-max))
858                 (forward-char -2)
859                 (unless (looking-at "\n\n")
860                   (goto-char (point-max))
861                   (unless (bolp)
862                     (insert "\n"))
863                   (insert "\n"))
864                 (goto-char (point-max))
865                 (let ((file-name-coding-system nnmail-pathname-coding-system))
866                   (mm-append-to-file (point-min) (point-max) filename))))
867           ;; File has been visited, in buffer OUTBUF.
868           (set-buffer outbuf)
869           (let ((buffer-read-only nil))
870             (goto-char (point-max))
871             (unless (eobp)
872               (insert "\n"))
873             (insert "\n")
874             (insert-buffer-substring tmpbuf)))))
875     (kill-buffer tmpbuf)))
876
877 (defun gnus-convert-article-to-rmail ()
878   "Convert article in current buffer to Rmail message format."
879   (let ((buffer-read-only nil))
880     ;; Convert article directly into Babyl format.
881     (goto-char (point-min))
882     (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
883     (while (search-forward "\n\^_" nil t) ;single char
884       (replace-match "\n^_" t t))       ;2 chars: "^" and "_"
885     (goto-char (point-max))
886     (insert "\^_")))
887
888 (defun gnus-map-function (funs arg)
889   "Applies the result of the first function in FUNS to the second, and so on.
890 ARG is passed to the first function."
891   (let ((myfuns funs))
892     (while myfuns
893       (setq arg (funcall (pop myfuns) arg)))
894     arg))
895
896 (defun gnus-run-hooks (&rest funcs)
897   "Does the same as `run-hooks', but saves excursion."
898   (let ((buf (current-buffer)))
899     (unwind-protect
900         (apply 'run-hooks funcs)
901       (set-buffer buf))))
902
903 ;;;
904 ;;; .netrc and .authinforc parsing
905 ;;;
906
907 (defun gnus-parse-netrc (file)
908   "Parse FILE and return an list of all entries in the file."
909   (when (file-exists-p file)
910     (with-temp-buffer
911       (let ((tokens '("machine" "default" "login"
912                       "password" "account" "macdef" "force"
913                       "port"))
914             alist elem result pair)
915         (insert-file-contents file)
916         (goto-char (point-min))
917         ;; Go through the file, line by line.
918         (while (not (eobp))
919           (narrow-to-region (point) (gnus-point-at-eol))
920           ;; For each line, get the tokens and values.
921           (while (not (eobp))
922             (skip-chars-forward "\t ")
923             ;; Skip lines that begin with a "#".
924             (if (eq (char-after) ?#)
925                 (goto-char (point-max))
926               (unless (eobp)
927                 (setq elem
928                       (if (= (following-char) ?\")
929                           (read (current-buffer))
930                         (buffer-substring
931                          (point) (progn (skip-chars-forward "^\t ")
932                                         (point)))))
933                 (cond
934                  ((equal elem "macdef")
935                   ;; We skip past the macro definition.
936                   (widen)
937                   (while (and (zerop (forward-line 1))
938                               (looking-at "$")))
939                   (narrow-to-region (point) (point)))
940                  ((member elem tokens)
941                   ;; Tokens that don't have a following value are ignored,
942                   ;; except "default".
943                   (when (and pair (or (cdr pair)
944                                       (equal (car pair) "default")))
945                     (push pair alist))
946                   (setq pair (list elem)))
947                  (t
948                   ;; Values that haven't got a preceding token are ignored.
949                   (when pair
950                     (setcdr pair elem)
951                     (push pair alist)
952                     (setq pair nil)))))))
953           (when alist
954             (push (nreverse alist) result))
955           (setq alist nil
956                 pair nil)
957           (widen)
958           (forward-line 1))
959         (nreverse result)))))
960
961 (defun gnus-netrc-machine (list machine &optional port defaultport)
962   "Return the netrc values from LIST for MACHINE or for the default entry.
963 If PORT specified, only return entries with matching port tokens.
964 Entries without port tokens default to DEFAULTPORT."
965   (let ((rest list)
966         result)
967     (while list
968       (when (equal (cdr (assoc "machine" (car list))) machine)
969         (push (car list) result))
970       (pop list))
971     (unless result
972       ;; No machine name matches, so we look for default entries.
973       (while rest
974         (when (assoc "default" (car rest))
975           (push (car rest) result))
976         (pop rest)))
977     (when result
978       (setq result (nreverse result))
979       (while (and result
980                   (not (equal (or port defaultport "nntp")
981                               (or (gnus-netrc-get (car result) "port")
982                                   defaultport "nntp"))))
983         (pop result))
984       (car result))))
985
986 (defun gnus-netrc-get (alist type)
987   "Return the value of token TYPE from ALIST."
988   (cdr (assoc type alist)))
989
990 ;;; Various
991
992 (defvar gnus-group-buffer)              ; Compiler directive
993 (defun gnus-alive-p ()
994   "Say whether Gnus is running or not."
995   (and (boundp 'gnus-group-buffer)
996        (get-buffer gnus-group-buffer)
997        (save-excursion
998          (set-buffer gnus-group-buffer)
999          (eq major-mode 'gnus-group-mode))))
1000
1001 (defun gnus-remove-duplicates (list)
1002   (let (new (tail list))
1003     (while tail
1004       (or (member (car tail) new)
1005           (setq new (cons (car tail) new)))
1006       (setq tail (cdr tail)))
1007     (nreverse new)))
1008
1009 (defun gnus-delete-if (predicate list)
1010   "Delete elements from LIST that satisfy PREDICATE."
1011   (let (out)
1012     (while list
1013       (unless (funcall predicate (car list))
1014         (push (car list) out))
1015       (pop list))
1016     (nreverse out)))
1017
1018 (if (fboundp 'assq-delete-all)
1019     (defalias 'gnus-delete-alist 'assq-delete-all)
1020   (defun gnus-delete-alist (key alist)
1021     "Delete from ALIST all elements whose car is KEY.
1022 Return the modified alist."
1023     (let (entry)
1024       (while (setq entry (assq key alist))
1025         (setq alist (delq entry alist)))
1026       alist)))
1027
1028 (defmacro gnus-pull (key alist &optional assoc-p)
1029   "Modify ALIST to be without KEY."
1030   (unless (symbolp alist)
1031     (error "Not a symbol: %s" alist))
1032   (let ((fun (if assoc-p 'assoc 'assq)))
1033     `(setq ,alist (delq (,fun ,key ,alist) ,alist))))
1034
1035 (defun gnus-globalify-regexp (re)
1036   "Returns a regexp that matches a whole line, iff RE matches a part of it."
1037   (concat (unless (string-match "^\\^" re) "^.*")
1038           re
1039           (unless (string-match "\\$$" re) ".*$")))
1040
1041 (defun gnus-set-window-start (&optional point)
1042   "Set the window start to POINT, or (point) if nil."
1043   (let ((win (gnus-get-buffer-window (current-buffer) t)))
1044     (when win
1045       (set-window-start win (or point (point))))))
1046
1047 (defun gnus-annotation-in-region-p (b e)
1048   (if (= b e)
1049       (eq (cadr (memq 'gnus-undeletable (text-properties-at b))) t)
1050     (text-property-any b e 'gnus-undeletable t)))
1051
1052 (defun gnus-or (&rest elems)
1053   "Return non-nil if any of the elements are non-nil."
1054   (catch 'found
1055     (while elems
1056       (when (pop elems)
1057         (throw 'found t)))))
1058
1059 (defun gnus-and (&rest elems)
1060   "Return non-nil if all of the elements are non-nil."
1061   (catch 'found
1062     (while elems
1063       (unless (pop elems)
1064         (throw 'found nil)))
1065     t))
1066
1067 (defun gnus-write-active-file (file hashtb &optional full-names)
1068   (let ((coding-system-for-write nnmail-active-file-coding-system))
1069     (with-temp-file file
1070       (mapatoms
1071        (lambda (sym)
1072          (when (and sym
1073                     (boundp sym)
1074                     (symbol-value sym))
1075            (insert (format "%S %d %d y\n"
1076                            (if full-names
1077                                sym
1078                              (intern (gnus-group-real-name (symbol-name sym))))
1079                            (or (cdr (symbol-value sym))
1080                                (car (symbol-value sym)))
1081                            (car (symbol-value sym))))))
1082        hashtb)
1083       (goto-char (point-max))
1084       (while (search-backward "\\." nil t)
1085         (delete-char 1)))))
1086
1087 (if (fboundp 'union)
1088     (defalias 'gnus-union 'union)
1089   (defun gnus-union (l1 l2)
1090     "Set union of lists L1 and L2."
1091     (cond ((null l1) l2)
1092           ((null l2) l1)
1093           ((equal l1 l2) l1)
1094           (t
1095            (or (>= (length l1) (length l2))
1096                (setq l1 (prog1 l2 (setq l2 l1))))
1097            (while l2
1098              (or (member (car l2) l1)
1099                  (push (car l2) l1))
1100              (pop l2))
1101            l1))))
1102
1103 (defun gnus-add-text-properties-when
1104   (property value start end properties &optional object)
1105   "Like `gnus-add-text-properties', only applied on where PROPERTY is VALUE."
1106   (let (point)
1107     (while (and start
1108                 (< start end) ;; XEmacs will loop for every when start=end.
1109                 (setq point (text-property-not-all start end property value)))
1110       (gnus-add-text-properties start point properties object)
1111       (setq start (text-property-any point end property value)))
1112     (if start
1113         (gnus-add-text-properties start end properties object))))
1114
1115 (defun gnus-remove-text-properties-when
1116   (property value start end properties &optional object)
1117   "Like `remove-text-properties', only applied on where PROPERTY is VALUE."
1118   (let (point)
1119     (while (and start
1120                 (< start end)
1121                 (setq point (text-property-not-all start end property value)))
1122       (remove-text-properties start point properties object)
1123       (setq start (text-property-any point end property value)))
1124     (if start
1125         (remove-text-properties start end properties object))
1126     t))
1127
1128 (defun gnus-string-equal (x y)
1129   "Like `string-equal', except it compares case-insensitively."
1130   (and (= (length x) (length y))
1131        (or (string-equal x y)
1132            (string-equal (downcase x) (downcase y)))))
1133
1134 (defcustom gnus-use-byte-compile t
1135   "If non-nil, byte-compile crucial run-time codes."
1136   :type 'boolean
1137   :version "21.1"
1138   :group 'gnus-various)
1139
1140 (defun gnus-byte-compile (form)
1141   "Byte-compile FORM if `gnus-use-byte-compile' is non-nil."
1142   (if gnus-use-byte-compile
1143       (progn
1144         (require 'bytecomp)
1145         (defalias 'gnus-byte-compile 'byte-compile)
1146         (byte-compile form))
1147     form))
1148
1149 (defun gnus-remassoc (key alist)
1150   "Delete by side effect any elements of LIST whose car is `equal' to KEY.
1151 The modified LIST is returned.  If the first member
1152 of LIST has a car that is `equal' to KEY, there is no way to remove it
1153 by side effect; therefore, write `(setq foo (remassoc key foo))' to be
1154 sure of changing the value of `foo'."
1155   (when alist
1156     (if (equal key (caar alist))
1157         (cdr alist)
1158       (setcdr alist (gnus-remassoc key (cdr alist)))
1159       alist)))
1160
1161 (defun gnus-update-alist-soft (key value alist)
1162   (if value
1163       (cons (cons key value) (gnus-remassoc key alist))
1164     (gnus-remassoc key alist)))
1165
1166 (defun gnus-create-info-command (node)
1167   "Create a command that will go to info NODE."
1168   `(lambda ()
1169      (interactive)
1170      ,(concat "Enter the info system at node " node)
1171      (Info-goto-node ,node)
1172      (setq gnus-info-buffer (current-buffer))
1173      (gnus-configure-windows 'info)))
1174
1175 (defun gnus-not-ignore (&rest args)
1176   t)
1177
1178 (defvar gnus-directory-sep-char-regexp "/"
1179   "The regexp of directory separator character.
1180 If you find some problem with the directory separator character, try
1181 \"[/\\\\\]\" for some systems.")
1182
1183 (defun gnus-url-unhex (x)
1184   (if (> x ?9)
1185       (if (>= x ?a)
1186           (+ 10 (- x ?a))
1187         (+ 10 (- x ?A)))
1188     (- x ?0)))
1189
1190 (defun gnus-url-unhex-string (str &optional allow-newlines)
1191   "Remove %XXX embedded spaces, etc in a url.
1192 If optional second argument ALLOW-NEWLINES is non-nil, then allow the
1193 decoding of carriage returns and line feeds in the string, which is normally
1194 forbidden in URL encoding."
1195   (setq str (or (mm-subst-char-in-string ?+ ?  str) ""))
1196   (let ((tmp "")
1197         (case-fold-search t))
1198     (while (string-match "%[0-9a-f][0-9a-f]" str)
1199       (let* ((start (match-beginning 0))
1200              (ch1 (gnus-url-unhex (elt str (+ start 1))))
1201              (code (+ (* 16 ch1)
1202                       (gnus-url-unhex (elt str (+ start 2))))))
1203         (setq tmp (concat
1204                    tmp (substring str 0 start)
1205                    (cond
1206                     (allow-newlines
1207                      (char-to-string code))
1208                     ((or (= code ?\n) (= code ?\r))
1209                      " ")
1210                     (t (char-to-string code))))
1211               str (substring str (match-end 0)))))
1212     (setq tmp (concat tmp str))
1213     tmp))
1214
1215 (defun gnus-make-predicate (spec)
1216   "Transform SPEC into a function that can be called.
1217 SPEC is a predicate specifier that contains stuff like `or', `and',
1218 `not', lists and functions.  The functions all take one parameter."
1219   `(lambda (elem) ,(gnus-make-predicate-1 spec)))
1220   
1221 (defun gnus-make-predicate-1 (spec)
1222   (cond
1223    ((symbolp spec)
1224     `(,spec elem))
1225    ((listp spec)
1226     (if (memq (car spec) '(or and not))
1227         `(,(car spec) ,@(mapcar 'gnus-make-predicate-1 (cdr spec)))
1228       (error "Invalid predicate specifier: %s" spec)))))
1229
1230 (defun gnus-local-map-property (map)
1231   "Return a list suitable for a text property list specifying keymap MAP."
1232   (cond
1233    ((featurep 'xemacs)
1234     (list 'keymap map))
1235    ((>= emacs-major-version 21)
1236     (list 'keymap map))
1237    (t
1238     (list 'local-map map))))
1239
1240 (defun gnus-completing-read (prompt table &optional predicate require-match
1241                                     history inherit-input-method)
1242   (when (and history
1243              (not (boundp history)))
1244     (set history nil))
1245   (completing-read
1246    (if (symbol-value history)
1247        (concat prompt " (" (car (symbol-value history)) "): ")
1248      (concat prompt ": "))
1249    table
1250    predicate
1251    require-match
1252    nil
1253    history
1254    (car (symbol-value history))
1255    inherit-input-method))
1256
1257 (provide 'gnus-util)
1258
1259 ;;; gnus-util.el ends here