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