Debian Codegraph @

mew-mule3.el

raw
1 ;;; mew-mule3.el --- Environment of Mule version 3 for Mew
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Mar 20, 1997
5
6 ;;; Code:
7
8 (eval-when-compile
9 (require 'mew-env0)
10 (require 'mew-func))
11
12 (eval-when-compile
13 (mew-no-warning-defun charset-priority-list))
14
15 ;; must be here
16 (if (fboundp 'find-coding-system)
17 (defun mew-coding-system-p (cs)
18 (if (null cs) t (find-coding-system cs)))
19 (defun mew-coding-system-p (cs)
20 (if (null cs) t (coding-system-p cs))))
21
22 ;; In the context of Mew, 'charset' means MIME charset.
23 ;; 'cs' means the internal representation of Emacs (was known as Mule).
24
25 ;;
26 ;; User CS definitions
27 ;;
28
29 ;; iso-2022-7bit-ss2 is iso-2022-jp-2
30
31 (define-coding-system-alias 'mew-cs-text 'raw-text)
32 (define-coding-system-alias 'mew-cs-text-lf 'raw-text-unix)
33 (define-coding-system-alias 'mew-cs-text-crlf 'raw-text-dos)
34 (define-coding-system-alias 'mew-cs-text-cr 'raw-text-mac)
35 (define-coding-system-alias 'mew-cs-text-net 'raw-text-dos)
36 (defun mew-cs-raw-p (cs)
37 (memq cs '(raw-text raw-text-unix raw-text-dos raw-text-mac)))
38
39 (defvar mew-cs-dummy 'binary)
40 (defvar mew-cs-binary 'binary)
41 (defvar mew-cs-text-for-read 'mew-cs-text)
42 (defvar mew-cs-text-for-write 'mew-cs-text-lf)
43 (defvar mew-cs-text-for-net 'mew-cs-text-net)
44 (defvar mew-cs-autoconv 'undecided)
45 ;; xxx should be utf-8-unix someday.
46 (defvar mew-cs-m17n (if (mew-coding-system-p 'ctext-unix) 'ctext-unix 'ctext))
47 (defvar mew-cs-utf-16be
48 (cond
49 ((mew-coding-system-p 'utf-16-be-no-signature) 'utf-16-be-no-signature)
50 ((mew-coding-system-p 'utf-16be) 'utf-16be)
51 (t nil)))
52
53 (defvar mew-cs-eol "\n")
54 (defun mew-eol-fix-for-read () ())
55 (defun mew-eol-fix-for-write () ())
56
57 ;; Latin 0 -- Nickname of Latin 9
58 ;; Latin 1 -- ISO-8859-1 West European
59 ;; Latin 2 -- ISO-8859-2 East European
60 ;; Latin 3 -- ISO-8859-3 South European
61 ;; Latin 4 -- ISO-8859-4 North European
62 ;; Latin 5 -- ISO-8859-9 Turkish
63 ;; Latin 6 -- ISO-8859-10 Nordic
64 ;; Latin 7 -- ISO-8859-13 Baltic Rim
65 ;; Latin 8 -- ISO-8859-14 Celtic
66 ;; Latin 9 -- ISO-5589-15 New West European
67
68 ;; ISO-8859-1 -- Latin 1 West European
69 ;; ISO-8859-2 -- Latin 2 East European
70 ;; ISO-8859-3 -- Latin 3 South European
71 ;; ISO-8859-4 -- Latin 4 North European
72 ;; ISO-8859-5 -- Cyrillic
73 ;; ISO-8859-6 -- Arabic
74 ;; ISO-8859-7 -- Greek
75 ;; ISO-8859-8 -- Hebrew
76 ;; ISO-8859-9 -- Latin 5 Turkish
77 ;; ISO-8859-10 -- Latin 6 Nordic
78 ;; ISO-8859-11 -- Thai
79 ;; ISO-8859-12 --
80 ;; ISO-8859-13 -- Latin 7 Baltic Rim
81 ;; ISO-8859-14 -- Latin 8 Celtic
82 ;; ISO-8859-15 -- Latin 9 New West European (or Latin 0)
83
84 (defvar mew-charset-utf-8-encoding "base64")
85 (defvar mew-charset-utf-8-header-encoding "B")
86
87 (mew-defstruct ecsdb lcs cs cte b-or-q delsp)
88
89 (defun mew-ecsdb-hcs (ecsdb)
90 (mew-ecsdb-get-cs ecsdb))
91
92 (defvar mew-cs-database-for-encoding
93 `(((ascii) nil "7bit" "7bit" nil)
94 ;; West European (Latin 1)
95 ((ascii latin-iso8859-1) iso-8859-1 "quoted-printable" "Q" nil)
96 ;; East European (Latin 2)
97 ((ascii latin-iso8859-2) iso-8859-2 "quoted-printable" "Q" nil)
98 ;; South European (Latin 3)
99 ((ascii latin-iso8859-3) iso-8859-3 "quoted-printable" "Q" nil)
100 ;; North European (Latin 4)
101 ((ascii latin-iso8859-4) iso-8859-4 "quoted-printable" "Q" nil)
102 ;; Cyrillic
103 ((ascii cyrillic-iso8859-5) koi8-r "quoted-printable" "Q" nil)
104 ;; Arabic
105 ((ascii arabic-iso8859-6) iso-8859-6 "base64" "B" t)
106 ;; Greek
107 ((ascii greek-iso8859-7) iso-8859-7 "base64" "B" t)
108 ;; Hebrew
109 ((ascii hebrew-iso8859-8) iso-8859-8 "base64" "B" t)
110 ;; Turkish (Latin 5)
111 ((ascii latin-iso8859-9) iso-8859-9 "quoted-printable" "Q" nil)
112 ;; Celtic (Latin 8)
113 ((ascii latin-iso8859-14) iso-8859-14 "quoted-printable" "Q" nil) ;; xxx
114 ;; New West European (Latin 9 or Latin 0)
115 ((ascii latin-iso8859-15) iso-8859-15 "quoted-printable" "Q" nil)
116 ((ascii thai-tis620) tis-620 "base64" "B" t)
117 ((ascii latin-jisx0201 japanese-jisx0208 japanese-jisx0208-1978)
118 iso-2022-jp "7bit" "B" t)
119 ((ascii korean-ksc5601) euc-kr "8bit" "B" t)
120 ((ascii chinese-gbk) gbk "base64" "B" t)
121 ((ascii chinese-gb2312) cn-gb-2312 "base64" "B" t)
122 ((ascii chinese-big5-1 chinese-big5-2)
123 chinese-big5 "base64" "B" t)
124 ;; ((ascii japanese-jisx0208 japanese-jisx0213-1 japanese-jisx0213-2)
125 ;; iso-2022-jp-3 "7bit" "B" t)
126 (nil utf-7 "7bit" "Q" t) ;; xxx
127 (nil utf-8 ,mew-charset-utf-8-encoding ,mew-charset-utf-8-header-encoding t)
128 (nil iso-2022-jp-2 "7bit" "B" t)))
129
130 (defvar mew-cs-database-for-arg
131 '((iso-2022-jp . euc-jp)
132 (iso-2022-kr . euc-kr)))
133
134 (defun mew-ecsdb-cs-for-arg (ecsdb)
135 (let* ((cs (mew-ecsdb-get-cs ecsdb))
136 (acs (cdr (assoc cs mew-cs-database-for-arg))))
137 (or acs cs)))
138
139 (if (and (not (mew-coding-system-p 'chinese-big5))
140 (mew-coding-system-p 'big5))
141 (define-coding-system-alias 'chinese-big5 'big5))
142
143 (mew-defstruct dcsdb charset cs)
144
145 (defvar mew-cs-database-for-decoding
146 `(("us-ascii" nil)
147 ("iso-8859-1" iso-8859-1)
148 ("iso-8859-2" iso-8859-2)
149 ("iso-8859-3" iso-8859-3)
150 ("iso-8859-4" iso-8859-4)
151 ("iso-8859-5" iso-8859-5)
152 ("iso-8859-6" iso-8859-6)
153 ("iso-8859-7" iso-8859-7)
154 ("iso-8859-8" iso-8859-8)
155 ("iso-8859-8-i" iso-8859-8) ;; temporary solution
156 ("iso-8859-9" iso-8859-9)
157 ("iso-8859-15" iso-8859-15)
158 ("iso-2022-cn" iso-2022-cn)
159 ("iso-2022-cn-ext" iso-2022-cn-ext)
160 ("gbk" gbk)
161 ("gb2312" cn-gb-2312) ;; should be before cn-gb
162 ("gb18030" gb18030)
163 ("cn-gb" cn-gb-2312)
164 ("hz-gb-2312" hz-gb-2312)
165 ("big5" chinese-big5)
166 ("cn-big5" chinese-big5)
167 ("iso-2022-kr" iso-2022-kr)
168 ("euc-kr" euc-kr)
169 ("ks_c_5601-1987" euc-kr)
170 ("iso-2022-jp" iso-2022-jp)
171 ("iso-2022-jp-2" iso-2022-jp-2)
172 ("iso-2022-jp-3" iso-2022-jp-3)
173 ("euc-jp" euc-japan)
174 ("shift_jis" shift_jis)
175 ("windows-31j" cp932)
176 ("tis-620" tis-620)
177 ("koi8-r" koi8-r)
178 ("iso-2022-int-1" iso-2022-int-1)
179 ("utf-7" utf-7)
180 ("unicode-1-1-utf-7" utf-7) ;; the old UTF-7 name, RFC 1642
181 ("utf-8" utf-8)
182 ,@(if (mew-coding-system-p 'windows-1251)
183 '(("windows-1250" windows-1250)
184 ("windows-1251" windows-1251)
185 ("windows-1252" windows-1252)
186 ("windows-1253" windows-1253)
187 ("windows-1254" windows-1254)
188 ("windows-1255" windows-1255)
189 ("windows-1256" windows-1256)
190 ("windows-1257" windows-1257)
191 ("windows-1258" windows-1258))
192 '(("windows-1250" cp1250)
193 ("windows-1251" cp1251)
194 ("windows-1252" cp1252)
195 ("windows-1253" cp1253)
196 ("windows-1254" cp1254)
197 ("windows-1255" cp1255)
198 ("windows-1256" cp1256)
199 ("windows-1257" cp1257)
200 ("windows-1258" cp1258)))))
201
202 ;;
203 ;; CS
204 ;;
205
206 (defvar mew-charset-priority-list '(japanese-jisx0208
207 korean-ksc5601
208 latin-iso8859-2
209 latin-iso8859-3
210 latin-iso8859-4
211 hebrew-iso8859-8
212 latin-iso8859-9
213 ;; for accent characters
214 cyrillic-iso8859-5
215 greek-iso8859-7
216 latin-iso8859-14
217 thai-tis620
218 latin-jisx0201
219 japanese-jisx0208-1978
220 japanese-jisx0213-1
221 japanese-jisx0213-2
222 katakana-jisx0201
223 unicode))
224
225 (if (fboundp 'set-charset-priority)
226 (defun mew-find-cs-region (beg end)
227 (let ((charset-list (charset-priority-list))
228 ret)
229 (catch 'find
230 (set-charset-priority 'latin-iso8859-1)
231 (setq ret (find-charset-region beg end))
232 (if (equal ret '(ascii latin-iso8859-1))
233 (throw 'find nil))
234 ;;
235 (set-charset-priority 'latin-iso8859-15)
236 (setq ret (find-charset-region beg end))
237 (if (equal ret '(ascii latin-iso8859-15))
238 (throw 'find nil))
239 ;;
240 (set-charset-priority 'cyrillic-iso8859-5)
241 (setq ret (find-charset-region beg end))
242 (if (equal ret '(ascii cyrillic-iso8859-5))
243 (throw 'find nil))
244 ;;
245 (set-charset-priority 'greek-iso8859-7)
246 (setq ret (find-charset-region beg end))
247 (if (equal ret '(ascii greek-iso8859-7))
248 (throw 'find nil))
249 ;;
250 (apply 'set-charset-priority mew-charset-priority-list)
251 (setq ret (find-charset-region beg end)))
252 (apply 'set-charset-priority charset-list)
253 ret))
254 (defalias 'mew-find-cs-region 'find-charset-region))
255
256 ;; to internal
257 (defun mew-cs-decode-region (beg end cs)
258 (if cs (decode-coding-region beg end cs)))
259
260 ;; to external
261 (defun mew-cs-encode-region (beg end cs)
262 (if cs (encode-coding-region beg end cs)))
263
264 ;; to internal
265 (defun mew-cs-decode-string (str cs)
266 (if cs (decode-coding-string str cs) str))
267
268 ;; to external
269 (defun mew-cs-encode-string (str cs)
270 (if cs (encode-coding-string str cs) str))
271
272 ;;
273 ;; Process environment
274 ;;
275
276 (defun mew-set-process-cs (process read write)
277 (set-process-coding-system process read write))
278
279 (defun mew-set-buffer-cs (write)
280 (setq buffer-file-coding-system write))
281
282 (defmacro mew-plet (&rest body)
283 (declare (debug (&rest form)))
284 `(let ((coding-system-for-read 'binary)
285 (coding-system-for-write 'binary))
286 ,@body))
287
288 (defmacro mew-piolet (read write &rest body)
289 ;; (declare (indent 2))
290 `(let ((coding-system-for-read ,read)
291 (coding-system-for-write ,write))
292 ,@body))
293 (put 'mew-piolet 'lisp-indent-function 2)
294
295 (defmacro mew-flet (&rest body)
296 (declare (debug (&rest form)))
297 `(let ((coding-system-for-read 'binary)
298 (coding-system-for-write 'binary)
299 (format-alist nil)
300 (auto-image-file-mode nil)
301 (jka-compr-inhibit t))
302 ,@body))
303
304 (defmacro mew-frwlet (read write &rest body)
305 ;; (declare (indent 2))
306 `(let ((coding-system-for-read ,read)
307 (coding-system-for-write ,write)
308 (format-alist nil)
309 (auto-image-file-mode nil)
310 (jka-compr-inhibit t))
311 ,@body))
312 (put 'mew-frwlet 'lisp-indent-function 2)
313
314 (defmacro mew-alet (&rest body)
315 (declare (debug (&rest form)))
316 `(let ((default-file-name-coding-system nil)
317 (file-name-coding-system nil))
318 ,@body))
319
320 ;;
321 ;;
322 ;;
323
324 (defun mew-substring (str width &optional cnt nopad)
325 (let ((sw (if (null str) 0 (string-width str)))
326 (i 0) (w 0) cw wid)
327 (condition-case nil
328 (cond
329 ((= sw width)
330 str)
331 ((< sw width)
332 (if nopad
333 str
334 (concat str (make-string (- width sw) mew-sp))))
335 (t
336 (if cnt (setq width (- width 2)))
337 (catch 'loop
338 (while t
339 (setq cw (char-width (aref str i)))
340 (if (get-text-property i 'composition str) ;; for Emacs 21
341 (setq i (1+ i)))
342 (if (> (+ w cw) width)
343 (throw 'loop t))
344 (setq w (+ w cw))
345 (setq i (+ i 1))))
346 (cond
347 ((= w width)
348 (if cnt
349 (concat (substring str 0 i) "..")
350 (substring str 0 i)))
351 (t
352 (setq wid (- width w))
353 (if cnt
354 (concat (substring str 0 i) (make-string wid mew-sp) "..")
355 (concat (substring str 0 i) (make-string wid mew-sp)))))))
356 (error
357 (if (> (length mew-error-broken-string) width)
358 (substring mew-error-broken-string 0 width)
359 mew-error-broken-string)))))
360
361 ;;
362 ;; Language specific
363 ;;
364
365 (defvar mew-lc-kana 'katakana-jisx0201)
366 (defvar mew-lc-jp 'japanese-jisx0208)
367
368 ;;
369 ;; Stolen from mule-cmd.el
370 ;;
371
372 (defun mew-coding-category-list () coding-category-list)
373 (defun mew-coding-category-system (cat) (eval cat))
374
375 (defun mew-reset-coding-systems (priority categories)
376 (let ((rest-ctgs categories))
377 (dolist (pri priority)
378 (set (car rest-ctgs) pri)
379 (setq rest-ctgs (cdr rest-ctgs)))
380 (if (fboundp 'update-coding-systems-internal)
381 (update-coding-systems-internal))
382 (mew-set-coding-priority categories)))
383
384 (defun mew-set-language-environment-coding-systems (language-name)
385 (let ((priority (get-language-info language-name 'coding-priority)))
386 (when priority
387 (let* ((categories (mapcar 'coding-system-category priority))
388 (orig-ctg (mew-coding-category-list))
389 (orig-pri (mapcar 'mew-coding-category-system orig-ctg)))
390 (mew-reset-coding-systems priority categories)
391 (cons orig-pri orig-ctg)))))
392
393 ;;
394 ;;
395 ;;
396
397 (require 'mew-mule)
398 (provide 'mew-mule3)
399
400 ;;; Copyright Notice:
401
402 ;; Copyright (C) 1997-2015 Mew developing team.
403 ;; All rights reserved.
404
405 ;; Redistribution and use in source and binary forms, with or without
406 ;; modification, are permitted provided that the following conditions
407 ;; are met:
408 ;;
409 ;; 1. Redistributions of source code must retain the above copyright
410 ;; notice, this list of conditions and the following disclaimer.
411 ;; 2. Redistributions in binary form must reproduce the above copyright
412 ;; notice, this list of conditions and the following disclaimer in the
413 ;; documentation and/or other materials provided with the distribution.
414 ;; 3. Neither the name of the team nor the names of its contributors
415 ;; may be used to endorse or promote products derived from this software
416 ;; without specific prior written permission.
417 ;;
418 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
419 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
420 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
421 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
422 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
423 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
424 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
425 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
426 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
427 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
428 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
429
430 ;;; mew-mule3.el ends here