1 ;;; wl-e21.el -- Wanderlust modules for Emacs 21.
3 ;; Copyright (C) 2000,2001 Katsumi Yamaoka <yamaoka@jpl.org>
4 ;; Copyright (C) 2000,2001 Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Author: Katsumi Yamaoka <yamaoka@jpl.org>
7 ;; Keywords: mail, net news
9 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
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)
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.
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.
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.
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*"))
45 ;; (setq from (point))
46 ;; (insert "-fj.wanderlust:0/0/0")
49 ;; (setq overlay (make-overlay from to))
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))
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.
70 (require 'wl-highlight)
71 (defvar-maybe wl-folder-mode-map (make-sparse-keymap))
72 (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
74 (add-hook 'wl-folder-mode-hook 'wl-setup-folder)
75 (add-hook 'wl-folder-mode-hook 'wl-folder-init-icons)
77 (add-hook 'wl-init-hook 'wl-biff-init-icons)
78 (add-hook 'wl-init-hook 'wl-plugged-init-icons)
80 (add-hook 'wl-summary-mode-hook 'wl-setup-summary)
82 (defvar wl-use-toolbar (image-type-available-p 'xpm))
83 (defvar wl-plugged-image nil)
84 (defvar wl-unplugged-image nil)
85 (defvar wl-biff-mail-image nil)
86 (defvar wl-biff-nomail-image nil)
88 (defvar wl-folder-toolbar
89 '([wl-folder-jump-to-current-entity
90 wl-folder-jump-to-current-entity t "Enter Current Folder"]
91 [wl-folder-next-entity
92 wl-folder-next-entity t "Next Folder"]
93 [wl-folder-prev-entity
94 wl-folder-prev-entity t "Previous Folder"]
95 [wl-folder-check-current-entity
96 wl-folder-check-current-entity t "Check Current Folder"]
98 ;; wl-draft t "Write a New Message"]
99 [wl-folder-sync-current-entity
100 wl-folder-sync-current-entity t "Sync Current Folder"]
102 wl-draft t "Write a New Message"]
103 [wl-folder-empty-trash
104 wl-folder-empty-trash t "Empty Trash"]
106 wl-exit t "Quit Wanderlust"]
108 "The Folder buffer toolbar.")
110 (defvar wl-summary-toolbar
112 wl-summary-read t "Read Messages"]
114 wl-summary-next t "Next Message"]
116 wl-summary-prev t "Previous Message"]
117 [wl-summary-jump-to-current-message
118 wl-summary-jump-to-current-message t "Jump to Current Message"]
119 [wl-summary-sync-force-update
120 wl-summary-sync-force-update t "Sync Current Folder"]
122 wl-summary-delete t "Delete Current Message"]
123 [wl-summary-mark-as-important
124 wl-summary-mark-as-important t "Mark Current Message as Important"]
126 wl-draft t "Write a New Message"]
128 wl-summary-reply t "Reply to Current Message" ]
129 [wl-summary-reply-with-citation
130 wl-summary-reply-with-citation t "Reply to Current Message with Citation"]
132 wl-summary-forward t "Forward Current Message"]
134 wl-summary-exit t "Exit Current Summary"]
136 "The Summary buffer toolbar.")
138 (defvar wl-message-toolbar
140 wl-message-read t "Read Contents"]
141 [wl-message-next-content
142 wl-message-next-content t "Next Content"]
143 [wl-message-prev-content
144 wl-message-prev-content t "Previous Content"]
146 wl-message-quit t "Back to Summary"]
147 [wl-message-play-content
148 wl-message-play-content t "Play Content"]
149 [wl-message-extract-content
150 wl-message-extract-content t "Extract Content"]
152 "The Message buffer toolbar.")
154 (defalias 'wl-draft-insert-signature 'insert-signature);; for draft toolbar.
156 (defvar wl-draft-toolbar
157 '([wl-draft-send-from-toolbar
158 wl-draft-send-from-toolbar t "Send Current Draft"]
159 [wl-draft-yank-original
160 wl-draft-yank-original t "Yank Displaying Message"]
161 [wl-draft-insert-signature
162 wl-draft-insert-signature t "Insert Signature"]
164 wl-draft-kill t "Kill Current Draft"]
166 "The Draft buffer toolbar.")
169 (defmacro wl-e21-display-image-p ()
170 '(and (display-graphic-p)
171 (image-type-available-p 'xpm))))
173 (defun wl-e21-setup-toolbar (bar)
174 (when (and wl-use-toolbar
175 (wl-e21-display-image-p))
176 (let ((load-path (cons wl-icon-dir load-path))
177 (props '(:type xpm :ascent center
178 :color-symbols (("backgroundToolBarColor" . "None"))
181 icon up down disabled name success)
183 (setq icon (aref (pop bar) 0))
184 (unless (boundp icon)
185 (setq name (symbol-name icon)
186 up (find-image `((,@props ,(concat name "-up.xpm")))))
189 (setq down (find-image `((,@props ,(concat name "-down.xpm"))))
191 `((,@props ,(concat name "-disabled.xpm")))))
192 (set icon (vector down up disabled disabled)))
197 (defvar wl-e21-toolbar-configurations
198 '((auto-resize-tool-bar . t)
199 (auto-raise-tool-bar-buttons . t)
200 (tool-bar-button-margin . 0)
201 (tool-bar-button-relief . 2)))
203 (defun wl-e21-make-toolbar-buttons (keymap defs)
204 (let ((configs wl-e21-toolbar-configurations)
206 (while (setq config (pop configs))
207 (set (make-local-variable (car config)) (cdr config))))
208 ;; Invalidate the default bindings.
209 (let ((keys (cdr (key-binding [tool-bar] t)))
211 (while (setq item (pop keys))
212 (when (setq item (car-safe item))
213 (define-key keymap (vector 'tool-bar item) 'undefined))))
214 (let ((n (length defs))
219 (define-key keymap (vector 'tool-bar (aref def 1))
220 (list 'menu-item (aref def 3) (aref def 1)
222 :image (symbol-value (aref def 0)))))))
224 (defun wl-e21-setup-folder-toolbar ()
225 (when (wl-e21-setup-toolbar wl-folder-toolbar)
226 (wl-e21-make-toolbar-buttons wl-folder-mode-map wl-folder-toolbar)))
228 (defun wl-e21-setup-summary-toolbar ()
229 (when (wl-e21-setup-toolbar wl-summary-toolbar)
230 (wl-e21-make-toolbar-buttons wl-summary-mode-map wl-summary-toolbar)))
233 (defsubst wl-e21-setup-message-toolbar (keymap)
234 (when (wl-e21-setup-toolbar wl-message-toolbar)
235 (wl-e21-make-toolbar-buttons keymap wl-message-toolbar)))
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))))
241 (defvar wl-folder-toggle-icon-list
242 '((wl-folder-opened-image . wl-opened-group-folder-icon)
243 (wl-folder-closed-image . wl-closed-group-folder-icon)))
246 (defsubst wl-e21-highlight-folder-group-line (start end icon numbers)
247 (when (wl-e21-display-image-p)
249 (let ((overlays (overlays-in start end)))
250 (while (and (setq overlay (pop overlays))
251 (not (overlay-get overlay 'wl-e21-icon)))))
253 (setq overlay (make-overlay start end))
254 (overlay-put overlay 'wl-e21-icon t)
255 (overlay-put overlay 'evaporate t))
256 (let ((image (get icon 'image)))
258 (let ((name (symbol-value
259 (cdr (assq icon wl-folder-toggle-icon-list))))
260 (load-path (cons wl-icon-dir load-path)))
261 (when (setq image (find-image `((:type xpm :file ,name
263 (setq image (put icon 'image (propertize name
265 (overlay-put overlay 'before-string image)
266 (overlay-put overlay 'invisible (and image t))
267 (when (and wl-use-highlight-mouse-line (display-mouse-p))
268 (let ((inhibit-read-only t))
269 (put-text-property (if image
270 (max (1- start) (line-beginning-position))
273 'mouse-face 'highlight)))))))
275 (defsubst wl-e21-highlight-folder-by-numbers (start end text-face numbers)
276 (when (display-color-p)
277 (let ((inhibit-read-only t))
278 (if (and wl-highlight-folder-by-numbers
279 numbers (nth 0 numbers) (nth 1 numbers)
280 (re-search-forward "[0-9-]+/[0-9-]+/[0-9-]+"
281 (line-end-position) t))
282 (let* ((unsync (nth 0 numbers))
283 (unread (nth 1 numbers))
284 (face (cond ((and unsync (zerop unsync))
285 (if (and unread (zerop unread))
286 'wl-highlight-folder-zero-face
287 'wl-highlight-folder-unread-face))
290 wl-folder-many-unsync-threshold))
291 'wl-highlight-folder-many-face)
293 'wl-highlight-folder-few-face))))
294 (if (numberp wl-highlight-folder-by-numbers)
296 (put-text-property start (match-beginning 0)
298 (put-text-property (match-beginning 0) (match-end 0)
300 (put-text-property start (match-end 0) 'face face)))
301 (put-text-property start (line-end-position) 'face text-face))))))
303 (defun wl-highlight-folder-current-line (&optional numbers)
307 (let (fld-name start end)
309 (;; opened folder group
310 (looking-at wl-highlight-folder-opened-regexp)
311 (setq start (match-beginning 1)
313 (wl-e21-highlight-folder-group-line start end
314 'wl-folder-opened-image
316 (wl-e21-highlight-folder-by-numbers start end
317 'wl-highlight-folder-opened-face
319 (;; closed folder group
320 (looking-at wl-highlight-folder-closed-regexp)
321 (setq start (match-beginning 1)
323 (wl-e21-highlight-folder-group-line start end
324 'wl-folder-closed-image
326 (wl-e21-highlight-folder-by-numbers start end
327 'wl-highlight-folder-closed-face
330 (and (setq fld-name (wl-folder-get-folder-name-by-id
331 (get-text-property (point) 'wl-folder-entity-id)))
332 (looking-at "[\t ]+\\([^\t\n ]+\\)"))
333 (setq start (match-beginning 1)
336 (when (wl-e21-display-image-p)
338 (let ((overlays (overlays-in start end)))
339 (while (and (setq overlay (pop overlays))
340 (not (overlay-get overlay 'wl-e21-icon)))))
342 (setq overlay (make-overlay start end))
343 (overlay-put overlay 'wl-e21-icon t)
344 (overlay-put overlay 'evaporate t))
346 (unless (get (caar wl-folder-internal-icon-list) 'image)
347 (wl-folder-init-icons))
349 (cond ((string= fld-name wl-trash-folder);; trash folder
350 (let ((num (nth 2 numbers)));; number of messages
351 (get (if (or (not num) (zerop num))
352 'wl-folder-trash-empty-image
353 'wl-folder-trash-image)
355 ((string= fld-name wl-draft-folder);; draft folder
356 (get 'wl-folder-draft-image 'image))
357 ((string= fld-name wl-queue-folder);; queue folder
358 (get 'wl-folder-queue-image 'image))
359 (;; and one of many other folders
360 (setq type (elmo-folder-get-type fld-name))
361 (get (intern (format "wl-folder-%s-image" type))
363 (overlay-put overlay 'before-string image)))
364 (when (and wl-use-highlight-mouse-line (display-mouse-p))
365 (let ((inhibit-read-only t))
366 (put-text-property (if image
368 (line-beginning-position))
371 'mouse-face 'highlight))))
372 (when (display-color-p)
373 (wl-e21-highlight-folder-by-numbers
375 (if (looking-at (format "^[\t ]*\\(%s\\|%s\\)"
376 wl-folder-unsubscribe-mark
377 wl-folder-removed-mark))
378 'wl-highlight-folder-killed-face
379 'wl-highlight-folder-unknown-face)
382 (defun wl-highlight-plugged-current-line ()
384 (when (wl-e21-display-image-p)
387 (when (looking-at "[\t ]*\\(\\[\\([^]]+\\)\\]\\)")
388 (let* ((start (match-beginning 1))
390 (status (match-string-no-properties 2))
391 (image (if (string-equal wl-plugged-plug-on status)
393 wl-unplugged-image)))
396 (let ((overlays (overlays-in start end)))
397 (while (and (setq overlay (pop overlays))
398 (not (overlay-get overlay 'wl-e21-icon)))))
400 (setq overlay (make-overlay start end))
401 (overlay-put overlay 'wl-e21-icon t)
402 (overlay-put overlay 'evaporate t))
403 (put-text-property 0 (length status) 'display image status)
404 (overlay-put overlay 'before-string status)
405 (overlay-put overlay 'invisible t))))))))
407 (defun wl-plugged-set-folder-icon (folder string)
408 (if (wl-e21-display-image-p)
410 (cond ((string= folder wl-queue-folder)
411 (concat (propertize " " 'display
412 (get 'wl-folder-queue-image 'image))
414 ((setq type (elmo-folder-get-type folder))
415 (concat (propertize " " 'display
416 (get (intern (format "wl-folder-%s-image"
424 (defvar wl-folder-internal-icon-list
425 ;; alist of (image . icon-file)
426 '((wl-folder-nntp-image . wl-nntp-folder-icon)
427 (wl-folder-imap4-image . wl-imap-folder-icon)
428 (wl-folder-pop3-image . wl-pop-folder-icon)
429 (wl-folder-localdir-image . wl-localdir-folder-icon)
430 (wl-folder-localnews-image . wl-localnews-folder-icon)
431 (wl-folder-internal-image . wl-internal-folder-icon)
432 (wl-folder-multi-image . wl-multi-folder-icon)
433 (wl-folder-filter-image . wl-filter-folder-icon)
434 (wl-folder-archive-image . wl-archive-folder-icon)
435 (wl-folder-pipe-image . wl-pipe-folder-icon)
436 (wl-folder-maildir-image . wl-maildir-folder-icon)
437 (wl-folder-trash-empty-image . wl-empty-trash-folder-icon)
438 (wl-folder-draft-image . wl-draft-folder-icon)
439 (wl-folder-queue-image . wl-queue-folder-icon)
440 (wl-folder-trash-image . wl-trash-folder-icon)))
442 (defun wl-folder-init-icons ()
443 (when (wl-e21-display-image-p)
444 (let ((load-path (cons wl-icon-dir load-path))
445 (icons wl-folder-internal-icon-list)
447 (while (setq icon (pop icons))
448 (unless (get (car icon) 'image)
449 (setq name (symbol-value (cdr icon))
450 image (find-image `((:type xpm :file ,name :ascent center))))
452 (put (car icon) 'image (propertize name 'display image))))))))
454 (defun wl-plugged-init-icons ()
455 (let ((props (when (display-mouse-p)
456 (list 'local-map (purecopy (make-mode-line-mouse2-map
457 #'wl-toggle-plugged))
458 'help-echo "mouse-2 toggles plugged status"))))
459 (if (wl-e21-display-image-p)
461 (unless wl-plugged-image
462 (let ((load-path (cons wl-icon-dir load-path)))
463 (setq wl-plugged-image (find-image
465 :file ,wl-plugged-icon
467 wl-unplugged-image (find-image
469 :file ,wl-unplugged-icon
471 (setq wl-modeline-plug-state-on
472 (apply 'propertize wl-plug-state-indicator-on
473 `(display ,wl-plugged-image ,@props))
474 wl-modeline-plug-state-off
475 (apply 'propertize wl-plug-state-indicator-off
476 `(display ,wl-unplugged-image ,@props))))
478 (setq wl-modeline-plug-state-on
479 (apply 'propertize wl-plug-state-indicator-on props)
480 wl-modeline-plug-state-off
481 (apply 'propertize wl-plug-state-indicator-off props))
482 (setq wl-modeline-plug-state-on wl-plug-state-indicator-on
483 wl-modeline-plug-state-off wl-plug-state-indicator-off)))))
485 (defun wl-biff-init-icons ()
486 (let ((props (when (display-mouse-p)
487 (list 'local-map (purecopy (make-mode-line-mouse2-map
488 #'wl-biff-check-folders))
489 'help-echo "mouse-2 checks new mails"))))
490 (if (wl-e21-display-image-p)
492 (unless wl-biff-mail-image
493 (let ((load-path (cons wl-icon-dir load-path)))
494 (setq wl-biff-mail-image (find-image
496 :file ,wl-biff-mail-icon
498 wl-biff-nomail-image (find-image
500 :file ,wl-biff-nomail-icon
502 (setq wl-modeline-biff-state-on
503 (apply 'propertize wl-biff-state-indicator-on
504 `(display ,wl-biff-mail-image ,@props))
505 wl-modeline-biff-state-off
506 (apply 'propertize wl-biff-state-indicator-off
507 `(display ,wl-biff-nomail-image ,@props))))
509 (setq wl-modeline-biff-state-on
510 (apply 'propertize wl-biff-state-indicator-on props)
511 wl-modeline-biff-state-off
512 (apply 'propertize wl-biff-state-indicator-off props))
513 (setq wl-modeline-biff-state-on wl-biff-state-indicator-on
514 wl-modeline-biff-state-off wl-biff-state-indicator-off)))))
516 (defun wl-make-date-string ()
517 (let ((system-time-locale "C"))
518 (format-time-string "%a, %d %b %Y %T %z")))
520 (defalias 'wl-setup-folder 'wl-e21-setup-folder-toolbar)
522 (defalias 'wl-setup-summary 'wl-e21-setup-summary-toolbar)
524 (defun wl-message-overload-functions ()
525 (let ((keymap (current-local-map)))
527 (wl-e21-setup-message-toolbar keymap)
528 (define-key keymap "l" 'wl-message-toggle-disp-summary)
529 (define-key keymap [mouse-2] 'wl-message-refer-article-or-url)
530 (define-key keymap [mouse-4] 'wl-message-wheel-down)
531 (define-key keymap [mouse-5] 'wl-message-wheel-up)
532 (define-key keymap [S-mouse-4] 'wl-message-wheel-down)
533 (define-key keymap [S-mouse-5] 'wl-message-wheel-up)
534 (set-keymap-parent wl-message-button-map keymap)
535 (define-key wl-message-button-map
536 [mouse-2] 'wl-message-button-dispatcher))))
538 (defun wl-message-wheel-up (event)
540 (if (string-match wl-message-buf-name (buffer-name))
541 (wl-message-next-page)
542 (let ((cur-buf (current-buffer))
544 (save-selected-window
545 (select-window (posn-window (event-start event)))
547 (setq proceed (wl-message-next-page)))
549 (if (memq 'shift (event-modifiers event))
551 (wl-summary-next t))))))
553 (defun wl-message-wheel-down (event)
555 (if (string-match wl-message-buf-name (buffer-name))
556 (wl-message-prev-page)
557 (let ((cur-buf (current-buffer))
559 (save-selected-window
560 (select-window (posn-window (event-start event)))
562 (setq proceed (wl-message-prev-page)))
564 (if (memq 'shift (event-modifiers event))
566 (wl-summary-prev t))))))
568 (defun wl-draft-overload-menubar ()
569 (let ((keymap (current-local-map)))
570 (define-key keymap [menu-bar mail send]
571 '("Send Message" . wl-draft-send-and-exit))
572 (define-key keymap [menu-bar mail send-stay]
573 '("Send, Keep Editing" . wl-draft-send))
574 (define-key keymap [menu-bar mail cancel]
575 '("Kill Current Draft" . wl-draft-kill))
576 (define-key keymap [menu-bar mail yank]
577 '("Cite Message" . wl-draft-yank-original))
578 (define-key keymap [menu-bar mail signature]
579 '("Insert Signature" . insert-signature))
580 (define-key keymap [menu-bar headers fcc]
581 '("Fcc" . wl-draft-fcc))))
583 (defun wl-draft-mode-setup ()
585 (define-derived-mode wl-draft-mode mail-mode "Draft"
586 "draft mode for Wanderlust derived from mail mode.
587 See info under Wanderlust for full documentation.
590 \\{wl-draft-mode-map}"))
592 (defun wl-draft-key-setup ()
593 (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
594 (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
595 (define-key wl-draft-mode-map "\C-c\C-a" 'wl-draft-insert-x-face-field)
596 (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
597 (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
598 (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
599 (define-key wl-draft-mode-map "\C-l" 'wl-draft-highlight-and-recenter)
600 (define-key wl-draft-mode-map "\C-i" 'wl-complete-field-body-or-tab)
601 (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
602 (define-key wl-draft-mode-map "\M-t" 'wl-toggle-plugged)
603 (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
604 (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
605 (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
606 (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
607 (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
608 (define-key wl-draft-mode-map "\C-xk" 'wl-draft-mimic-kill-buffer))
610 (defun wl-draft-overload-functions ()
611 (wl-mode-line-buffer-identification)
612 (local-set-key "\C-c\C-s" 'wl-draft-send);; override
613 (wl-e21-setup-draft-toolbar)
614 (wl-draft-overload-menubar))
616 (defalias 'wl-defface 'defface)
618 (defun wl-read-event-char ()
619 "Get the next event."
620 (let ((event (read-event)))
621 (cons (and (numberp event) event) event)))
624 (product-provide (provide 'wl-e21) (require 'wl-version))
626 ;;; wl-e21.el ends here