1 ;;; wl-e21.el -- Wanderlust modules for Emacs 21.
3 ;; Copyright (C) 2000 Katsumi Yamaoka <yamaoka@jpl.org>
4 ;; Copyright (C) 2000 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))
66 (require 'wl-highlight)
67 (defvar-maybe wl-folder-mode-map (make-sparse-keymap))
68 (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
70 (add-hook 'wl-folder-mode-hook 'wl-setup-folder)
71 (add-hook 'wl-folder-mode-hook 'wl-folder-init-icons)
73 (add-hook 'wl-init-hook 'wl-biff-init-icons)
74 (add-hook 'wl-init-hook 'wl-plugged-init-icons)
76 (add-hook 'wl-summary-mode-hook 'wl-setup-summary)
78 (defvar wl-use-toolbar (image-type-available-p 'xpm))
79 (defvar wl-plugged-image nil)
80 (defvar wl-unplugged-image nil)
81 (defvar wl-biff-mail-image nil)
82 (defvar wl-biff-nomail-image nil)
84 (defvar wl-folder-toolbar
85 '([wl-folder-jump-to-current-entity
86 wl-folder-jump-to-current-entity t "Enter Current Folder"]
87 [wl-folder-next-entity
88 wl-folder-next-entity t "Next Folder"]
89 [wl-folder-prev-entity
90 wl-folder-prev-entity t "Previous Folder"]
91 [wl-folder-check-current-entity
92 wl-folder-check-current-entity t "Check Current Folder"]
94 ;; wl-draft t "Write a New Message"]
95 [wl-folder-sync-current-entity
96 wl-folder-sync-current-entity t "Sync Current Folder"]
98 wl-draft t "Write a New Message"]
99 [wl-folder-empty-trash
100 wl-folder-empty-trash t "Empty Trash"]
102 wl-exit t "Quit Wanderlust"]
104 "The Folder buffer toolbar.")
106 (defvar wl-summary-toolbar
108 wl-summary-read t "Read Messages"]
110 wl-summary-next t "Next Message"]
112 wl-summary-prev t "Previous Message"]
113 [wl-summary-jump-to-current-message
114 wl-summary-jump-to-current-message t "Jump to Current Message"]
115 [wl-summary-sync-force-update
116 wl-summary-sync-force-update t "Sync Current Folder"]
118 wl-summary-delete t "Delete Current Message"]
119 [wl-summary-mark-as-important
120 wl-summary-mark-as-important t "Mark Current Message as Important"]
122 wl-draft t "Write a New Message"]
124 wl-summary-reply t "Reply to Current Message" ]
125 [wl-summary-reply-with-citation
126 wl-summary-reply-with-citation t "Reply to Current Message with Citation"]
128 wl-summary-forward t "Forward Current Message"]
130 wl-summary-exit t "Exit Current Summary"]
132 "The Summary buffer toolbar.")
134 (defvar wl-message-toolbar
136 wl-message-read t "Read Contents"]
137 [wl-message-next-content
138 wl-message-next-content t "Next Content"]
139 [wl-message-prev-content
140 wl-message-prev-content t "Previous Content"]
142 wl-message-quit t "Back to Summary"]
143 [wl-message-play-content
144 wl-message-play-content t "Play Content"]
145 [wl-message-extract-content
146 wl-message-extract-content t "Extract Content"]
148 "The Message buffer toolbar.")
150 (defalias 'wl-draft-insert-signature 'insert-signature);; for draft toolbar.
152 (defvar wl-draft-toolbar
153 '([wl-draft-send-from-toolbar
154 wl-draft-send-from-toolbar t "Send Current Draft"]
155 [wl-draft-yank-original
156 wl-draft-yank-original t "Yank Displaying Message"]
157 [wl-draft-insert-signature
158 wl-draft-insert-signature t "Insert Signature"]
160 wl-draft-kill t "Kill Current Draft"]
162 "The Draft buffer toolbar.")
164 (defun wl-e21-setup-toolbar (bar)
165 (let ((load-path (cons wl-icon-dir load-path))
166 (props '(:type xpm :ascent center
167 :color-symbols (("backgroundToolBarColor" . "None"))
170 icon up down disabled name success)
172 (setq icon (aref (pop bar) 0))
173 (unless (boundp icon)
174 (setq name (symbol-name icon)
175 up (find-image `((,@props ,(concat name "-up.xpm")))))
178 (setq down (find-image `((,@props ,(concat name "-down.xpm"))))
179 disabled (find-image `((,@props
180 ,(concat name "-disabled.xpm")))))
181 (set icon (vector down up disabled disabled)))
186 (defvar wl-e21-toolbar-configurations
187 '((auto-resize-tool-bar . t)
188 (auto-raise-tool-bar-buttons . t)
189 (tool-bar-button-margin . 0)
190 (tool-bar-button-relief . 2)))
192 (defun wl-e21-make-toolbar-buttons (keymap defs)
193 (let ((configs wl-e21-toolbar-configurations)
195 (while (setq config (pop configs))
196 (set (make-local-variable (car config)) (cdr config))))
197 ;; Invalidate the default bindings.
198 (let ((keys (cdr (key-binding [tool-bar] t)))
200 (while (setq item (pop keys))
201 (when (setq item (car-safe item))
202 (define-key keymap (vector 'tool-bar item) 'undefined))))
203 (let ((n (length defs))
208 (define-key keymap (vector 'tool-bar (aref def 1))
209 (list 'menu-item (aref def 3) (aref def 1)
211 :image (symbol-value (aref def 0)))))))
213 (defun wl-e21-setup-folder-toolbar ()
216 (wl-e21-setup-toolbar wl-folder-toolbar)
217 (wl-e21-make-toolbar-buttons wl-folder-mode-map wl-folder-toolbar)))
219 (defun wl-e21-setup-summary-toolbar ()
222 (wl-e21-setup-toolbar wl-summary-toolbar)
223 (wl-e21-make-toolbar-buttons wl-summary-mode-map wl-summary-toolbar)))
226 (defsubst wl-e21-setup-message-toolbar (keymap)
229 (wl-e21-setup-toolbar wl-message-toolbar)
230 (wl-e21-make-toolbar-buttons keymap wl-message-toolbar)))
232 (defsubst wl-e21-setup-draft-toolbar ()
235 (wl-e21-setup-toolbar wl-draft-toolbar)
236 (wl-e21-make-toolbar-buttons wl-draft-mode-map wl-draft-toolbar))))
238 (defvar wl-folder-toggle-icon-list
239 '((wl-folder-opened-image . wl-opened-group-folder-icon)
240 (wl-folder-closed-image . wl-closed-group-folder-icon)))
243 (defsubst wl-e21-highlight-folder-group-line (start end icon numbers)
244 (when (display-graphic-p)
246 (let ((overlays (overlays-in start end)))
247 (while (and (setq overlay (pop overlays))
248 (not (overlay-get overlay 'wl-e21-icon)))))
250 (setq overlay (make-overlay start end))
251 (overlay-put overlay 'wl-e21-icon t)
252 (overlay-put overlay 'evaporate t))
253 (let ((image (get icon 'image)))
255 (let ((name (symbol-value
256 (cdr (assq icon wl-folder-toggle-icon-list))))
257 (load-path (cons wl-icon-dir load-path)))
258 (when (setq image (find-image `((:type xpm :file ,name
260 (setq image (put icon 'image (propertize name
262 (overlay-put overlay 'before-string image)
263 (overlay-put overlay 'invisible (and image t))
264 (when (and wl-use-highlight-mouse-line (display-mouse-p))
265 (let ((inhibit-read-only t))
266 (put-text-property (if image
267 (max (1- start) (line-beginning-position))
270 'mouse-face 'highlight)))))))
272 (defsubst wl-e21-highlight-folder-by-numbers (start end text-face numbers)
273 (when (display-color-p)
274 (let ((inhibit-read-only t))
275 (if (and wl-highlight-folder-by-numbers
276 numbers (nth 0 numbers) (nth 1 numbers)
277 (re-search-forward "[0-9-]+/[0-9-]+/[0-9-]+"
278 (line-end-position) t))
279 (let* ((unsync (nth 0 numbers))
280 (unread (nth 1 numbers))
281 (face (cond ((and unsync (zerop unsync))
282 (if (and unread (zerop unread))
283 'wl-highlight-folder-zero-face
284 'wl-highlight-folder-unread-face))
287 wl-folder-many-unsync-threshold))
288 'wl-highlight-folder-many-face)
290 'wl-highlight-folder-few-face))))
291 (if (numberp wl-highlight-folder-by-numbers)
293 (put-text-property start (match-beginning 0)
295 (put-text-property (match-beginning 0) (match-end 0)
297 (put-text-property start (match-end 0) 'face face)))
298 (put-text-property start (line-end-position) 'face text-face))))))
300 (defun wl-highlight-folder-current-line (&optional numbers)
304 (let (fld-name start end)
306 (;; opened folder group
307 (looking-at wl-highlight-folder-opened-regexp)
308 (setq start (match-beginning 1)
310 (wl-e21-highlight-folder-group-line start end
311 'wl-folder-opened-image
313 (wl-e21-highlight-folder-by-numbers start end
314 'wl-highlight-folder-opened-face
316 (;; closed folder group
317 (looking-at wl-highlight-folder-closed-regexp)
318 (setq start (match-beginning 1)
320 (wl-e21-highlight-folder-group-line start end
321 'wl-folder-closed-image
323 (wl-e21-highlight-folder-by-numbers start end
324 'wl-highlight-folder-closed-face
327 (and (setq fld-name (wl-folder-get-folder-name-by-id
328 (get-text-property (point) 'wl-folder-entity-id)))
329 (looking-at "[\t ]+\\([^\t\n ]+\\)"))
330 (setq start (match-beginning 1)
333 (when (display-graphic-p)
335 (let ((overlays (overlays-in start end)))
336 (while (and (setq overlay (pop overlays))
337 (not (overlay-get overlay 'wl-e21-icon)))))
339 (setq overlay (make-overlay start end))
340 (overlay-put overlay 'wl-e21-icon t)
341 (overlay-put overlay 'evaporate t))
344 (cond ((string= fld-name wl-trash-folder);; trash folder
345 (let ((num (nth 2 numbers)));; number of messages
346 (get (if (or (not num) (zerop num))
347 'wl-folder-trash-empty-image
348 'wl-folder-trash-image)
350 ((string= fld-name wl-draft-folder);; draft folder
351 (get 'wl-folder-draft-image 'image))
352 ((string= fld-name wl-queue-folder);; queue folder
353 (get 'wl-folder-queue-image 'image))
354 (;; and one of many other folders
355 (setq type (elmo-folder-get-type fld-name))
356 (get (intern (format "wl-folder-%s-image" type))
358 (overlay-put overlay 'before-string image)))
359 (when (and wl-use-highlight-mouse-line (display-mouse-p))
360 (let ((inhibit-read-only t))
361 (put-text-property (if image
363 (line-beginning-position))
366 'mouse-face 'highlight))))
367 (when (display-color-p)
368 (wl-e21-highlight-folder-by-numbers
370 (if (looking-at (format "^[\t ]*\\(%s\\|%s\\)"
371 wl-folder-unsubscribe-mark
372 wl-folder-removed-mark))
373 'wl-highlight-folder-killed-face
374 'wl-highlight-folder-unknown-face)
377 (defun wl-highlight-plugged-current-line ()
379 (when (display-graphic-p)
382 (when (looking-at "[\t ]*\\(\\[\\([^]]+\\)\\]\\)")
383 (let* ((start (match-beginning 1))
385 (status (match-string-no-properties 2))
386 (image (if (string-equal wl-plugged-plug-on status)
388 wl-unplugged-image)))
391 (let ((overlays (overlays-in start end)))
392 (while (and (setq overlay (pop overlays))
393 (not (overlay-get overlay 'wl-e21-icon)))))
395 (setq overlay (make-overlay start end))
396 (overlay-put overlay 'wl-e21-icon t)
397 (overlay-put overlay 'evaporate t))
398 (put-text-property 0 (length status) 'display image status)
399 (overlay-put overlay 'before-string status)
400 (overlay-put overlay 'invisible t))))))))
402 (defun wl-plugged-set-folder-icon (folder string)
403 (if (display-graphic-p)
405 (cond ((string= folder wl-queue-folder)
406 (concat (propertize " " 'display
407 (get 'wl-folder-queue-image 'image))
409 ((setq type (elmo-folder-get-type folder))
410 (concat (propertize " " 'display
411 (get (intern (format "wl-folder-%s-image"
419 (defvar wl-folder-internal-icon-list
420 ;; alist of (image . icon-file)
421 '((wl-folder-nntp-image . wl-nntp-folder-icon)
422 (wl-folder-imap4-image . wl-imap-folder-icon)
423 (wl-folder-pop3-image . wl-pop-folder-icon)
424 (wl-folder-localdir-image . wl-localdir-folder-icon)
425 (wl-folder-localnews-image . wl-localnews-folder-icon)
426 (wl-folder-internal-image . wl-internal-folder-icon)
427 (wl-folder-multi-image . wl-multi-folder-icon)
428 (wl-folder-filter-image . wl-filter-folder-icon)
429 (wl-folder-archive-image . wl-archive-folder-icon)
430 (wl-folder-pipe-image . wl-pipe-folder-icon)
431 (wl-folder-maildir-image . wl-maildir-folder-icon)
432 (wl-folder-trash-empty-image . wl-empty-trash-folder-icon)
433 (wl-folder-draft-image . wl-draft-folder-icon)
434 (wl-folder-queue-image . wl-queue-folder-icon)
435 (wl-folder-trash-image . wl-trash-folder-icon)))
437 (defun wl-folder-init-icons ()
438 (let ((load-path (cons wl-icon-dir load-path))
439 (icons wl-folder-internal-icon-list)
441 (while (setq icon (pop icons))
442 (unless (get (car icon) 'image)
443 (setq name (symbol-value (cdr icon))
444 image (find-image `((:type xpm :file ,name :ascent center))))
446 (put (car icon) 'image (propertize name 'display image)))))))
448 (defun wl-plugged-init-icons ()
449 (unless wl-plugged-image
450 (let ((load-path (cons wl-icon-dir load-path)))
451 (setq wl-plugged-image (find-image `((:type xpm
452 :file ,wl-plugged-icon
454 wl-unplugged-image (find-image `((:type xpm
455 :file ,wl-unplugged-icon
457 (if (display-mouse-p)
458 (let ((props (list 'local-map (purecopy (make-mode-line-mouse2-map
459 #'wl-toggle-plugged))
460 'help-echo "mouse-2 toggles plugged status")))
461 (if (display-graphic-p)
462 (setq wl-modeline-plug-state-on
463 (apply 'propertize wl-plug-state-indicator-on
464 `(display ,wl-plugged-image ,@props))
465 wl-modeline-plug-state-off
466 (apply 'propertize wl-plug-state-indicator-off
467 `(display ,wl-unplugged-image ,@props)))
468 (setq wl-modeline-plug-state-on
469 (apply 'propertize wl-plug-state-indicator-on props)
470 wl-modeline-plug-state-off
471 (apply 'propertize wl-plug-state-indicator-off props))))
472 (setq wl-modeline-plug-state-on wl-plug-state-indicator-on
473 wl-modeline-plug-state-off wl-plug-state-indicator-off)))
475 (defun wl-biff-init-icons ()
476 (unless wl-biff-mail-image
477 (let ((load-path (cons wl-icon-dir load-path)))
478 (setq wl-biff-mail-image (find-image
479 `((:type xpm :file ,wl-biff-mail-icon
481 wl-biff-nomail-image (find-image
482 `((:type xpm :file ,wl-biff-nomail-icon
484 (if (display-mouse-p)
485 (let ((props (list 'local-map (purecopy (make-mode-line-mouse2-map
488 'wl-biff-check-folders))))
489 'help-echo "mouse-2 checks new mails")))
490 (if (display-graphic-p)
491 (setq wl-modeline-biff-state-on
492 (apply 'propertize wl-biff-state-indicator-on
493 `(display ,wl-biff-mail-image ,@props))
494 wl-modeline-biff-state-off
495 (apply 'propertize wl-biff-state-indicator-off
496 `(display ,wl-biff-nomail-image ,@props)))
497 (setq wl-modeline-biff-state-on
498 (apply 'propertize wl-biff-state-indicator-on props)
499 wl-modeline-biff-state-off
500 (apply 'propertize wl-biff-state-indicator-off props))))
501 (setq wl-modeline-biff-state-on wl-biff-state-indicator-on
502 wl-modeline-biff-state-off wl-biff-state-indicator-off)))
504 (defun wl-make-date-string ()
505 (format-time-string "%a, %d %b %Y %T %z"))
507 (defalias 'wl-setup-folder 'wl-e21-setup-folder-toolbar)
509 (defalias 'wl-setup-summary 'wl-e21-setup-summary-toolbar)
511 (defun wl-message-overload-functions ()
512 (let ((keymap (current-local-map)))
514 (wl-e21-setup-message-toolbar keymap)
515 (define-key keymap "l" 'wl-message-toggle-disp-summary)
516 (define-key keymap [mouse-2] 'wl-message-refer-article-or-url)
517 (define-key keymap [mouse-4] 'wl-message-wheel-down)
518 (define-key keymap [mouse-5] 'wl-message-wheel-up)
519 (define-key keymap [S-mouse-4] 'wl-message-wheel-down)
520 (define-key keymap [S-mouse-5] 'wl-message-wheel-up)
521 (set-keymap-parent wl-message-button-map keymap)
522 (define-key wl-message-button-map
523 [mouse-2] 'wl-message-button-dispatcher))))
525 (defun wl-message-wheel-up (event)
527 (if (string-match wl-message-buf-name (buffer-name))
528 (wl-message-next-page)
529 (let ((cur-buf (current-buffer))
531 (save-selected-window
532 (select-window (posn-window (event-start event)))
534 (setq proceed (wl-message-next-page)))
536 (if (memq 'shift (event-modifiers event))
538 (wl-summary-next t))))))
540 (defun wl-message-wheel-down (event)
542 (if (string-match wl-message-buf-name (buffer-name))
543 (wl-message-prev-page)
544 (let ((cur-buf (current-buffer))
546 (save-selected-window
547 (select-window (posn-window (event-start event)))
549 (setq proceed (wl-message-prev-page)))
551 (if (memq 'shift (event-modifiers event))
553 (wl-summary-prev t))))))
555 (defun wl-draft-overload-menubar ()
556 (let ((keymap (current-local-map)))
557 (define-key keymap [menu-bar mail send]
558 '("Send Message" . wl-draft-send-and-exit))
559 (define-key keymap [menu-bar mail send-stay]
560 '("Send, Keep Editing" . wl-draft-send))
561 (define-key keymap [menu-bar mail cancel]
562 '("Kill Current Draft" . wl-draft-kill))
563 (define-key keymap [menu-bar mail yank]
564 '("Cite Message" . wl-draft-yank-original))
565 (define-key keymap [menu-bar mail signature]
566 '("Insert Signature" . insert-signature))
567 (define-key keymap [menu-bar headers fcc]
568 '("FCC" . wl-draft-fcc))))
570 (defun wl-draft-mode-setup ()
572 (define-derived-mode wl-draft-mode mail-mode "Draft"
573 "draft mode for Wanderlust derived from mail mode.
574 See info under Wanderlust for full documentation.
577 \\{wl-draft-mode-map}"))
579 (defun wl-draft-key-setup ()
580 (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
581 (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
582 (define-key wl-draft-mode-map "\C-c\C-a" 'wl-draft-insert-x-face-field)
583 (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
584 (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
585 (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
586 (define-key wl-draft-mode-map "\C-l" 'wl-draft-highlight-and-recenter)
587 (define-key wl-draft-mode-map "\C-i" 'wl-complete-field-body-or-tab)
588 (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
589 (define-key wl-draft-mode-map "\M-t" 'wl-toggle-plugged)
590 (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
591 (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
592 (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
593 (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
594 (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
595 (define-key wl-draft-mode-map "\C-xk" 'wl-draft-mimic-kill-buffer))
597 (defun wl-draft-overload-functions ()
598 (wl-mode-line-buffer-identification)
599 (local-set-key "\C-c\C-s" 'wl-draft-send);; override
600 (wl-e21-setup-draft-toolbar)
601 (wl-draft-overload-menubar))
603 (defalias 'wl-defface 'defface)
606 (product-provide (provide 'wl-e21) (require 'wl-version))
608 ;;; wl-e21.el ends here