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