1 ;;; wl-xmas.el -- Wanderlust modules for XEmacsen.
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7 ;; Time-stamp: <00/03/24 14:44:00 teranisi>
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.
38 (require 'wl-highlight)
39 (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
41 (defun wl-xmas-setup-toolbar (bar)
42 (let ((dir wl-icon-dir)
43 icon up down disabled name)
46 (setq icon (aref (car bar) 0)
47 name (symbol-name icon)
49 (when (not (boundp icon))
50 (setq up (concat dir elmo-path-sep name "-up.xpm"))
51 (setq down (concat dir elmo-path-sep name "-down.xpm"))
52 (setq disabled (concat dir elmo-path-sep name "-disabled.xpm"))
53 (if (not (file-exists-p up))
56 (set icon (toolbar-make-button-list
57 up (and (file-exists-p down) down)
58 (and (file-exists-p disabled) disabled)))))))
61 (defvar wl-use-toolbar (if (featurep 'toolbar) 'default-toolbar nil))
62 (defvar wl-plugged-glyph nil)
63 (defvar wl-unplugged-glyph nil)
65 (defvar wl-folder-toolbar
66 '([wl-folder-jump-to-current-entity
67 wl-folder-jump-to-current-entity t "Enter Current Folder"]
68 [wl-folder-next-entity
69 wl-folder-next-entity t "Next Folder"]
70 [wl-folder-prev-entity
71 wl-folder-prev-entity t "Previous Folder"]
72 [wl-folder-check-current-entity
73 wl-folder-check-current-entity t "Check Current Folder"]
75 ; wl-draft t "Write a New Message"]
76 [wl-folder-sync-current-entity
77 wl-folder-sync-current-entity t "Sync Current Folder"]
79 wl-draft t "Write a New Message"]
80 [wl-folder-empty-trash
81 wl-folder-empty-trash t "Empty Trash"]
83 wl-exit t "Quit Wanderlust"]
85 "The Folder buffer toolbar.")
87 (defvar wl-summary-toolbar
89 wl-summary-read t "Read Messages"]
91 wl-summary-next t "Next Message"]
93 wl-summary-prev t "Previous Message"]
94 [wl-summary-jump-to-current-message
95 wl-summary-jump-to-current-message t "Jump to Current Message"]
96 [wl-summary-sync-force-update
97 wl-summary-sync-force-update t "Sync Current Folder"]
99 wl-summary-delete t "Delete Current Message"]
100 [wl-summary-mark-as-important
101 wl-summary-mark-as-important t "Mark Current Message as Important"]
103 wl-draft t "Write a New Message"]
105 wl-summary-reply t "Reply to Current Message" ]
106 [wl-summary-reply-with-citation
107 wl-summary-reply-with-citation t "Reply to Current Message with Citation"]
109 wl-summary-forward t "Forward Current Message"]
111 wl-summary-exit t "Exit Current Summary"]
113 "The Summary buffer toolbar.")
115 (defvar wl-message-toolbar
117 wl-message-read t "Read Contents"]
118 [wl-message-next-content
119 wl-message-next-content t "Next Content"]
120 [wl-message-prev-content
121 wl-message-prev-content t "Previous Content"]
123 wl-message-quit t "Back to Summary"]
124 [wl-message-play-content
125 wl-message-play-content t "Play Content"]
126 [wl-message-extract-content
127 wl-message-extract-content t "Extract Content"]
129 "The Message buffer toolbar.")
131 (defalias 'wl-draft-insert-signature 'insert-signature) ;; for draft toolbar.
133 (defvar wl-draft-toolbar
134 '([wl-draft-send-from-toolbar
135 wl-draft-send-from-toolbar t "Send Current Draft"]
136 [wl-draft-yank-original
137 wl-draft-yank-original t "Yank Displaying Message"]
138 [wl-draft-insert-signature
139 wl-draft-insert-signature t "Insert Signature"]
141 wl-draft-kill t "Kill Current Draft"]
143 "The Draft buffer toolbar.")
145 (defun wl-xmas-setup-folder-toolbar ()
147 (wl-xmas-setup-toolbar wl-folder-toolbar)
148 (set-specifier (symbol-value wl-use-toolbar)
149 (cons (current-buffer) wl-folder-toolbar))))
151 (defun wl-xmas-setup-summary-toolbar ()
153 (wl-xmas-setup-toolbar wl-summary-toolbar)
154 (set-specifier (symbol-value wl-use-toolbar)
155 (cons (current-buffer) wl-summary-toolbar))))
157 (defun wl-xmas-setup-message-toolbar ()
159 (wl-xmas-setup-toolbar wl-message-toolbar)
160 (set-specifier (symbol-value wl-use-toolbar)
161 (cons (current-buffer) wl-message-toolbar))))
163 (defun wl-xmas-setup-draft-toolbar ()
165 (wl-xmas-setup-toolbar wl-draft-toolbar)
166 (set-specifier (symbol-value wl-use-toolbar)
167 (cons (current-buffer) wl-draft-toolbar))))
169 ;; XEmacs implementations.
170 (defun wl-highlight-folder-current-line (&optional numbers)
173 (let ((highlights (list "opened" "closed"))
174 (inhibit-read-only t)
175 (fld-name (wl-folder-get-folder-name-by-id
176 (get-text-property (point) 'wl-folder-entity-id)))
177 fregexp fsymbol bol eol matched type extent num type glyph)
178 (setq eol (progn (end-of-line) (point))
179 bol (progn (beginning-of-line) (point)))
180 (when (and fld-name (looking-at "[ \t]+\\([^ \t]+\\)"))
181 (if (and (setq extent (extent-at (match-beginning 1) nil nil nil 'at))
182 (extent-begin-glyph extent))
183 (delete-extent extent))
184 (setq extent (make-extent (match-beginning 1) (match-beginning 1)))
186 ((string= fld-name wl-trash-folder) ;; set trash folder icon
187 (setq num (nth 2 numbers)) ;; number of messages
188 (set-extent-begin-glyph extent
191 wl-folder-trash-empty-glyph
192 wl-folder-trash-glyph)))
193 ((string= fld-name wl-draft-folder) ;; set draft folder icon
194 (set-extent-begin-glyph extent wl-folder-draft-glyph))
195 ((string= fld-name wl-queue-folder)
196 (set-extent-begin-glyph extent wl-folder-queue-glyph))
197 ((and (setq type (elmo-folder-get-type fld-name))
198 (or numbers ;; XXX dirty...!!
199 (not (assoc fld-name wl-folder-group-alist))))
201 (set-extent-begin-glyph extent
203 (intern (format "wl-folder-%s-glyph"
205 (when (and numbers (nth 0 numbers) (nth 1 numbers))
207 (let ((unsync (nth 0 numbers))
208 (unread (nth 1 numbers)))
209 (cond ((and unsync (eq unsync 0))
210 (if (and unread (> unread 0))
211 'wl-highlight-folder-unread-face
212 'wl-highlight-folder-zero-face))
214 (>= unsync wl-folder-many-unsync-threshold))
215 'wl-highlight-folder-many-face)
217 'wl-highlight-folder-few-face))))
218 (put-text-property bol eol 'face nil)
219 (put-text-property bol eol 'face fsymbol)
222 (setq fregexp (symbol-value
223 (intern (format "wl-highlight-folder-%s-regexp"
225 (if (not wl-highlight-group-folder-by-numbers)
226 (setq fsymbol (intern (format "wl-highlight-folder-%s-face"
228 (when (looking-at fregexp)
229 (setq extent (make-extent (match-beginning 1) (match-end 1))
230 glyph (intern (format "wl-folder-%s-glyph"
232 (if (null (symbol-value glyph))
233 (set glyph (wl-xmas-make-icon-glyph
234 (extent-string extent)
236 (cdr (assq glyph wl-folder-toggle-icon-list))))))
237 (setq glyph (symbol-value glyph))
238 (set-extent-property extent 'end-open t)
239 (set-extent-property extent 'start-closed t)
240 (set-extent-property extent 'invisible t)
241 (set-extent-end-glyph extent glyph)
242 (put-text-property bol eol 'face nil)
243 (put-text-property bol eol 'face fsymbol)
244 (setq matched t highlights nil))
245 (setq highlights (cdr highlights)))
247 (put-text-property bol eol 'face nil)
248 (if (looking-at (format "^[ ]*\\(%s\\|%s\\)"
249 wl-folder-unsubscribe-mark
250 wl-folder-removed-mark))
251 (put-text-property bol eol 'face
252 'wl-highlight-folder-killed-face)
253 (put-text-property bol eol 'face
254 'wl-highlight-folder-unknown-face)))
255 (if wl-use-highlight-mouse-line
256 (wl-highlight-folder-mouse-line))
257 (if (and (featurep 'dragdrop) wl-use-dnd)
258 (wl-dnd-set-drop-target bol eol)))))
260 (defun wl-highlight-plugged-current-line ()
263 (let ((inhibit-read-only t)
266 (when (looking-at "[ \t]*\\(\\[\\([^]]+\\)\\]\\)")
267 (setq switch (elmo-match-buffer 2))
268 (if (and (setq extent (extent-at (match-end 1) nil nil nil 'at))
269 (extent-end-glyph extent))
270 (delete-extent extent))
271 (setq extent (make-extent (match-beginning 1) (match-end 1)))
272 (set-extent-property extent 'end-open t)
273 (set-extent-property extent 'start-closed t)
274 (set-extent-property extent 'invisible t)
275 (set-extent-end-glyph extent (if (string= switch wl-plugged-plug-on)
277 wl-unplugged-glyph))))))
279 (defun wl-plugged-set-folder-icon (folder string)
280 (let ((string (copy-sequence string))
281 (len (length string))
283 (if (string= folder wl-queue-folder)
284 (put-text-property 0 len 'begin-glyph wl-folder-queue-glyph string)
285 (if (setq type (elmo-folder-get-type folder))
286 (put-text-property 0 len
289 (intern (format "wl-folder-%s-glyph" type)))
293 (defvar wl-folder-internal-icon-list
294 ;; alist of (glyph . icon-file)
295 '((wl-folder-nntp-glyph . wl-nntp-folder-icon)
296 (wl-folder-imap4-glyph . wl-imap-folder-icon)
297 (wl-folder-pop3-glyph . wl-pop-folder-icon)
298 (wl-folder-localdir-glyph . wl-localdir-folder-icon)
299 (wl-folder-localnews-glyph . wl-localnews-folder-icon)
300 (wl-folder-internal-glyph . wl-internal-folder-icon)
301 (wl-folder-multi-glyph . wl-multi-folder-icon)
302 (wl-folder-filter-glyph . wl-filter-folder-icon)
303 (wl-folder-archive-glyph . wl-archive-folder-icon)
304 (wl-folder-pipe-glyph . wl-pipe-folder-icon)
305 (wl-folder-maildir-glyph . wl-maildir-folder-icon)
306 (wl-folder-trash-empty-glyph . wl-empty-trash-folder-icon)
307 (wl-folder-draft-glyph . wl-draft-folder-icon)
308 (wl-folder-queue-glyph . wl-queue-folder-icon)
309 (wl-folder-trash-glyph . wl-trash-folder-icon)))
311 (defvar wl-folder-toggle-icon-list
312 '((wl-folder-opened-glyph . wl-opened-group-folder-icon)
313 (wl-folder-closed-glyph . wl-closed-group-folder-icon)))
315 (defun wl-xmas-make-icon-glyph (icon-string icon-file &optional locale tag-set)
316 (let ((glyph (make-glyph (vector 'string :data icon-string))))
317 (if wl-highlight-folder-with-icon
318 (set-glyph-image glyph
319 (vector 'xpm :file (expand-file-name
320 icon-file wl-icon-dir))
321 locale tag-set 'prepend))
324 (defun wl-folder-init-icons ()
327 (if (null (symbol-value (car x)))
328 (set (car x) (wl-xmas-make-icon-glyph "" (symbol-value (cdr x))))))
329 wl-folder-internal-icon-list))
331 (defun wl-plugged-init-icons ()
332 (if (null wl-plugged-glyph)
333 (setq wl-plugged-glyph
334 (wl-xmas-make-icon-glyph
335 (concat "[" wl-plugged-plug-on "]")
337 (if (null wl-unplugged-glyph)
338 (setq wl-unplugged-glyph
339 (wl-xmas-make-icon-glyph
340 (concat "[" wl-plugged-plug-off "]")
341 wl-unplugged-icon))))
343 (defun wl-make-modeline ()
344 "Make modeline for Wanderlust"
345 (wl-plugged-init-icons)
346 (let ((extent (make-extent nil nil))
347 (toggle-keymap (make-sparse-keymap)))
348 (define-key toggle-keymap 'button2 (make-modeline-command-wrapper
350 (set-extent-keymap extent toggle-keymap)
351 (set-extent-property extent 'help-echo "button2 toggles plugged status")
352 (setq wl-plug-state-indicator-on (cons extent wl-plugged-glyph))
353 (setq wl-plug-state-indicator-off (cons extent wl-unplugged-glyph))
354 (setq wl-plug-state-indicator (if wl-plugged
355 wl-plug-state-indicator-on
356 wl-plug-state-indicator-off)))
357 (wl-make-modeline-subr))
359 (defun wl-make-date-string ()
360 (let ((s (current-time-string)))
361 (string-match "\\`\\([A-Z][a-z][a-z]\\) +[A-Z][a-z][a-z] +[0-9][0-9]? *[0-9][0-9]?:[0-9][0-9]:[0-9][0-9] *[0-9]?[0-9]?[0-9][0-9]"
363 (concat (wl-match-string 1 s) ", "
364 (timezone-make-date-arpa-standard s (current-time-zone)))))
367 (defun wl-xmas-setup-folder ()
368 (and (featurep 'scrollbar)
369 (set-specifier scrollbar-height (cons (current-buffer) 0)))
370 (wl-xmas-setup-folder-toolbar))
372 (defun wl-xmas-setup-summary ()
373 (make-local-variable 'dragdrop-drop-functions)
374 (setq dragdrop-drop-functions '((wl-dnd-default-drop-message t t)))
375 (and (featurep 'scrollbar)
376 (set-specifier scrollbar-height (cons (current-buffer) 0)))
377 (wl-xmas-setup-summary-toolbar))
379 (defun wl-message-overload-functions ()
380 (wl-xmas-setup-message-toolbar)
381 (local-set-key "l" 'wl-message-toggle-disp-summary)
382 (local-set-key 'button2 'wl-message-refer-article-or-url)
383 (local-set-key 'button4 'wl-message-wheel-down)
384 (local-set-key 'button5 'wl-message-wheel-up)
385 (local-set-key [(shift button4)] 'wl-message-wheel-down)
386 (local-set-key [(shift button5)] 'wl-message-wheel-up))
388 (defun wl-message-wheel-up (event)
390 (let ((cur-buf (current-buffer))
392 (save-selected-window
393 (select-window (event-window event))
395 (setq proceed (wl-message-next-page)))
397 (if (memq 'shift (event-modifiers event))
399 (wl-summary-next t)))))
401 (defun wl-message-wheel-down (event)
403 (let ((cur-buf (current-buffer))
405 (save-selected-window
406 (select-window (event-window event))
408 (setq proceed (wl-message-prev-page)))
410 (if (memq 'shift (event-modifiers event))
412 (wl-summary-prev t)))))
414 (defun wl-draft-overload-menubar ()
415 (add-menu-item '("Mail") "Send, Keep Editing"
416 'wl-draft-send t "Send Mail")
417 (add-menu-item '("Mail") "Send Message"
418 'wl-draft-send-and-exit t "Send and Exit")
419 (delete-menu-item '("Mail" "Send Mail"))
420 (delete-menu-item '("Mail" "Send and Exit"))
423 (defun wl-draft-mode-setup ()
425 (define-derived-mode wl-draft-mode mail-mode "Draft"
426 "draft mode for Wanderlust derived from mail mode.
427 See info under Wanderlust for full documentation.
430 \\{wl-draft-mode-map}"))
432 (defun wl-draft-key-setup ()
433 (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
434 (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
435 (define-key wl-draft-mode-map "\C-c\C-a" 'wl-draft-insert-x-face-field)
436 (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
437 (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
438 (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
439 (define-key wl-draft-mode-map "\C-l" 'wl-draft-highlight-and-recenter)
440 (define-key wl-draft-mode-map "\C-i" 'wl-complete-field-body-or-tab)
441 (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
442 (define-key wl-draft-mode-map "\M-t" 'wl-toggle-plugged)
443 (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
444 (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
445 (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
446 (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
447 (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
448 (define-key wl-draft-mode-map "\C-xk" 'wl-draft-mimic-kill-buffer))
450 (defun wl-draft-overload-functions ()
451 (setq mode-line-buffer-identification
452 (format "Wanderlust: %s" (buffer-name)))
453 (local-set-key "\C-c\C-s" 'wl-draft-send) ; override
454 (wl-xmas-setup-draft-toolbar)
455 (wl-draft-overload-menubar)
456 (when wl-show-plug-status-on-modeline
457 (setq mode-line-format (wl-make-modeline))))
459 (defalias 'wl-defface 'defface)
463 ;;; wl-xmas.el ends here