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