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