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))
67 (require 'wl-highlight)
68 (defvar-maybe wl-folder-mode-map (make-sparse-keymap))
69 (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
71 (add-hook 'wl-folder-mode-hook 'wl-setup-folder)
72 (add-hook 'wl-folder-mode-hook 'wl-folder-init-icons)
74 (add-hook 'wl-init-hook 'wl-biff-init-icons)
75 (add-hook 'wl-init-hook 'wl-plugged-init-icons)
77 (add-hook 'wl-summary-mode-hook 'wl-setup-summary)
79 (defvar wl-use-toolbar (image-type-available-p 'xpm))
80 (defvar wl-plugged-image nil)
81 (defvar wl-unplugged-image nil)
82 (defvar wl-biff-mail-image nil)
83 (defvar wl-biff-nomail-image nil)
85 (defvar wl-folder-toolbar
86 '([wl-folder-jump-to-current-entity
87 wl-folder-jump-to-current-entity t "Enter Current Folder"]
88 [wl-folder-next-entity
89 wl-folder-next-entity t "Next Folder"]
90 [wl-folder-prev-entity
91 wl-folder-prev-entity t "Previous Folder"]
92 [wl-folder-check-current-entity
93 wl-folder-check-current-entity t "Check Current Folder"]
95 ;; wl-draft t "Write a New Message"]
96 [wl-folder-sync-current-entity
97 wl-folder-sync-current-entity t "Sync Current Folder"]
99 wl-draft t "Write a New Message"]
100 [wl-folder-empty-trash
101 wl-folder-empty-trash t "Empty Trash"]
103 wl-exit t "Quit Wanderlust"]
105 "The Folder buffer toolbar.")
107 (defvar wl-summary-toolbar
109 wl-summary-read t "Read Messages"]
111 wl-summary-next t "Next Message"]
113 wl-summary-prev t "Previous Message"]
114 [wl-summary-jump-to-current-message
115 wl-summary-jump-to-current-message t "Jump to Current Message"]
116 [wl-summary-sync-force-update
117 wl-summary-sync-force-update t "Sync Current Folder"]
119 wl-summary-delete t "Delete Current Message"]
120 [wl-summary-mark-as-important
121 wl-summary-mark-as-important t "Mark Current Message as Important"]
123 wl-draft t "Write a New Message"]
125 wl-summary-reply t "Reply to Current Message" ]
126 [wl-summary-reply-with-citation
127 wl-summary-reply-with-citation t "Reply to Current Message with Citation"]
129 wl-summary-forward t "Forward Current Message"]
131 wl-summary-exit t "Exit Current Summary"]
133 "The Summary buffer toolbar.")
135 (defvar wl-message-toolbar
137 wl-message-read t "Read Contents"]
138 [wl-message-next-content
139 wl-message-next-content t "Next Content"]
140 [wl-message-prev-content
141 wl-message-prev-content t "Previous Content"]
143 wl-message-quit t "Back to Summary"]
144 [wl-message-play-content
145 wl-message-play-content t "Play Content"]
146 [wl-message-extract-content
147 wl-message-extract-content t "Extract Content"]
149 "The Message buffer toolbar.")
151 (defalias 'wl-draft-insert-signature 'insert-signature);; for draft toolbar.
153 (defvar wl-draft-toolbar
154 '([wl-draft-send-from-toolbar
155 wl-draft-send-from-toolbar t "Send Current Draft"]
156 [wl-draft-yank-original
157 wl-draft-yank-original t "Yank Displaying Message"]
158 [wl-draft-insert-signature
159 wl-draft-insert-signature t "Insert Signature"]
161 wl-draft-kill t "Kill Current Draft"]
163 "The Draft buffer toolbar.")
165 (defun wl-e21-setup-toolbar (bar)
166 (let ((load-path (cons wl-icon-dir load-path))
167 (props '(:type xpm :ascent center
168 :color-symbols (("backgroundToolBarColor" . "None"))
171 icon up down disabled name success)
173 (setq icon (aref (pop bar) 0))
174 (unless (boundp icon)
175 (setq name (symbol-name icon)
176 up (find-image `((,@props ,(concat name "-up.xpm")))))
179 (setq down (find-image `((,@props ,(concat name "-down.xpm"))))
180 disabled (find-image `((,@props
181 ,(concat name "-disabled.xpm")))))
182 (set icon (vector down up disabled disabled)))
187 (defvar wl-e21-toolbar-configurations
188 '((auto-resize-tool-bar . t)
189 (auto-raise-tool-bar-buttons . t)
190 (tool-bar-button-margin . 0)
191 (tool-bar-button-relief . 2)))
193 (defun wl-e21-make-toolbar-buttons (keymap defs)
194 (let ((configs wl-e21-toolbar-configurations)
196 (while (setq config (pop configs))
197 (set (make-local-variable (car config)) (cdr config))))
198 ;; Invalidate the default bindings.
199 (let ((keys (cdr (key-binding [tool-bar] t)))
201 (while (setq item (pop keys))
202 (when (setq item (car-safe item))
203 (define-key keymap (vector 'tool-bar item) 'undefined))))
204 (let ((n (length defs))
209 (define-key keymap (vector 'tool-bar (aref def 1))
210 (list 'menu-item (aref def 3) (aref def 1)
212 :image (symbol-value (aref def 0)))))))
214 (defun wl-e21-setup-folder-toolbar ()
217 (wl-e21-setup-toolbar wl-folder-toolbar)
218 (wl-e21-make-toolbar-buttons wl-folder-mode-map wl-folder-toolbar)))
220 (defun wl-e21-setup-summary-toolbar ()
223 (wl-e21-setup-toolbar wl-summary-toolbar)
224 (wl-e21-make-toolbar-buttons wl-summary-mode-map wl-summary-toolbar)))
227 (defsubst wl-e21-setup-message-toolbar (keymap)
230 (wl-e21-setup-toolbar wl-message-toolbar)
231 (wl-e21-make-toolbar-buttons keymap wl-message-toolbar)))
233 (defsubst wl-e21-setup-draft-toolbar ()
236 (wl-e21-setup-toolbar wl-draft-toolbar)
237 (wl-e21-make-toolbar-buttons wl-draft-mode-map wl-draft-toolbar))))
239 (defvar wl-folder-toggle-icon-list
240 '((wl-folder-opened-image . wl-opened-group-folder-icon)
241 (wl-folder-closed-image . wl-closed-group-folder-icon)))
244 (defsubst wl-e21-highlight-folder-group-line (start end icon numbers)
245 (when (display-graphic-p)
247 (let ((overlays (overlays-in start end)))
248 (while (and (setq overlay (pop overlays))
249 (not (overlay-get overlay 'wl-e21-icon)))))
251 (setq overlay (make-overlay start end))
252 (overlay-put overlay 'wl-e21-icon t)
253 (overlay-put overlay 'evaporate t))
254 (let ((image (get icon 'image)))
256 (let ((name (symbol-value
257 (cdr (assq icon wl-folder-toggle-icon-list))))
258 (load-path (cons wl-icon-dir load-path)))
259 (when (setq image (find-image `((:type xpm :file ,name
261 (setq image (put icon 'image (propertize name
263 (overlay-put overlay 'before-string image)
264 (overlay-put overlay 'invisible (and image t))
265 (when (and wl-use-highlight-mouse-line (display-mouse-p))
266 (let ((inhibit-read-only t))
267 (put-text-property (if image
268 (max (1- start) (line-beginning-position))
271 'mouse-face 'highlight)))))))
273 (defsubst wl-e21-highlight-folder-by-numbers (start end text-face numbers)
274 (when (display-color-p)
275 (let ((inhibit-read-only t))
276 (if (and wl-highlight-folder-by-numbers
277 numbers (nth 0 numbers) (nth 1 numbers)
278 (re-search-forward "[0-9-]+/[0-9-]+/[0-9-]+"
279 (line-end-position) t))
280 (let* ((unsync (nth 0 numbers))
281 (unread (nth 1 numbers))
282 (face (cond ((and unsync (zerop unsync))
283 (if (and unread (zerop unread))
284 'wl-highlight-folder-zero-face
285 'wl-highlight-folder-unread-face))
288 wl-folder-many-unsync-threshold))
289 'wl-highlight-folder-many-face)
291 'wl-highlight-folder-few-face))))
292 (if (numberp wl-highlight-folder-by-numbers)
294 (put-text-property start (match-beginning 0)
296 (put-text-property (match-beginning 0) (match-end 0)
298 (put-text-property start (match-end 0) 'face face)))
299 (put-text-property start (line-end-position) 'face text-face))))))
301 (defun wl-highlight-folder-current-line (&optional numbers)
305 (let (fld-name start end)
307 (;; opened folder group
308 (looking-at wl-highlight-folder-opened-regexp)
309 (setq start (match-beginning 1)
311 (wl-e21-highlight-folder-group-line start end
312 'wl-folder-opened-image
314 (wl-e21-highlight-folder-by-numbers start end
315 'wl-highlight-folder-opened-face
317 (;; closed folder group
318 (looking-at wl-highlight-folder-closed-regexp)
319 (setq start (match-beginning 1)
321 (wl-e21-highlight-folder-group-line start end
322 'wl-folder-closed-image
324 (wl-e21-highlight-folder-by-numbers start end
325 'wl-highlight-folder-closed-face
328 (and (setq fld-name (wl-folder-get-folder-name-by-id
329 (get-text-property (point) 'wl-folder-entity-id)))
330 (looking-at "[\t ]+\\([^\t\n ]+\\)"))
331 (setq start (match-beginning 1)
334 (when (display-graphic-p)
336 (let ((overlays (overlays-in start end)))
337 (while (and (setq overlay (pop overlays))
338 (not (overlay-get overlay 'wl-e21-icon)))))
340 (setq overlay (make-overlay start end))
341 (overlay-put overlay 'wl-e21-icon t)
342 (overlay-put overlay 'evaporate t))
344 (unless (get (caar wl-folder-internal-icon-list) 'image)
345 (wl-folder-init-icons))
347 (cond ((string= fld-name wl-trash-folder);; trash folder
348 (let ((num (nth 2 numbers)));; number of messages
349 (get (if (or (not num) (zerop num))
350 'wl-folder-trash-empty-image
351 'wl-folder-trash-image)
353 ((string= fld-name wl-draft-folder);; draft folder
354 (get 'wl-folder-draft-image 'image))
355 ((string= fld-name wl-queue-folder);; queue folder
356 (get 'wl-folder-queue-image 'image))
357 (;; and one of many other folders
358 (setq type (elmo-folder-type fld-name))
359 (get (intern (format "wl-folder-%s-image" type))
361 (overlay-put overlay 'before-string image)))
362 (when (and wl-use-highlight-mouse-line (display-mouse-p))
363 (let ((inhibit-read-only t))
364 (put-text-property (if image
366 (line-beginning-position))
369 'mouse-face 'highlight))))
370 (when (display-color-p)
371 (wl-e21-highlight-folder-by-numbers
373 (if (looking-at (format "^[\t ]*\\(%s\\|%s\\)"
374 wl-folder-unsubscribe-mark
375 wl-folder-removed-mark))
376 'wl-highlight-folder-killed-face
377 'wl-highlight-folder-unknown-face)
380 (defun wl-highlight-plugged-current-line ()
382 (when (display-graphic-p)
385 (when (looking-at "[\t ]*\\(\\[\\([^]]+\\)\\]\\)")
386 (let* ((start (match-beginning 1))
388 (status (match-string-no-properties 2))
389 (image (if (string-equal wl-plugged-plug-on status)
391 wl-unplugged-image)))
394 (let ((overlays (overlays-in start end)))
395 (while (and (setq overlay (pop overlays))
396 (not (overlay-get overlay 'wl-e21-icon)))))
398 (setq overlay (make-overlay start end))
399 (overlay-put overlay 'wl-e21-icon t)
400 (overlay-put overlay 'evaporate t))
401 (put-text-property 0 (length status) 'display image status)
402 (overlay-put overlay 'before-string status)
403 (overlay-put overlay 'invisible t))))))))
405 (defun wl-plugged-set-folder-icon (folder string)
406 (if (display-graphic-p)
408 (cond ((string= folder wl-queue-folder)
409 (concat (propertize " " 'display
410 (get 'wl-folder-queue-image 'image))
412 ((setq type (elmo-folder-type folder))
413 (concat (propertize " " 'display
414 (get (intern (format "wl-folder-%s-image"
422 (defvar wl-folder-internal-icon-list
423 ;; alist of (image . icon-file)
424 '((wl-folder-nntp-image . wl-nntp-folder-icon)
425 (wl-folder-imap4-image . wl-imap-folder-icon)
426 (wl-folder-pop3-image . wl-pop-folder-icon)
427 (wl-folder-localdir-image . wl-localdir-folder-icon)
428 (wl-folder-localnews-image . wl-localnews-folder-icon)
429 (wl-folder-internal-image . wl-internal-folder-icon)
430 (wl-folder-multi-image . wl-multi-folder-icon)
431 (wl-folder-filter-image . wl-filter-folder-icon)
432 (wl-folder-archive-image . wl-archive-folder-icon)
433 (wl-folder-pipe-image . wl-pipe-folder-icon)
434 (wl-folder-maildir-image . wl-maildir-folder-icon)
435 (wl-folder-nmz-image . wl-nmz-folder-icon)
436 (wl-folder-trash-empty-image . wl-empty-trash-folder-icon)
437 (wl-folder-draft-image . wl-draft-folder-icon)
438 (wl-folder-queue-image . wl-queue-folder-icon)
439 (wl-folder-trash-image . wl-trash-folder-icon)))
441 (defun wl-folder-init-icons ()
442 (when (display-graphic-p)
443 (let ((load-path (cons wl-icon-dir load-path))
444 (icons wl-folder-internal-icon-list)
446 (while (setq icon (pop icons))
447 (unless (get (car icon) 'image)
448 (setq name (symbol-value (cdr icon))
449 image (find-image `((:type xpm :file ,name :ascent center))))
451 (put (car icon) 'image (propertize name 'display image))))))))
453 (defun wl-plugged-init-icons ()
454 (if (display-mouse-p)
455 (let ((props (list 'local-map (purecopy (make-mode-line-mouse2-map
456 #'wl-toggle-plugged))
457 'help-echo "mouse-2 toggles plugged status")))
458 (if (display-graphic-p)
460 (unless wl-plugged-image
461 (let ((load-path (cons wl-icon-dir load-path)))
462 (setq wl-plugged-image (find-image
464 :file ,wl-plugged-icon
466 wl-unplugged-image (find-image
468 :file ,wl-unplugged-icon
470 (setq wl-modeline-plug-state-on
471 (apply 'propertize wl-plug-state-indicator-on
472 `(display ,wl-plugged-image ,@props))
473 wl-modeline-plug-state-off
474 (apply 'propertize wl-plug-state-indicator-off
475 `(display ,wl-unplugged-image ,@props))))
476 (setq wl-modeline-plug-state-on
477 (apply 'propertize wl-plug-state-indicator-on props)
478 wl-modeline-plug-state-off
479 (apply 'propertize wl-plug-state-indicator-off props))))
480 (setq wl-modeline-plug-state-on wl-plug-state-indicator-on
481 wl-modeline-plug-state-off wl-plug-state-indicator-off)))
483 (defun wl-biff-init-icons ()
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)
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
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 (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 (regexp-quote wl-message-buffer-cache-name)
541 (regexp-quote (buffer-name)))
542 (wl-message-next-page)
543 (let ((cur-buf (current-buffer))
545 (save-selected-window
546 (select-window (posn-window (event-start event)))
548 (setq proceed (wl-message-next-page)))
550 (if (memq 'shift (event-modifiers event))
552 (wl-summary-next t))))))
554 (defun wl-message-wheel-down (event)
556 (if (string-match (regexp-quote wl-message-buffer-cache-name)
557 (regexp-quote (buffer-name)))
558 (wl-message-prev-page)
559 (let ((cur-buf (current-buffer))
561 (save-selected-window
562 (select-window (posn-window (event-start event)))
564 (setq proceed (wl-message-prev-page)))
566 (if (memq 'shift (event-modifiers event))
568 (wl-summary-prev t))))))
570 (defun wl-draft-overload-menubar ()
571 (let ((keymap (current-local-map)))
572 (define-key keymap [menu-bar mail send]
573 '("Send Message" . wl-draft-send-and-exit))
574 (define-key keymap [menu-bar mail send-stay]
575 '("Send, Keep Editing" . wl-draft-send))
576 (define-key keymap [menu-bar mail cancel]
577 '("Kill Current Draft" . wl-draft-kill))
578 (define-key keymap [menu-bar mail yank]
579 '("Cite Message" . wl-draft-yank-original))
580 (define-key keymap [menu-bar mail signature]
581 '("Insert Signature" . insert-signature))
582 (define-key keymap [menu-bar headers fcc]
583 '("FCC" . wl-draft-fcc))))
585 (defun wl-draft-mode-setup ()
587 (define-derived-mode wl-draft-mode mail-mode "Draft"
588 "draft mode for Wanderlust derived from mail mode.
589 See info under Wanderlust for full documentation.
592 \\{wl-draft-mode-map}"))
594 (defun wl-draft-key-setup ()
595 (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
596 (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
597 (define-key wl-draft-mode-map "\C-c\C-a" 'wl-draft-insert-x-face-field)
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-x\C-s" 'wl-draft-save)
610 (define-key wl-draft-mode-map "\C-xk" 'wl-draft-mimic-kill-buffer))
612 (defun wl-draft-overload-functions ()
613 (wl-mode-line-buffer-identification)
614 (local-set-key "\C-c\C-s" 'wl-draft-send);; override
615 (wl-e21-setup-draft-toolbar)
616 (wl-draft-overload-menubar))
618 (defalias 'wl-defface 'defface)
620 (defun wl-read-event-char ()
621 "Get the next event."
622 (let ((event (read-event)))
623 (cons (and (numberp event) event) event)))
626 (product-provide (provide 'wl-e21) (require 'wl-version))
628 ;;; wl-e21.el ends here