* wl-e21.el (wl-draft-overload-menubar): Use define-key-after to
[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-folder-mode-map (make-sparse-keymap))
73   (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
74
75 (add-hook 'wl-folder-mode-hook 'wl-setup-folder)
76 (add-hook 'wl-folder-mode-hook 'wl-folder-init-icons)
77
78 (add-hook 'wl-init-hook 'wl-biff-init-icons)
79 (add-hook 'wl-init-hook 'wl-plugged-init-icons)
80
81 (add-hook 'wl-summary-mode-hook 'wl-setup-summary)
82
83 (add-hook 'wl-message-display-internal-hook 'wl-setup-message)
84
85 (defvar wl-use-toolbar (image-type-available-p 'xpm))
86 (defvar wl-plugged-image nil)
87 (defvar wl-unplugged-image nil)
88 (defvar wl-biff-mail-image nil)
89 (defvar wl-biff-nomail-image nil)
90
91 (defvar wl-folder-toolbar
92   '([wl-folder-jump-to-current-entity
93      wl-folder-jump-to-current-entity t "Enter Current Folder"]
94     [wl-folder-next-entity
95      wl-folder-next-entity t "Next Folder"]
96     [wl-folder-prev-entity
97      wl-folder-prev-entity t "Previous Folder"]
98     [wl-folder-check-current-entity
99      wl-folder-check-current-entity t "Check Current Folder"]
100     [wl-folder-sync-current-entity
101      wl-folder-sync-current-entity t "Sync Current Folder"]
102     [wl-draft
103      wl-draft t "Write a New Message"]
104     [wl-write-current-folder
105      wl-folder-write-current-folder t "Write for Current Folder"]
106     [wl-folder-goto-draft-folder
107      wl-folder-goto-draft-folder t "Go to Draft Folder"]
108     [wl-folder-empty-trash
109      wl-folder-empty-trash t "Empty Trash"]
110     [wl-exit
111      wl-exit t "Quit Wanderlust"]
112     )
113   "The Folder buffer toolbar.")
114
115 (defvar wl-summary-toolbar
116   '([wl-summary-read
117      wl-summary-read t "Read Messages"]
118     [wl-summary-next
119      wl-summary-next t "Next Message"]
120     [wl-summary-prev
121      wl-summary-prev t "Previous Message"]
122     [wl-summary-jump-to-current-message
123      wl-summary-jump-to-current-message t "Jump to Current Message"]
124     [wl-summary-sync-force-update
125      wl-summary-sync-force-update t "Sync Current Folder"]
126     [wl-summary-delete
127      wl-summary-delete t "Delete Current Message"]
128     [wl-summary-mark-as-important
129      wl-summary-mark-as-important t "Mark Current Message as Important"]
130     [wl-draft
131      wl-draft t "Write a New Message"]
132     [wl-write-current-folder
133      wl-summary-write-current-folder t "Write for Current Folder"]
134     [wl-summary-reply
135      wl-summary-reply t "Reply to Current Message" ]
136     [wl-summary-reply-with-citation
137      wl-summary-reply-with-citation t "Reply to Current Message with Citation"]
138     [wl-summary-forward
139      wl-summary-forward t "Forward Current Message"]
140     [wl-summary-exit
141      wl-summary-exit t "Exit Current Summary"]
142     )
143   "The Summary buffer toolbar.")
144
145 (defvar wl-message-toolbar
146   '([wl-message-read
147      wl-message-read t "Read Contents"]
148     [wl-message-next-content
149      wl-message-next-content t "Next Content"]
150     [wl-message-prev-content
151      wl-message-prev-content t "Previous Content"]
152     [wl-message-quit
153      wl-message-quit t "Back to Summary"]
154     [wl-message-play-content
155      wl-message-play-content t "Play Content"]
156     [wl-message-extract-content
157      wl-message-extract-content t "Extract Content"]
158     )
159   "The Message buffer toolbar.")
160
161 (defalias 'wl-draft-insert-signature 'insert-signature);; for draft toolbar.
162
163 (defvar wl-draft-toolbar
164   '([wl-draft-send-from-toolbar
165      wl-draft-send-from-toolbar t "Send Current Draft"]
166     [wl-draft-yank-original
167      wl-draft-yank-original t "Yank Displaying Message"]
168     [wl-draft-insert-signature
169      wl-draft-insert-signature t "Insert Signature"]
170     [wl-draft-kill
171      wl-draft-kill t "Kill Current Draft"]
172     [wl-draft-save-and-exit
173      wl-draft-save-and-exit t "Save Draft and Exit"]
174     )
175   "The Draft buffer toolbar.")
176
177 (eval-when-compile
178   (defmacro wl-e21-display-image-p ()
179     '(and (display-images-p)
180           (image-type-available-p 'xpm))))
181
182 (defun wl-e21-setup-toolbar (bar)
183   (when (and wl-use-toolbar
184              (wl-e21-display-image-p))
185     (let ((load-path (cons wl-icon-directory load-path))
186           (props '(:type xpm :ascent center
187                          :color-symbols (("backgroundToolBarColor" . "None"))
188                          :file))
189           (success t)
190           icon up down disabled name)
191       (while bar
192         (setq icon (aref (pop bar) 0))
193         (unless (boundp icon)
194           (setq name (symbol-name icon)
195                 up (find-image `((,@props ,(concat name "-up.xpm")))))
196           (if up
197               (progn
198                 (setq down (find-image `((,@props ,(concat name "-down.xpm"))))
199                       disabled (find-image
200                                 `((,@props ,(concat name "-disabled.xpm")))))
201                 (set icon (vector down up disabled disabled)))
202             (setq bar nil
203                   success nil))))
204       success)))
205
206 (defvar wl-e21-toolbar-configurations
207   '((auto-resize-tool-bars       . t)
208     (auto-raise-tool-bar-buttons . t)
209     (tool-bar-button-margin      . 0)
210     (tool-bar-button-relief      . 2)))
211
212 (defun wl-e21-make-toolbar-buttons (keymap defs)
213   (let ((configs wl-e21-toolbar-configurations)
214         config)
215     (while (setq config (pop configs))
216       (set (make-local-variable (car config)) (cdr config))))
217   ;; Invalidate the default bindings.
218   (let ((keys (cdr (key-binding [tool-bar] t)))
219         item)
220     (while (setq item (pop keys))
221       (when (setq item (car-safe item))
222         (define-key keymap (vector 'tool-bar item) 'undefined))))
223   (let ((n (length defs))
224         def)
225     (while (>= n 0)
226       (setq n (1- n)
227             def (nth n defs))
228       (define-key keymap (vector 'tool-bar (aref def 1))
229         (list 'menu-item (aref def 3) (aref def 1)
230               :enable (aref def 2)
231               :image (symbol-value (aref def 0)))))))
232
233 (defun wl-e21-setup-folder-toolbar ()
234   (when (wl-e21-setup-toolbar wl-folder-toolbar)
235     (wl-e21-make-toolbar-buttons wl-folder-mode-map wl-folder-toolbar)))
236
237 (defun wl-e21-setup-summary-toolbar ()
238   (when (wl-e21-setup-toolbar wl-summary-toolbar)
239     (wl-e21-make-toolbar-buttons wl-summary-mode-map wl-summary-toolbar)))
240
241 (eval-when-compile
242   (defsubst wl-e21-setup-draft-toolbar ()
243     (when (wl-e21-setup-toolbar wl-draft-toolbar)
244       (wl-e21-make-toolbar-buttons wl-draft-mode-map wl-draft-toolbar))))
245
246 (defun wl-e21-setup-message-toolbar ()
247   (when (wl-e21-setup-toolbar wl-message-toolbar)
248     (wl-e21-make-toolbar-buttons (current-local-map) wl-message-toolbar)))
249
250 (defvar wl-folder-toggle-icon-list
251   '((wl-folder-opened-image       . wl-opened-group-folder-icon)
252     (wl-folder-closed-image       . wl-closed-group-folder-icon)))
253
254 (eval-when-compile
255   (defsubst wl-e21-highlight-folder-group-line (start end icon numbers)
256     (when (wl-e21-display-image-p)
257       (let (overlay)
258         (let ((overlays (overlays-in start end)))
259           (while (and (setq overlay (pop overlays))
260                       (not (overlay-get overlay 'wl-e21-icon)))))
261         (unless overlay
262           (setq overlay (make-overlay start end))
263           (overlay-put overlay 'wl-e21-icon t)
264           (overlay-put overlay 'evaporate t))
265         (let ((image (get icon 'image)))
266           (unless image
267             (let ((name (symbol-value
268                          (cdr (assq icon wl-folder-toggle-icon-list))))
269                   (load-path (cons wl-icon-directory load-path)))
270               (when (setq image (find-image `((:type xpm :file ,name
271                                                      :ascent center))))
272                 (setq image (put icon 'image (propertize name
273                                                          'display image))))))
274           (overlay-put overlay 'before-string image)
275           (overlay-put overlay 'invisible (and image t))
276           (when (and wl-use-highlight-mouse-line (display-mouse-p))
277             (let ((inhibit-read-only t))
278               (put-text-property (if image
279                                      (max (1- start) (line-beginning-position))
280                                    start)
281                                  (line-end-position)
282                                  'mouse-face 'highlight)))))))
283
284   (defsubst wl-e21-highlight-folder-by-numbers (start end text-face numbers)
285     (when (display-color-p)
286       (let ((inhibit-read-only t))
287         (if (and wl-highlight-folder-by-numbers
288                  numbers (nth 0 numbers) (nth 1 numbers)
289                  (re-search-forward "[-[:digit:]]+/[-[:digit:]]+/[-[:digit:]]+"
290                                     (line-end-position) t))
291             (let* ((unsync (nth 0 numbers))
292                    (unread (nth 1 numbers))
293                    (face (cond ((and unsync (zerop unsync))
294                                 (if (and unread (zerop unread))
295                                     'wl-highlight-folder-zero-face
296                                   'wl-highlight-folder-unread-face))
297                                ((and unsync
298                                      (>= unsync
299                                          wl-folder-many-unsync-threshold))
300                                 'wl-highlight-folder-many-face)
301                                (t
302                                 'wl-highlight-folder-few-face))))
303               (if (numberp wl-highlight-folder-by-numbers)
304                   (progn
305                     (put-text-property start (match-beginning 0)
306                                        'face text-face)
307                     (put-text-property (match-beginning 0) (match-end 0)
308                                        'face face))
309                 (put-text-property start (match-end 0) 'face face)))
310           (put-text-property start (line-end-position) 'face text-face))))))
311
312 (defun wl-highlight-folder-current-line (&optional numbers)
313   (interactive)
314   (save-excursion
315     (beginning-of-line)
316     (let (fld-name start end)
317       (cond
318        (;; opened folder group
319         (looking-at wl-highlight-folder-opened-regexp)
320         (setq start (match-beginning 1)
321               end (match-end 1))
322         (wl-e21-highlight-folder-group-line start end
323                                             'wl-folder-opened-image
324                                             numbers)
325         (wl-e21-highlight-folder-by-numbers start end
326                                             'wl-highlight-folder-opened-face
327                                             numbers))
328        (;; closed folder group
329         (looking-at wl-highlight-folder-closed-regexp)
330         (setq start (match-beginning 1)
331               end (match-end 1))
332         (wl-e21-highlight-folder-group-line start end
333                                             'wl-folder-closed-image
334                                             numbers)
335         (wl-e21-highlight-folder-by-numbers start end
336                                             'wl-highlight-folder-closed-face
337                                             numbers))
338        (;; basic folder
339         (and (setq fld-name (wl-folder-get-folder-name-by-id
340                              (get-text-property (point) 'wl-folder-entity-id)))
341              (looking-at "[[:blank:]]+\\([^[:blank:]\n]+\\)"))
342         (setq start (match-beginning 1)
343               end (match-end 1))
344         (let (image)
345           (when (wl-e21-display-image-p)
346             (let (overlay)
347               (let ((overlays (overlays-in start end)))
348                 (while (and (setq overlay (pop overlays))
349                             (not (overlay-get overlay 'wl-e21-icon)))))
350               (unless overlay
351                 (setq overlay (make-overlay start end))
352                 (overlay-put overlay 'wl-e21-icon t)
353                 (overlay-put overlay 'evaporate t))
354               (let (type)
355                 (unless (get (caar wl-folder-internal-icon-list) 'image)
356                   (wl-folder-init-icons))
357                 (setq image
358                       (cond ((string= fld-name wl-trash-folder);; trash folder
359                              (let ((num (nth 2 numbers)));; number of messages
360                                (get (if (or (not num) (zerop num))
361                                         'wl-folder-trash-empty-image
362                                       'wl-folder-trash-image)
363                                     'image)))
364                             ((string= fld-name wl-draft-folder);; draft folder
365                              (get 'wl-folder-draft-image 'image))
366                             ((string= fld-name wl-queue-folder);; queue folder
367                              (get 'wl-folder-queue-image 'image))
368                             (;; and one of many other folders
369                              (setq type (elmo-folder-type fld-name))
370                              (get (intern (format "wl-folder-%s-image" type))
371                                   'image)))))
372               (overlay-put overlay 'before-string image)))
373           (when (and wl-use-highlight-mouse-line (display-mouse-p))
374             (let ((inhibit-read-only t))
375               (put-text-property (if image
376                                      (max (1- start)
377                                           (line-beginning-position))
378                                    start)
379                                  (line-end-position)
380                                  'mouse-face 'highlight))))
381         (when (display-color-p)
382           (wl-e21-highlight-folder-by-numbers
383            start end
384            (if (looking-at (format "^[[:blank:]]*\\(?:%s\\|%s\\)"
385                                    wl-folder-unsubscribe-mark
386                                    wl-folder-removed-mark))
387                'wl-highlight-folder-killed-face
388              'wl-highlight-folder-unknown-face)
389            numbers)))))))
390
391 (defun wl-highlight-plugged-current-line ()
392   (interactive)
393   (when (wl-e21-display-image-p)
394     (save-excursion
395       (beginning-of-line)
396       (when (looking-at "[[:blank:]]*\\(\\[\\([^]]+\\)\\]\\)")
397         (let* ((start (match-beginning 1))
398                (end (match-end 1))
399                (status (match-string-no-properties 2))
400                (image (if (string-equal wl-plugged-plug-on status)
401                           wl-plugged-image
402                         wl-unplugged-image)))
403           (when image
404             (let (overlay)
405               (let ((overlays (overlays-in start end)))
406                 (while (and (setq overlay (pop overlays))
407                             (not (overlay-get overlay 'wl-e21-icon)))))
408               (unless overlay
409                 (setq overlay (make-overlay start end))
410                 (overlay-put overlay 'wl-e21-icon t)
411                 (overlay-put overlay 'evaporate t))
412               (put-text-property 0 (length status) 'display image status)
413               (overlay-put overlay 'before-string status)
414               (overlay-put overlay 'invisible t))))))))
415
416 (defun wl-plugged-set-folder-icon (folder string)
417   (if (wl-e21-display-image-p)
418       (let (type)
419         (cond ((string= folder wl-queue-folder)
420                (concat (get 'wl-folder-queue-image 'image)
421                        string))
422               ((setq type (elmo-folder-type folder))
423                (concat (get (intern (format "wl-folder-%s-image"
424                                             type))
425                             'image)
426                        string))
427               (t
428                string)))
429     string))
430
431 (defvar wl-folder-internal-icon-list
432   ;; alist of (image . icon-file)
433   '((wl-folder-nntp-image         . wl-nntp-folder-icon)
434     (wl-folder-imap4-image        . wl-imap-folder-icon)
435     (wl-folder-pop3-image         . wl-pop-folder-icon)
436     (wl-folder-localdir-image     . wl-localdir-folder-icon)
437     (wl-folder-localnews-image    . wl-localnews-folder-icon)
438     (wl-folder-internal-image     . wl-internal-folder-icon)
439     (wl-folder-multi-image        . wl-multi-folder-icon)
440     (wl-folder-filter-image       . wl-filter-folder-icon)
441     (wl-folder-archive-image      . wl-archive-folder-icon)
442     (wl-folder-pipe-image         . wl-pipe-folder-icon)
443     (wl-folder-maildir-image      . wl-maildir-folder-icon)
444     (wl-folder-nmz-image          . wl-nmz-folder-icon)
445     (wl-folder-shimbun-image      . wl-shimbun-folder-icon)
446     (wl-folder-trash-empty-image  . wl-empty-trash-folder-icon)
447     (wl-folder-draft-image        . wl-draft-folder-icon)
448     (wl-folder-queue-image        . wl-queue-folder-icon)
449     (wl-folder-trash-image        . wl-trash-folder-icon)))
450
451 (defun wl-folder-init-icons ()
452   (when (wl-e21-display-image-p)
453     (let ((load-path (cons wl-icon-directory load-path))
454           (icons wl-folder-internal-icon-list)
455           icon name image)
456       (while (setq icon (pop icons))
457         (unless (get (car icon) 'image)
458           (setq name (symbol-value (cdr icon))
459                 image (find-image `((:type xpm :file ,name :ascent center))))
460           (when image
461             (put (car icon) 'image (propertize name 'display image))))))))
462
463 (defun wl-plugged-init-icons ()
464   (let ((props (when (display-mouse-p)
465                  (list 'local-map (purecopy (make-mode-line-mouse-map
466                                              'mouse-2 #'wl-toggle-plugged))
467                        'help-echo "mouse-2 toggles plugged status"))))
468     (if (wl-e21-display-image-p)
469         (progn
470           (unless wl-plugged-image
471             (let ((load-path (cons wl-icon-directory load-path)))
472               (setq wl-plugged-image (find-image
473                                       `((:type xpm
474                                                :file ,wl-plugged-icon
475                                                :ascent center)))
476                     wl-unplugged-image (find-image
477                                         `((:type xpm
478                                                  :file ,wl-unplugged-icon
479                                                  :ascent center))))))
480           (setq wl-modeline-plug-state-on
481                 (apply 'propertize wl-plug-state-indicator-on
482                        `(display ,wl-plugged-image ,@props))
483                 wl-modeline-plug-state-off
484                 (apply 'propertize wl-plug-state-indicator-off
485                        `(display ,wl-unplugged-image ,@props))))
486       (if props
487           (setq wl-modeline-plug-state-on
488                 (apply 'propertize wl-plug-state-indicator-on props)
489                 wl-modeline-plug-state-off
490                 (apply 'propertize wl-plug-state-indicator-off props))
491         (setq wl-modeline-plug-state-on wl-plug-state-indicator-on
492               wl-modeline-plug-state-off wl-plug-state-indicator-off)))))
493
494 (defun wl-biff-init-icons ()
495   (let ((props (when (display-mouse-p)
496                  (list 'local-map (purecopy (make-mode-line-mouse-map
497                                              'mouse-2 #'wl-biff-check-folders))
498                        'help-echo "mouse-2 checks new mails"))))
499     (if (wl-e21-display-image-p)
500         (progn
501           (unless wl-biff-mail-image
502             (let ((load-path (cons wl-icon-directory load-path)))
503               (setq wl-biff-mail-image (find-image
504                                         `((:type xpm
505                                                  :file ,wl-biff-mail-icon
506                                                  :ascent center)))
507                     wl-biff-nomail-image (find-image
508                                           `((:type xpm
509                                                    :file ,wl-biff-nomail-icon
510                                                    :ascent center))))))
511           (setq wl-modeline-biff-state-on
512                 (apply 'propertize wl-biff-state-indicator-on
513                        `(display ,wl-biff-mail-image ,@props))
514                 wl-modeline-biff-state-off
515                 (apply 'propertize wl-biff-state-indicator-off
516                        `(display ,wl-biff-nomail-image ,@props))))
517       (if props
518           (setq wl-modeline-biff-state-on
519                 (apply 'propertize wl-biff-state-indicator-on props)
520                 wl-modeline-biff-state-off
521                 (apply 'propertize wl-biff-state-indicator-off props))
522         (setq wl-modeline-biff-state-on wl-biff-state-indicator-on
523               wl-modeline-biff-state-off wl-biff-state-indicator-off)))))
524
525 (defun wl-make-date-string ()
526   (let ((system-time-locale "C"))
527     (format-time-string "%a, %d %b %Y %T %z")))
528
529 (defalias 'wl-setup-folder 'wl-e21-setup-folder-toolbar)
530
531 (defalias 'wl-setup-summary 'wl-e21-setup-summary-toolbar)
532
533 (defun wl-message-define-keymap ()
534   (let ((keymap (make-sparse-keymap)))
535     (define-key keymap "l" 'wl-message-toggle-disp-summary)
536     (define-key keymap [mouse-4] 'wl-message-wheel-down)
537     (define-key keymap [mouse-5] 'wl-message-wheel-up)
538     (define-key keymap [S-mouse-4] 'wl-message-wheel-down)
539     (define-key keymap [S-mouse-5] 'wl-message-wheel-up)
540     (set-keymap-parent wl-message-button-map keymap)
541     (define-key wl-message-button-map
542       [mouse-2] 'wl-message-button-dispatcher)
543     keymap))
544
545 (defalias 'wl-setup-message 'wl-e21-setup-message-toolbar)
546
547 (defun wl-message-wheel-up (event)
548   (interactive "e")
549   (if (string-match (regexp-quote wl-message-buffer-cache-name)
550                     (regexp-quote (buffer-name)))
551       (wl-message-next-page)
552     (let ((cur-buf (current-buffer))
553           proceed)
554       (save-selected-window
555         (select-window (posn-window (event-start event)))
556         (set-buffer cur-buf)
557         (setq proceed (wl-message-next-page)))
558       (if proceed
559           (if (memq 'shift (event-modifiers event))
560               (wl-summary-down t)
561             (wl-summary-next t))))))
562
563 (defun wl-message-wheel-down (event)
564   (interactive "e")
565   (if (string-match (regexp-quote wl-message-buffer-cache-name)
566                     (regexp-quote (buffer-name)))
567       (wl-message-prev-page)
568     (let ((cur-buf (current-buffer))
569           proceed)
570       (save-selected-window
571         (select-window (posn-window (event-start event)))
572         (set-buffer cur-buf)
573         (setq proceed (wl-message-prev-page)))
574       (if proceed
575           (if (memq 'shift (event-modifiers event))
576               (wl-summary-up t)
577             (wl-summary-prev t))))))
578
579 (defun wl-draft-overload-menubar ()
580   (let ((keymap (current-local-map)))
581     (define-key keymap [menu-bar mail send]
582       '("Send Message" . wl-draft-send-and-exit))
583     (define-key keymap [menu-bar mail send-stay]
584       '("Send, Keep Editing" . wl-draft-send))
585     (define-key-after (lookup-key keymap [menu-bar mail])
586       [mail-sep-send] '("--")
587       'send-stay)
588     (define-key keymap [menu-bar mail cancel]
589       '("Kill Current Draft" . wl-draft-kill))
590     (define-key-after (lookup-key keymap [menu-bar mail])
591       [save] '("Save Draft and Exit" . wl-draft-save-and-exit)
592       'cancel)
593     (define-key-after (lookup-key keymap [menu-bar mail])
594       [mail-sep-exit] '("--")
595       'save)
596     (define-key-after (lookup-key keymap [menu-bar mail])
597       [preview] '("Preview Message" . wl-draft-preview-message)
598       'mail-sep-exit)
599     (define-key keymap [menu-bar mail yank]
600       '("Cite Message" . wl-draft-yank-original))
601     (define-key keymap [menu-bar mail signature]
602       '("Insert Signature" . insert-signature))
603     (define-key keymap [menu-bar headers fcc]
604       '("Fcc" . wl-draft-fcc))))
605
606 (defun wl-draft-mode-setup ()
607   (require 'derived)
608   (define-derived-mode wl-draft-mode mail-mode "Draft"
609     "draft mode for Wanderlust derived from mail mode.
610 See info under Wanderlust for full documentation.
611
612 Special commands:
613 \\{wl-draft-mode-map}"))
614
615 (defun wl-draft-key-setup ()
616   (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
617   (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
618   (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
619   (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
620   (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
621   (define-key wl-draft-mode-map "\C-l" 'wl-draft-highlight-and-recenter)
622   (define-key wl-draft-mode-map "\C-i" 'wl-complete-field-body-or-tab)
623   (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
624   (define-key wl-draft-mode-map "\M-t" 'wl-toggle-plugged)
625   (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
626   (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
627   (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
628   (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
629   (define-key wl-draft-mode-map "\C-c\C-a" 'wl-addrmgr)
630 ;;  (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
631   (define-key wl-draft-mode-map "\C-xk"    'wl-draft-mimic-kill-buffer)
632   (define-key wl-draft-mode-map "\C-c\C-d" 'wl-draft-elide-region))
633
634 (defun wl-draft-overload-functions ()
635   (wl-mode-line-buffer-identification)
636 ;;  (local-set-key "\C-c\C-s" 'wl-draft-send);; override
637   (wl-e21-setup-draft-toolbar)
638   (wl-draft-overload-menubar))
639
640 (defalias 'wl-defface 'defface)
641
642 (defun wl-read-event-char ()
643   "Get the next event."
644   (let ((event (read-event)))
645     (cons (and (numberp event) event) event)))
646
647 (require 'product)
648 (product-provide (provide 'wl-e21) (require 'wl-version))
649
650 ;;; wl-e21.el ends here