c2487c5a085a49801eeaa04905ddebe5118a1a72
[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 (defun wl-e21-make-toolbar-buttons (keymap defs)
219   (let ((configs wl-e21-toolbar-configurations)
220         config)
221     (while (setq config (pop configs))
222       (set (make-local-variable (car config)) (cdr config))))
223   ;; Invalidate the default bindings.
224   (let ((keys (cdr (key-binding [tool-bar] t)))
225         item)
226     (unless (eq (caar keys) 'keymap) ;; Emacs >= 24
227       (while (setq item (pop keys))
228         (when (setq item (car-safe item))
229           (define-key keymap (vector 'tool-bar item) 'undefined)))))
230   (let ((n (length defs))
231         def)
232     (while (>= n 0)
233       (setq n (1- n)
234             def (nth n defs))
235       (define-key keymap (vector 'tool-bar (aref def 1))
236         (list 'menu-item (aref def 3) (aref def 1)
237               :enable (aref def 2)
238               :image (symbol-value (aref def 0)))))))
239
240 (defun wl-e21-setup-folder-toolbar ()
241   (when (wl-e21-setup-toolbar wl-folder-toolbar)
242     (wl-e21-make-toolbar-buttons wl-folder-mode-map wl-folder-toolbar)))
243
244 (defun wl-e21-setup-summary-toolbar ()
245   (when (wl-e21-setup-toolbar wl-summary-toolbar)
246     (wl-e21-make-toolbar-buttons wl-summary-mode-map wl-summary-toolbar)))
247
248 (eval-when-compile
249   (defsubst wl-e21-setup-draft-toolbar ()
250     (when (wl-e21-setup-toolbar wl-draft-toolbar)
251       (wl-e21-make-toolbar-buttons wl-draft-mode-map wl-draft-toolbar))))
252
253 (defun wl-e21-setup-message-toolbar ()
254   (when (wl-e21-setup-toolbar wl-message-toolbar)
255     (wl-e21-make-toolbar-buttons (current-local-map) wl-message-toolbar)))
256
257 (defvar wl-folder-toggle-icon-list
258   '((wl-folder-opened-image       . wl-opened-group-folder-icon)
259     (wl-folder-closed-image       . wl-closed-group-folder-icon)))
260
261 (eval-when-compile
262   (defsubst wl-e21-highlight-folder-group-line (start end icon numbers)
263     (let (image)
264       (when (wl-e21-display-image-p)
265         (let (overlay)
266           (let ((overlays (overlays-in start end)))
267             (while (and (setq overlay (pop overlays))
268                         (not (overlay-get overlay 'wl-e21-icon)))))
269           (unless overlay
270             (setq overlay (make-overlay start end))
271             (overlay-put overlay 'wl-e21-icon t)
272             (overlay-put overlay 'evaporate t))
273           (setq image (get icon 'image))
274           (unless image
275             (let ((name (symbol-value
276                          (cdr (assq icon wl-folder-toggle-icon-list)))))
277               (setq image (wl-e21-find-image
278                            `((:type xpm :file ,name :ascent center))))))
279           (overlay-put overlay 'display image)))
280       (when (and wl-use-highlight-mouse-line (display-mouse-p))
281         (let ((inhibit-read-only t))
282           (put-text-property (if image
283                                  (max (1- start) (line-beginning-position))
284                                start)
285                              (line-end-position)
286                              'mouse-face 'highlight)))))
287
288   (defsubst wl-e21-highlight-folder-by-numbers (start end text-face numbers)
289     (when (display-color-p)
290       (let ((inhibit-read-only t))
291         (if (and wl-highlight-folder-by-numbers
292                  numbers (nth 0 numbers) (nth 1 numbers)
293                  (re-search-forward "[-[:digit:]]+/[-[:digit:]]+/[-[:digit:]]+"
294                                     (line-end-position) t))
295             (let* ((unsync (nth 0 numbers))
296                    (unread (nth 1 numbers))
297                    (face (cond ((and unsync (zerop unsync))
298                                 (if (and unread (zerop unread))
299                                     'wl-highlight-folder-zero-face
300                                   'wl-highlight-folder-unread-face))
301                                ((and unsync
302                                      (>= unsync
303                                          wl-folder-many-unsync-threshold))
304                                 'wl-highlight-folder-many-face)
305                                (t
306                                 'wl-highlight-folder-few-face))))
307               (if (numberp wl-highlight-folder-by-numbers)
308                   (progn
309                     (put-text-property start (match-beginning 0)
310                                        'face text-face)
311                     (put-text-property (match-beginning 0) (match-end 0)
312                                        'face face))
313                 (put-text-property start (match-end 0) 'face face)))
314           (put-text-property start (line-end-position) 'face text-face))))))
315
316 (defun wl-highlight-folder-current-line (&optional numbers)
317   (interactive)
318   (save-excursion
319     (beginning-of-line)
320     (let (fld-name start end)
321       (cond
322        ;; opened folder group
323        ((and (wl-folder-buffer-group-p)
324              (looking-at wl-highlight-folder-opened-regexp))
325         (setq start (match-beginning 1)
326               end (match-end 1))
327         (wl-e21-highlight-folder-group-line start end
328                                             'wl-folder-opened-image
329                                             numbers)
330         (wl-e21-highlight-folder-by-numbers start end
331                                             'wl-highlight-folder-opened-face
332                                             numbers))
333        ;; closed folder group
334        ((and (wl-folder-buffer-group-p)
335              (looking-at wl-highlight-folder-closed-regexp))
336         (setq start (match-beginning 1)
337               end (match-end 1))
338         (wl-e21-highlight-folder-group-line start end
339                                             'wl-folder-closed-image
340                                             numbers)
341         (wl-e21-highlight-folder-by-numbers start end
342                                             'wl-highlight-folder-closed-face
343                                             numbers))
344        ;; basic folder
345        ((and (setq fld-name (wl-folder-get-folder-name-by-id
346                              (get-text-property (point) 'wl-folder-entity-id)))
347              (looking-at "[[:blank:]]+\\([^[:blank:]\n]+\\)"))
348         (setq start (match-beginning 1)
349               end (match-end 1))
350         (let (image)
351           (when (wl-e21-display-image-p)
352             (let (overlay)
353               (let ((overlays (overlays-in start end)))
354                 (while (and (setq overlay (pop overlays))
355                             (not (overlay-get overlay 'wl-e21-icon)))))
356               (unless overlay
357                 (setq overlay (make-overlay start end))
358                 (overlay-put overlay 'wl-e21-icon t)
359                 (overlay-put overlay 'evaporate t))
360               (let (type)
361                 (unless (get (caar wl-folder-internal-icon-list) 'image)
362                   (wl-folder-init-icons))
363                 (setq image
364                       (cond
365                        ;; trash folder
366                        ((string= fld-name wl-trash-folder)
367                         (let ((num (nth 2 numbers))) ; number of messages
368                           (get (if (or (not num) (zerop num))
369                                    'wl-folder-trash-empty-image
370                                  'wl-folder-trash-image)
371                                'image)))
372                        ;; draft folder
373                        ((string= fld-name wl-draft-folder)
374                         (get 'wl-folder-draft-image 'image))
375                        ;; queue folder
376                        ((string= fld-name wl-queue-folder)
377                         (get 'wl-folder-queue-image 'image))
378                        ;; and one of many other folders
379                        ((setq type (or (elmo-folder-type fld-name)
380                                        (elmo-folder-type-internal
381                                         (elmo-make-folder fld-name))))
382                         (get (intern (format "wl-folder-%s-image" type))
383                              'image)))))
384               (overlay-put overlay 'before-string
385                            (propertize " " 'display image
386                                        'invisible t))))
387           (when (and wl-use-highlight-mouse-line (display-mouse-p))
388             (let ((inhibit-read-only t))
389               (put-text-property (if image
390                                      (max (1- start)
391                                           (line-beginning-position))
392                                    start)
393                                  (line-end-position)
394                                  'mouse-face 'highlight))))
395         (when (display-color-p)
396           (wl-e21-highlight-folder-by-numbers
397            start end
398            (if (looking-at (format "^[[:blank:]]*\\(?:%s\\|%s\\)"
399                                    wl-folder-unsubscribe-mark
400                                    wl-folder-removed-mark))
401                'wl-highlight-folder-killed-face
402              'wl-highlight-folder-unknown-face)
403            numbers)))))))
404
405 (defun wl-highlight-plugged-current-line ()
406   (interactive)
407   (when (wl-e21-display-image-p)
408     (save-excursion
409       (beginning-of-line)
410       (when (looking-at "[[:blank:]]*\\(\\[\\([^]]+\\)\\]\\)")
411         (let* ((start (match-beginning 1))
412                (end (match-end 1))
413                (status (match-string-no-properties 2))
414                (image (if (string-equal wl-plugged-plug-on status)
415                           wl-plugged-image
416                         wl-unplugged-image)))
417           (when image
418             (let (overlay)
419               (let ((overlays (overlays-in start end)))
420                 (while (and (setq overlay (pop overlays))
421                             (not (overlay-get overlay 'wl-e21-icon)))))
422               (unless overlay
423                 (setq overlay (make-overlay start end))
424                 (overlay-put overlay 'wl-e21-icon t)
425                 (overlay-put overlay 'evaporate t))
426               (overlay-put overlay 'display image))))))))
427
428 (defun wl-plugged-set-folder-icon (folder string)
429   (let (image type)
430     (when (wl-e21-display-image-p)
431       (setq image
432             (cond ((string= folder wl-queue-folder)
433                    (get 'wl-folder-queue-image 'image))
434                   ((setq type (or (elmo-folder-type folder)
435                                   (elmo-folder-type-internal
436                                    (elmo-make-folder folder))))
437                    (get (intern (format "wl-folder-%s-image" type))
438                         'image)))))
439     (if image
440         (concat (propertize " " 'display image 'invisible t) string)
441       string)))
442
443 (defvar wl-folder-internal-icon-list
444   ;; alist of (image . icon-file)
445   '((wl-folder-nntp-image         . wl-nntp-folder-icon)
446     (wl-folder-imap4-image        . wl-imap-folder-icon)
447     (wl-folder-pop3-image         . wl-pop-folder-icon)
448     (wl-folder-localdir-image     . wl-localdir-folder-icon)
449     (wl-folder-localnews-image    . wl-localnews-folder-icon)
450     (wl-folder-internal-image     . wl-internal-folder-icon)
451     (wl-folder-multi-image        . wl-multi-folder-icon)
452     (wl-folder-filter-image       . wl-filter-folder-icon)
453     (wl-folder-archive-image      . wl-archive-folder-icon)
454     (wl-folder-pipe-image         . wl-pipe-folder-icon)
455     (wl-folder-maildir-image      . wl-maildir-folder-icon)
456     (wl-folder-search-image       . wl-search-folder-icon)
457     (wl-folder-shimbun-image      . wl-shimbun-folder-icon)
458     (wl-folder-file-image         . wl-file-folder-icon)
459     (wl-folder-access-image       . wl-access-folder-icon)
460     (wl-folder-trash-empty-image  . wl-empty-trash-folder-icon)
461     (wl-folder-draft-image        . wl-draft-folder-icon)
462     (wl-folder-queue-image        . wl-queue-folder-icon)
463     (wl-folder-trash-image        . wl-trash-folder-icon)))
464
465 (defun wl-folder-init-icons ()
466   (when (wl-e21-display-image-p)
467     (let ((icons wl-folder-internal-icon-list)
468           icon name image)
469       (while (setq icon (pop icons))
470         (unless (get (car icon) 'image)
471           (setq name (symbol-value (cdr icon))
472                 image (wl-e21-find-image
473                        `((:type xpm :file ,name :ascent center))))
474           (when image
475             (put (car icon) 'image image)))))))
476
477 (defun wl-plugged-init-icons ()
478   (let ((props (when (display-mouse-p)
479                  (list 'local-map (purecopy (make-mode-line-mouse-map
480                                              'mouse-2 #'wl-toggle-plugged))
481                        'help-echo "mouse-2 toggles plugged status"))))
482     (if (wl-e21-display-image-p)
483         (progn
484           (unless wl-plugged-image
485             (setq wl-plugged-image (wl-e21-find-image
486                                     `((:type xpm
487                                              :file ,wl-plugged-icon
488                                              :ascent center)))
489                   wl-unplugged-image (wl-e21-find-image
490                                       `((:type xpm
491                                                :file ,wl-unplugged-icon
492                                                :ascent center)))))
493           (setq wl-modeline-plug-state-on
494                 (apply 'propertize wl-plug-state-indicator-on
495                        `(display ,wl-plugged-image ,@props))
496                 wl-modeline-plug-state-off
497                 (apply 'propertize wl-plug-state-indicator-off
498                        `(display ,wl-unplugged-image ,@props))))
499       (if props
500           (setq wl-modeline-plug-state-on
501                 (apply 'propertize wl-plug-state-indicator-on props)
502                 wl-modeline-plug-state-off
503                 (apply 'propertize wl-plug-state-indicator-off props))
504         (setq wl-modeline-plug-state-on wl-plug-state-indicator-on
505               wl-modeline-plug-state-off wl-plug-state-indicator-off)))))
506
507 (defun wl-biff-init-icons ()
508   (let ((props (when (display-mouse-p)
509                  (list 'local-map (purecopy (make-mode-line-mouse-map
510                                              'mouse-2 #'wl-biff-check-folders))
511                        'help-echo "mouse-2 checks new mails"))))
512     (if (wl-e21-display-image-p)
513         (progn
514           (unless wl-biff-mail-image
515             (setq wl-biff-mail-image (wl-e21-find-image
516                                       `((:type xpm
517                                                :file ,wl-biff-mail-icon
518                                                :ascent center)))
519                   wl-biff-nomail-image (wl-e21-find-image
520                                         `((:type xpm
521                                                  :file ,wl-biff-nomail-icon
522                                                  :ascent center)))))
523           (setq wl-modeline-biff-state-on
524                 (apply 'propertize wl-biff-state-indicator-on
525                        `(display ,wl-biff-mail-image ,@props))
526                 wl-modeline-biff-state-off
527                 (apply 'propertize wl-biff-state-indicator-off
528                        `(display ,wl-biff-nomail-image ,@props))))
529       (if props
530           (setq wl-modeline-biff-state-on
531                 (apply 'propertize wl-biff-state-indicator-on props)
532                 wl-modeline-biff-state-off
533                 (apply 'propertize wl-biff-state-indicator-off props))
534         (setq wl-modeline-biff-state-on wl-biff-state-indicator-on
535               wl-modeline-biff-state-off wl-biff-state-indicator-off)))))
536
537 (defun wl-make-date-string ()
538   (let ((system-time-locale "C"))
539     (format-time-string "%a, %d %b %Y %T %z")))
540
541 (defalias 'wl-setup-folder 'wl-e21-setup-folder-toolbar)
542
543 (defalias 'wl-setup-summary 'wl-e21-setup-summary-toolbar)
544
545 (defun wl-message-define-keymap ()
546   (let ((keymap (make-sparse-keymap)))
547     (define-key keymap "D" 'wl-message-delete-current-part)
548     (define-key keymap "l" 'wl-message-toggle-disp-summary)
549     (define-key keymap "\C-c:d" 'wl-message-decrypt-pgp-nonmime)
550     (define-key keymap "\C-c:v" 'wl-message-verify-pgp-nonmime)
551     (define-key keymap "w" 'wl-draft)
552     (define-key keymap [mouse-4] 'wl-message-wheel-down)
553     (define-key keymap [mouse-5] 'wl-message-wheel-up)
554     (define-key keymap [S-mouse-4] 'wl-message-wheel-down)
555     (define-key keymap [S-mouse-5] 'wl-message-wheel-up)
556     ;; Meadow2
557     (define-key keymap [mouse-wheel1] 'wl-message-wheel-dispatcher)
558     (define-key keymap [S-mouse-wheel1] 'wl-message-wheel-dispatcher)
559     (set-keymap-parent wl-message-button-map keymap)
560     (define-key wl-message-button-map
561       [mouse-2] 'wl-message-button-dispatcher)
562     keymap))
563
564 (defalias 'wl-setup-message 'wl-e21-setup-message-toolbar)
565
566 ;; Wheel handling for Meadow2
567 (defun wl-message-wheel-dispatcher (event)
568   (interactive "e")
569   (if (< (nth 4 (nth 1 event)) 0)
570       (wl-message-wheel-up event)
571     (wl-message-wheel-down event)))
572
573 (defun wl-summary-wheel-dispatcher (event)
574   (interactive "e")
575   (if (< (nth 4 (nth 1 event)) 0)
576       (if (memq 'shift (event-modifiers event))
577           (wl-summary-down)
578         (wl-summary-next))
579     (if (memq 'shift (event-modifiers event))
580         (wl-summary-up)
581       (wl-summary-prev))))
582
583 (defun wl-message-wheel-up (event)
584   (interactive "e")
585   (if (string-match (regexp-quote wl-message-buffer-name)
586                     (regexp-quote (buffer-name)))
587       (wl-message-next-page)
588     (let ((cur-buf (current-buffer))
589           proceed)
590       (save-selected-window
591         (select-window (posn-window (event-start event)))
592         (set-buffer cur-buf)
593         (setq proceed (wl-message-next-page)))
594       (if proceed
595           (if (memq 'shift (event-modifiers event))
596               (wl-summary-down t)
597             (wl-summary-next t))))))
598
599 (defun wl-message-wheel-down (event)
600   (interactive "e")
601   (if (string-match (regexp-quote wl-message-buffer-name)
602                     (regexp-quote (buffer-name)))
603       (wl-message-prev-page)
604     (let ((cur-buf (current-buffer))
605           proceed)
606       (save-selected-window
607         (select-window (posn-window (event-start event)))
608         (set-buffer cur-buf)
609         (setq proceed (wl-message-prev-page)))
610       (if proceed
611           (if (memq 'shift (event-modifiers event))
612               (wl-summary-up t)
613             (wl-summary-prev t))))))
614
615 (defun wl-draft-overload-menubar ()
616   (let ((keymap (current-local-map)))
617     (define-key keymap [menu-bar mail send]
618       '("Send Message" . wl-draft-send-and-exit))
619     (define-key keymap [menu-bar mail send-stay]
620       '("Send, Keep Editing" . wl-draft-send))
621     (define-key-after (lookup-key keymap [menu-bar mail])
622       [mail-sep-send] '("--")
623       'send-stay)
624     (define-key keymap [menu-bar mail cancel]
625       '("Kill Current Draft" . wl-draft-kill))
626     (define-key-after (lookup-key keymap [menu-bar mail])
627       [save] '("Save Draft and Exit" . wl-draft-save-and-exit)
628       'cancel)
629     (define-key-after (lookup-key keymap [menu-bar mail])
630       [mail-sep-exit] '("--")
631       'save)
632     (define-key-after (lookup-key keymap [menu-bar mail])
633       [preview] '("Preview Message" . wl-draft-preview-message)
634       'mail-sep-exit)
635     (define-key keymap [menu-bar mail yank]
636       '("Cite Message" . wl-draft-yank-original))
637     (define-key keymap [menu-bar mail signature]
638       '("Insert Signature" . insert-signature))
639     (define-key keymap [menu-bar headers fcc]
640       '("Fcc" . wl-draft-fcc))))
641
642 (defun wl-draft-mode-setup ()
643   (require 'derived)
644   (define-derived-mode wl-draft-mode mail-mode "Draft"
645     "draft mode for Wanderlust derived from mail mode.
646 See info under Wanderlust for full documentation.
647
648 Special commands:
649 \\{wl-draft-mode-map}"
650     (setq font-lock-defaults nil)))
651
652 (defun wl-draft-key-setup ()
653   (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
654   (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
655   (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
656   (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
657   (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
658   (define-key wl-draft-mode-map "\C-l" 'wl-draft-highlight-and-recenter)
659   (define-key wl-draft-mode-map "\C-i" 'wl-complete-field-body-or-tab)
660   (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
661   (define-key wl-draft-mode-map "\M-t" 'wl-toggle-plugged)
662   (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
663   (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
664   (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
665   (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
666   (define-key wl-draft-mode-map "\C-c\C-a" 'wl-addrmgr)
667 ;;;  (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
668   (define-key wl-draft-mode-map "\C-xk"    'wl-draft-mimic-kill-buffer)
669   (define-key wl-draft-mode-map "\C-c\C-d" 'wl-draft-elide-region)
670   (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line)
671   (define-key wl-draft-mode-map "\M-p" 'wl-draft-previous-history-element)
672   (define-key wl-draft-mode-map "\M-n" 'wl-draft-next-history-element))
673
674 (defun wl-draft-overload-functions ()
675   (wl-mode-line-buffer-identification)
676 ;;;  (local-set-key "\C-c\C-s" 'wl-draft-send) ; override
677   (wl-e21-setup-draft-toolbar)
678   (wl-draft-overload-menubar))
679
680 (defalias 'wl-defface 'defface)
681
682 (defun wl-read-event-char (&optional prompt)
683   "Get the next event."
684   (let ((event (read-event prompt)))
685     (cons (and (numberp event) event) event)))
686
687 (put 'wl-modeline-biff-state-on 'risky-local-variable t)
688 (put 'wl-modeline-biff-state-off 'risky-local-variable t)
689 (put 'wl-modeline-plug-state-on 'risky-local-variable t)
690 (put 'wl-modeline-plug-state-off 'risky-local-variable t)
691
692 (require 'product)
693 (product-provide (provide 'wl-e21) (require 'wl-version))
694
695 ;;; wl-e21.el ends here