Mercurial > emacs
annotate lisp/gnus/mm-util.el @ 38497:bd96796d6d4b
(x_fill_stretch_glyph_string): Remove an assertion.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Fri, 20 Jul 2001 09:35:17 +0000 |
parents | a26d9b55abb6 |
children | b7c0bc16b250 |
rev | line source |
---|---|
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
36557
diff
changeset
|
1 ;;; mm-util.el --- utility functions for MIME things |
35793 | 2 ;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
31717 | 3 |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | |
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp> | |
6 ;; This file is part of GNU Emacs. | |
7 | |
8 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
9 ;; it under the terms of the GNU General Public License as published by | |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 ;; Boston, MA 02111-1307, USA. | |
22 | |
23 ;;; Commentary: | |
24 | |
25 ;;; Code: | |
26 | |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
27 (eval-when-compile (require 'cl)) |
31717 | 28 (require 'mail-prsvr) |
29 | |
36557 | 30 (defun mm-coding-system-p (sym) |
31 "Return non-nil if SYM is a coding system." | |
32 (or (and (fboundp 'coding-system-p) (coding-system-p sym)) | |
33 (memq sym (mm-get-coding-system-list)))) | |
36556
8af75e618534
(mm-mime-mule-charset-alist): Move it after definition of
Dave Love <fx@gnu.org>
parents:
36539
diff
changeset
|
34 |
31717 | 35 (defvar mm-mime-mule-charset-alist |
35793 | 36 `((us-ascii ascii) |
31717 | 37 (iso-8859-1 latin-iso8859-1) |
38 (iso-8859-2 latin-iso8859-2) | |
39 (iso-8859-3 latin-iso8859-3) | |
40 (iso-8859-4 latin-iso8859-4) | |
41 (iso-8859-5 cyrillic-iso8859-5) | |
42 ;; Non-mule (X)Emacs uses the last mule-charset for 8bit characters. | |
43 ;; The fake mule-charset, gnus-koi8-r, tells Gnus that the default | |
44 ;; charset is koi8-r, not iso-8859-5. | |
45 (koi8-r cyrillic-iso8859-5 gnus-koi8-r) | |
46 (iso-8859-6 arabic-iso8859-6) | |
47 (iso-8859-7 greek-iso8859-7) | |
48 (iso-8859-8 hebrew-iso8859-8) | |
49 (iso-8859-9 latin-iso8859-9) | |
35148
a408e1d28e3d
(mm-mime-mule-charset-alist): Add Latin-{8,9}.
Dave Love <fx@gnu.org>
parents:
34724
diff
changeset
|
50 (iso-8859-14 latin-iso8859-14) |
a408e1d28e3d
(mm-mime-mule-charset-alist): Add Latin-{8,9}.
Dave Love <fx@gnu.org>
parents:
34724
diff
changeset
|
51 (iso-8859-15 latin-iso8859-15) |
31717 | 52 (viscii vietnamese-viscii-lower) |
53 (iso-2022-jp latin-jisx0201 japanese-jisx0208 japanese-jisx0208-1978) | |
54 (euc-kr korean-ksc5601) | |
35838
53eebdb81828
2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
35793
diff
changeset
|
55 (gb2312 chinese-gb2312) |
53eebdb81828
2001-02-01 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
35793
diff
changeset
|
56 (big5 chinese-big5-1 chinese-big5-2) |
31717 | 57 (tibetan tibetan) |
58 (thai-tis620 thai-tis620) | |
59 (iso-2022-7bit ethiopic arabic-1-column arabic-2-column) | |
60 (iso-2022-jp-2 latin-iso8859-1 greek-iso8859-7 | |
61 latin-jisx0201 japanese-jisx0208-1978 | |
62 chinese-gb2312 japanese-jisx0208 | |
63 korean-ksc5601 japanese-jisx0212 | |
64 katakana-jisx0201) | |
65 (iso-2022-int-1 latin-iso8859-1 greek-iso8859-7 | |
66 latin-jisx0201 japanese-jisx0208-1978 | |
67 chinese-gb2312 japanese-jisx0208 | |
68 korean-ksc5601 japanese-jisx0212 | |
69 chinese-cns11643-1 chinese-cns11643-2) | |
70 (iso-2022-int-1 latin-iso8859-1 latin-iso8859-2 | |
71 cyrillic-iso8859-5 greek-iso8859-7 | |
72 latin-jisx0201 japanese-jisx0208-1978 | |
73 chinese-gb2312 japanese-jisx0208 | |
74 korean-ksc5601 japanese-jisx0212 | |
75 chinese-cns11643-1 chinese-cns11643-2 | |
76 chinese-cns11643-3 chinese-cns11643-4 | |
77 chinese-cns11643-5 chinese-cns11643-6 | |
78 chinese-cns11643-7) | |
36539
9b4d3e18dcf7
(mm-mime-mule-charset-alist): Fix utf-8 case.
Dave Love <fx@gnu.org>
parents:
36474
diff
changeset
|
79 ;; utf-8 comes either from Mule-UCS or Mule 5+. |
9b4d3e18dcf7
(mm-mime-mule-charset-alist): Fix utf-8 case.
Dave Love <fx@gnu.org>
parents:
36474
diff
changeset
|
80 ,@(if (mm-coding-system-p 'utf-8) |
9b4d3e18dcf7
(mm-mime-mule-charset-alist): Fix utf-8 case.
Dave Love <fx@gnu.org>
parents:
36474
diff
changeset
|
81 (list (cons 'utf-8 (delete 'ascii |
9b4d3e18dcf7
(mm-mime-mule-charset-alist): Fix utf-8 case.
Dave Love <fx@gnu.org>
parents:
36474
diff
changeset
|
82 (coding-system-get |
9b4d3e18dcf7
(mm-mime-mule-charset-alist): Fix utf-8 case.
Dave Love <fx@gnu.org>
parents:
36474
diff
changeset
|
83 'mule-utf-8 |
9b4d3e18dcf7
(mm-mime-mule-charset-alist): Fix utf-8 case.
Dave Love <fx@gnu.org>
parents:
36474
diff
changeset
|
84 'safe-charsets)))))) |
31717 | 85 "Alist of MIME-charset/MULE-charsets.") |
86 | |
87 (eval-and-compile | |
36557 | 88 (mapcar |
89 (lambda (elem) | |
90 (let ((nfunc (intern (format "mm-%s" (car elem))))) | |
91 (if (fboundp (car elem)) | |
92 (defalias nfunc (car elem)) | |
93 (defalias nfunc (cdr elem))))) | |
94 '((decode-coding-string . (lambda (s a) s)) | |
95 (encode-coding-string . (lambda (s a) s)) | |
96 (encode-coding-region . ignore) | |
97 (coding-system-list . ignore) | |
98 (decode-coding-region . ignore) | |
99 (char-int . identity) | |
100 (device-type . ignore) | |
101 (coding-system-equal . equal) | |
102 (annotationp . ignore) | |
103 (set-buffer-file-coding-system . ignore) | |
104 (make-char | |
105 . (lambda (charset int) | |
106 (int-to-char int))) | |
107 (read-coding-system | |
108 . (lambda (prompt) | |
109 "Prompt the user for a coding system." | |
110 (completing-read | |
111 prompt (mapcar (lambda (s) (list (symbol-name (car s)))) | |
112 mm-mime-mule-charset-alist)))) | |
113 (read-charset | |
114 . (lambda (prompt) | |
115 "Return a charset." | |
116 (intern | |
117 (completing-read | |
118 prompt | |
119 (mapcar (lambda (e) (list (symbol-name (car e)))) | |
120 mm-mime-mule-charset-alist) | |
121 nil t)))) | |
122 (string-as-unibyte . identity) | |
123 (multibyte-string-p . ignore) | |
124 ))) | |
125 | |
126 (eval-and-compile | |
31717 | 127 (defalias 'mm-char-or-char-int-p |
128 (cond | |
129 ((fboundp 'char-or-char-int-p) 'char-or-char-int-p) | |
130 ((fboundp 'char-valid-p) 'char-valid-p) | |
131 (t 'identity)))) | |
132 | |
133 (defvar mm-coding-system-list nil) | |
134 (defun mm-get-coding-system-list () | |
135 "Get the coding system list." | |
136 (or mm-coding-system-list | |
137 (setq mm-coding-system-list (mm-coding-system-list)))) | |
138 | |
139 (defvar mm-charset-synonym-alist | |
32414
cbdba3c57536
(mm-charset-synonym-alist): Add windows-1252.
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
140 `((big5 . cn-big5) |
31717 | 141 (gb2312 . cn-gb-2312) |
32414
cbdba3c57536
(mm-charset-synonym-alist): Add windows-1252.
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
142 ;; Windows-1252 is actually a superset of Latin-1. See also |
cbdba3c57536
(mm-charset-synonym-alist): Add windows-1252.
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
143 ;; `gnus-article-dumbquotes-map'. |
34724
15c6663e5676
2000-12-19 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
33378
diff
changeset
|
144 ,(unless (mm-coding-system-p 'windows-1252) ; should be defined eventually |
15c6663e5676
2000-12-19 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
33378
diff
changeset
|
145 '(windows-1252 . iso-8859-1)) |
31717 | 146 (x-ctext . ctext)) |
147 "A mapping from invalid charset names to the real charset names.") | |
148 | |
149 (defvar mm-binary-coding-system | |
150 (cond | |
151 ((mm-coding-system-p 'binary) 'binary) | |
152 ((mm-coding-system-p 'no-conversion) 'no-conversion) | |
153 (t nil)) | |
154 "100% binary coding system.") | |
155 | |
156 (defvar mm-text-coding-system | |
157 (or (if (memq system-type '(windows-nt ms-dos ms-windows)) | |
158 (and (mm-coding-system-p 'raw-text-dos) 'raw-text-dos) | |
159 (and (mm-coding-system-p 'raw-text) 'raw-text)) | |
160 mm-binary-coding-system) | |
161 "Text-safe coding system (For removing ^M).") | |
162 | |
163 (defvar mm-text-coding-system-for-write nil | |
164 "Text coding system for write.") | |
165 | |
166 (defvar mm-auto-save-coding-system | |
167 (cond | |
168 ((mm-coding-system-p 'emacs-mule) | |
169 (if (memq system-type '(windows-nt ms-dos ms-windows)) | |
170 (if (mm-coding-system-p 'emacs-mule-dos) | |
171 'emacs-mule-dos mm-binary-coding-system) | |
172 'emacs-mule)) | |
173 ((mm-coding-system-p 'escape-quoted) 'escape-quoted) | |
174 (t mm-binary-coding-system)) | |
175 "Coding system of auto save file.") | |
176 | |
177 ;;; Internal variables: | |
178 | |
179 ;;; Functions: | |
180 | |
181 (defun mm-mule-charset-to-mime-charset (charset) | |
33378 | 182 "Return the MIME charset corresponding to the given Mule CHARSET." |
31717 | 183 (let ((alist mm-mime-mule-charset-alist) |
184 out) | |
185 (while alist | |
186 (when (memq charset (cdar alist)) | |
187 (setq out (caar alist) | |
188 alist nil)) | |
189 (pop alist)) | |
190 out)) | |
191 | |
192 (defun mm-charset-to-coding-system (charset &optional lbt) | |
193 "Return coding-system corresponding to CHARSET. | |
194 CHARSET is a symbol naming a MIME charset. | |
195 If optional argument LBT (`unix', `dos' or `mac') is specified, it is | |
196 used as the line break code type of the coding system." | |
197 (when (stringp charset) | |
198 (setq charset (intern (downcase charset)))) | |
199 (setq charset | |
200 (or (cdr (assq charset mm-charset-synonym-alist)) | |
201 charset)) | |
202 (when lbt | |
203 (setq charset (intern (format "%s-%s" charset lbt)))) | |
204 (cond | |
205 ;; Running in a non-MULE environment. | |
206 ((null (mm-get-coding-system-list)) | |
207 charset) | |
208 ;; ascii | |
209 ((eq charset 'us-ascii) | |
210 'ascii) | |
33378 | 211 ;; Check to see whether we can handle this charset. (This depends |
212 ;; on there being some coding system matching each `mime-charset' | |
213 ;; coding sysytem property defined, as there should be.) | |
31717 | 214 ((memq charset (mm-get-coding-system-list)) |
215 charset) | |
216 ;; Nope. | |
217 (t | |
218 nil))) | |
219 | |
220 (if (fboundp 'subst-char-in-string) | |
221 (defsubst mm-replace-chars-in-string (string from to) | |
222 (subst-char-in-string from to string)) | |
223 (defun mm-replace-chars-in-string (string from to) | |
224 "Replace characters in STRING from FROM to TO." | |
225 (let ((string (substring string 0)) ;Copy string. | |
226 (len (length string)) | |
227 (idx 0)) | |
228 ;; Replace all occurrences of FROM with TO. | |
229 (while (< idx len) | |
230 (when (= (aref string idx) from) | |
231 (aset string idx to)) | |
232 (setq idx (1+ idx))) | |
233 string))) | |
234 | |
235 (defsubst mm-enable-multibyte () | |
33378 | 236 "Set the multibyte flag of the current buffer. |
237 Only do this if the default value of `enable-multibyte-characters' is | |
238 non-nil. This is a no-op in XEmacs." | |
31717 | 239 (when (and (fboundp 'set-buffer-multibyte) |
240 (boundp 'enable-multibyte-characters) | |
241 (default-value 'enable-multibyte-characters)) | |
242 (set-buffer-multibyte t))) | |
243 | |
244 (defsubst mm-disable-multibyte () | |
33378 | 245 "Unset the multibyte flag of in the current buffer. |
246 This is a no-op in XEmacs." | |
31717 | 247 (when (fboundp 'set-buffer-multibyte) |
248 (set-buffer-multibyte nil))) | |
249 | |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
250 (defsubst mm-enable-multibyte-mule4 () |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
251 "Enable multibyte in the current buffer. |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
252 Only used in Emacs Mule 4." |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
253 (when (and (fboundp 'set-buffer-multibyte) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
254 (boundp 'enable-multibyte-characters) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
255 (default-value 'enable-multibyte-characters) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
256 (not (charsetp 'eight-bit-control))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
257 (set-buffer-multibyte t))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
258 |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
259 (defsubst mm-disable-multibyte-mule4 () |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
260 "Disable multibyte in the current buffer. |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
261 Only used in Emacs Mule 4." |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
262 (when (and (fboundp 'set-buffer-multibyte) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
263 (not (charsetp 'eight-bit-control))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
264 (set-buffer-multibyte nil))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
265 |
31717 | 266 (defun mm-preferred-coding-system (charset) |
267 ;; A typo in some Emacs versions. | |
268 (or (get-charset-property charset 'prefered-coding-system) | |
269 (get-charset-property charset 'preferred-coding-system))) | |
270 | |
271 (defun mm-charset-after (&optional pos) | |
272 "Return charset of a character in current buffer at position POS. | |
273 If POS is nil, it defauls to the current point. | |
274 If POS is out of range, the value is nil. | |
275 If the charset is `composition', return the actual one." | |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
276 (let ((char (char-after pos)) charset) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
277 (if (< (mm-char-int char) 128) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
278 (setq charset 'ascii) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
279 ;; charset-after is fake in some Emacsen. |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
280 (setq charset (and (fboundp 'char-charset) (char-charset char))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
281 (if (eq charset 'composition) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
282 (let ((p (or pos (point)))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
283 (cadr (find-charset-region p (1+ p)))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
284 (if (and charset (not (memq charset '(ascii eight-bit-control |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
285 eight-bit-graphic)))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
286 charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
287 (or |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
288 mail-parse-mule-charset ;; cached mule-charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
289 (progn |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
290 (setq mail-parse-mule-charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
291 (and (boundp 'current-language-environment) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
292 (car (last |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
293 (assq 'charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
294 (assoc current-language-environment |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
295 language-info-alist)))))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
296 (if (or (not mail-parse-mule-charset) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
297 (eq mail-parse-mule-charset 'ascii)) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
298 (setq mail-parse-mule-charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
299 (or (car (last (assq mail-parse-charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
300 mm-mime-mule-charset-alist))) |
35793 | 301 ;; Fixme: don't fix that! |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
302 'latin-iso8859-1))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
303 mail-parse-mule-charset))))))) |
31717 | 304 |
305 (defun mm-mime-charset (charset) | |
33378 | 306 "Return the MIME charset corresponding to the given Mule CHARSET." |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
307 (if (and (fboundp 'coding-system-get) (fboundp 'get-charset-property)) |
31717 | 308 ;; This exists in Emacs 20. |
309 (or | |
310 (and (mm-preferred-coding-system charset) | |
311 (coding-system-get | |
312 (mm-preferred-coding-system charset) 'mime-charset)) | |
313 (and (eq charset 'ascii) | |
314 'us-ascii) | |
315 (mm-mule-charset-to-mime-charset charset)) | |
316 ;; This is for XEmacs. | |
317 (mm-mule-charset-to-mime-charset charset))) | |
318 | |
319 (defun mm-delete-duplicates (list) | |
320 "Simple substitute for CL `delete-duplicates', testing with `equal'." | |
321 (let (result head) | |
322 (while list | |
323 (setq head (car list)) | |
324 (setq list (delete head list)) | |
325 (setq result (cons head result))) | |
326 (nreverse result))) | |
327 | |
328 (defun mm-find-mime-charset-region (b e) | |
329 "Return the MIME charsets needed to encode the region between B and E." | |
330 (let ((charsets (mapcar 'mm-mime-charset | |
331 (delq 'ascii | |
332 (mm-find-charset-region b e))))) | |
333 (when (memq 'iso-2022-jp-2 charsets) | |
334 (setq charsets (delq 'iso-2022-jp charsets))) | |
335 (setq charsets (mm-delete-duplicates charsets)) | |
336 (if (and (> (length charsets) 1) | |
337 (fboundp 'find-coding-systems-region) | |
35793 | 338 (let ((cs (find-coding-systems-region b e))) |
339 (or (memq 'utf-8 cs) (memq 'mule-utf-8 cs)))) | |
31717 | 340 '(utf-8) |
341 charsets))) | |
342 | |
343 (defsubst mm-multibyte-p () | |
344 "Say whether multibyte is enabled." | |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
345 (if (and (not (featurep 'xemacs)) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
346 (boundp 'enable-multibyte-characters)) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
347 enable-multibyte-characters |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
348 (featurep 'mule))) |
31717 | 349 |
350 (defmacro mm-with-unibyte-buffer (&rest forms) | |
351 "Create a temporary buffer, and evaluate FORMS there like `progn'. | |
33378 | 352 Use unibyte mode for this." |
353 `(let (default-enable-multibyte-characters) | |
354 (with-temp-buffer ,@forms))) | |
31717 | 355 (put 'mm-with-unibyte-buffer 'lisp-indent-function 0) |
356 (put 'mm-with-unibyte-buffer 'edebug-form-spec '(body)) | |
357 | |
358 (defmacro mm-with-unibyte-current-buffer (&rest forms) | |
33378 | 359 "Evaluate FORMS with current current buffer temporarily made unibyte. |
360 Also bind `default-enable-multibyte-characters' to nil. | |
361 Equivalent to `progn' in XEmacs" | |
31717 | 362 (let ((multibyte (make-symbol "multibyte"))) |
33378 | 363 `(if (fboundp 'set-buffer-multibyte) |
364 (let ((,multibyte enable-multibyte-characters)) | |
365 (unwind-protect | |
366 (let (default-enable-multibyte-characters) | |
367 (set-buffer-multibyte nil) | |
368 ,@forms) | |
369 (set-buffer-multibyte ,multibyte))) | |
370 (progn | |
371 ,@forms)))) | |
31717 | 372 (put 'mm-with-unibyte-current-buffer 'lisp-indent-function 0) |
373 (put 'mm-with-unibyte-current-buffer 'edebug-form-spec '(body)) | |
374 | |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
375 (defmacro mm-with-unibyte-current-buffer-mule4 (&rest forms) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
376 "Evaluate FORMS there like `progn' in current buffer. |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
377 Mule4 only." |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
378 (let ((multibyte (make-symbol "multibyte"))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
379 `(if (or (featurep 'xemacs) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
380 (not (fboundp 'set-buffer-multibyte)) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
381 (charsetp 'eight-bit-control)) ;; For Emacs Mule 4 only. |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
382 (progn |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
383 ,@forms) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
384 (let ((,multibyte (default-value 'enable-multibyte-characters))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
385 (unwind-protect |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
386 (let ((buffer-file-coding-system mm-binary-coding-system) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
387 (coding-system-for-read mm-binary-coding-system) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
388 (coding-system-for-write mm-binary-coding-system)) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
389 (set-buffer-multibyte nil) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
390 (setq-default enable-multibyte-characters nil) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
391 ,@forms) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
392 (setq-default enable-multibyte-characters ,multibyte) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
393 (set-buffer-multibyte ,multibyte)))))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
394 (put 'mm-with-unibyte-current-buffer-mule4 'lisp-indent-function 0) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
395 (put 'mm-with-unibyte-current-buffer-mule4 'edebug-form-spec '(body)) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
396 |
31717 | 397 (defmacro mm-with-unibyte (&rest forms) |
33378 | 398 "Eval the FORMS with the default value of `enable-multibyte-characters' nil, ." |
399 `(let (default-enable-multibyte-characters) | |
400 ,@forms)) | |
31717 | 401 (put 'mm-with-unibyte 'lisp-indent-function 0) |
402 (put 'mm-with-unibyte 'edebug-form-spec '(body)) | |
403 | |
404 (defun mm-find-charset-region (b e) | |
33378 | 405 "Return a list of Emacs charsets in the region B to E." |
31717 | 406 (cond |
407 ((and (mm-multibyte-p) | |
408 (fboundp 'find-charset-region)) | |
409 ;; Remove composition since the base charsets have been included. | |
410 (delq 'composition (find-charset-region b e))) | |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
411 (t |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
412 ;; We are in a unibyte buffer or XEmacs non-mule, so we futz around a bit. |
31717 | 413 (save-excursion |
414 (save-restriction | |
415 (narrow-to-region b e) | |
416 (goto-char (point-min)) | |
417 (skip-chars-forward "\0-\177") | |
418 (if (eobp) | |
419 '(ascii) | |
32976
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
420 (let (charset) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
421 (setq charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
422 (and (boundp 'current-language-environment) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
423 (car (last (assq 'charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
424 (assoc current-language-environment |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
425 language-info-alist)))))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
426 (if (eq charset 'ascii) (setq charset nil)) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
427 (or charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
428 (setq charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
429 (car (last (assq mail-parse-charset |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
430 mm-mime-mule-charset-alist))))) |
aa9dc4e7c5ac
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
32414
diff
changeset
|
431 (list 'ascii (or charset 'latin-iso8859-1))))))))) |
31717 | 432 |
433 (if (fboundp 'shell-quote-argument) | |
434 (defalias 'mm-quote-arg 'shell-quote-argument) | |
435 (defun mm-quote-arg (arg) | |
436 "Return a version of ARG that is safe to evaluate in a shell." | |
437 (let ((pos 0) new-pos accum) | |
438 ;; *** bug: we don't handle newline characters properly | |
439 (while (setq new-pos (string-match "[]*[;!'`\"$\\& \t{} |()<>]" arg pos)) | |
440 (push (substring arg pos new-pos) accum) | |
441 (push "\\" accum) | |
442 (push (list (aref arg new-pos)) accum) | |
443 (setq pos (1+ new-pos))) | |
444 (if (= pos 0) | |
445 arg | |
446 (apply 'concat (nconc (nreverse accum) (list (substring arg pos)))))))) | |
447 | |
448 (defun mm-auto-mode-alist () | |
449 "Return an `auto-mode-alist' with only the .gz (etc) thingies." | |
450 (let ((alist auto-mode-alist) | |
451 out) | |
452 (while alist | |
453 (when (listp (cdar alist)) | |
454 (push (car alist) out)) | |
455 (pop alist)) | |
456 (nreverse out))) | |
457 | |
458 (defvar mm-inhibit-file-name-handlers | |
36473
c1e752e8d255
(mm-inhibit-file-name-handlers): Add
Dave Love <fx@gnu.org>
parents:
35838
diff
changeset
|
459 '(jka-compr-handler image-file-handler) |
31717 | 460 "A list of handlers doing (un)compression (etc) thingies.") |
461 | |
462 (defun mm-insert-file-contents (filename &optional visit beg end replace | |
463 inhibit) | |
464 "Like `insert-file-contents', q.v., but only reads in the file. | |
465 A buffer may be modified in several ways after reading into the buffer due | |
466 to advanced Emacs features, such as file-name-handlers, format decoding, | |
467 find-file-hooks, etc. | |
468 If INHIBIT is non-nil, inhibit mm-inhibit-file-name-handlers. | |
469 This function ensures that none of these modifications will take place." | |
470 (let ((format-alist nil) | |
471 (auto-mode-alist (if inhibit nil (mm-auto-mode-alist))) | |
472 (default-major-mode 'fundamental-mode) | |
473 (enable-local-variables nil) | |
474 (after-insert-file-functions nil) | |
475 (enable-local-eval nil) | |
476 (find-file-hooks nil) | |
477 (inhibit-file-name-operation (if inhibit | |
478 'insert-file-contents | |
479 inhibit-file-name-operation)) | |
480 (inhibit-file-name-handlers | |
481 (if inhibit | |
482 (append mm-inhibit-file-name-handlers | |
483 inhibit-file-name-handlers) | |
484 inhibit-file-name-handlers))) | |
485 (insert-file-contents filename visit beg end replace))) | |
486 | |
487 (defun mm-append-to-file (start end filename &optional codesys inhibit) | |
488 "Append the contents of the region to the end of file FILENAME. | |
489 When called from a function, expects three arguments, | |
490 START, END and FILENAME. START and END are buffer positions | |
491 saying what text to write. | |
492 Optional fourth argument specifies the coding system to use when | |
493 encoding the file. | |
494 If INHIBIT is non-nil, inhibit mm-inhibit-file-name-handlers." | |
495 (let ((coding-system-for-write | |
496 (or codesys mm-text-coding-system-for-write | |
497 mm-text-coding-system)) | |
498 (inhibit-file-name-operation (if inhibit | |
499 'append-to-file | |
500 inhibit-file-name-operation)) | |
501 (inhibit-file-name-handlers | |
502 (if inhibit | |
503 (append mm-inhibit-file-name-handlers | |
504 inhibit-file-name-handlers) | |
505 inhibit-file-name-handlers))) | |
506 (append-to-file start end filename))) | |
507 | |
508 (defun mm-write-region (start end filename &optional append visit lockname | |
509 coding-system inhibit) | |
510 | |
511 "Like `write-region'. | |
512 If INHIBIT is non-nil, inhibit mm-inhibit-file-name-handlers." | |
513 (let ((coding-system-for-write | |
514 (or coding-system mm-text-coding-system-for-write | |
515 mm-text-coding-system)) | |
516 (inhibit-file-name-operation (if inhibit | |
517 'write-region | |
518 inhibit-file-name-operation)) | |
519 (inhibit-file-name-handlers | |
520 (if inhibit | |
521 (append mm-inhibit-file-name-handlers | |
522 inhibit-file-name-handlers) | |
523 inhibit-file-name-handlers))) | |
524 (write-region start end filename append visit lockname))) | |
525 | |
526 (provide 'mm-util) | |
527 | |
528 ;;; mm-util.el ends here |