wl-e21.el (wl-e21-make-toolbar-buttons): Work around the Emacs 24 error:
[elisp/wanderlust.git] / wl / wl-e21.el
1 ;;; wl-e21.el --- Wanderlust modules for Emacs 21.
2
3 ;; Copyright (C) 2000,2001 Katsumi Yamaoka <yamaoka@jpl.org>
4 ;; Copyright (C) 2000,2001 Yuuichi Teranishi <teranisi@gohome.org>
5
6 ;; Author: Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, net news
8
9 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25 ;;
26
27 ;;; Commentary:
28 ;;
29 ;; This module uses `before-string' overlay property to show icon
30 ;; images instead of `insert-image', so don't delete such overlays
31 ;; sloppily.  Here is a sample code to show icons in the buffer.
32 ;;
33 ;;(let (image icon from to overlay)
34 ;;  ;; The function `find-image' will look for an image first on `load-path'
35 ;;  ;; and then in `data-directory'.
36 ;;  (let ((load-path (cons wl-icon-directory load-path)))
37 ;;    (setq image (find-image (list (list :type 'xpm :file wl-nntp-folder-icon
38 ;;                                      :ascent 'center)))))
39 ;;  ;; `propertize' is a convenient function in such a case.
40 ;;  ;; String must have one or more length to wear an image.
41 ;;  (setq icon (propertize "any string" 'display image))
42 ;;  (pop-to-buffer (get-buffer-create "*wl-e21-demo*"))
43 ;;  (erase-buffer)
44 ;;  (insert "   ")
45 ;;  (setq from (point))
46 ;;  (insert "-fj.wanderlust:0/0/0")
47 ;;  (setq to (point))
48 ;;  (insert "\n")
49 ;;  (setq overlay (make-overlay from to))
50 ;;  ;; Put an image.
51 ;;  (overlay-put overlay 'before-string icon)
52 ;;  ;; Put a mark to indicate that this overlay is made by `wl-e21'.
53 ;;  ;; It is not always necessarily.
54 ;;  (overlay-put overlay 'wl-e21-icon t)
55 ;;  ;; Make it to be removable.
56 ;;  (overlay-put overlay 'evaporate t))
57 ;;
58 ;; Note that a port of Emacs to some platforms (e.g. MS-Windoze) does
59 ;; not yet support images.  It is a pity that neither icons nor tool-
60 ;; bars will not be displayed in such systems.
61
62 ;;; Code:
63 ;;
64
65 (require 'elmo)
66 (eval-when-compile
67   (require 'wl-folder)
68   (require 'wl-summary)
69   (require 'wl-draft)
70   (require 'wl-message)
71   (require 'wl-highlight)
72   (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
73
74 (add-hook 'wl-folder-mode-hook 'wl-setup-folder)
75 (add-hook 'wl-folder-mode-hook 'wl-folder-init-icons)
76
77 (add-hook 'wl-init-hook 'wl-biff-init-icons)
78 (add-hook 'wl-init-hook 'wl-plugged-init-icons)
79
80 (add-hook 'wl-summary-mode-hook 'wl-setup-summary)
81
82 (add-hook 'wl-message-display-internal-hook 'wl-setup-message)
83
84 (defvar wl-use-toolbar (image-type-available-p 'xpm))
85 (defvar wl-plugged-image nil)
86 (defvar wl-unplugged-image nil)
87 (defvar wl-biff-mail-image nil)
88 (defvar wl-biff-nomail-image nil)
89
90 (defvar wl-folder-toolbar
91   '([wl-folder-jump-to-current-entity
92      wl-folder-jump-to-current-entity t "Enter Current Folder"]
93     [wl-folder-next-entity
94      wl-folder-next-entity t "Next Folder"]
95     [wl-folder-prev-entity
96      wl-folder-prev-entity t "Previous Folder"]
97     [wl-folder-check-current-entity
98      wl-folder-check-current-entity t "Check Current Folder"]
99     [wl-folder-sync-current-entity
100      wl-folder-sync-current-entity t "Sync Current Folder"]
101     [wl-draft
102      wl-draft t "Write a New Message"]
103     [wl-folder-goto-draft-folder
104      wl-folder-goto-draft-folder t "Go to Draft Folder"]
105     [wl-folder-empty-trash
106      wl-folder-empty-trash t "Empty Trash"]
107     [wl-exit
108      wl-exit t "Quit Wanderlust"]
109     )
110   "The Folder buffer toolbar.")
111
112 (defvar wl-summary-toolbar
113   '([wl-summary-read
114      wl-summary-read t "Read Messages"]
115     [wl-summary-next
116      wl-summary-next t "Next Message"]
117     [wl-summary-prev
118      wl-summary-prev t "Previous Message"]
119     [wl-summary-jump-to-current-message
120      wl-summary-jump-to-current-message t "Jump to Current Message"]
121     [wl-summary-sync-force-update
122      wl-summary-sync-force-update t "Sync Current Folder"]
123     [wl-summary-dispose
124      wl-summary-dispose t "Dispose Current Message"]
125     [wl-summary-set-flags
126      wl-summary-set-flags t "Set Flags"]
127     [wl-draft
128      wl-summary-write-current-folder t "Write for Current Folder"]
129     [wl-summary-reply
130      wl-summary-reply t "Reply to Current Message" ]
131     [wl-summary-reply-with-citation
132      wl-summary-reply-with-citation t "Reply to Current Message with Citation"]
133     [wl-summary-forward
134      wl-summary-forward t "Forward Current Message"]
135     [wl-summary-exit
136      wl-summary-exit t "Exit Current Summary"]
137     )
138   "The Summary buffer toolbar.")
139
140 (defvar wl-message-toolbar
141   '([wl-message-read
142      wl-message-read t "Read Contents"]
143     [wl-message-next-content
144      wl-message-next-content t "Next Content"]
145     [wl-message-prev-content
146      wl-message-prev-content t "Previous Content"]
147     [wl-message-quit
148      wl-message-quit t "Back to Summary"]
149     [wl-message-play-content
150      wl-message-play-content t "Play Content"]
151     [wl-message-extract-content
152      wl-message-extract-content t "Extract Content"]
153     )
154   "The Message buffer toolbar.")
155
156 (defalias 'wl-draft-insert-signature 'insert-signature) ; for draft toolbar.
157
158 (defvar wl-draft-toolbar
159   '([wl-draft-send-from-toolbar
160      wl-draft-send-from-toolbar t "Send Current Draft"]
161     [wl-draft-yank-original
162      wl-draft-yank-original t "Yank Displaying Message"]
163     [wl-draft-insert-signature
164      wl-draft-insert-signature t "Insert Signature"]
165     [wl-draft-kill
166      wl-draft-kill t "Kill Current Draft"]
167     [wl-draft-save-and-exit
168      wl-draft-save-and-exit t "Save Draft and Exit"]
169     )
170   "The Draft buffer toolbar.")
171
172 (eval-when-compile
173   (defmacro wl-e21-display-image-p ()
174     '(and wl-highlight-folder-with-icon
175           (image-type-available-p 'xpm))))
176
177 (eval-and-compile
178   (if (boundp 'image-load-path)
179       (defun wl-e21-find-image (specs)
180         (let ((image-load-path (cons 'wl-icon-directory image-load-path)))
181           (find-image specs)))
182     (defun wl-e21-find-image (specs)
183       (let ((load-path (cons wl-icon-directory load-path)))
184         (find-image specs)))))
185
186 (defun wl-e21-setup-toolbar (bar)
187   (when (and wl-use-toolbar
188              (wl-e21-display-image-p))
189     (let ((props '(:type xpm :ascent center
190                          :color-symbols (("backgroundToolBarColor" . "None"))
191                          :file))
192           (success t)
193           icon up down disabled name)
194       (while bar
195         (setq icon (aref (pop bar) 0))
196         (unless (boundp icon)
197           (setq name (symbol-name icon)
198                 up (wl-e21-find-image `((,@props ,(concat name "-up.xpm")))))
199           (if up
200               (progn
201                 (setq down (wl-e21-find-image
202                             `((,@props ,(concat name "-down.xpm"))))
203                       disabled (wl-e21-find-image
204                                 `((,@props ,(concat name "-disabled.xpm")))))
205                 (if (and down disabled)
206                     (set icon (vector down up disabled disabled))
207                   (set icon up)))
208             (setq bar nil
209                   success nil))))
210       success)))
211
212 (defvar wl-e21-toolbar-configurations
213   '((auto-resize-tool-bars       . t)
214     (auto-raise-tool-bar-buttons . t)
215     (tool-bar-button-margin      . 2)
216     (tool-bar-button-relief      . 1)))
217
218 ;; FIXME: this function should be rewritten in a proper way.
219 (defun wl-e21-make-toolbar-buttons (keymap defs)
220   (let ((configs wl-e21-toolbar-configurations)
221         config)
222     (while (setq config (pop configs))
223       (set (make-local-variable (car config)) (cdr config))))
224   ;; Invalidate the default bindings.
225   (let ((keys (cdr (key-binding [tool-bar] t)))
226         item)
227     (while (setq item (pop keys))
228       (when (setq item (car-safe item))
229         (ignore-errors ;; workaround
230           (define-key keymap (vector 'tool-bar item) 'undefined)))))
231   (let ((n (length defs))
232         def)
233     (while (>= n 0)
234       (setq n (1- n)
235             def (nth n defs))
236       (ignore-errors ;; workaround
237         (define-key keymap (vector 'tool-bar (aref def 1))
238           (list 'menu-item (aref def 3) (aref def 1)
239                 :enable (aref def 2)
240                 :image (symbol-value (aref def 0))))))))
241
242 (defun wl-e21-setup-folder-toolbar ()
243   (when (wl-e21-setup-toolbar wl-folder-toolbar)
244     (wl-e21-make-toolbar-buttons wl-folder-mode-map wl-folder-toolbar)))
245
246 (defun wl-e21-setup-summary-toolbar ()
247   (when (wl-e21-setup-toolbar wl-summary-toolbar)
248     (wl-e21-make-toolbar-buttons wl-summary-mode-map wl-summary-toolbar)))
249
250 (eval-when-compile
251   (defsubst wl-e21-setup-draft-toolbar ()
252     (when (wl-e21-setup-toolbar wl-draft-toolbar)
253       (wl-e21-make-toolbar-buttons wl-draft-mode-map wl-draft-toolbar))))
254
255 (defun wl-e21-setup-message-toolbar ()
256   (when (wl-e21-setup-toolbar wl-message-toolbar)
257     (wl-e21-make-toolbar-buttons (current-local-map) wl-message-toolbar)))
258
259 (defvar wl-folder-toggle-icon-list
260   '((wl-folder-opened-image       . wl-opened-group-folder-icon)
261     (wl-folder-closed-image       . wl-closed-group-folder-icon)))
262
263 (eval-when-compile
264   (defsubst wl-e21-highlight-folder-group-line (start end icon numbers)
265     (let (image)
266       (when (wl-e21-display-image-p)
267         (let (overlay)
268           (let ((overlays (overlays-in start end)))
269             (while (and (setq overlay (pop overlays))
270                         (not (overlay-get overlay 'wl-e21-icon)))))
271           (unless overlay
272             (setq overlay (make-overlay start end))
273             (overlay-put overlay 'wl-e21-icon t)
274             (overlay-put overlay 'evaporate t))
275           (setq image (get icon 'image))
276           (unless image
277             (let ((name (symbol-value
278                          (cdr (assq icon wl-folder-toggle-icon-list)))))
279               (setq image (wl-e21-find-image
280                            `((:type xpm :file ,name :ascent center))))))
281           (overlay-put overlay 'display image)))
282       (when (and wl-use-highlight-mouse-line (display-mouse-p))
283         (let ((inhibit-read-only t))
284           (put-text-property (if image
285                                  (max (1- start) (line-beginning-position))
286                                start)
287                              (line-end-position)
288                              'mouse-face 'highlight)))))
289
290   (defsubst wl-e21-highlight-folder-by-numbers (start end text-face numbers)
291     (when (display-color-p)
292       (let ((inhibit-read-only t))
293         (if (and wl-highlight-folder-by-numbers
294                  numbers (nth 0 numbers) (nth 1 numbers)
295                  (re-search-forward "[-[:digit:]]+/[-[:digit:]]+/[-[:digit:]]+"
296                                     (line-end-position) t))
297             (let* ((unsync (nth 0 numbers))
298                    (unread (nth 1 numbers))
299                    (face (cond ((and unsync (zerop unsync))
300                                 (if (and unread (zerop unread))
301                                     'wl-highlight-folder-zero-face
302                                   'wl-highlight-folder-unread-face))
303                                ((and unsync
304                                      (>= unsync
305                                          wl-folder-many-unsync-threshold))
306                                 'wl-highlight-folder-many-face)
307                                (t
308                                 'wl-highlight-folder-few-face))))
309               (if (numberp wl-highlight-folder-by-numbers)
310                   (progn
311                     (put-text-property start (match-beginning 0)
312                                        'face text-face)
313                     (put-text-property (match-beginning 0) (match-end 0)
314                                        'face face))
315                 (put-text-property start (match-end 0) 'face face)))
316           (put-text-property start (line-end-position) 'face text-face))))))
317
318 (defun wl-highlight-folder-current-line (&optional numbers)
319   (interactive)
320   (save-excursion
321     (beginning-of-line)
322     (let (fld-name start end)
323       (cond
324        ;; opened folder group
325        ((and (wl-folder-buffer-group-p)
326              (looking-at wl-highlight-folder-opened-regexp))
327         (setq start (match-beginning 1)
328               end (match-end 1))
329         (wl-e21-highlight-folder-group-line start end
330                                             'wl-folder-opened-image
331                                             numbers)
332         (wl-e21-highlight-folder-by-numbers start end
333                                             'wl-highlight-folder-opened-face
334                                             numbers))
335        ;; closed folder group
336        ((and (wl-folder-buffer-group-p)
337              (looking-at wl-highlight-folder-closed-regexp))
338         (setq start (match-beginning 1)
339               end (match-end 1))
340         (wl-e21-highlight-folder-group-line start end
341                                             'wl-folder-closed-image
342                                             numbers)
343         (wl-e21-highlight-folder-by-numbers start end
344                                             'wl-highlight-folder-closed-face
345                                             numbers))
346        ;; basic folder
347        ((and (setq fld-name (wl-folder-get-folder-name-by-id
348                              (get-text-property (point) 'wl-folder-entity-id)))
349              (looking-at "[[:blank:]]+\\([^[:blank:]\n]+\\)"))
350         (setq start (match-beginning 1)
351               end (match-end 1))
352         (let (image)
353           (when (wl-e21-display-image-p)
354             (let (overlay)
355               (let ((overlays (overlays-in start end)))
356                 (while (and (setq overlay (pop overlays))
357                             (not (overlay-get overlay 'wl-e21-icon)))))
358               (unless overlay
359                 (setq overlay (make-overlay start end))
360                 (overlay-put overlay 'wl-e21-icon t)
361                 (overlay-put overlay 'evaporate t))
362               (let (type)
363                 (unless (get (caar wl-folder-internal-icon-list) 'image)
364                   (wl-folder-init-icons))
365                 (setq image
366                       (cond
367                        ;; trash folder
368                        ((string= fld-name wl-trash-folder)
369                         (let ((num (nth 2 numbers))) ; number of messages
370                           (get (if (or (not num) (zerop num))
371                                    'wl-folder-trash-empty-image
372                                  'wl-folder-trash-image)
373                                'image)))
374                        ;; draft folder
375                        ((string= fld-name wl-draft-folder)
376                         (get 'wl-folder-draft-image 'image))
377                        ;; queue folder
378                        ((string= fld-name wl-queue-folder)
379                         (get 'wl-folder-queue-image 'image))
380                        ;; and one of many other folders
381                        ((setq type (or (elmo-folder-type fld-name)
382                                        (elmo-folder-type-internal
383                                         (elmo-make-folder fld-name))))
384                         (get (intern (format "wl-folder-%s-image" type))
385                              'image)))))
386               (overlay-put overlay 'before-string
387                            (propertize " " 'display image
388                                        'invisible t))))
389           (when (and wl-use-highlight-mouse-line (display-mouse-p))
390             (let ((inhibit-read-only t))
391               (put-text-property (if image
392                                      (max (1- start)
393                                           (line-beginning-position))
394                                    start)
395                                  (line-end-position)
396                                  'mouse-face 'highlight))))
397         (when (display-color-p)
398           (wl-e21-highlight-folder-by-numbers
399            start end
400            (if (looking-at (format "^[[:blank:]]*\\(?:%s\\|%s\\)"
401                                    wl-folder-unsubscribe-mark
402                                    wl-folder-removed-mark))
403                'wl-highlight-folder-killed-face
404              'wl-highlight-folder-unknown-face)
405            numbers)))))))
406
407 (defun wl-highlight-plugged-current-line ()
408   (interactive)
409   (when (wl-e21-display-image-p)
410     (save-excursion
411       (beginning-of-line)
412       (when (looking-at "[[:blank:]]*\\(\\[\\([^]]+\\)\\]\\)")
413         (let* ((start (match-beginning 1))
414                (end (match-end 1))
415                (status (match-string-no-properties 2))
416                (image (if (string-equal wl-plugged-plug-on status)
417                           wl-plugged-image
418                         wl-unplugged-image)))
419           (when image
420             (let (overlay)
421               (let ((overlays (overlays-in start end)))
422                 (while (and (setq overlay (pop overlays))
423                             (not (overlay-get overlay 'wl-e21-icon)))))
424               (unless overlay
425                 (setq overlay (make-overlay start end))
426                 (overlay-put overlay 'wl-e21-icon t)
427                 (overlay-put overlay 'evaporate t))
428               (overlay-put overlay 'display image))))))))
429
430 (defun wl-plugged-set-folder-icon (folder string)
431   (let (image type)
432     (when (wl-e21-display-image-p)
433       (setq image
434             (cond ((string= folder wl-queue-folder)
435                    (get 'wl-folder-queue-image 'image))
436                   ((setq type (or (elmo-folder-type folder)
437                                   (elmo-folder-type-internal
438                                    (elmo-make-folder folder))))
439                    (get (intern (format "wl-folder-%s-image" type))
440                         'image)))))
441     (if image
442         (concat (propertize " " 'display image 'invisible t) string)
443       string)))
444
445 (defvar wl-folder-internal-icon-list
446   ;; alist of (image . icon-file)
447   '((wl-folder-nntp-image         . wl-nntp-folder-icon)
448     (wl-folder-imap4-image        . wl-imap-folder-icon)
449     (wl-folder-pop3-image         . wl-pop-folder-icon)
450     (wl-folder-localdir-image     . wl-localdir-folder-icon)
451     (wl-folder-localnews-image    . wl-localnews-folder-icon)
452     (wl-folder-internal-image     . wl-internal-folder-icon)
453     (wl-folder-multi-image        . wl-multi-folder-icon)
454     (wl-folder-filter-image       . wl-filter-folder-icon)
455     (wl-folder-archive-image      . wl-archive-folder-icon)
456     (wl-folder-pipe-image         . wl-pipe-folder-icon)
457     (wl-folder-maildir-image      . wl-maildir-folder-icon)
458     (wl-folder-search-image       . wl-search-folder-icon)
459     (wl-folder-shimbun-image      . wl-shimbun-folder-icon)
460     (wl-folder-file-image         . wl-file-folder-icon)
461     (wl-folder-access-image       . wl-access-folder-icon)
462     (wl-folder-trash-empty-image  . wl-empty-trash-folder-icon)
463     (wl-folder-draft-image        . wl-draft-folder-icon)
464     (wl-folder-queue-image        . wl-queue-folder-icon)
465     (wl-folder-trash-image        . wl-trash-folder-icon)))
466
467 (defun wl-folder-init-icons ()
468   (when (wl-e21-display-image-p)
469     (let ((icons wl-folder-internal-icon-list)
470           icon name image)
471       (while (setq icon (pop icons))
472         (unless (get (car icon) 'image)
473           (setq name (symbol-value (cdr icon))
474                 image (wl-e21-find-image
475                        `((:type xpm :file ,name :ascent center))))
476           (when image
477             (put (car icon) 'image image)))))))
478
479 (defun wl-plugged-init-icons ()
480   (let ((props (when (display-mouse-p)
481                  (list 'local-map (purecopy (make-mode-line-mouse-map
482                                              'mouse-2 #'wl-toggle-plugged))
483                        'help-echo "mouse-2 toggles plugged status"))))
484     (if (wl-e21-display-image-p)
485         (progn
486           (unless wl-plugged-image
487             (setq wl-plugged-image (wl-e21-find-image
488                                     `((:type xpm
489                                              :file ,wl-plugged-icon
490                                              :ascent center)))
491                   wl-unplugged-image (wl-e21-find-image
492                                       `((:type xpm
493                                                :file ,wl-unplugged-icon
494                                                :ascent center)))))
495           (setq wl-modeline-plug-state-on
496                 (apply 'propertize wl-plug-state-indicator-on
497                        `(display ,wl-plugged-image ,@props))
498                 wl-modeline-plug-state-off
499                 (apply 'propertize wl-plug-state-indicator-off
500                        `(display ,wl-unplugged-image ,@props))))
501       (if props
502           (setq wl-modeline-plug-state-on
503                 (apply 'propertize wl-plug-state-indicator-on props)
504                 wl-modeline-plug-state-off
505                 (apply 'propertize wl-plug-state-indicator-off props))
506         (setq wl-modeline-plug-state-on wl-plug-state-indicator-on
507               wl-modeline-plug-state-off wl-plug-state-indicator-off)))))
508
509 (defun wl-biff-init-icons ()
510   (let ((props (when (display-mouse-p)
511                  (list 'local-map (purecopy (make-mode-line-mouse-map
512                                              'mouse-2 #'wl-biff-check-folders))
513                        'help-echo "mouse-2 checks new mails"))))
514     (if (wl-e21-display-image-p)
515         (progn
516           (unless wl-biff-mail-image
517             (setq wl-biff-mail-image (wl-e21-find-image
518                                       `((:type xpm
519                                                :file ,wl-biff-mail-icon
520                                                :ascent center)))
521                   wl-biff-nomail-image (wl-e21-find-image
522                                         `((:type xpm
523                                                  :file ,wl-biff-nomail-icon
524                                                  :ascent center)))))
525           (setq wl-modeline-biff-state-on
526                 (apply 'propertize wl-biff-state-indicator-on
527                        `(display ,wl-biff-mail-image ,@props))
528                 wl-modeline-biff-state-off
529                 (apply 'propertize wl-biff-state-indicator-off
530                        `(display ,wl-biff-nomail-image ,@props))))
531       (if props
532           (setq wl-modeline-biff-state-on
533                 (apply 'propertize wl-biff-state-indicator-on props)
534                 wl-modeline-biff-state-off
535                 (apply 'propertize wl-biff-state-indicator-off props))
536         (setq wl-modeline-biff-state-on wl-biff-state-indicator-on
537               wl-modeline-biff-state-off wl-biff-state-indicator-off)))))
538
539 (defun wl-make-date-string ()
540   (let ((system-time-locale "C"))
541     (format-time-string "%a, %d %b %Y %T %z")))
542
543 (defalias 'wl-setup-folder 'wl-e21-setup-folder-toolbar)
544
545 (defalias 'wl-setup-summary 'wl-e21-setup-summary-toolbar)
546
547 (defun wl-message-define-keymap ()
548   (let ((keymap (make-sparse-keymap)))
549     (define-key keymap "D" 'wl-message-delete-current-part)
550     (define-key keymap "l" 'wl-message-toggle-disp-summary)
551     (define-key keymap "\C-c:d" 'wl-message-decrypt-pgp-nonmime)
552     (define-key keymap "\C-c:v" 'wl-message-verify-pgp-nonmime)
553     (define-key keymap "w" 'wl-draft)
554     (define-key keymap [mouse-4] 'wl-message-wheel-down)
555     (define-key keymap [mouse-5] 'wl-message-wheel-up)
556     (define-key keymap [S-mouse-4] 'wl-message-wheel-down)
557     (define-key keymap [S-mouse-5] 'wl-message-wheel-up)
558     ;; Meadow2
559     (define-key keymap [mouse-wheel1] 'wl-message-wheel-dispatcher)
560     (define-key keymap [S-mouse-wheel1] 'wl-message-wheel-dispatcher)
561     (set-keymap-parent wl-message-button-map keymap)
562     (define-key wl-message-button-map
563       [mouse-2] 'wl-message-button-dispatcher)
564     keymap))
565
566 (defalias 'wl-setup-message 'wl-e21-setup-message-toolbar)
567
568 ;; Wheel handling for Meadow2
569 (defun wl-message-wheel-dispatcher (event)
570   (interactive "e")
571   (if (< (nth 4 (nth 1 event)) 0)
572       (wl-message-wheel-up event)
573     (wl-message-wheel-down event)))
574
575 (defun wl-summary-wheel-dispatcher (event)
576   (interactive "e")
577   (if (< (nth 4 (nth 1 event)) 0)
578       (if (memq 'shift (event-modifiers event))
579           (wl-summary-down)
580         (wl-summary-next))
581     (if (memq 'shift (event-modifiers event))
582         (wl-summary-up)
583       (wl-summary-prev))))
584
585 (defun wl-message-wheel-up (event)
586   (interactive "e")
587   (if (string-match (regexp-quote wl-message-buffer-name)
588                     (regexp-quote (buffer-name)))
589       (wl-message-next-page)
590     (let ((cur-buf (current-buffer))
591           proceed)
592       (save-selected-window
593         (select-window (posn-window (event-start event)))
594         (set-buffer cur-buf)
595         (setq proceed (wl-message-next-page)))
596       (if proceed
597           (if (memq 'shift (event-modifiers event))
598               (wl-summary-down t)
599             (wl-summary-next t))))))
600
601 (defun wl-message-wheel-down (event)
602   (interactive "e")
603   (if (string-match (regexp-quote wl-message-buffer-name)
604                     (regexp-quote (buffer-name)))
605       (wl-message-prev-page)
606     (let ((cur-buf (current-buffer))
607           proceed)
608       (save-selected-window
609         (select-window (posn-window (event-start event)))
610         (set-buffer cur-buf)
611         (setq proceed (wl-message-prev-page)))
612       (if proceed
613           (if (memq 'shift (event-modifiers event))
614               (wl-summary-up t)
615             (wl-summary-prev t))))))
616
617 (defun wl-draft-overload-menubar ()
618   (let ((keymap (current-local-map)))
619     (define-key keymap [menu-bar mail send]
620       '("Send Message" . wl-draft-send-and-exit))
621     (define-key keymap [menu-bar mail send-stay]
622       '("Send, Keep Editing" . wl-draft-send))
623     (define-key-after (lookup-key keymap [menu-bar mail])
624       [mail-sep-send] '("--")
625       'send-stay)
626     (define-key keymap [menu-bar mail cancel]
627       '("Kill Current Draft" . wl-draft-kill))
628     (define-key-after (lookup-key keymap [menu-bar mail])
629       [save] '("Save Draft and Exit" . wl-draft-save-and-exit)
630       'cancel)
631     (define-key-after (lookup-key keymap [menu-bar mail])
632       [mail-sep-exit] '("--")
633       'save)
634     (define-key-after (lookup-key keymap [menu-bar mail])
635       [preview] '("Preview Message" . wl-draft-preview-message)
636       'mail-sep-exit)
637     (define-key keymap [menu-bar mail yank]
638       '("Cite Message" . wl-draft-yank-original))
639     (define-key keymap [menu-bar mail signature]
640       '("Insert Signature" . insert-signature))
641     (define-key keymap [menu-bar headers fcc]
642       '("Fcc" . wl-draft-fcc))))
643
644 (defun wl-draft-mode-setup ()
645   (require 'derived)
646   (define-derived-mode wl-draft-mode mail-mode "Draft"
647     "draft mode for Wanderlust derived from mail mode.
648 See info under Wanderlust for full documentation.
649
650 Special commands:
651 \\{wl-draft-mode-map}"
652     (setq font-lock-defaults nil)))
653
654 (defun wl-draft-key-setup ()
655   (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
656   (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
657   (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
658   (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
659   (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
660   (define-key wl-draft-mode-map "\C-l" 'wl-draft-highlight-and-recenter)
661   (define-key wl-draft-mode-map "\C-i" 'wl-complete-field-body-or-tab)
662   (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
663   (define-key wl-draft-mode-map "\M-t" 'wl-toggle-plugged)
664   (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
665   (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
666   (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
667   (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
668   (define-key wl-draft-mode-map "\C-c\C-a" 'wl-addrmgr)
669 ;;;  (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
670   (define-key wl-draft-mode-map "\C-xk"    'wl-draft-mimic-kill-buffer)
671   (define-key wl-draft-mode-map "\C-c\C-d" 'wl-draft-elide-region)
672   (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line)
673   (define-key wl-draft-mode-map "\M-p" 'wl-draft-previous-history-element)
674   (define-key wl-draft-mode-map "\M-n" 'wl-draft-next-history-element))
675
676 (defun wl-draft-overload-functions ()
677   (wl-mode-line-buffer-identification)
678 ;;;  (local-set-key "\C-c\C-s" 'wl-draft-send) ; override
679   (wl-e21-setup-draft-toolbar)
680   (wl-draft-overload-menubar))
681
682 (defalias 'wl-defface 'defface)
683
684 (defun wl-read-event-char (&optional prompt)
685   "Get the next event."
686   (let ((event (read-event prompt)))
687     (cons (and (numberp event) event) event)))
688
689 (put 'wl-modeline-biff-state-on 'risky-local-variable t)
690 (put 'wl-modeline-biff-state-off 'risky-local-variable t)
691 (put 'wl-modeline-plug-state-on 'risky-local-variable t)
692 (put 'wl-modeline-plug-state-off 'risky-local-variable t)
693
694 (require 'product)
695 (product-provide (provide 'wl-e21) (require 'wl-version))
696
697 ;;; wl-e21.el ends here