Debian Codegraph @

mew-env.el

raw
1 ;;; mew-env.el --- Environment setup for Mew
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Mar 6, 1997
5
6 ;;; Code:
7
8 (require 'mew)
9
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11 ;;;
12 ;;;
13 ;;;
14
15 ;; to avoid competition with mh-e.el, sigh.
16 (let ((ent (rassq 'mh-letter-mode auto-mode-alist)))
17 (and ent (setq auto-mode-alist (delq ent auto-mode-alist))))
18
19 (defvar mew-connection-type1 nil
20 "Connection type for many processes. 't' means PTY and 'nil' means PIPE.
21 PIPE is usually recommended for speed but some OSes such as Linux
22 requires PTY.")
23
24 (defvar mew-connection-type2 t
25 "Connection type for processes that requires a password.")
26
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;;
29 ;;; Emacsen
30 ;;;
31
32 (if window-system (require 'faces))
33
34 (defvar mew-icon-p (and (featurep 'tool-bar) window-system))
35
36 (defvar mew-internal-utf-8p nil)
37 (if (or (fboundp 'utf-translate-cjk-mode) ;; Emacs 22.1 or later
38 (coding-system-p 'utf-8-emacs))
39 (setq mew-internal-utf-8p t))
40
41 (require 'mew-key)
42 (require 'mew-gemacs)
43 (require 'mew-mule3)
44
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
46 ;;;
47 ;;; Misc
48 ;;;
49
50 (defun mew-mark () (marker-position (mark-marker)))
51
52 (defun mew-md5 (str) (md5 str nil nil 'binary))
53
54 (defun mew-timer (sec func) (run-at-time sec sec func))
55
56 (if (fboundp 'characterp)
57 (defalias 'mew-characterp 'characterp)
58 (defalias 'mew-characterp 'integerp))
59
60 (if (fboundp 'mouse-region-match)
61 (defalias 'mew-mouse-region-p 'mouse-region-match)
62 (defmacro mew-mouse-region-p (&rest _args) nil))
63
64 (cond
65 ((boundp 'auto-hscroll-mode) ;; Emacs 21.3.50 or later
66 (defun mew-hscroll ()
67 (set (make-local-variable 'auto-hscroll-mode) t)))
68 ((boundp 'automatic-hscrolling) ;; Emacs 21.3 or earlier
69 (defun mew-hscroll ()
70 (set (make-local-variable 'automatic-hscrolling) t))))
71
72 (if (fboundp 'minibuffer-prompt-end)
73 (defalias 'mew-minibuf-point-min 'minibuffer-prompt-end)
74 (defalias 'mew-minibuf-point-min 'point-min))
75
76 (eval-when-compile
77 (unless (fboundp 'with-no-warnings)
78 (defmacro with-no-warnings (&rest body)
79 (declare (debug (&rest form)))
80 `(progn ,@body))))
81
82 (if (fboundp 'set-process-query-on-exit-flag)
83 (defun mew-process-silent-exit (pro)
84 (set-process-query-on-exit-flag pro nil))
85 (with-no-warnings
86 (defun mew-process-silent-exit (pro)
87 (process-kill-without-query pro)))) ;; Emacs 21.4
88
89 (with-no-warnings
90 (defun mew-set-coding-priority (pri)
91 (apply 'set-coding-system-priority
92 (mapcar (lambda (x) (symbol-value x)) pri))))
93
94 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
95 ;;;
96 ;;; Sticky
97 ;;;
98
99 (defun mew-front-sticky (beg end)
100 (put-text-property beg end 'front-sticky t))
101
102 (defun mew-front-nonsticky (beg end)
103 (put-text-property beg end 'front-sticky nil))
104
105 (defun mew-rear-sticky (beg end)
106 (put-text-property beg end 'rear-nonsticky nil))
107
108 (defun mew-rear-nonsticky (beg end)
109 (put-text-property beg end 'rear-nonsticky t))
110
111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;;
113 ;;; Overlay
114 ;;;
115
116 (defun mew-overlay-make (beg end)
117 (let ((ovl (make-overlay beg end)))
118 (overlay-put ovl 'mew t)
119 ovl))
120
121 (defun mew-overlay-delete (ovl)
122 (and (overlay-get ovl 'mew) (delete-overlay ovl)))
123
124 (defun mew-overlay-delete-region (beg end)
125 "Delete overlays in the region."
126 (interactive "r")
127 (mapc 'mew-overlay-delete (overlays-in beg end))
128 (if (fboundp 'remove-images) (remove-images beg end))) ;; xxx
129
130 (defun mew-overlay-delete-buffer ()
131 (save-restriction
132 (widen)
133 (mew-overlay-delete-region (point-min) (point-max))))
134
135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136 ;;;
137 ;;; File operations
138 ;;;
139
140 (cond
141 ((fboundp 'make-symbolic-link)
142 (defun mew-symbolic-link (filename newname &optional OK-IF-ALREADY-EXISTS)
143 (if (file-directory-p (file-chase-links filename))
144 (error "Cannot make a symbolic link to directory")
145 (make-symbolic-link filename newname OK-IF-ALREADY-EXISTS)))
146 (defun mew-link (filename newname &optional OK-IF-ALREADY-EXISTS)
147 (if (file-directory-p (file-chase-links filename))
148 (error "Cannot make a link to directory")
149 (condition-case nil
150 (add-name-to-file filename newname OK-IF-ALREADY-EXISTS)
151 (file-error
152 (copy-file filename newname OK-IF-ALREADY-EXISTS 'keepdate))))))
153 (t
154 (defun mew-symbolic-link (filename newname &optional OK-IF-ALREADY-EXISTS)
155 (if (file-directory-p filename)
156 (error "Cannot make a copy of directory")
157 (copy-file filename newname OK-IF-ALREADY-EXISTS 'keepdate)))
158 (defun mew-link (filename newname &optional OK-IF-ALREADY-EXISTS)
159 (if (file-directory-p filename)
160 (error "Cannot make a copy of directory")
161 (copy-file filename newname OK-IF-ALREADY-EXISTS 'keepdate)))))
162
163 (if (and (fboundp 'set-file-times)
164 (memq system-type '(darwin windows-nt cygwin)))
165 (defalias 'mew-set-file-times 'set-file-times)
166 (defmacro mew-set-file-times (&rest _args) nil))
167
168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
169 ;;;
170 ;;; Property
171 ;;;
172
173 (defalias 'mew-buffer-substring 'buffer-substring-no-properties)
174
175 (if (fboundp 'match-string-no-properties)
176 (defalias 'mew-match-string 'match-string-no-properties)
177 (defalias 'mew-match-string 'match-string))
178
179 (defun mew-insert-buffer-substring (buf beg end)
180 (insert (with-current-buffer buf (mew-buffer-substring beg end))))
181
182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
183 ;;;
184 ;;; Base64
185 ;;;
186
187 (defun mew-base64-encode-string (str)
188 (base64-encode-string str 'no-line-break))
189
190 (defun mew-base64-decode-string (str64)
191 (condition-case nil
192 (base64-decode-string str64)
193 (error nil)))
194
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 ;;;
197 ;;; Language
198 ;;;
199
200 ;; to load the thread separator
201 (cond
202 ((and (boundp 'current-language-environment)
203 (string= current-language-environment "Japanese"))
204 (require 'mew-lang-jp))
205 ((and (boundp 'current-language-environment)
206 (string= current-language-environment "Korean"))
207 (require 'mew-lang-kr)))
208
209 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
210 ;;;
211 ;;; Unix and Mac
212 ;;;
213
214 (if (fboundp 'unix-sync)
215 (defalias 'mew-unix-sync 'unix-sync)
216 (defmacro mew-unix-sync (&rest _args) nil))
217
218 (if (fboundp 'mac-set-file-type)
219 (defalias 'mew-mac-set-file-type 'mac-set-file-type)
220 (defmacro mew-mac-set-file-type (&rest _args) nil))
221
222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
223 ;;;
224 ;;; Face
225 ;;;
226
227 (cond
228 ((fboundp 'face-all-attributes) ;; Emacs 23
229 (defalias 'mew-face-spec-func 'cons)
230 (defun mew-face-spec-primitive (col bold)
231 (if col
232 (if bold
233 (list :foreground col :weight 'bold)
234 (list :foreground col :weight 'normal))
235 (if bold
236 (list :weight 'bold)
237 (list :weight 'normal)))))
238 (t
239 (defalias 'mew-face-spec-func 'list)
240 (defun mew-face-spec-primitive (col bold)
241 (if col
242 (if bold
243 (list :foreground col :bold t)
244 (list :foreground col))
245 (if bold
246 (list :bold t)
247 nil)))))
248
249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
250 ;;;
251 ;;; Misc
252 ;;;
253
254 (if (fboundp 'fill-match-adaptive-prefix)
255 (defalias 'mew-fill-match-adaptive-prefix 'fill-match-adaptive-prefix)
256 ;; Emacs 21.4
257 (defun mew-fill-match-adaptive-prefix ()
258 (let ((str (or
259 (and adaptive-fill-function (funcall adaptive-fill-function))
260 (and adaptive-fill-regexp (looking-at adaptive-fill-regexp)
261 (match-string-no-properties 0)))))
262 (if (>= (+ (current-left-margin) (length str)) (current-fill-column))
263 ;; Death to insanely long prefixes.
264 nil
265 str))))
266
267 (if (fboundp 'create-animated-image)
268 (defalias 'mew-create-image 'create-animated-image)
269 (defalias 'mew-create-image 'create-image))
270
271 (if (fboundp 'run-mode-hooks)
272 (defun mew-run-mode-hooks (&rest funcs)
273 (apply 'run-mode-hooks funcs))
274 (defun mew-run-mode-hooks (&rest funcs)
275 (apply 'run-hooks funcs)))
276
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278 ;;;
279 ;;; Unix/Mac/Win
280 ;;;
281
282 (cond
283 ((memq system-type '(windows-nt cygwin))
284 (defun mew-set-file-type (_file) ())
285 (defvar mew-cs-est 'shift_jis)
286 (defun mew-focus-frame (frame)
287 (if (fboundp 'w32-focus-frame) (w32-focus-frame frame))))
288 ((eq system-type 'darwin)
289 (defun mew-set-file-type (_file) ;; prevent byte-compile warning
290 (unless mew-use-suffix
291 (mew-mac-set-file-type _file mew-file-type)))
292 (defvar mew-cs-est 'utf-8)
293 (defun mew-focus-frame (_frame)
294 (when focus-follows-mouse
295 (set-mouse-position
296 (selected-frame) (1- (frame-width)) 0))))
297 (t
298 (defun mew-set-file-type (_file) ())
299 (defvar mew-cs-est 'utf-8)
300 (defun mew-focus-frame (_frame)
301 (when focus-follows-mouse
302 (set-mouse-position
303 (selected-frame) (1- (frame-width)) 0)))))
304
305
306 (provide 'mew-env)
307
308 ;;; Copyright Notice:
309
310 ;; Copyright (C) 1997-2015 Mew developing team.
311 ;; All rights reserved.
312
313 ;; Redistribution and use in source and binary forms, with or without
314 ;; modification, are permitted provided that the following conditions
315 ;; are met:
316 ;;
317 ;; 1. Redistributions of source code must retain the above copyright
318 ;; notice, this list of conditions and the following disclaimer.
319 ;; 2. Redistributions in binary form must reproduce the above copyright
320 ;; notice, this list of conditions and the following disclaimer in the
321 ;; documentation and/or other materials provided with the distribution.
322 ;; 3. Neither the name of the team nor the names of its contributors
323 ;; may be used to endorse or promote products derived from this software
324 ;; without specific prior written permission.
325 ;;
326 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
327 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
328 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
329 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
330 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
331 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
332 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
333 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
334 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
335 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
336 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
337
338 ;;; mew-env.el ends here