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