Add (eval-when-compile (require 'cl)).
[elisp/wanderlust.git] / wl / wl-util.el
1 ;;; wl-util.el --- Utility modules for Wanderlust.
2
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 2000 A. SAGATA <sagata@nttvdt.hil.ntt.co.jp>
5 ;; Copyright (C) 2000 Katsumi Yamaoka <yamaoka@jpl.org>
6
7 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
8 ;;      A. SAGATA <sagata@nttvdt.hil.ntt.co.jp>
9 ;;      Katsumi Yamaoka <yamaoka@jpl.org>
10 ;; Keywords: mail, net news
11
12 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
13
14 ;; This program is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18 ;;
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23 ;;
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
28 ;;
29
30 ;;; Commentary:
31 ;;
32
33 ;;; Code:
34 ;;
35 (require 'bytecomp)
36 (require 'elmo-util)
37 (require 'elmo-flag)
38 (require 'wl-vars)
39
40 (condition-case nil (require 'pp) (error nil))
41
42 (eval-when-compile
43   (require 'cl)
44   (require 'time-stamp)
45   (defalias-maybe 'next-command-event 'ignore)
46   (defalias-maybe 'event-to-character 'ignore)
47   (defalias-maybe 'key-press-event-p 'ignore)
48   (defalias-maybe 'button-press-event-p 'ignore)
49   (defalias-maybe 'set-process-kanji-code 'ignore)
50   (defalias-maybe 'set-process-coding-system 'ignore)
51   (defalias-maybe 'dispatch-event 'ignore))
52
53 (defalias 'wl-set-work-buf 'elmo-set-work-buf)
54 (make-obsolete 'wl-set-work-buf 'elmo-set-work-buf)
55
56 (defmacro wl-append (val func)
57   (list 'if val
58       (list 'nconc val func)
59     (list 'setq val func)))
60
61 (defalias 'wl-parse 'elmo-parse)
62 (make-obsolete 'wl-parse 'elmo-parse)
63
64 (defun wl-delete-duplicates (list &optional all hack-addresses)
65   "Delete duplicate equivalent strings from the LIST.
66 If ALL is t, then if there is more than one occurrence of a string in the LIST,
67  then all occurrences of it are removed instead of just the subsequent ones.
68 If HACK-ADDRESSES is t, then the strings are considered to be mail addresses,
69  and only the address part is compared (so that \"Name <foo>\" and \"foo\"
70  would be considered to be equivalent.)"
71   (let ((hashtable (make-vector 29 0))
72         (new-list nil)
73         sym-string sym)
74     (fillarray hashtable 0)
75     (while list
76       (setq sym-string
77             (if hack-addresses
78                 (wl-address-header-extract-address (car list))
79               (car list))
80             sym-string (or sym-string "-unparseable-garbage-")
81             sym (intern sym-string hashtable))
82       (if (boundp sym)
83           (and all (setcar (symbol-value sym) nil))
84         (setq new-list (cons (car list) new-list))
85         (set sym new-list))
86       (setq list (cdr list)))
87     (delq nil (nreverse new-list))))
88
89 ;; string utils.
90 (defalias 'wl-string-member 'elmo-string-member)
91 (defalias 'wl-string-match-member 'elmo-string-match-member)
92 (defalias 'wl-string-delete-match 'elmo-string-delete-match)
93 (defalias 'wl-string-match-assoc 'elmo-string-match-assoc)
94 (defalias 'wl-string-assoc 'elmo-string-assoc)
95 (defalias 'wl-string-rassoc 'elmo-string-rassoc)
96
97 (defalias 'wl-parse-addresses 'elmo-parse-addresses)
98
99 (defun wl-append-element (list element)
100   (if element
101       (append list (list element))
102     list))
103
104 (defmacro wl-push (v l)
105   "Insert V at the head of the list stored in L."
106   (list 'setq l (list 'cons v l)))
107
108 (defmacro wl-pop (l)
109   "Remove the head of the list stored in L."
110   (list 'car (list 'prog1 l (list 'setq l (list 'cdr l)))))
111
112 (defun wl-ask-folder (func mes-string)
113   (let* (key keve
114              (cmd (if (featurep 'xemacs)
115                       (event-to-character last-command-event)
116                     (string-to-char (format "%s" (this-command-keys))))))
117     (message "%s" mes-string)
118     (setq key (car (setq keve (wl-read-event-char))))
119     (if (or (equal key ?\ )
120             (and cmd
121                  (equal key cmd)))
122         (progn
123           (message "")
124           (funcall func))
125       (wl-push (cdr keve) unread-command-events))))
126
127 (defun wl-require-update-all-folder-p (name)
128   "Return non-nil if NAME is draft or queue folder."
129   (or (string= name wl-draft-folder)
130       (string= name wl-queue-folder)))
131
132 ;(defalias 'wl-make-hash 'elmo-make-hash)
133 ;;(make-obsolete 'wl-make-hash 'elmo-make-hash)
134
135 ;;(defalias 'wl-get-hash-val 'elmo-get-hash-val)
136 ;;(make-obsolete 'wl-get-hash-val 'elmo-get-hash-val)
137
138 ;;(defalias 'wl-set-hash-val 'elmo-set-hash-val)
139 ;;(make-obsolete 'wl-set-hash-val 'elmo-set-hash-val)
140
141 (defsubst wl-set-string-width (width string &optional padding ignore-invalid)
142   "Make a new string which have specified WIDTH and content of STRING.
143 `wl-invalid-character-message' is used when invalid character is contained.
144 If WIDTH is negative number, padding chars are added to the head and
145 otherwise, padding chars are added to the tail of the string.
146 The optional 3rd arg PADDING, if non-nil, specifies a padding character
147 to add the result instead of white space.
148 If optional 4th argument is non-nil, don't use `wl-invalid-character-message'
149 even when invalid character is contained."
150   (static-cond
151    ((and (fboundp 'string-width) (fboundp 'truncate-string-to-width)
152          (not (featurep 'xemacs)))
153     (if (> (string-width string) (abs width))
154         (setq string (truncate-string-to-width string (abs width))))
155     (if (= (string-width string) (abs width))
156         string
157       (when (and (not ignore-invalid)
158                  (< (abs width) (string-width string)))
159         (setq string
160               (truncate-string-to-width wl-invalid-character-message
161                                         (abs width))))
162       (let ((paddings (make-string
163                        (max 0 (- (abs width) (string-width string)))
164                        (or padding ?\ ))))
165         (if (< width 0)
166             (concat paddings string)
167           (concat string paddings)))))
168    (t
169     (elmo-set-work-buf
170      (set-buffer-multibyte default-enable-multibyte-characters)
171      (insert string)
172      (when (> (current-column) (abs width))
173        (when (> (move-to-column (abs width)) (abs width))
174          (condition-case nil ; ignore error
175              (backward-char 1)
176            (error)))
177        (setq string (buffer-substring (point-min) (point))))
178      (if (= (current-column) (abs width))
179          string
180        (let ((paddings (make-string (- (abs width) (current-column))
181                                     (or padding ?\ ))))
182          (if (< width 0)
183              (concat paddings string)
184            (concat string paddings))))))))
185
186 (defun wl-mode-line-buffer-identification (&optional id)
187   (let ((priorities '(biff plug title)))
188     (let ((items (reverse wl-mode-line-display-priority-list))
189           item)
190       (while items
191         (setq item (car items)
192               items (cdr items))
193         (unless (memq item '(biff plug))
194           (setq item 'title))
195         (setq priorities (cons item (delq item priorities)))))
196     (let (priority result)
197       (while priorities
198         (setq priority (car priorities)
199               priorities (cdr priorities))
200         (cond
201          ((eq 'biff priority)
202           (when wl-biff-check-folder-list
203             (setq result (append result '((wl-modeline-biff-status
204                                            wl-modeline-biff-state-on
205                                            wl-modeline-biff-state-off))))))
206          ((eq 'plug priority)
207           (when wl-show-plug-status-on-modeline
208             (setq result (append result '((wl-modeline-plug-status
209                                            wl-modeline-plug-state-on
210                                            wl-modeline-plug-state-off))))))
211          (t
212           (setq result (append result (or id '("Wanderlust: %12b")))))))
213       (prog1
214           (setq mode-line-buffer-identification (if (stringp (car result))
215                                                     result
216                                                   (cons "" result)))
217         (force-mode-line-update t)))))
218
219 (defalias 'wl-display-error 'elmo-display-error)
220 (make-obsolete 'wl-display-error 'elmo-display-error)
221
222 (defun wl-get-assoc-list-value (assoc-list folder &optional match)
223   (catch 'found
224     (let ((alist assoc-list)
225           value pair)
226       (while alist
227         (setq pair (car alist))
228         (if (and (eq match 'function)
229                  (functionp (car pair)))
230             (when (funcall (car pair) folder)
231               (throw 'found (cdr pair)))
232           (if (string-match (car pair) folder)
233               (cond ((eq match 'all)
234                      (setq value (append value (list (cdr pair)))))
235                     ((eq match 'all-list)
236                      (setq value (append value (cdr pair))))
237                     ((or (not match) (eq match 'function))
238                      (throw 'found (cdr pair))))))
239         (setq alist (cdr alist)))
240       value)))
241
242 (defmacro wl-match-string (pos string)
243   "Substring POSth matched STRING."
244   `(substring ,string (match-beginning ,pos) (match-end ,pos)))
245
246 (defmacro wl-match-buffer (pos)
247   "Substring POSth matched from the current buffer."
248   `(buffer-substring-no-properties
249     (match-beginning ,pos) (match-end ,pos)))
250
251 (put 'wl-as-coding-system 'lisp-indent-function 1)
252 (put 'wl-as-mime-charset 'lisp-indent-function 1)
253
254 (eval-and-compile
255   (cond
256    (wl-on-mule3
257     (defmacro wl-as-coding-system (coding-system &rest body)
258       `(let ((coding-system-for-read ,coding-system)
259              (coding-system-for-write ,coding-system))
260          ,@body)))
261    (wl-on-mule
262     (defmacro wl-as-coding-system (coding-system &rest body)
263       `(let ((file-coding-system-for-read ,coding-system)
264              (file-coding-system ,coding-system))
265          ,@body)))
266    (t
267     (defmacro wl-as-coding-system (coding-system &rest body)
268       `(progn ,@body)))))
269
270 (defmacro wl-as-mime-charset (mime-charset &rest body)
271   `(wl-as-coding-system (mime-charset-to-coding-system ,mime-charset)
272      ,@body))
273
274 (defalias 'wl-string 'elmo-string)
275 (make-obsolete 'wl-string 'elmo-string)
276
277 (if (not (fboundp 'overlays-in))
278     (defun overlays-in (beg end)
279       "Return a list of the overlays that overlap the region BEG ... END.
280 Overlap means that at least one character is contained within the overlay
281 and also contained within the specified region.
282 Empty overlays are included in the result if they are located at BEG
283 or between BEG and END."
284       (let ((ovls (overlay-lists))
285             tmp retval)
286         (if (< end beg)
287             (setq tmp end
288                   end beg
289                   beg tmp))
290         (setq ovls (nconc (car ovls) (cdr ovls)))
291         (while ovls
292           (setq tmp (car ovls)
293                 ovls (cdr ovls))
294           (if (or (and (<= (overlay-start tmp) end)
295                        (>= (overlay-start tmp) beg))
296                   (and (<= (overlay-end tmp) end)
297                        (>= (overlay-end tmp) beg)))
298               (setq retval (cons tmp retval))))
299         retval)))
300
301 (defsubst wl-repeat-string (str times)
302   (let ((loop times)
303         ret-val)
304     (while (> loop 0)
305       (setq ret-val (concat ret-val str))
306       (setq loop (- loop 1)))
307     ret-val))
308
309 (defun wl-append-assoc-list (item value alist)
310   "make assoc list '((item1 value1-1 value1-2 ...)) (item2 value2-1 ...)))"
311   (let ((entry (assoc item alist)))
312     (if entry
313         (progn
314           (when (not (member value (cdr entry)))
315             (nconc entry (list value)))
316           alist)
317       (append alist
318               (list (list item value))))))
319
320 (defun wl-delete-alist (key alist)
321   "Delete by side effect any entries specified with KEY from ALIST.
322 Return the modified ALIST.  Key comparison is done with `assq'.
323 Write `(setq foo (wl-delete-alist key foo))' to be sure of changing
324 the value of `foo'."
325   (let (entry)
326     (while (setq entry (assq key alist))
327       (setq alist (delq entry alist)))
328     alist))
329
330 (defun wl-delete-associations (keys alist)
331   "Delete by side effect any entries specified with KEYS from ALIST.
332 Return the modified ALIST.  KEYS must be a list of keys for ALIST.
333 Deletion is done with `wl-delete-alist'.
334 Write `(setq foo (wl-delete-associations keys foo))' to be sure of
335 changing the value of `foo'."
336   (while keys
337     (setq alist (wl-delete-alist (car keys) alist))
338     (setq keys (cdr keys)))
339   alist)
340
341 (defun wl-filter-associations (keys alist)
342   (let (entry result)
343     (while keys
344       (when (setq entry (assq (car keys) alist))
345         (setq result (cons entry result)))
346       (setq keys (cdr keys)))
347     result))
348
349 (defun wl-inverse-alist (keys alist)
350   "Inverse ALIST, copying.
351 Return an association list represents the inverse mapping of ALIST,
352 from objects to KEYS.
353 The objects mapped (cdrs of elements of the ALIST) are shared."
354   (let (x y tmp result)
355     (while keys
356       (setq x (car keys))
357       (setq y (cdr (assq x alist)))
358       (if y
359           (if (setq tmp (assoc y result))
360               (setq result (cons (append tmp (list x))
361                                  (delete tmp result)))
362             (setq result (cons (list y x) result))))
363       (setq keys (cdr keys)))
364     result))
365
366 (eval-when-compile
367   (require 'static))
368 (static-unless (fboundp 'pp)
369   (defvar pp-escape-newlines t)
370   (defun pp (object &optional stream)
371     "Output the pretty-printed representation of OBJECT, any Lisp object.
372 Quoting characters are printed when needed to make output that `read'
373 can handle, whenever this is possible.
374 Output stream is STREAM, or value of `standard-output' (which see)."
375     (princ (pp-to-string object) (or stream standard-output)))
376
377   (defun pp-to-string (object)
378     "Return a string containing the pretty-printed representation of OBJECT,
379 any Lisp object.  Quoting characters are used when needed to make output
380 that `read' can handle, whenever this is possible."
381     (save-excursion
382       (set-buffer (generate-new-buffer " pp-to-string"))
383       (unwind-protect
384           (progn
385             (lisp-mode-variables t)
386             (let ((print-escape-newlines pp-escape-newlines))
387               (prin1 object (current-buffer)))
388             (goto-char (point-min))
389             (while (not (eobp))
390               (cond
391                ((looking-at "\\s(\\|#\\s(")
392                 (while (looking-at "\\s(\\|#\\s(")
393                   (forward-char 1)))
394                ((and (looking-at "\\(quote[ \t]+\\)\\([^.)]\\)")
395                      (> (match-beginning 1) 1)
396                      (= ?\( (char-after (1- (match-beginning 1))))
397                      ;; Make sure this is a two-element list.
398                      (save-excursion
399                        (goto-char (match-beginning 2))
400                        (forward-sexp)
401                        ;; Avoid mucking with match-data; does this test work?
402                        (char-equal ?\) (char-after (point)))))
403                 ;; -1 gets the paren preceding the quote as well.
404                 (delete-region (1- (match-beginning 1)) (match-end 1))
405                 (insert "'")
406                 (forward-sexp 1)
407                 (if (looking-at "[ \t]*\)")
408                     (delete-region (match-beginning 0) (match-end 0))
409                   (error "Malformed quote"))
410                 (backward-sexp 1))
411                ((condition-case err-var
412                     (prog1 t (down-list 1))
413                   (error nil))
414                 (backward-char 1)
415                 (skip-chars-backward " \t")
416                 (delete-region
417                  (point)
418                  (progn (skip-chars-forward " \t") (point)))
419                 (if (not (char-equal ?' (char-after (1- (point)))))
420                     (insert ?\n)))
421                ((condition-case err-var
422                     (prog1 t (up-list 1))
423                   (error nil))
424                 (while (looking-at "\\s)")
425                   (forward-char 1))
426                 (skip-chars-backward " \t")
427                 (delete-region
428                  (point)
429                  (progn (skip-chars-forward " \t") (point)))
430                 (if (not (char-equal ?' (char-after (1- (point)))))
431                     (insert ?\n)))
432                (t (goto-char (point-max)))))
433             (goto-char (point-min))
434             (indent-sexp)
435             (buffer-string))
436         (kill-buffer (current-buffer))))))
437
438 (defsubst wl-get-date-iso8601 (date)
439   (or (get-text-property 0 'wl-date date)
440       (let* ((d1 (timezone-fix-time date nil nil))
441              (time (format "%04d%02d%02dT%02d%02d%02d"
442                            (aref d1 0) (aref d1 1) (aref d1 2)
443                            (aref d1 3) (aref d1 4) (aref d1 5))))
444         (put-text-property 0 1 'wl-date time date)
445         time)))
446
447 (defun wl-make-date-string ()
448   (let ((s (current-time-string)))
449     (string-match "\\`\\([A-Z][a-z][a-z]\\) +[A-Z][a-z][a-z] +[0-9][0-9]? *[0-9][0-9]?:[0-9][0-9]:[0-9][0-9] *[0-9]?[0-9]?[0-9][0-9]"
450                   s)
451     (concat (wl-match-string 1 s) ", "
452             (timezone-make-date-arpa-standard s (current-time-zone)))))
453
454 (defun wl-date-iso8601 (date)
455   "Convert the DATE to YYMMDDTHHMMSS."
456   (condition-case ()
457       (wl-get-date-iso8601 date)
458     (error "")))
459
460 (defun wl-url-news (url &rest args)
461   (interactive "sURL: ")
462   (if (string-match "^news:\\(.*\\)$" url)
463       (wl-summary-goto-folder-subr
464        (concat "-" (elmo-match-string 1 url)) nil nil nil t)
465     (message "Not a news: url.")))
466
467 (defun wl-url-nntp (url &rest args)
468   (interactive "sURL: ")
469   (let (folder fld-name server port msg)
470     (if (string-match
471          "^nntp://\\([^:/]*\\):?\\([0-9]*\\)/\\([^/]*\\)/\\([0-9]*\\).*$" url)
472         (progn
473           (if (eq (length (setq fld-name
474                                 (elmo-match-string 3 url))) 0)
475               (setq fld-name nil))
476           (if (eq (length (setq port
477                                 (elmo-match-string 2 url))) 0)
478               (setq port (int-to-string elmo-nntp-default-port)))
479           (if (eq (length (setq server
480                                 (elmo-match-string 1 url))) 0)
481               (setq server elmo-nntp-default-server))
482           (setq folder (concat "-" fld-name "@" server ":" port))
483           (if (eq (length (setq msg
484                                 (elmo-match-string 4 url))) 0)
485               (wl-summary-goto-folder-subr
486                folder nil nil nil t)
487             (wl-summary-goto-folder-subr
488              folder 'update nil nil t)
489             (wl-summary-jump-to-msg (string-to-number msg))
490             (wl-summary-redisplay)))
491       (message "Not a nntp: url."))))
492
493 (defmacro wl-concat-list (list separator)
494   `(mapconcat 'identity (delete "" (delq nil ,list)) ,separator))
495
496 (defun wl-current-message-buffer ()
497   (when (buffer-live-p wl-current-summary-buffer)
498     (with-current-buffer wl-current-summary-buffer
499       (or wl-message-buffer
500           (and (wl-summary-message-number)
501                (wl-message-buffer-display
502                 wl-summary-buffer-elmo-folder
503                 (wl-summary-message-number)
504                 wl-summary-buffer-display-mime-mode
505                 nil nil))))))
506
507 (defmacro wl-kill-buffers (regexp)
508   `(mapcar (function
509             (lambda (x)
510               (if (and (buffer-name x)
511                        (string-match ,regexp (buffer-name x)))
512                   (and (get-buffer x)
513                        (kill-buffer x)))))
514            (buffer-list)))
515
516 (defun wl-collect-summary ()
517   (let (result)
518     (mapcar
519      (function (lambda (x)
520                  (if (and (string-match "^Summary"
521                                         (buffer-name x))
522                           (save-excursion
523                             (set-buffer x)
524                             (equal major-mode 'wl-summary-mode)))
525                      (setq result (nconc result (list x))))))
526      (buffer-list))
527     result))
528
529 (defun wl-collect-draft ()
530   (let ((draft-regexp (concat "^" (regexp-quote wl-draft-folder)))
531         result)
532     (dolist (buffer (buffer-list))
533       (when (with-current-buffer buffer
534               (and (eq major-mode 'wl-draft-mode)
535                    (buffer-name)
536                    (string-match draft-regexp (buffer-name))))
537         (setq result (cons buffer result))))
538     (nreverse result)))
539
540 (defvar wl-inhibit-save-drafts nil)
541 (defvar wl-disable-auto-save nil)
542 (make-variable-buffer-local 'wl-disable-auto-save)
543
544 (defun wl-save-drafts ()
545   "Save all drafts. Return nil if there is no draft buffer."
546   (if wl-inhibit-save-drafts
547       'inhibited
548     (let ((wl-inhibit-save-drafts t)
549           (msg (current-message))
550           (buffers (wl-collect-draft)))
551       (save-excursion
552         (dolist (buffer buffers)
553           (set-buffer buffer)
554           (when (and (not wl-disable-auto-save)
555                      (buffer-modified-p))
556             (wl-draft-save))))
557       (message "%s" (or msg ""))
558       buffers)))
559
560 (static-if (fboundp 'read-directory-name)
561     (defun wl-read-directory-name (prompt dir)
562       (read-directory-name prompt dir dir))
563   (defun wl-read-directory-name (prompt dir)
564     (let ((dir (read-file-name prompt dir)))
565       (unless (file-directory-p dir)
566         (error "%s is not directory" dir))
567       dir)))
568
569 ;; local variable check.
570 (static-if (fboundp 'local-variable-p)
571     (defalias 'wl-local-variable-p 'local-variable-p)
572   (defmacro wl-local-variable-p (symbol &optional buffer)
573     `(if (assq ,symbol (buffer-local-variables ,buffer))
574          t)))
575
576 (defun wl-number-base36 (num len)
577   (if (if (< len 0)
578           (<= num 0)
579         (= len 0))
580       ""
581     (concat (wl-number-base36 (/ num 36) (1- len))
582             (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210"
583                                   (% num 36))))))
584
585 (defvar wl-unique-id-char nil)
586
587 (defun wl-unique-id ()
588   ;; Don't use microseconds from (current-time), they may be unsupported.
589   ;; Instead we use this randomly inited counter.
590   (setq wl-unique-id-char
591         (% (1+ (or wl-unique-id-char (logand (random t) (1- (lsh 1 20)))))
592            ;; (current-time) returns 16-bit ints,
593            ;; and 2^16*25 just fits into 4 digits i base 36.
594            (* 25 25)))
595   (let ((tm (static-if (fboundp 'current-time)
596                 (current-time)
597               (let* ((cts (split-string (current-time-string) "[ :]"))
598                      (m (cdr (assoc (nth 1 cts)
599                                     '(("Jan" . "01") ("Feb" . "02")
600                                       ("Mar" . "03") ("Apr" . "04")
601                                       ("May" . "05") ("Jun" . "06")
602                                       ("Jul" . "07") ("Aug" . "08")
603                                       ("Sep" . "09") ("Oct" . "10")
604                                       ("Nov" . "11") ("Dec" . "12"))))))
605                 (list (string-to-number (concat (nth 6 cts) m
606                                                 (substring (nth 2 cts) 0 1)))
607                       (string-to-number (concat (substring (nth 2 cts) 1)
608                                                 (nth 4 cts) (nth 5 cts)
609                                                 (nth 6 cts))))))))
610     (concat
611      (if (memq system-type '(ms-dos emx vax-vms))
612          (let ((user (downcase (user-login-name))))
613            (while (string-match "[^a-z0-9_]" user)
614              (aset user (match-beginning 0) ?_))
615            user)
616        (wl-number-base36 (user-uid) -1))
617      (wl-number-base36 (+ (car   tm)
618                           (lsh (% wl-unique-id-char 25) 16)) 4)
619      (wl-number-base36 (+ (nth 1 tm)
620                           (lsh (/ wl-unique-id-char 25) 16)) 4)
621      ;; Append the name of the message interface, because while the
622      ;; generated ID is unique to this newsreader, other newsreaders
623      ;; might otherwise generate the same ID via another algorithm.
624      wl-unique-id-suffix)))
625
626 (defvar wl-message-id-function 'wl-draft-make-message-id-string)
627 (defun wl-draft-make-message-id-string ()
628   "Return Message-ID field value."
629   (concat "<" (wl-unique-id)
630           (let (from user domain)
631             (if (and wl-message-id-use-wl-from
632                      (progn
633                        (setq from (wl-address-header-extract-address wl-from))
634                        (and (string-match "^\\(.*\\)@\\(.*\\)$" from)
635                             (setq user   (match-string 1 from))
636                             (setq domain (match-string 2 from)))))
637                 (format "%%%s@%s>" user domain)
638               (format "@%s>"
639                       (or wl-message-id-domain
640                           (if wl-local-domain
641                               (concat (system-name) "." wl-local-domain)
642                             (system-name))))))))
643
644 ;;; Profile loading.
645 (defvar wl-load-profile-function 'wl-local-load-profile)
646 (defun wl-local-load-profile ()
647   "Load `wl-init-file'."
648   (message "Initializing...")
649   (load wl-init-file 'noerror 'nomessage))
650
651 (defun wl-load-profile ()
652   "Call `wl-load-profile-function' function."
653   (funcall wl-load-profile-function))
654
655 ;;;
656
657 (defmacro wl-count-lines ()
658   '(save-excursion
659      (beginning-of-line)
660      (count-lines 1 (point))))
661
662 (defun wl-horizontal-recenter ()
663   "Recenter the current buffer horizontally."
664   (beginning-of-line)
665   (re-search-forward "[[<]" (point-at-eol) t)
666   (if (< (current-column) (/ (window-width) 2))
667       (set-window-hscroll (get-buffer-window (current-buffer) t) 0)
668     (let* ((orig (point))
669            (end (window-end (get-buffer-window (current-buffer) t)))
670            (max 0))
671       (when end
672         ;; Find the longest line currently displayed in the window.
673         (goto-char (window-start))
674         (while (and (not (eobp))
675                     (< (point) end))
676           (end-of-line)
677           (setq max (max max (current-column)))
678           (forward-line 1))
679         (goto-char orig)
680         ;; Scroll horizontally to center (sort of) the point.
681         (if (> max (window-width))
682             (set-window-hscroll
683              (get-buffer-window (current-buffer) t)
684              (min (- (current-column) (/ (window-width) 3))
685                   (+ 2 (- max (window-width)))))
686           (set-window-hscroll (get-buffer-window (current-buffer) t) 0))
687         max))))
688
689 ;; Draft auto-save
690 (defun wl-auto-save-drafts ()
691   (unless (wl-save-drafts)
692     (wl-stop-save-drafts)))
693
694 (static-cond
695  (wl-on-xemacs
696   (defvar wl-save-drafts-timer-name "wl-save-drafts")
697
698   (defun wl-start-save-drafts ()
699     (when (numberp wl-auto-save-drafts-interval)
700       (unless (get-itimer wl-save-drafts-timer-name)
701         (start-itimer wl-save-drafts-timer-name
702                       'wl-auto-save-drafts
703                       wl-auto-save-drafts-interval
704                       wl-auto-save-drafts-interval
705                       t))))
706
707   (defun wl-stop-save-drafts ()
708     (when (get-itimer wl-save-drafts-timer-name)
709       (delete-itimer wl-save-drafts-timer-name))))
710  (t
711   (defun wl-start-save-drafts ()
712     (when (numberp wl-auto-save-drafts-interval)
713       (require 'timer)
714       (if (get 'wl-save-drafts 'timer)
715           (progn
716             (timer-set-idle-time (get 'wl-save-drafts 'timer)
717                                  wl-auto-save-drafts-interval t)
718             (timer-activate-when-idle (get 'wl-save-drafts 'timer)))
719         (put 'wl-save-drafts 'timer
720              (run-with-idle-timer
721               wl-auto-save-drafts-interval t 'wl-auto-save-drafts)))))
722
723   (defun wl-stop-save-drafts ()
724     (when (get 'wl-save-drafts 'timer)
725       (cancel-timer (get 'wl-save-drafts 'timer))))))
726
727 (defun wl-set-auto-save-draft (&optional arg)
728   (interactive "P")
729   (unless (setq wl-disable-auto-save
730                 (cond
731                  ((null arg) (not wl-disable-auto-save))
732                  ((< (prefix-numeric-value arg) 0) t)
733                  (t nil)))
734     (wl-start-save-drafts))
735   (when (interactive-p)
736     (message "Auto save is %s (in this buffer)"
737              (if wl-disable-auto-save "disabled" "enabled"))))
738
739 ;; Biff
740 (static-cond
741  (wl-on-xemacs
742   (defvar wl-biff-timer-name "wl-biff")
743
744   (defun wl-biff-stop ()
745     (when (get-itimer wl-biff-timer-name)
746       (delete-itimer wl-biff-timer-name)))
747
748   (defun wl-biff-start ()
749     (wl-biff-stop)
750     (when wl-biff-check-folder-list
751       (start-itimer wl-biff-timer-name 'wl-biff-check-folders
752                     wl-biff-check-interval wl-biff-check-interval
753                     wl-biff-use-idle-timer))))
754
755  (t
756   (defun wl-biff-stop ()
757     (when (get 'wl-biff 'timer)
758       (cancel-timer (get 'wl-biff 'timer))))
759
760   (defun wl-biff-start ()
761     (require 'timer)
762     (when wl-biff-check-folder-list
763       (if wl-biff-use-idle-timer
764           (if (get 'wl-biff 'timer)
765               (progn (timer-set-idle-time (get 'wl-biff 'timer)
766                                           wl-biff-check-interval t)
767                      (timer-activate-when-idle (get 'wl-biff 'timer)))
768             (put 'wl-biff 'timer
769                  (run-with-idle-timer
770                   wl-biff-check-interval t 'wl-biff-event-handler)))
771         (if (get 'wl-biff 'timer)
772             (progn
773               (timer-set-time (get 'wl-biff 'timer)
774                               (timer-next-integral-multiple-of-time
775                                (current-time) wl-biff-check-interval)
776                               wl-biff-check-interval)
777               (timer-activate (get 'wl-biff 'timer)))
778           (put 'wl-biff 'timer
779                (run-at-time
780                 (timer-next-integral-multiple-of-time
781                  (current-time) wl-biff-check-interval)
782                 wl-biff-check-interval
783                 'wl-biff-event-handler))))))
784
785   (defun-maybe timer-next-integral-multiple-of-time (time secs)
786     "Yield the next value after TIME that is an integral multiple of SECS.
787 More precisely, the next value, after TIME, that is an integral multiple
788 of SECS seconds since the epoch.  SECS may be a fraction.
789 This function is imported from Emacs 20.7."
790     (let ((time-base (ash 1 16)))
791       (if (fboundp 'atan)
792           ;; Use floating point, taking care to not lose precision.
793           (let* ((float-time-base (float time-base))
794                  (million 1000000.0)
795                  (time-usec (+ (* million
796                                   (+ (* float-time-base (nth 0 time))
797                                      (nth 1 time)))
798                                (nth 2 time)))
799                  (secs-usec (* million secs))
800                  (mod-usec (mod time-usec secs-usec))
801                  (next-usec (+ (- time-usec mod-usec) secs-usec))
802                  (time-base-million (* float-time-base million)))
803             (list (floor next-usec time-base-million)
804                   (floor (mod next-usec time-base-million) million)
805                   (floor (mod next-usec million))))
806         ;; Floating point is not supported.
807         ;; Use integer arithmetic, avoiding overflow if possible.
808         (let* ((mod-sec (mod (+ (* (mod time-base secs)
809                                    (mod (nth 0 time) secs))
810                                 (nth 1 time))
811                              secs))
812                (next-1-sec (+ (- (nth 1 time) mod-sec) secs)))
813           (list (+ (nth 0 time) (floor next-1-sec time-base))
814                 (mod next-1-sec time-base)
815                 0)))))
816
817   (defun wl-biff-event-handler ()
818     ;; PAKURing from FSF:time.el
819     (wl-biff-check-folders)
820     ;; Do redisplay right now, if no input pending.
821     (sit-for 0)
822     (let* ((current (current-time))
823            (timer (get 'wl-biff 'timer))
824            ;; Compute the time when this timer will run again, next.
825            (next-time (timer-relative-time
826                        (list (aref timer 1) (aref timer 2) (aref timer 3))
827                        (* 5 (aref timer 4)) 0)))
828       ;; If the activation time is far in the past,
829       ;; skip executions until we reach a time in the future.
830       ;; This avoids a long pause if Emacs has been suspended for hours.
831       (or (> (nth 0 next-time) (nth 0 current))
832           (and (= (nth 0 next-time) (nth 0 current))
833                (> (nth 1 next-time) (nth 1 current)))
834           (and (= (nth 0 next-time) (nth 0 current))
835                (= (nth 1 next-time) (nth 1 current))
836                (> (nth 2 next-time) (nth 2 current)))
837           (progn
838             (timer-set-time timer (timer-next-integral-multiple-of-time
839                                    current wl-biff-check-interval)
840                             wl-biff-check-interval)
841             (timer-activate timer)))))))
842
843 (defsubst wl-biff-notify (new-mails notify-minibuf)
844   (when (and (not wl-modeline-biff-status) (> new-mails 0))
845     (run-hooks 'wl-biff-notify-hook))
846   (when (and wl-modeline-biff-status (eq new-mails 0))
847     (run-hooks 'wl-biff-unnotify-hook))
848   (setq wl-modeline-biff-status (> new-mails 0))
849   (force-mode-line-update t)
850   (when notify-minibuf
851     (cond ((zerop new-mails) (message "No mail."))
852           ((= 1 new-mails) (message "You have a new mail."))
853           (t (message "You have %d new mails." new-mails)))))
854
855 ;; Internal variable.
856 (defvar wl-biff-check-folders-running nil)
857
858 (defun wl-biff-check-folders ()
859   (interactive)
860   (if wl-biff-check-folders-running
861       (when (interactive-p)
862         (message "Biff process is running."))
863     (setq wl-biff-check-folders-running t)
864     (when (interactive-p)
865       (message "Checking new mails..."))
866     (let ((new-mails 0)
867           (flist (or wl-biff-check-folder-list (list wl-default-folder)))
868           folder)
869       (if (eq (length flist) 1)
870           (wl-biff-check-folder-async (wl-folder-get-elmo-folder
871                                        (car flist) 'biff) (interactive-p))
872         (unwind-protect
873             (while flist
874               (setq folder (wl-folder-get-elmo-folder (car flist))
875                     flist (cdr flist))
876               (elmo-folder-set-biff-internal folder t)
877               (when (and (elmo-folder-plugged-p folder)
878                          (elmo-folder-exists-p folder))
879                 (setq new-mails
880                       (+ new-mails
881                          (nth 0 (wl-biff-check-folder folder))))))
882           (setq wl-biff-check-folders-running nil)
883           (wl-biff-notify new-mails (interactive-p)))))))
884
885 (defun wl-biff-check-folder (folder)
886   (if (eq (elmo-folder-type-internal folder) 'pop3)
887       (unless (elmo-pop3-get-session folder 'any-exists)
888         (wl-folder-check-one-entity (elmo-folder-name-internal folder)
889                                     'biff))
890     (wl-folder-check-one-entity (elmo-folder-name-internal folder)
891                                 'biff)))
892
893 (defun wl-biff-check-folder-async-callback (diff data)
894   (if (nth 1 data)
895       (with-current-buffer (nth 1 data)
896         (wl-folder-entity-hashtb-set wl-folder-entity-hashtb
897                                      (nth 0 data)
898                                      (list (nth 0 diff)
899                                            (- (nth 1 diff) (nth 0 diff))
900                                            (nth 2 diff))
901                                      (current-buffer))))
902   (setq wl-folder-info-alist-modified t)
903   (setq wl-biff-check-folders-running nil)
904   (sit-for 0)
905   (wl-biff-notify (car diff) (nth 2 data)))
906
907 (defun wl-biff-check-folder-async (folder notify-minibuf)
908   (if (and (elmo-folder-plugged-p folder)
909            (wl-folder-entity-exists-p (elmo-folder-name-internal folder)))
910       (progn
911         (elmo-folder-set-biff-internal folder t)
912         (if (and (eq (elmo-folder-type-internal folder) 'imap4)
913                  (elmo-folder-use-flag-p folder))
914             ;; Check asynchronously only when IMAP4 and use server diff.
915             (progn
916               (setq elmo-folder-diff-async-callback
917                     'wl-biff-check-folder-async-callback)
918               (setq elmo-folder-diff-async-callback-data
919                     (list (elmo-folder-name-internal folder)
920                           (get-buffer wl-folder-buffer-name)
921                           notify-minibuf))
922               (elmo-folder-diff-async folder))
923           (unwind-protect
924               (wl-biff-notify (car (wl-biff-check-folder folder))
925                               notify-minibuf)
926             (setq wl-biff-check-folders-running nil))))
927     (setq wl-biff-check-folders-running nil)))
928
929 (if (and (fboundp 'regexp-opt)
930          (not (featurep 'xemacs)))
931     (defalias 'wl-regexp-opt 'regexp-opt)
932   (defun wl-regexp-opt (strings &optional paren)
933     "Return a regexp to match a string in STRINGS.
934 Each string should be unique in STRINGS and should not contain any regexps,
935 quoted or not.  If optional PAREN is non-nil, ensure that the returned regexp
936 is enclosed by at least one regexp grouping construct."
937     (let ((open-paren (if paren "\\(" "")) (close-paren (if paren "\\)" "")))
938       (concat open-paren (mapconcat 'regexp-quote strings "\\|")
939               close-paren))))
940
941 (defalias 'wl-expand-newtext 'elmo-expand-newtext)
942 (defalias 'wl-regexp-opt 'elmo-regexp-opt)
943
944 (defun wl-region-exists-p ()
945   "Return non-nil if a region exists on current buffer."
946   (static-if (featurep 'xemacs)
947       (region-active-p)
948     (and transient-mark-mode mark-active)))
949
950 (defun wl-deactivate-region ()
951   "Deactivate region on current buffer"
952   (static-if (not (featurep 'xemacs))
953       (setq mark-active nil)))
954
955 (defvar wl-line-string)
956 (defun wl-line-parse-format (format spec-alist)
957   "Make a formatter from FORMAT and SPEC-ALIST."
958   (let (f spec specs stack)
959     (setq f
960           (with-temp-buffer
961             (insert format)
962             (goto-char (point-min))
963             (while (search-forward "%" nil t)
964               (cond
965                ((looking-at "%")
966                 (goto-char (match-end 0)))
967                ((looking-at "\\(-?\\(0?\\)[0-9]*\\)\\([^0-9]\\)")
968                 (cond
969                  ((string= (match-string 3) "(")
970                   (if (zerop (length (match-string 1)))
971                       (error "No number specification for %%( line format"))
972                   (push (list
973                          (match-beginning 0) ; start
974                          (match-end 0)       ; start-content
975                          (string-to-number
976                           (match-string 1))  ; width
977                          specs) ; specs
978                         stack)
979                   (setq specs nil))
980                  ((string= (match-string 3) ")")
981                   (let ((entry (pop stack))
982                         form)
983                     (unless entry
984                       (error
985                        "No matching %%( parenthesis in summary line format"))
986                     (goto-char (car entry)) ; start
987                     (setq form (buffer-substring (nth 1 entry) ; start-content
988                                                  (- (match-beginning 0) 1)))
989                     (delete-region (car entry) (match-end 0))
990                     (insert "s")
991                     (setq specs
992                           (append
993                            (nth 3 entry)
994                            (list (list 'wl-set-string-width (nth 2 entry)
995                                        (append
996                                         (list 'format form)
997                                         specs)))))))
998                  (t
999                   (setq spec
1000                         (if (setq spec (assq (string-to-char (match-string 3))
1001                                              spec-alist))
1002                             (nth 1 spec)
1003                           (match-string 3)))
1004                   (unless (string= "" (match-string 1))
1005                     (setq spec (list 'wl-set-string-width
1006                                      (string-to-number (match-string 1))
1007                                      spec
1008                                      (unless (string= "" (match-string 2))
1009                                        (string-to-char (match-string 2))))))
1010                   (replace-match "s" 'fixed)
1011                   (setq specs (append specs
1012                                       (list
1013                                        (list
1014                                         'setq 'wl-line-string
1015                                         spec)))))))))
1016             (buffer-string)))
1017     (append (list 'format f) specs)))
1018
1019 (defmacro wl-line-formatter-setup (formatter format alist)
1020   `(let (byte-compile-warnings)
1021      (setq ,formatter
1022            (byte-compile
1023             (list 'lambda ()
1024                   (wl-line-parse-format ,format ,alist))))
1025      (when (get-buffer "*Compile-Log*")
1026        (bury-buffer "*Compile-Log*"))
1027      (when (get-buffer "*Compile-Log-Show*")
1028        (bury-buffer "*Compile-Log-Show*"))))
1029
1030 (defsubst wl-copy-local-variables (src dst local-variables)
1031   "Copy value of LOCAL-VARIABLES from SRC buffer to DST buffer."
1032   (with-current-buffer dst
1033     (dolist (variable local-variables)
1034       (set (make-local-variable variable)
1035            (with-current-buffer src
1036              (symbol-value variable))))))
1037
1038 ;;; Search Condition
1039 (defun wl-search-condition-fields ()
1040   (let ((denial-fields
1041          (nconc (mapcar 'capitalize elmo-msgdb-extra-fields)
1042                 (mapcar 'capitalize wl-additional-search-condition-fields)
1043                 '("Flag" "Since" "Before"
1044                   "From" "Subject" "To" "Cc" "Body" "ToCc"
1045                   "Larger" "Smaller"))))
1046     (append '("Last" "First")
1047             denial-fields
1048             (mapcar (lambda (f) (concat "!" f))
1049                     denial-fields))))
1050
1051 (defun wl-read-search-condition (default)
1052   "Read search condition string interactively."
1053   (wl-read-search-condition-internal "Search by" default))
1054
1055 (defun wl-read-search-condition-internal (prompt default &optional paren)
1056   (let* ((completion-ignore-case t)
1057          (field (completing-read
1058                  (format "%s (%s): " prompt default)
1059                  (mapcar #'list
1060                          (append '("AND" "OR") (wl-search-condition-fields)))))
1061          value)
1062     (setq field (if (string= field "")
1063                     (setq field default)
1064                   field))
1065     (cond
1066      ((or (string= field "AND") (string= field "OR"))
1067       (concat (if paren "(" "")
1068               (wl-read-search-condition-internal
1069                (concat field "(1) Search by") default 'paren)
1070               (if (string= field "AND") "&" "|")
1071               (wl-read-search-condition-internal
1072                (concat field "(2) Search by") default 'paren)
1073               (if paren ")" "")))
1074      ((string-match "Since\\|Before" field)
1075       (let ((default (format-time-string "%Y-%m-%d")))
1076         (setq value (completing-read
1077                      (format "Value for '%s' [%s]: " field default)
1078                      (mapcar (function
1079                               (lambda (x)
1080                                 (list (format "%s" (car x)))))
1081                              elmo-date-descriptions)))
1082         (concat (downcase field) ":"
1083                 (if (equal value "") default value))))
1084      ((string-match "!?Flag" field)
1085       (while (null value)
1086         (setq value (downcase
1087                      (completing-read
1088                       (format "Value for '%s': " field)
1089                       (mapcar (lambda (f) (list (capitalize (symbol-name f))))
1090                               (elmo-uniq-list
1091                                (append
1092                                 '(unread answered forwarded digest any)
1093                                 (copy-sequence elmo-global-flags))
1094                                #'delq)))))
1095         (unless (elmo-flag-valid-p value)
1096           (message "Invalid char in `%s'" value)
1097           (setq value nil)
1098           (sit-for 1)))
1099       (unless (string-match (concat "^" elmo-condition-atom-regexp "$")
1100                             value)
1101         (setq value (prin1-to-string value)))
1102       (concat (downcase field) ":" value))
1103      (t
1104       (setq value (read-from-minibuffer (format "Value for '%s': " field)))
1105       (unless (string-match (concat "^" elmo-condition-atom-regexp "$")
1106                             value)
1107         (setq value (prin1-to-string value)))
1108       (concat (downcase field) ":" value)))))
1109
1110 (defun wl-y-or-n-p-with-scroll (prompt &optional scroll-by-SPC)
1111   (let ((prompt (concat prompt (if scroll-by-SPC
1112                                    "<y/n/SPC(down)/BS(up)> "
1113                                  "<y/n/j(down)/k(up)> "))))
1114     (catch 'done
1115       (while t
1116         (discard-input)
1117         (case (let ((cursor-in-echo-area t))
1118                 (cdr (wl-read-event-char prompt)))
1119           ((?y ?Y)
1120            (throw 'done t))
1121           (?\ 
1122            (if scroll-by-SPC
1123                (ignore-errors (scroll-up))
1124              (throw 'done t)))
1125           ((?v ?j ?J next)
1126            (ignore-errors (scroll-up)))
1127           ((?^ ?k ?K prior backspace)
1128            (ignore-errors (scroll-down)))
1129           (t
1130            (throw 'done nil)))))))
1131
1132 (defun wl-find-region (beg-regexp end-regexp)
1133   (if (or (re-search-forward end-regexp nil t)
1134           (re-search-backward end-regexp nil t))
1135       (let ((end (match-end 0))
1136             (beg (re-search-backward beg-regexp nil t)))
1137         (if beg
1138             (cons beg end)))))
1139
1140 (defun wl-simple-display-progress (label action current total)
1141   (message "%s... %d%%"
1142            action
1143            (if (> total 0) (floor (* (/ current (float total)) 100)) 0)))
1144
1145 (when (fboundp 'progress-feedback-with-label)
1146   (defun wl-display-progress-with-gauge (label action current total)
1147     (progress-feedback-with-label
1148      label
1149      "%s..."
1150      (if (> total 0) (floor (* (/ current (float total)) 100)) 0)
1151      action)))
1152
1153 (defun wl-progress-callback-function (label action current total)
1154   (case current
1155     (query
1156      (let ((threshold (if (consp wl-display-progress-threshold)
1157                           (cdr (or (assq label wl-display-progress-threshold)
1158                                    (assq t wl-display-progress-threshold)))
1159                         wl-display-progress-threshold)))
1160        (and threshold
1161             (>= total threshold))))
1162     (start
1163      (message "%s..." action))
1164     (done
1165      (message "%s...done" action))
1166     (t
1167      (when wl-display-progress-function
1168        (funcall wl-display-progress-function label action current total)))))
1169
1170 ;; read multiple strings with completion
1171 (defun wl-completing-read-multiple-1 (prompt
1172                                       table
1173                                       &optional predicate
1174                                       require-match initial-input
1175                                       hist def inherit-input-method)
1176     "Read multiple strings in the minibuffer"
1177     (split-string
1178      (completing-read prompt table predicate nil
1179                       initial-input hist def inherit-input-method)
1180      ","))
1181
1182 (static-when (fboundp 'completing-read-multiple)
1183   (eval-when-compile
1184     (require 'crm))
1185   (defun wl-completing-read-multiple-2 (prompt
1186                                         table
1187                                         &optional predicate
1188                                         require-match initial-input
1189                                         hist def inherit-input-method)
1190     "Read multiple strings in the minibuffer"
1191     (let ((ret (completing-read-multiple prompt table predicate
1192                                          require-match initial-input
1193                                          hist def inherit-input-method)))
1194       (if (and def (equal ret '("")))
1195           (split-string def crm-separator)
1196         ret))))
1197
1198 (static-cond
1199  ((not (fboundp 'completing-read-multiple))
1200   (defalias 'wl-completing-read-multiple 'wl-completing-read-multiple-1))
1201  ((< emacs-major-version 22)
1202   (defun wl-completing-read-multiple (prompt
1203                                       table
1204                                       &optional predicate
1205                                       require-match initial-input
1206                                       hist def inherit-input-method)
1207     "Read multiple strings in the minibuffer"
1208     (if require-match
1209         (wl-completing-read-multiple-1 prompt table predicate
1210                                        nil initial-input
1211                                        hist def inherit-input-method)
1212       (wl-completing-read-multiple-2 prompt table predicate
1213                                      nil initial-input
1214                                      hist def inherit-input-method))))
1215  (t
1216   (defalias 'wl-completing-read-multiple 'completing-read-multiple)))
1217
1218
1219 (cond
1220  ((fboundp 'shell-command-read-minibuffer)
1221   (defun wl-read-shell-command (prompt &optional
1222                                        initial-contents keymap read hist)
1223     (shell-command-read-minibuffer prompt default-directory
1224                                    initial-contents keymap read hist)))
1225  (t
1226   (defalias 'wl-read-shell-command 'read-from-minibuffer)))
1227
1228 (require 'product)
1229 (product-provide (provide 'wl-util) (require 'wl-version))
1230
1231 ;;; wl-util.el ends here