1 ;;; wl-e21.el -- Wanderlust modules for Emacs 21.
3 ;; Copyright 2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Katsumi Yamaoka <yamaoka@jpl.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
28 ;; This module uses `before-string' overlay property to show icon
29 ;; images instead of `insert-image', so don't delete such overlays
30 ;; sloppily. Here is a sample code to show icons in the buffer.
32 ;;(let (image from to icon overlay)
33 ;; ;; The function `find-image' will look for an image first on `load-path'
34 ;; ;; and then in `data-directory'.
35 ;; (let ((load-path (cons wl-icon-dir load-path)))
36 ;; (setq image (find-image (list (list :type 'xpm :file wl-nntp-folder-icon
37 ;; :ascent 'center)))))
38 ;; ;; `propertize' is a convenient function in such a case.
39 ;; ;; String must have one or more length to wear an image.
40 ;; (setq icon (propertize "any string" 'display image))
41 ;; (pop-to-buffer (get-buffer-create "*wl-e21-demo*"))
44 ;; (setq from (point))
45 ;; (insert "-fj.wanderlust:0/0/0")
48 ;; (setq overlay (make-overlay from to))
50 ;; (overlay-put overlay 'before-string icon)
51 ;; ;; Put a mark to indicate that this overlay is made by `wl-e21'.
52 ;; ;; It is not always necessarily.
53 ;; (overlay-put overlay 'wl-e21-icon t)
54 ;; ;; Make it can be removable.
55 ;; (overlay-put overlay 'evaporate t))
65 (require 'wl-highlight)
66 (defvar-maybe wl-folder-mode-map (make-sparse-keymap))
67 (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
69 (add-hook 'wl-folder-mode-hook 'wl-setup-folder)
70 (add-hook 'wl-folder-mode-hook 'wl-folder-init-icons)
72 (add-hook 'wl-make-plugged-hook 'wl-biff-init-icons)
73 (add-hook 'wl-make-plugged-hook 'wl-plugged-init-icons)
75 (add-hook 'wl-summary-mode-hook 'wl-setup-summary)
77 (defvar wl-use-toolbar (image-type-available-p 'xpm))
78 (defvar wl-plugged-image nil)
79 (defvar wl-unplugged-image nil)
80 (defvar wl-biff-mail-image nil)
81 (defvar wl-biff-nomail-image nil)
83 (defvar wl-folder-toolbar
84 '([wl-folder-jump-to-current-entity
85 wl-folder-jump-to-current-entity t "Enter Current Folder"]
86 [wl-folder-next-entity
87 wl-folder-next-entity t "Next Folder"]
88 [wl-folder-prev-entity
89 wl-folder-prev-entity t "Previous Folder"]
90 [wl-folder-check-current-entity
91 wl-folder-check-current-entity t "Check Current Folder"]
93 ;; wl-draft t "Write a New Message"]
94 [wl-folder-sync-current-entity
95 wl-folder-sync-current-entity t "Sync Current Folder"]
97 wl-draft t "Write a New Message"]
98 [wl-folder-empty-trash
99 wl-folder-empty-trash t "Empty Trash"]
101 wl-exit t "Quit Wanderlust"]
103 "The Folder buffer toolbar.")
105 (defvar wl-summary-toolbar
107 wl-summary-read t "Read Messages"]
109 wl-summary-next t "Next Message"]
111 wl-summary-prev t "Previous Message"]
112 [wl-summary-jump-to-current-message
113 wl-summary-jump-to-current-message t "Jump to Current Message"]
114 [wl-summary-sync-force-update
115 wl-summary-sync-force-update t "Sync Current Folder"]
117 wl-summary-delete t "Delete Current Message"]
118 [wl-summary-mark-as-important
119 wl-summary-mark-as-important t "Mark Current Message as Important"]
121 wl-draft t "Write a New Message"]
123 wl-summary-reply t "Reply to Current Message" ]
124 [wl-summary-reply-with-citation
125 wl-summary-reply-with-citation t "Reply to Current Message with Citation"]
127 wl-summary-forward t "Forward Current Message"]
129 wl-summary-exit t "Exit Current Summary"]
131 "The Summary buffer toolbar.")
133 (defvar wl-message-toolbar
135 wl-message-read t "Read Contents"]
136 [wl-message-next-content
137 wl-message-next-content t "Next Content"]
138 [wl-message-prev-content
139 wl-message-prev-content t "Previous Content"]
141 wl-message-quit t "Back to Summary"]
142 [wl-message-play-content
143 wl-message-play-content t "Play Content"]
144 [wl-message-extract-content
145 wl-message-extract-content t "Extract Content"]
147 "The Message buffer toolbar.")
149 (defalias 'wl-draft-insert-signature 'insert-signature);; for draft toolbar.
151 (defvar wl-draft-toolbar
152 '([wl-draft-send-from-toolbar
153 wl-draft-send-from-toolbar t "Send Current Draft"]
154 [wl-draft-yank-original
155 wl-draft-yank-original t "Yank Displaying Message"]
156 [wl-draft-insert-signature
157 wl-draft-insert-signature t "Insert Signature"]
159 wl-draft-kill t "Kill Current Draft"]
161 "The Draft buffer toolbar.")
163 (defun wl-e21-setup-toolbar (bar)
164 (let ((load-path (cons wl-icon-dir load-path))
165 (props '(:type xpm :ascent center
166 :color-symbols (("backgroundToolBarColor" . "None"))
169 icon up down disabled name success)
171 (setq icon (aref (pop bar) 0))
172 (unless (boundp icon)
173 (setq name (symbol-name icon)
174 up (find-image `((,@props ,(concat name "-up.xpm")))))
177 (setq down (find-image `((,@props ,(concat name "-down.xpm"))))
178 disabled (find-image `((,@props
179 ,(concat name "-disabled.xpm")))))
180 (set icon (vector down up disabled disabled)))
185 (defvar wl-e21-toolbar-configurations
186 '((auto-resize-tool-bar . t)
187 (auto-raise-tool-bar-buttons . t)
188 (tool-bar-button-margin . 0)
189 (tool-bar-button-relief . 2)))
191 (defun wl-e21-make-toolbar-buttons (keymap defs)
192 (let ((configs wl-e21-toolbar-configurations)
194 (while (setq config (pop configs))
195 (set (make-local-variable (car config)) (cdr config))))
196 ;; Invalidate the default bindings.
197 (let ((keys (cdr (key-binding [tool-bar] t)))
199 (while (setq item (pop keys))
200 (when (setq item (car-safe item))
201 (define-key keymap (vector 'tool-bar item) 'undefined))))
202 (let ((n (length defs))
207 (define-key keymap (vector 'tool-bar (aref def 1))
208 (list 'menu-item (aref def 3) (aref def 1)
210 :image (symbol-value (aref def 0)))))))
212 (defun wl-e21-setup-folder-toolbar ()
215 (wl-e21-setup-toolbar wl-folder-toolbar)
216 (wl-e21-make-toolbar-buttons wl-folder-mode-map wl-folder-toolbar)))
218 (defun wl-e21-setup-summary-toolbar ()
221 (wl-e21-setup-toolbar wl-summary-toolbar)
222 (wl-e21-make-toolbar-buttons wl-summary-mode-map wl-summary-toolbar)))
225 (defsubst wl-e21-setup-message-toolbar ()
228 (wl-e21-setup-toolbar wl-message-toolbar)
229 (wl-e21-make-toolbar-buttons (current-local-map) wl-message-toolbar)))
231 (defsubst wl-e21-setup-draft-toolbar ()
234 (wl-e21-setup-toolbar wl-draft-toolbar)
235 (wl-e21-make-toolbar-buttons wl-draft-mode-map wl-draft-toolbar))))
237 (defvar wl-folder-toggle-icon-list
238 '((wl-folder-opened-image . wl-opened-group-folder-icon)
239 (wl-folder-closed-image . wl-closed-group-folder-icon)))
242 (defsubst wl-e21-highlight-folder-group-line (start end icon numbers)
243 (when (display-graphic-p)
245 (let ((overlays (overlays-in start end)))
246 (while (and (setq overlay (pop overlays))
247 (not (overlay-get overlay 'wl-e21-icon)))))
249 (setq overlay (make-overlay start end))
250 (overlay-put overlay 'wl-e21-icon t)
251 (overlay-put overlay 'evaporate t))
252 (let ((image (get icon 'image)))
254 (let ((name (symbol-value
255 (cdr (assq icon wl-folder-toggle-icon-list))))
256 (load-path (cons wl-icon-dir load-path)))
257 (when (setq image (find-image `((:type xpm :file ,name
259 (setq image (put icon 'image (propertize name
261 (overlay-put overlay 'before-string image)
262 (overlay-put overlay 'invisible (and image t))
263 (when (and wl-use-highlight-mouse-line (display-mouse-p))
264 (let ((inhibit-read-only t))
265 (put-text-property (if image
266 (max (1- start) (line-beginning-position))
269 'mouse-face 'highlight)))))))
271 (defsubst wl-e21-highlight-folder-by-numbers (start end text-face numbers)
272 (when (display-color-p)
273 (let ((inhibit-read-only t))
274 (if (and wl-highlight-folder-by-numbers
275 numbers (nth 0 numbers) (nth 1 numbers)
276 (re-search-forward "[0-9-]+/[0-9-]+/[0-9-]+"
277 (line-end-position) t))
278 (let* ((unsync (nth 0 numbers))
279 (unread (nth 1 numbers))
280 (face (cond ((and unsync (zerop unsync))
281 (if (and unread (zerop unread))
282 'wl-highlight-folder-zero-face
283 'wl-highlight-folder-unread-face))
286 wl-folder-many-unsync-threshold))
287 'wl-highlight-folder-many-face)
289 'wl-highlight-folder-few-face))))
290 (if (numberp wl-highlight-folder-by-numbers)
292 (put-text-property start (match-beginning 0)
294 (put-text-property (match-beginning 0) (match-end 0)
296 (put-text-property start (match-end 0) 'face face)))
297 (put-text-property start (line-end-position) 'face text-face))))))
299 (defun wl-highlight-folder-current-line (&optional numbers)
303 (let (fld-name start end)
305 (;; opened folder group
306 (looking-at wl-highlight-folder-opened-regexp)
307 (setq start (match-beginning 1)
309 (wl-e21-highlight-folder-group-line start end
310 'wl-folder-opened-image
312 (wl-e21-highlight-folder-by-numbers start end
313 'wl-highlight-folder-opened-face
315 (;; closed folder group
316 (looking-at wl-highlight-folder-closed-regexp)
317 (setq start (match-beginning 1)
319 (wl-e21-highlight-folder-group-line start end
320 'wl-folder-closed-image
322 (wl-e21-highlight-folder-by-numbers start end
323 'wl-highlight-folder-closed-face
326 (and (setq fld-name (wl-folder-get-folder-name-by-id
327 (get-text-property (point) 'wl-folder-entity-id)))
328 (looking-at "[\t ]+\\([^\t\n ]+\\)"))
329 (setq start (match-beginning 1)
332 (when (display-graphic-p)
334 (let ((overlays (overlays-in start end)))
335 (while (and (setq overlay (pop overlays))
336 (not (overlay-get overlay 'wl-e21-icon)))))
338 (setq overlay (make-overlay start end))
339 (overlay-put overlay 'wl-e21-icon t)
340 (overlay-put overlay 'evaporate t))
343 (cond ((string= fld-name wl-trash-folder);; trash folder
344 (let ((num (nth 2 numbers)));; number of messages
345 (get (if (or (not num) (zerop num))
346 'wl-folder-trash-empty-image
347 'wl-folder-trash-image)
349 ((string= fld-name wl-draft-folder);; draft folder
350 (get 'wl-folder-draft-image 'image))
351 ((string= fld-name wl-queue-folder);; queue folder
352 (get 'wl-folder-queue-image 'image))
353 (;; and one of many other folders
354 (setq type (elmo-folder-get-type fld-name))
355 (get (intern (format "wl-folder-%s-image" type))
357 (overlay-put overlay 'before-string image)))
358 (when (and wl-use-highlight-mouse-line (display-mouse-p))
359 (let ((inhibit-read-only t))
360 (put-text-property (if image
362 (line-beginning-position))
365 'mouse-face 'highlight))))
366 (when (display-color-p)
367 (wl-e21-highlight-folder-by-numbers
369 (if (looking-at (format "^[\t ]*\\(%s\\|%s\\)"
370 wl-folder-unsubscribe-mark
371 wl-folder-removed-mark))
372 'wl-highlight-folder-killed-face
373 'wl-highlight-folder-unknown-face)
376 (defun wl-highlight-plugged-current-line ()
378 (when (display-graphic-p)
381 (when (looking-at "[\t ]*\\(\\[\\([^]]+\\)\\]\\)")
382 (let* ((start (match-beginning 1))
384 (status (match-string-no-properties 2))
385 (image (if (string-equal wl-plugged-plug-on status)
387 wl-unplugged-image)))
390 (let ((overlays (overlays-in start end)))
391 (while (and (setq overlay (pop overlays))
392 (not (overlay-get overlay 'wl-e21-icon)))))
394 (setq overlay (make-overlay start end))
395 (overlay-put overlay 'wl-e21-icon t)
396 (overlay-put overlay 'evaporate t))
397 (put-text-property 0 (length status) 'display image status)
398 (overlay-put overlay 'before-string status)
399 (overlay-put overlay 'invisible t))))))))
401 (defun wl-plugged-set-folder-icon (folder string)
402 (if (display-graphic-p)
404 (cond ((string= folder wl-queue-folder)
405 (concat (propertize " " 'display
406 (get 'wl-folder-queue-image 'image))
408 ((setq type (elmo-folder-get-type folder))
409 (concat (propertize " " 'display
410 (get (intern (format "wl-folder-%s-image"
418 (defvar wl-folder-internal-icon-list
419 ;; alist of (image . icon-file)
420 '((wl-folder-nntp-image . wl-nntp-folder-icon)
421 (wl-folder-imap4-image . wl-imap-folder-icon)
422 (wl-folder-pop3-image . wl-pop-folder-icon)
423 (wl-folder-localdir-image . wl-localdir-folder-icon)
424 (wl-folder-localnews-image . wl-localnews-folder-icon)
425 (wl-folder-internal-image . wl-internal-folder-icon)
426 (wl-folder-multi-image . wl-multi-folder-icon)
427 (wl-folder-filter-image . wl-filter-folder-icon)
428 (wl-folder-archive-image . wl-archive-folder-icon)
429 (wl-folder-pipe-image . wl-pipe-folder-icon)
430 (wl-folder-maildir-image . wl-maildir-folder-icon)
431 (wl-folder-trash-empty-image . wl-empty-trash-folder-icon)
432 (wl-folder-draft-image . wl-draft-folder-icon)
433 (wl-folder-queue-image . wl-queue-folder-icon)
434 (wl-folder-trash-image . wl-trash-folder-icon)))
436 (defun wl-folder-init-icons ()
437 (let ((load-path (cons wl-icon-dir load-path))
438 (icons wl-folder-internal-icon-list)
440 (while (setq icon (pop icons))
441 (unless (get (car icon) 'image)
442 (setq name (symbol-value (cdr icon))
443 image (find-image `((:type xpm :file ,name :ascent center))))
445 (put (car icon) 'image (propertize name 'display image)))))))
447 (defun wl-plugged-init-icons ()
448 (unless wl-plugged-image
449 (let ((load-path (cons wl-icon-dir load-path)))
450 (setq wl-plugged-image (find-image `((:type xpm
451 :file ,wl-plugged-icon
453 wl-unplugged-image (find-image `((:type xpm
454 :file ,wl-unplugged-icon
456 (if (display-mouse-p)
457 (let ((props (list 'local-map (purecopy (make-mode-line-mouse2-map
458 #'wl-toggle-plugged))
459 'help-echo "mouse-2 toggles plugged status")))
460 (if (display-graphic-p)
461 (setq wl-modeline-plug-state-on
462 (apply 'propertize wl-plug-state-indicator-on
463 `(display ,wl-plugged-image ,@props))
464 wl-modeline-plug-state-off
465 (apply 'propertize wl-plug-state-indicator-off
466 `(display ,wl-unplugged-image ,@props)))
467 (setq wl-modeline-plug-state-on
468 (apply 'propertize wl-plug-state-indicator-on props)
469 wl-modeline-plug-state-off
470 (apply 'propertize wl-plug-state-indicator-off props))))
471 (setq wl-modeline-plug-state-on wl-plug-state-indicator-on
472 wl-modeline-plug-state-off wl-plug-state-indicator-off)))
474 (defun wl-biff-init-icons ()
475 (unless wl-biff-mail-image
476 (let ((load-path (cons wl-icon-dir load-path)))
477 (setq wl-biff-mail-image (find-image
478 `((:type xpm :file ,wl-biff-mail-icon
480 wl-biff-nomail-image (find-image
481 `((:type xpm :file ,wl-biff-nomail-icon
483 (if (display-mouse-p)
484 (let ((props (list 'local-map (purecopy (make-mode-line-mouse2-map
487 'wl-biff-check-folders))))
488 'help-echo "mouse-2 checks new mails")))
489 (if (display-graphic-p)
490 (setq wl-modeline-biff-state-on
491 (apply 'propertize wl-biff-state-indicator-on
492 `(display ,wl-biff-mail-image ,@props))
493 wl-modeline-biff-state-off
494 (apply 'propertize wl-biff-state-indicator-off
495 `(display ,wl-biff-nomail-image ,@props)))
496 (setq wl-modeline-biff-state-on
497 (apply 'propertize wl-biff-state-indicator-on props)
498 wl-modeline-biff-state-off
499 (apply 'propertize wl-biff-state-indicator-off props))))
500 (setq wl-modeline-biff-state-on wl-biff-state-indicator-on
501 wl-modeline-biff-state-off wl-biff-state-indicator-off)))
503 (defun wl-make-date-string ()
504 (format-time-string "%a, %d %b %Y %T %z"))
506 (defalias 'wl-setup-folder 'wl-e21-setup-folder-toolbar)
508 (defalias 'wl-setup-summary 'wl-e21-setup-summary-toolbar)
510 (defun wl-message-overload-functions ()
511 (wl-e21-setup-message-toolbar)
512 (let ((keymap (current-local-map)))
513 (define-key keymap "l" 'wl-message-toggle-disp-summary)
514 (define-key keymap [mouse-2] 'wl-message-refer-article-or-url)
515 (define-key keymap [mouse-4] 'wl-message-wheel-down)
516 (define-key keymap [mouse-5] 'wl-message-wheel-up)
517 (define-key keymap [S-mouse-4] 'wl-message-wheel-down)
518 (define-key keymap [S-mouse-5] 'wl-message-wheel-up)
519 (set-keymap-parent wl-message-button-map keymap))
520 (define-key wl-message-button-map [mouse-2] 'wl-message-button-dispatcher))
522 (defun wl-message-wheel-up (event)
524 (if (string-match wl-message-buf-name (buffer-name))
525 (wl-message-next-page)
526 (let ((cur-buf (current-buffer))
528 (save-selected-window
529 (select-window (posn-window (event-start event)))
531 (setq proceed (wl-message-next-page)))
533 (if (memq 'shift (event-modifiers event))
535 (wl-summary-next t))))))
537 (defun wl-message-wheel-down (event)
539 (if (string-match wl-message-buf-name (buffer-name))
540 (wl-message-prev-page)
541 (let ((cur-buf (current-buffer))
543 (save-selected-window
544 (select-window (posn-window (event-start event)))
546 (setq proceed (wl-message-prev-page)))
548 (if (memq 'shift (event-modifiers event))
550 (wl-summary-prev t))))))
552 (defun wl-draft-overload-menubar ()
553 (let ((keymap (current-local-map)))
554 (define-key keymap [menu-bar mail send]
555 '("Send Message" . wl-draft-send-and-exit))
556 (define-key keymap [menu-bar mail send-stay]
557 '("Send, Keep Editing" . wl-draft-send))
558 (define-key keymap [menu-bar mail cancel]
559 '("Kill Current Draft" . wl-draft-kill))
560 (define-key keymap [menu-bar mail yank]
561 '("Cite Message" . wl-draft-yank-original))
562 (define-key keymap [menu-bar mail signature]
563 '("Insert Signature" . insert-signature))
564 (define-key keymap [menu-bar headers fcc]
565 '("FCC" . wl-draft-fcc))))
567 (defun wl-draft-mode-setup ()
569 (define-derived-mode wl-draft-mode mail-mode "Draft"
570 "draft mode for Wanderlust derived from mail mode.
571 See info under Wanderlust for full documentation.
574 \\{wl-draft-mode-map}"))
576 (defun wl-draft-key-setup ()
577 (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
578 (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
579 (define-key wl-draft-mode-map "\C-c\C-a" 'wl-draft-insert-x-face-field)
580 (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
581 (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
582 (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
583 (define-key wl-draft-mode-map "\C-l" 'wl-draft-highlight-and-recenter)
584 (define-key wl-draft-mode-map "\C-i" 'wl-complete-field-body-or-tab)
585 (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
586 (define-key wl-draft-mode-map "\M-t" 'wl-toggle-plugged)
587 (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
588 (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
589 (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
590 (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
591 (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
592 (define-key wl-draft-mode-map "\C-xk" 'wl-draft-mimic-kill-buffer))
594 (defun wl-draft-overload-functions ()
595 (wl-mode-line-buffer-identification)
596 (local-set-key "\C-c\C-s" 'wl-draft-send);; override
597 (wl-e21-setup-draft-toolbar)
598 (wl-draft-overload-menubar))
600 (defalias 'wl-defface 'defface)
603 (product-provide (provide 'wl-e21) (require 'wl-version))
605 ;;; wl-e21.el ends here