Update.
[elisp/wanderlust.git] / wl / wl-mule.el
1 ;;; wl-mule.el --- Wanderlust modules for Mule compatible Emacsen.
2
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
9
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)
13 ;; any later version.
14 ;;
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.
19 ;;
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.
24 ;;
25
26 ;;; Commentary:
27 ;; For Mule2.3@19.34, Emacs 20.x
28
29 ;;; Code:
30 ;;
31
32 (eval-when-compile
33   (require 'wl-folder)
34   (require 'wl-summary)
35   (require 'wl-draft)
36   (require 'wl-message)
37   (require 'wl-highlight)
38   (require 'wl-vars)
39   (defvar-maybe wl-draft-mode-map (make-sparse-keymap)))
40
41 (defun wl-draft-mode-setup ()
42   (require 'derived)
43   (define-derived-mode wl-draft-mode mail-mode "Draft"
44     "draft mode for Wanderlust derived from mail mode.
45 See info under Wanderlust for full documentation.
46
47 Special commands:
48 \\{wl-draft-mode-map}"))
49
50 ;; Common implementations.
51 (defun wl-highlight-folder-current-line (&optional numbers)
52   "Highlight current folder line."
53   (interactive)
54   (save-excursion
55     (end-of-line)
56     (let ((end (point))
57           (start (progn (beginning-of-line) (point)))
58           (inhibit-read-only t)
59           (text-face
60            (cond ((and (wl-folder-buffer-group-p)
61                        (looking-at wl-highlight-folder-opened-regexp))
62                   'wl-highlight-folder-opened-face)
63                  ((and (wl-folder-buffer-group-p)
64                        (looking-at wl-highlight-folder-closed-regexp))
65                   'wl-highlight-folder-closed-face)
66                  (t
67                   (if (looking-at (format "^[ \t]*\\(%s\\|%s\\)"
68                                           wl-folder-unsubscribe-mark
69                                           wl-folder-removed-mark))
70                       'wl-highlight-folder-killed-face
71                     'wl-highlight-folder-unknown-face)))))
72       (if (and wl-highlight-folder-by-numbers
73                numbers (nth 0 numbers) (nth 1 numbers)
74                (re-search-forward "[0-9-]+/[0-9-]+/[0-9-]+" end t))
75           (let* ((unsync (nth 0 numbers))
76                  (unread (nth 1 numbers))
77                  (face (cond
78                         ((and unsync (zerop unsync))
79                          (if (and unread (zerop unread))
80                              'wl-highlight-folder-zero-face
81                            'wl-highlight-folder-unread-face))
82                         ((and unsync
83                               (>= unsync wl-folder-many-unsync-threshold))
84                          'wl-highlight-folder-many-face)
85                         (t
86                          'wl-highlight-folder-few-face))))
87             (if (numberp wl-highlight-folder-by-numbers)
88                 (progn
89                   (put-text-property start (match-beginning 0) 'face text-face)
90                   (put-text-property (match-beginning 0) (point) 'face face))
91               ;; Remove previous face.
92               (put-text-property start (point) 'face nil)
93               (put-text-property start (point) 'face face))
94             (goto-char start))
95         (put-text-property start end 'face text-face)))
96     (when wl-use-highlight-mouse-line
97       (wl-highlight-folder-mouse-line))))
98
99 (defun wl-highlight-plugged-current-line ())
100 (defun wl-plugged-set-folder-icon (folder string)
101   string)
102
103 (defun wl-message-define-keymap ()
104   (let ((keymap (make-sparse-keymap)))
105     (define-key keymap "D" 'wl-message-delete-current-part)
106     (define-key keymap "l" 'wl-message-toggle-disp-summary)
107     (define-key keymap "\C-c:d" 'wl-message-decrypt-pgp-nonmime)
108     (define-key keymap "\C-c:v" 'wl-message-verify-pgp-nonmime)
109     (define-key keymap [mouse-4] 'wl-message-wheel-down)
110     (define-key keymap [mouse-5] 'wl-message-wheel-up)
111     (define-key keymap [S-mouse-4] 'wl-message-wheel-down)
112     (define-key keymap [S-mouse-5] 'wl-message-wheel-up)
113     (set-keymap-parent wl-message-button-map keymap)
114     (define-key wl-message-button-map [mouse-2]
115       'wl-message-button-dispatcher)
116     keymap))
117
118 (defun wl-message-wheel-up (event)
119   (interactive "e")
120   (if (string-match (regexp-quote wl-message-buffer-name)
121                     (regexp-quote (buffer-name)))
122       (wl-message-next-page)
123     (let ((cur-buf (current-buffer))
124           proceed)
125       (save-selected-window
126         (select-window (posn-window (event-start event)))
127         (set-buffer cur-buf)
128         (setq proceed (wl-message-next-page)))
129       (if proceed
130           (if (memq 'shift (event-modifiers event))
131               (wl-summary-down t)
132             (wl-summary-next t))))))
133
134 (defun wl-message-wheel-down (event)
135   (interactive "e")
136   (if (string-match (regexp-quote wl-message-buffer-name)
137                     (regexp-quote (buffer-name)))
138       (wl-message-prev-page)
139     (let ((cur-buf (current-buffer))
140           proceed)
141       (save-selected-window
142         (select-window (posn-window (event-start event)))
143         (set-buffer cur-buf)
144         (setq proceed (wl-message-prev-page)))
145       (if proceed
146           (if (memq 'shift (event-modifiers event))
147               (wl-summary-up t)
148             (wl-summary-prev t))))))
149
150 (defun wl-draft-key-setup ()
151   (define-key wl-draft-mode-map "\C-c\C-y" 'wl-draft-yank-original)
152   (define-key wl-draft-mode-map "\C-c\C-s" 'wl-draft-send)
153   (define-key wl-draft-mode-map "\C-c\C-c" 'wl-draft-send-and-exit)
154   (define-key wl-draft-mode-map "\C-c\C-z" 'wl-draft-save-and-exit)
155   (define-key wl-draft-mode-map "\C-c\C-k" 'wl-draft-kill)
156   (define-key wl-draft-mode-map "\C-l"     'wl-draft-highlight-and-recenter)
157   (define-key wl-draft-mode-map "\C-i"     'wl-complete-field-body-or-tab)
158   (define-key wl-draft-mode-map "\C-c\C-r" 'wl-draft-caesar-region)
159   (define-key wl-draft-mode-map "\M-t"     'wl-toggle-plugged)
160   (define-key wl-draft-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
161   (define-key wl-draft-mode-map "\C-c\C-e" 'wl-draft-config-exec)
162   (define-key wl-draft-mode-map "\C-c\C-j" 'wl-template-select)
163   (define-key wl-draft-mode-map "\C-c\C-p" 'wl-draft-preview-message)
164 ;;   (define-key wl-draft-mode-map "\C-x\C-s" 'wl-draft-save)
165   (define-key wl-draft-mode-map "\C-c\C-a" 'wl-addrmgr)
166   (define-key wl-draft-mode-map "\C-xk" 'wl-draft-mimic-kill-buffer)
167   (define-key wl-draft-mode-map "\C-c\C-d" 'wl-draft-elide-region)
168   (define-key wl-draft-mode-map "\C-a" 'wl-draft-beginning-of-line)
169   (define-key wl-draft-mode-map "\M-p" 'wl-draft-previous-history-element)
170   (define-key wl-draft-mode-map "\M-n" 'wl-draft-next-history-element))
171
172 (defun wl-draft-overload-menubar ()
173   (let ((keymap (current-local-map)))
174     (define-key keymap [menu-bar mail send]
175       '("Send Message" . wl-draft-send-and-exit))
176     (define-key keymap [menu-bar mail send-stay]
177       '("Send, Keep Editing" . wl-draft-send))
178     (define-key-after (lookup-key keymap [menu-bar mail])
179       [mail-sep-send] '("--")
180       'send-stay)
181     (define-key keymap [menu-bar mail cancel]
182       '("Kill Current Draft" . wl-draft-kill))
183     (define-key-after (lookup-key keymap [menu-bar mail])
184       [save] '("Save Draft and Exit" . wl-draft-save-and-exit)
185       'cancel)
186     (define-key-after (lookup-key keymap [menu-bar mail])
187       [mail-sep-exit] '("--")
188       'save)
189     (define-key-after (lookup-key keymap [menu-bar mail])
190       [preview] '("Preview Message" . wl-draft-preview-message)
191       'mail-sep-exit)
192     (define-key keymap [menu-bar mail yank]
193       '("Cite Message" . wl-draft-yank-original))
194     (define-key keymap [menu-bar mail signature]
195       '("Insert Signature" . insert-signature))
196     (define-key keymap [menu-bar headers fcc]
197       '("Fcc" . wl-draft-fcc))))
198
199 (defun wl-draft-overload-functions ()
200   (wl-mode-line-buffer-identification)
201 ;;  (local-set-key "\C-c\C-s" 'wl-draft-send);; override
202   (wl-draft-overload-menubar))
203
204 ;; for "ja-mule-canna-2.3.mini" on PocketBSD
205 (defun-maybe make-face (a))
206
207 (eval-when-compile
208   (require 'static))
209 (static-cond
210  ((and (fboundp 'defface)
211        (not (featurep 'tinycustom)))
212   (defalias 'wl-defface 'defface)
213   (eval-when-compile
214     (defun wl-face-spec-set-match-display (display frame))
215     (defun wl-frame-parameter (frame property &optional default))
216     (defun wl-get-frame-properties (&optional frame))))
217  (t
218   (defmacro wl-defface (face spec doc &rest args)
219     (nconc (list 'wl-declare-face (list 'quote face) spec)))
220
221   (defun wl-declare-face (face spec)
222     (make-face face)
223     (while spec
224       (let* ((entry (car spec))
225              (display (nth 0 entry))
226              (atts (nth 1 entry)))
227         (setq spec (cdr spec))
228         (when (wl-face-spec-set-match-display display nil)
229           (apply 'wl-face-attributes-set face nil atts)))))
230
231   (defconst wl-face-attributes
232     '((:bold set-face-bold-p)
233       (:italic set-face-italic-p)
234       (:underline set-face-underline-p)
235       (:foreground set-face-foreground)
236       (:background set-face-background)
237       (:stipple set-face-stipple)))
238
239   (defun wl-face-attributes-set (face frame &rest atts)
240     "For FACE on FRAME set the attributes [KEYWORD VALUE]....
241 Each keyword should be listed in `custom-face-attributes'.
242
243 If FRAME is nil, set the default face."
244     (while atts
245       (let* ((name (nth 0 atts))
246              (value (nth 1 atts))
247              (fun (nth 1 (assq name wl-face-attributes))))
248         (setq atts (cdr (cdr atts)))
249         (condition-case nil
250             (funcall fun face value frame)
251           (error nil)))))
252
253   (defun wl-frame-parameter (frame property &optional default)
254     "Return FRAME's value for property PROPERTY."
255     (or (cdr (assq property (frame-parameters frame)))
256         default))
257
258   (eval-when-compile
259     (defun-maybe x-display-grayscale-p ()))
260
261   (defun wl-get-frame-properties (&optional frame)
262     "Return a plist with the frame properties of FRAME used by custom."
263     (list (cons 'type window-system)
264           (cons 'class (or (wl-frame-parameter frame 'display-type)
265                            (when window-system
266                              (cond ((x-display-color-p)
267                                     'color)
268                                    ((and (fboundp 'x-display-grayscale-p)
269                                          (x-display-grayscale-p))
270                                     'grayscale)
271                                    (t 'mono)))))
272           (cons 'background (or (wl-frame-parameter frame 'background-mode)
273                                 wl-highlight-background-mode))))
274
275   (defun wl-face-spec-set-match-display (display frame)
276     "Non-nil iff DISPLAY matches FRAME.
277 If FRAME is nil, the current FRAME is used."
278     ;; This is a kludge to get started, we really should use specifiers!
279     (if (eq display t)
280         t
281       (let* ((props (wl-get-frame-properties frame))
282              (type (cdr (assq 'type props)))
283              (class (cdr (assq 'class props)))
284              (background (cdr (assq 'background props)))
285              (match t)
286              (entries display)
287              entry req options)
288         (while (and entries match)
289           (setq entry (car entries)
290                 entries (cdr entries)
291                 req (car entry)
292                 options (cdr entry)
293                 match (cond ((eq req 'type)
294                              (memq type options))
295                             ((eq req 'class)
296                              (memq class options))
297                             ((eq req 'background)
298                              (memq background options))
299                             (t
300                              (message "\
301 Warning: Unknown req `%S' with options `%S'" req options)
302                              nil))))
303         match)))))
304
305 (defun wl-read-event-char ()
306   "Get the next event."
307   (let ((event (read-event)))
308     (cons (and (numberp event) event) event)))
309
310 (require 'product)
311 (product-provide (provide 'wl-mule) (require 'wl-version))
312
313 ;;; wl-mule.el ends here