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