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