* wl-highlight.el (wl-highlight-summary-deleted-face): Changed default
[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
170 (defun wl-draft-overload-menubar ()
171   (let ((keymap (current-local-map)))
172     (define-key keymap [menu-bar mail send]
173       '("Send Message" . wl-draft-send-and-exit))
174     (define-key keymap [menu-bar mail send-stay]
175       '("Send, Keep Editing" . wl-draft-send))
176     (define-key-after (lookup-key keymap [menu-bar mail])
177       [mail-sep-send] '("--")
178       'send-stay)
179     (define-key keymap [menu-bar mail cancel]
180       '("Kill Current Draft" . wl-draft-kill))
181     (define-key-after (lookup-key keymap [menu-bar mail])
182       [save] '("Save Draft and Exit" . wl-draft-save-and-exit)
183       'cancel)
184     (define-key-after (lookup-key keymap [menu-bar mail])
185       [mail-sep-exit] '("--")
186       'save)
187     (define-key-after (lookup-key keymap [menu-bar mail])
188       [preview] '("Preview Message" . wl-draft-preview-message)
189       'mail-sep-exit)
190     (define-key keymap [menu-bar mail yank]
191       '("Cite Message" . wl-draft-yank-original))
192     (define-key keymap [menu-bar mail signature]
193       '("Insert Signature" . insert-signature))
194     (define-key keymap [menu-bar headers fcc]
195       '("Fcc" . wl-draft-fcc))))
196
197 (defun wl-draft-overload-functions ()
198   (wl-mode-line-buffer-identification)
199 ;;  (local-set-key "\C-c\C-s" 'wl-draft-send);; override
200   (wl-draft-overload-menubar))
201
202 ;; for "ja-mule-canna-2.3.mini" on PocketBSD
203 (defun-maybe make-face (a))
204
205 (eval-when-compile
206   (require 'static))
207 (static-cond
208  ((and (fboundp 'defface)
209        (not (featurep 'tinycustom)))
210   (defalias 'wl-defface 'defface)
211   (eval-when-compile
212     (defun wl-face-spec-set-match-display (display frame))
213     (defun wl-frame-parameter (frame property &optional default))
214     (defun wl-get-frame-properties (&optional frame))))
215  (t
216   (defmacro wl-defface (face spec doc &rest args)
217     (nconc (list 'wl-declare-face (list 'quote face) spec)))
218
219   (defun wl-declare-face (face spec)
220     (make-face face)
221     (while spec
222       (let* ((entry (car spec))
223              (display (nth 0 entry))
224              (atts (nth 1 entry)))
225         (setq spec (cdr spec))
226         (when (wl-face-spec-set-match-display display nil)
227           (apply 'wl-face-attributes-set face nil atts)))))
228
229   (defconst wl-face-attributes
230     '((:bold set-face-bold-p)
231       (:italic set-face-italic-p)
232       (:underline set-face-underline-p)
233       (:foreground set-face-foreground)
234       (:background set-face-background)
235       (:stipple set-face-stipple)))
236
237   (defun wl-face-attributes-set (face frame &rest atts)
238     "For FACE on FRAME set the attributes [KEYWORD VALUE]....
239 Each keyword should be listed in `custom-face-attributes'.
240
241 If FRAME is nil, set the default face."
242     (while atts
243       (let* ((name (nth 0 atts))
244              (value (nth 1 atts))
245              (fun (nth 1 (assq name wl-face-attributes))))
246         (setq atts (cdr (cdr atts)))
247         (condition-case nil
248             (funcall fun face value frame)
249           (error nil)))))
250
251   (defun wl-frame-parameter (frame property &optional default)
252     "Return FRAME's value for property PROPERTY."
253     (or (cdr (assq property (frame-parameters frame)))
254         default))
255
256   (eval-when-compile
257     (defun-maybe x-display-grayscale-p ()))
258
259   (defun wl-get-frame-properties (&optional frame)
260     "Return a plist with the frame properties of FRAME used by custom."
261     (list (cons 'type window-system)
262           (cons 'class (or (wl-frame-parameter frame 'display-type)
263                            (when window-system
264                              (cond ((x-display-color-p)
265                                     'color)
266                                    ((and (fboundp 'x-display-grayscale-p)
267                                          (x-display-grayscale-p))
268                                     'grayscale)
269                                    (t 'mono)))))
270           (cons 'background (or (wl-frame-parameter frame 'background-mode)
271                                 wl-highlight-background-mode))))
272
273   (defun wl-face-spec-set-match-display (display frame)
274     "Non-nil iff DISPLAY matches FRAME.
275 If FRAME is nil, the current FRAME is used."
276     ;; This is a kludge to get started, we really should use specifiers!
277     (if (eq display t)
278         t
279       (let* ((props (wl-get-frame-properties frame))
280              (type (cdr (assq 'type props)))
281              (class (cdr (assq 'class props)))
282              (background (cdr (assq 'background props)))
283              (match t)
284              (entries display)
285              entry req options)
286         (while (and entries match)
287           (setq entry (car entries)
288                 entries (cdr entries)
289                 req (car entry)
290                 options (cdr entry)
291                 match (cond ((eq req 'type)
292                              (memq type options))
293                             ((eq req 'class)
294                              (memq class options))
295                             ((eq req 'background)
296                              (memq background options))
297                             (t
298                              (message "\
299 Warning: Unknown req `%S' with options `%S'" req options)
300                              nil))))
301         match)))))
302
303 (defun wl-read-event-char ()
304   "Get the next event."
305   (let ((event (read-event)))
306     (cons (and (numberp event) event) event)))
307
308 (require 'product)
309 (product-provide (provide 'wl-mule) (require 'wl-version))
310
311 ;;; wl-mule.el ends here