1 ;;; mm-util.el --- Utility functions for Mule and low level things
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
38 (let ((nfunc (intern (format "mm-%s" (car elem)))))
39 (if (fboundp (car elem))
40 (defalias nfunc (car elem))
41 (defalias nfunc (cdr elem)))))
42 '((decode-coding-string . (lambda (s a) s))
43 (encode-coding-string . (lambda (s a) s))
44 (encode-coding-region . ignore)
45 (coding-system-list . ignore)
46 (decode-coding-region . ignore)
48 (coding-system-equal . equal)
49 (annotationp . ignore)
50 (set-buffer-file-coding-system . ignore)
57 (mapcar (lambda (e) (list (symbol-name (car e))))
58 mm-mime-mule-charset-alist)
61 . (lambda (from to string &optional inplace)
62 ;; stolen (and renamed) from nnheader.el
63 "Replace characters in STRING from FROM to TO.
64 Unless optional argument INPLACE is non-nil, return a new string."
65 (let ((string (if inplace string (copy-sequence string)))
68 ;; Replace all occurrences of FROM with TO.
70 (when (= (aref string idx) from)
75 . (lambda (string regexp rep &optional literal)
76 "See `replace-regexp-in-string', only the order of args differs."
77 (replace-regexp-in-string regexp rep string nil literal)))
78 (string-as-unibyte . identity)
79 (string-make-unibyte . identity)
80 ;; string-as-multibyte often doesn't really do what you think it does.
82 ;; (aref (string-as-multibyte "\201") 0) -> 129 (aka ?\201)
83 ;; (aref (string-as-multibyte "\300") 0) -> 192 (aka ?\300)
84 ;; (aref (string-as-multibyte "\300\201") 0) -> 192 (aka ?\300)
85 ;; (aref (string-as-multibyte "\300\201") 1) -> 129 (aka ?\201)
87 ;; (aref (string-as-multibyte "\201\300") 0) -> 2240
88 ;; (aref (string-as-multibyte "\201\300") 1) -> <error>
89 ;; Better use string-to-multibyte or encode-coding-string.
90 ;; If you really need string-as-multibyte somewhere it's usually
91 ;; because you're using the internal emacs-mule representation (maybe
92 ;; because you're using string-as-unibyte somewhere), which is
93 ;; generally a problem in itself.
94 ;; Here is an approximate equivalence table to help think about it:
95 ;; (string-as-multibyte s) ~= (decode-coding-string s 'emacs-mule)
96 ;; (string-to-multibyte s) ~= (decode-coding-string s 'binary)
97 ;; (string-make-multibyte s) ~= (decode-coding-string s locale-coding-system)
98 (string-as-multibyte . identity)
101 "Return a multibyte string with the same individual chars as string."
103 (lambda (ch) (mm-string-as-multibyte (char-to-string ch)))
105 (multibyte-string-p . ignore)
106 (insert-byte . insert-char)
107 (multibyte-char-to-unibyte . identity)
109 . (lambda (buffer-name)
110 "Returns non-nil if a buffer named BUFFER-NAME gets a special frame."
111 (and special-display-function
112 (or (and (member buffer-name special-display-buffer-names) t)
113 (cdr (assoc buffer-name special-display-buffer-names))
115 (dolist (elem special-display-regexps)
117 (string-match elem buffer-name)
121 (string-match (car elem) buffer-name)
122 (throw 'return (cdr elem))))))))))))
125 (defalias 'mm-char-or-char-int-p
127 ((fboundp 'char-or-char-int-p) 'char-or-char-int-p)
128 ((fboundp 'char-valid-p) 'char-valid-p)
131 ;; Fixme: This seems always to be used to read a MIME charset, so it
132 ;; should be re-named and fixed (in Emacs) to offer completion only on
133 ;; proper charset names (base coding systems which have a
134 ;; mime-charset defined). XEmacs doesn't believe in mime-charset;
136 ;; `(or (coding-system-get 'iso-8859-1 'mime-charset)
137 ;; (coding-system-get 'iso-8859-1 :mime-charset))'
138 ;; Actually, there should be an `mm-coding-system-mime-charset'.
140 (defalias 'mm-read-coding-system
142 ((fboundp 'read-coding-system)
143 (if (and (featurep 'xemacs)
144 (<= (string-to-number emacs-version) 21.1))
145 (lambda (prompt &optional default-coding-system)
146 (read-coding-system prompt))
147 'read-coding-system))
148 (t (lambda (prompt &optional default-coding-system)
149 "Prompt the user for a coding system."
151 prompt (mapcar (lambda (s) (list (symbol-name (car s))))
152 mm-mime-mule-charset-alist)))))))
154 (defvar mm-coding-system-list nil)
155 (defun mm-get-coding-system-list ()
156 "Get the coding system list."
157 (or mm-coding-system-list
158 (setq mm-coding-system-list (mm-coding-system-list))))
160 (defun mm-coding-system-p (cs)
161 "Return non-nil if CS is a symbol naming a coding system.
162 In XEmacs, also return non-nil if CS is a coding system object.
163 If CS is available, return CS itself in Emacs, and return a coding
164 system object in XEmacs."
165 (if (fboundp 'find-coding-system)
166 (and cs (find-coding-system cs))
167 (if (fboundp 'coding-system-p)
168 (when (coding-system-p cs)
170 ;; Is this branch ever actually useful?
171 (car (memq cs (mm-get-coding-system-list))))))
173 (defun mm-codepage-setup (number &optional alias)
174 "Create a coding system cpNUMBER.
175 The coding system is created using `codepage-setup'. If ALIAS is
176 non-nil, an alias is created and added to
177 `mm-charset-synonym-alist'. If ALIAS is a string, it's used as
178 the alias. Else windows-NUMBER is used."
180 (let ((completion-ignore-case t)
181 (candidates (cp-supported-codepages)))
182 (list (completing-read "Setup DOS Codepage: (default 437) " candidates
183 nil t nil nil "437"))))
185 (setq alias (if (stringp alias)
187 (intern (format "windows-%s" number)))))
188 (let* ((cp (intern (format "cp%s" number))))
189 (unless (mm-coding-system-p cp)
190 (codepage-setup number))
192 ;; Don't add alias if setup of cp failed.
193 (mm-coding-system-p cp))
194 (add-to-list 'mm-charset-synonym-alist (cons alias cp)))))
196 (defvar mm-charset-synonym-alist
198 ;; Not in XEmacs, but it's not a proper MIME charset anyhow.
199 ,@(unless (mm-coding-system-p 'x-ctext)
200 '((x-ctext . ctext)))
201 ;; ISO-8859-15 is very similar to ISO-8859-1. But it's _different_!
202 ,@(unless (mm-coding-system-p 'iso-8859-15)
203 '((iso-8859-15 . iso-8859-1)))
204 ;; BIG-5HKSCS is similar to, but different than, BIG-5.
205 ,@(unless (mm-coding-system-p 'big5-hkscs)
206 '((big5-hkscs . big5)))
207 ;; Windows-1252 is actually a superset of Latin-1. See also
208 ;; `gnus-article-dumbquotes-map'.
209 ,@(unless (mm-coding-system-p 'windows-1252)
210 (if (mm-coding-system-p 'cp1252)
211 '((windows-1252 . cp1252))
212 '((windows-1252 . iso-8859-1))))
213 ;; Windows-1250 is a variant of Latin-2 heavily used by Microsoft
214 ;; Outlook users in Czech republic. Use this to allow reading of their
215 ;; e-mails. cp1250 should be defined by M-x codepage-setup.
216 ,@(if (and (not (mm-coding-system-p 'windows-1250))
217 (mm-coding-system-p 'cp1250))
218 '((windows-1250 . cp1250)))
219 ;; A Microsoft misunderstanding.
220 ,@(if (and (not (mm-coding-system-p 'unicode))
221 (mm-coding-system-p 'utf-16-le))
222 '((unicode . utf-16-le)))
223 ;; A Microsoft misunderstanding.
224 ,@(unless (mm-coding-system-p 'ks_c_5601-1987)
225 (if (mm-coding-system-p 'cp949)
226 '((ks_c_5601-1987 . cp949))
227 '((ks_c_5601-1987 . euc-kr))))
229 "A mapping from unknown or invalid charset names to the real charset names.")
231 (defcustom mm-charset-override-alist
232 `((iso-8859-1 . windows-1252))
233 "A mapping from undesired charset names to their replacement.
235 You may add pair like (iso-8859-1 . windows-1252) here,
236 i.e. treat iso-8859-1 as windows-1252. windows-1252 is a
237 superset of iso-8859-1."
238 :type '(list (set :inline t
239 (const (iso-8859-1 . windows-1252))
240 (const (undecided . windows-1252)))
243 (cons (symbol :tag "From charset")
244 (symbol :tag "To charset"))))
245 :version "23.0" ;; No Gnus
248 (defcustom mm-charset-eval-alist
249 (if (featurep 'xemacs)
250 nil ;; I don't know what would be useful for XEmacs.
251 '(;; Emacs 21 offers 1250 1251 1253 1257. Emacs 22 provides autoloads for
252 ;; 1250-1258 (i.e. `mm-codepage-setup' does nothing).
253 (windows-1250 . (mm-codepage-setup 1250 t))
254 (windows-1251 . (mm-codepage-setup 1251 t))
255 (windows-1253 . (mm-codepage-setup 1253 t))
256 (windows-1257 . (mm-codepage-setup 1257 t))))
257 "An alist of (CHARSET . FORM) pairs.
258 If an article is encoded in an unknown CHARSET, FORM is
259 evaluated. This allows to load additional libraries providing
260 charsets on demand. If supported by your Emacs version, you
261 could use `autoload-coding-system' here."
262 :version "23.0" ;; No Gnus
263 :type '(list (set :inline t
264 (const (windows-1250 . (mm-codepage-setup 1250 t)))
265 (const (windows-1251 . (mm-codepage-setup 1251 t)))
266 (const (windows-1253 . (mm-codepage-setup 1253 t)))
267 (const (windows-1257 . (mm-codepage-setup 1257 t)))
268 (const (cp850 . (mm-codepage-setup 850 nil))))
271 (cons (symbol :tag "charset")
272 (symbol :tag "form"))))
275 (defvar mm-binary-coding-system
277 ((mm-coding-system-p 'binary) 'binary)
278 ((mm-coding-system-p 'no-conversion) 'no-conversion)
280 "100% binary coding system.")
282 (defvar mm-text-coding-system
283 (or (if (memq system-type '(windows-nt ms-dos ms-windows))
284 (and (mm-coding-system-p 'raw-text-dos) 'raw-text-dos)
285 (and (mm-coding-system-p 'raw-text) 'raw-text))
286 mm-binary-coding-system)
287 "Text-safe coding system (For removing ^M).")
289 (defvar mm-text-coding-system-for-write nil
290 "Text coding system for write.")
292 (defvar mm-auto-save-coding-system
294 ((mm-coding-system-p 'utf-8-emacs) ; Mule 7
295 (if (memq system-type '(windows-nt ms-dos ms-windows))
296 (if (mm-coding-system-p 'utf-8-emacs-dos)
297 'utf-8-emacs-dos mm-binary-coding-system)
299 ((mm-coding-system-p 'emacs-mule)
300 (if (memq system-type '(windows-nt ms-dos ms-windows))
301 (if (mm-coding-system-p 'emacs-mule-dos)
302 'emacs-mule-dos mm-binary-coding-system)
304 ((mm-coding-system-p 'escape-quoted) 'escape-quoted)
305 (t mm-binary-coding-system))
306 "Coding system of auto save file.")
308 (defvar mm-universal-coding-system mm-auto-save-coding-system
309 "The universal coding system.")
311 ;; Fixme: some of the cars here aren't valid MIME charsets. That
312 ;; should only matter with XEmacs, though.
313 (defvar mm-mime-mule-charset-alist
315 (iso-8859-1 latin-iso8859-1)
316 (iso-8859-2 latin-iso8859-2)
317 (iso-8859-3 latin-iso8859-3)
318 (iso-8859-4 latin-iso8859-4)
319 (iso-8859-5 cyrillic-iso8859-5)
320 ;; Non-mule (X)Emacs uses the last mule-charset for 8bit characters.
321 ;; The fake mule-charset, gnus-koi8-r, tells Gnus that the default
322 ;; charset is koi8-r, not iso-8859-5.
323 (koi8-r cyrillic-iso8859-5 gnus-koi8-r)
324 (iso-8859-6 arabic-iso8859-6)
325 (iso-8859-7 greek-iso8859-7)
326 (iso-8859-8 hebrew-iso8859-8)
327 (iso-8859-9 latin-iso8859-9)
328 (iso-8859-14 latin-iso8859-14)
329 (iso-8859-15 latin-iso8859-15)
330 (viscii vietnamese-viscii-lower)
331 (iso-2022-jp latin-jisx0201 japanese-jisx0208 japanese-jisx0208-1978)
332 (euc-kr korean-ksc5601)
333 (gb2312 chinese-gb2312)
334 (big5 chinese-big5-1 chinese-big5-2)
336 (thai-tis620 thai-tis620)
337 (windows-1251 cyrillic-iso8859-5)
338 (iso-2022-7bit ethiopic arabic-1-column arabic-2-column)
339 (iso-2022-jp-2 latin-iso8859-1 greek-iso8859-7
340 latin-jisx0201 japanese-jisx0208-1978
341 chinese-gb2312 japanese-jisx0208
342 korean-ksc5601 japanese-jisx0212)
343 (iso-2022-int-1 latin-iso8859-1 greek-iso8859-7
344 latin-jisx0201 japanese-jisx0208-1978
345 chinese-gb2312 japanese-jisx0208
346 korean-ksc5601 japanese-jisx0212
347 chinese-cns11643-1 chinese-cns11643-2)
348 (iso-2022-int-1 latin-iso8859-1 latin-iso8859-2
349 cyrillic-iso8859-5 greek-iso8859-7
350 latin-jisx0201 japanese-jisx0208-1978
351 chinese-gb2312 japanese-jisx0208
352 korean-ksc5601 japanese-jisx0212
353 chinese-cns11643-1 chinese-cns11643-2
354 chinese-cns11643-3 chinese-cns11643-4
355 chinese-cns11643-5 chinese-cns11643-6
357 (iso-2022-jp-3 latin-jisx0201 japanese-jisx0208-1978 japanese-jisx0208
358 japanese-jisx0213-1 japanese-jisx0213-2)
359 (shift_jis latin-jisx0201 katakana-jisx0201 japanese-jisx0208)
360 ,(if (or (not (fboundp 'charsetp)) ;; non-Mule case
361 (charsetp 'unicode-a)
362 (not (mm-coding-system-p 'mule-utf-8)))
363 '(utf-8 unicode-a unicode-b unicode-c unicode-d unicode-e)
364 ;; If we have utf-8 we're in Mule 5+.
367 (coding-system-get 'mule-utf-8 'safe-charsets)))))
368 "Alist of MIME-charset/MULE-charsets.")
370 (defun mm-enrich-utf-8-by-mule-ucs ()
371 "Make the `utf-8' MIME charset usable by the Mule-UCS package.
372 This function will run when the `un-define' module is loaded under
373 XEmacs, and fill the `utf-8' entry in `mm-mime-mule-charset-alist'
374 with Mule charsets. It is completely useless for Emacs."
375 (unless (cdr (delete '(mm-enrich-utf-8-by-mule-ucs)
376 (assoc "un-define" after-load-alist)))
377 (setq after-load-alist
378 (delete '("un-define") after-load-alist)))
379 (when (boundp 'unicode-basic-translation-charset-order-list)
385 'unicode-basic-translation-charset-order-list))))
386 (elem (assq 'utf-8 mm-mime-mule-charset-alist)))
389 (setq mm-mime-mule-charset-alist
390 (nconc mm-mime-mule-charset-alist
391 (list (cons 'utf-8 val))))))
394 ;; Correct by construction, but should be unnecessary for Emacs:
395 (if (featurep 'xemacs)
396 (eval-after-load "un-define" '(mm-enrich-utf-8-by-mule-ucs))
397 (when (and (fboundp 'coding-system-list)
398 (fboundp 'sort-coding-systems))
399 (let ((css (sort-coding-systems (coding-system-list 'base-only)))
403 mime (or (coding-system-get cs :mime-charset) ; Emacs 22
404 (coding-system-get cs 'mime-charset)))
406 (not (eq t (setq mule
407 (coding-system-get cs 'safe-charsets))))
408 (not (assq mime alist)))
409 (push (cons mime (delq 'ascii mule)) alist)))
410 (setq mm-mime-mule-charset-alist (nreverse alist)))))
412 (defvar mm-hack-charsets '(iso-8859-15 iso-2022-jp-2)
413 "A list of special charsets.
414 Valid elements include:
415 `iso-8859-15' convert ISO-8859-1, -9 to ISO-8859-15 if ISO-8859-15 exists.
416 `iso-2022-jp-2' convert ISO-2022-jp to ISO-2022-jp-2 if ISO-2022-jp-2 exists."
419 (defvar mm-iso-8859-15-compatible
420 '((iso-8859-1 "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE")
421 (iso-8859-9 "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE\xD0\xDD\xDE\xF0\xFD\xFE"))
422 "ISO-8859-15 exchangeable coding systems and inconvertible characters.")
424 (defvar mm-iso-8859-x-to-15-table
425 (and (fboundp 'coding-system-p)
426 (mm-coding-system-p 'iso-8859-15)
429 (if (mm-coding-system-p (car cs))
430 (let ((c (string-to-char
431 (decode-coding-string "\341" (car cs)))))
432 (cons (char-charset c)
435 (decode-coding-string "\341" 'iso-8859-15)) c)
436 (string-to-list (decode-coding-string (car (cdr cs))
439 mm-iso-8859-15-compatible))
440 "A table of the difference character between ISO-8859-X and ISO-8859-15.")
442 (defcustom mm-coding-system-priorities
443 (if (boundp 'current-language-environment)
444 (let ((lang (symbol-value 'current-language-environment)))
445 (cond ((string= lang "Japanese")
446 ;; Japanese users prefer iso-2022-jp to euc-japan or
447 ;; shift_jis, however iso-8859-1 should be used when
448 ;; there are only ASCII text and Latin-1 characters.
449 '(iso-8859-1 iso-2022-jp iso-2022-jp-2 shift_jis utf-8)))))
450 "Preferred coding systems for encoding outgoing messages.
452 More than one suitable coding system may be found for some text.
453 By default, the coding system with the highest priority is used
454 to encode outgoing messages (see `sort-coding-systems'). If this
455 variable is set, it overrides the default priority."
457 :type '(repeat (symbol :tag "Coding system"))
461 (defvar mm-use-find-coding-systems-region
462 (fboundp 'find-coding-systems-region)
463 "Use `find-coding-systems-region' to find proper coding systems.
465 Setting it to nil is useful on Emacsen supporting Unicode if sending
466 mail with multiple parts is preferred to sending a Unicode one.")
468 ;;; Internal variables:
472 (defun mm-mule-charset-to-mime-charset (charset)
473 "Return the MIME charset corresponding to the given Mule CHARSET."
474 (if (and (fboundp 'find-coding-systems-for-charsets)
475 (fboundp 'sort-coding-systems))
476 (let ((css (sort (sort-coding-systems
477 (find-coding-systems-for-charsets (list charset)))
478 'mm-sort-coding-systems-predicate))
480 (while (and (not mime)
482 (when (setq cs (pop css))
483 (setq mime (or (coding-system-get cs :mime-charset)
484 (coding-system-get cs 'mime-charset)))))
486 (let ((alist (mapcar (lambda (cs)
487 (assq cs mm-mime-mule-charset-alist))
488 (sort (mapcar 'car mm-mime-mule-charset-alist)
489 'mm-sort-coding-systems-predicate)))
492 (when (memq charset (cdar alist))
493 (setq out (caar alist)
498 (defun mm-charset-to-coding-system (charset &optional lbt
500 "Return coding-system corresponding to CHARSET.
501 CHARSET is a symbol naming a MIME charset.
502 If optional argument LBT (`unix', `dos' or `mac') is specified, it is
503 used as the line break code type of the coding system.
505 If ALLOW-OVERRIDE is given, use `mm-charset-override-alist' to
506 map undesired charset names to their replacement. This should
507 only be used for decoding, not for encoding."
508 ;; OVERRIDE is used (only) in `mm-decode-body'.
509 (when (stringp charset)
510 (setq charset (intern (downcase charset))))
512 (setq charset (intern (format "%s-%s" charset lbt))))
516 ;; Running in a non-MULE environment.
517 ((or (null (mm-get-coding-system-list))
518 (not (fboundp 'coding-system-get)))
520 ;; Check override list quite early. Should only used for decoding, not for
523 (let ((cs (cdr (assq charset mm-charset-override-alist))))
524 (and cs (mm-coding-system-p cs) cs))))
526 ((eq charset 'us-ascii)
528 ;; Check to see whether we can handle this charset. (This depends
529 ;; on there being some coding system matching each `mime-charset'
530 ;; property defined, as there should be.)
531 ((and (mm-coding-system-p charset)
532 ;;; Doing this would potentially weed out incorrect charsets.
534 ;;; (eq charset (coding-system-get charset 'mime-charset))
537 ;; Eval expressions from `mm-charset-eval-alist'
538 ((let* ((el (assq charset mm-charset-eval-alist))
545 (condition-case nil (eval form) (error nil))
546 ;; (message "Failed to eval `%s'" form))
547 (mm-coding-system-p cs)
548 (message "Added charset `%s' via `mm-charset-eval-alist'" cs))
550 ;; Translate invalid charsets.
551 ((let ((cs (cdr (assq charset mm-charset-synonym-alist))))
553 (mm-coding-system-p cs)
555 ;; "Using synonym `%s' from `mm-charset-synonym-alist' for `%s'"
558 ;; Last resort: search the coding system list for entries which
559 ;; have the right mime-charset in case the canonical name isn't
560 ;; defined (though it should be).
562 ;; mm-get-coding-system-list returns a list of cs without lbt.
564 (dolist (c (mm-get-coding-system-list))
566 (eq charset (or (coding-system-get c :mime-charset)
567 (coding-system-get c 'mime-charset))))
570 ;; Warn the user about unknown charset:
571 (if (fboundp 'gnus-message)
572 (gnus-message 7 "Unknown charset: %s" charset)
573 (message "Unknown charset: %s" charset)))
577 (defvar mm-emacs-mule (and (not (featurep 'xemacs))
578 (boundp 'default-enable-multibyte-characters)
579 default-enable-multibyte-characters
580 (fboundp 'set-buffer-multibyte))
581 "True in Emacs with Mule.")
584 (defun mm-enable-multibyte ()
585 "Set the multibyte flag of the current buffer.
586 Only do this if the default value of `enable-multibyte-characters' is
587 non-nil. This is a no-op in XEmacs."
588 (set-buffer-multibyte 'to))
589 (defalias 'mm-enable-multibyte 'ignore))
592 (defun mm-disable-multibyte ()
593 "Unset the multibyte flag of in the current buffer.
594 This is a no-op in XEmacs."
595 (set-buffer-multibyte nil))
596 (defalias 'mm-disable-multibyte 'ignore)))
598 (defun mm-preferred-coding-system (charset)
599 ;; A typo in some Emacs versions.
600 (or (get-charset-property charset 'preferred-coding-system)
601 (get-charset-property charset 'prefered-coding-system)))
603 ;; Mule charsets shouldn't be used.
604 (defsubst mm-guess-charset ()
605 "Guess Mule charset from the language environment."
607 mail-parse-mule-charset ;; cached mule-charset
609 (setq mail-parse-mule-charset
610 (and (boundp 'current-language-environment)
613 (assoc current-language-environment
614 language-info-alist))))))
615 (if (or (not mail-parse-mule-charset)
616 (eq mail-parse-mule-charset 'ascii))
617 (setq mail-parse-mule-charset
618 (or (car (last (assq mail-parse-charset
619 mm-mime-mule-charset-alist)))
622 mail-parse-mule-charset)))
624 (defun mm-charset-after (&optional pos)
625 "Return charset of a character in current buffer at position POS.
626 If POS is nil, it defauls to the current point.
627 If POS is out of range, the value is nil.
628 If the charset is `composition', return the actual one."
629 (let ((char (char-after pos)) charset)
630 (if (< (mm-char-int char) 128)
631 (setq charset 'ascii)
632 ;; charset-after is fake in some Emacsen.
633 (setq charset (and (fboundp 'char-charset) (char-charset char)))
634 (if (eq charset 'composition) ; Mule 4
635 (let ((p (or pos (point))))
636 (cadr (find-charset-region p (1+ p))))
637 (if (and charset (not (memq charset '(ascii eight-bit-control
638 eight-bit-graphic))))
640 (mm-guess-charset))))))
642 (defun mm-mime-charset (charset)
643 "Return the MIME charset corresponding to the given Mule CHARSET."
644 (if (eq charset 'unknown)
645 (error "The message contains non-printable characters, please use attachment"))
646 (if (and (fboundp 'coding-system-get) (fboundp 'get-charset-property))
647 ;; This exists in Emacs 20.
649 (and (mm-preferred-coding-system charset)
650 (or (coding-system-get
651 (mm-preferred-coding-system charset) :mime-charset)
653 (mm-preferred-coding-system charset) 'mime-charset)))
654 (and (eq charset 'ascii)
656 (mm-preferred-coding-system charset)
657 (mm-mule-charset-to-mime-charset charset))
658 ;; This is for XEmacs.
659 (mm-mule-charset-to-mime-charset charset)))
661 (if (fboundp 'delete-dups)
662 (defalias 'mm-delete-duplicates 'delete-dups)
663 (defun mm-delete-duplicates (list)
664 "Destructively remove `equal' duplicates from LIST.
665 Store the result in LIST and return it. LIST must be a proper list.
666 Of several `equal' occurrences of an element in LIST, the first
669 This is a compatibility function for Emacsen without `delete-dups'."
670 ;; Code from `subr.el' in Emacs 22:
673 (setcdr tail (delete (car tail) (cdr tail)))
674 (setq tail (cdr tail))))
677 ;; Fixme: This is used in places when it should be testing the
678 ;; default multibyteness. See mm-default-multibyte-p.
680 (if (and (not (featurep 'xemacs))
681 (boundp 'enable-multibyte-characters))
682 (defun mm-multibyte-p ()
683 "Non-nil if multibyte is enabled in the current buffer."
684 enable-multibyte-characters)
685 (defun mm-multibyte-p () (featurep 'mule))))
687 (defun mm-default-multibyte-p ()
688 "Return non-nil if the session is multibyte.
689 This affects whether coding conversion should be attempted generally."
691 (if (boundp 'default-enable-multibyte-characters)
692 default-enable-multibyte-characters
695 (defun mm-iso-8859-x-to-15-region (&optional b e)
696 (if (fboundp 'char-charset)
697 (let (charset item c inconvertible)
699 (if e (narrow-to-region b e))
700 (goto-char (point-min))
701 (skip-chars-forward "\0-\177")
704 ((not (setq item (assq (char-charset (setq c (char-after)))
705 mm-iso-8859-x-to-15-table)))
707 ((memq c (cdr (cdr item)))
708 (setq inconvertible t)
711 (insert-before-markers (prog1 (+ c (car (cdr item)))
713 (skip-chars-forward "\0-\177")))
714 (not inconvertible))))
716 (defun mm-sort-coding-systems-predicate (a b)
719 ;; Note: invalid entries are dropped silently
720 (and (setq cs (mm-coding-system-p cs))
721 (coding-system-base cs)))
722 mm-coding-system-priorities)))
723 (and (setq a (mm-coding-system-p a))
724 (if (setq b (mm-coding-system-p b))
725 (> (length (memq (coding-system-base a) priorities))
726 (length (memq (coding-system-base b) priorities)))
730 (autoload 'latin-unity-massage-name "latin-unity")
731 (autoload 'latin-unity-maybe-remap "latin-unity")
732 (autoload 'latin-unity-representations-feasible-region "latin-unity")
733 (autoload 'latin-unity-representations-present-region "latin-unity")
734 (defvar latin-unity-coding-systems)
735 (defvar latin-unity-ucs-list))
737 (defun mm-xemacs-find-mime-charset-1 (begin end)
738 "Determine which MIME charset to use to send region as message.
739 This uses the XEmacs-specific latin-unity package to better handle the
740 case where identical characters from diverse ISO-8859-? character sets
741 can be encoded using a single one of the corresponding coding systems.
743 It treats `mm-coding-system-priorities' as the list of preferred
744 coding systems; a useful example setting for this list in Western
745 Europe would be '(iso-8859-1 iso-8859-15 utf-8), which would default
746 to the very standard Latin 1 coding system, and only move to coding
747 systems that are less supported as is necessary to encode the
748 characters that exist in the buffer.
750 Latin Unity doesn't know about those non-ASCII Roman characters that
751 are available in various East Asian character sets. As such, its
752 behavior if you have a JIS 0212 LATIN SMALL LETTER A WITH ACUTE in a
753 buffer and it can otherwise be encoded as Latin 1, won't be ideal.
754 But this is very much a corner case, so don't worry about it."
755 (let ((systems mm-coding-system-priorities) csets psets curset)
757 ;; Load the Latin Unity library, if available.
758 (when (and (not (featurep 'latin-unity)) (locate-library "latin-unity"))
759 (require 'latin-unity))
761 ;; Now, can we use it?
762 (if (featurep 'latin-unity)
764 (setq csets (latin-unity-representations-feasible-region begin end)
765 psets (latin-unity-representations-present-region begin end))
769 ;; Pass back the first coding system in the preferred list
770 ;; that can encode the whole region.
771 (dolist (curset systems)
772 (setq curset (latin-unity-massage-name 'buffer-default curset))
774 ;; If the coding system is a universal coding system, then
775 ;; it can certainly encode all the characters in the region.
776 (if (memq curset latin-unity-ucs-list)
777 (throw 'done (list curset)))
779 ;; If a coding system isn't universal, and isn't in
780 ;; the list that latin unity knows about, we can't
781 ;; decide whether to use it here. Leave that until later
782 ;; in `mm-find-mime-charset-region' function, whence we
784 (unless (memq curset latin-unity-coding-systems)
787 ;; Right, we know about this coding system, and it may
788 ;; conceivably be able to encode all the characters in
790 (if (latin-unity-maybe-remap begin end curset csets psets t)
791 (throw 'done (list curset))))
793 ;; Can't encode using anything from the
794 ;; `mm-coding-system-priorities' list.
795 ;; Leave `mm-find-mime-charset' to do most of the work.
798 ;; Right, latin unity isn't available; let `mm-find-charset-region'
799 ;; take its default action, which equally applies to GNU Emacs.
802 (defmacro mm-xemacs-find-mime-charset (begin end)
803 (when (featurep 'xemacs)
804 `(and (featurep 'mule) (mm-xemacs-find-mime-charset-1 ,begin ,end))))
806 (defun mm-find-mime-charset-region (b e &optional hack-charsets)
807 "Return the MIME charsets needed to encode the region between B and E.
808 nil means ASCII, a single-element list represents an appropriate MIME
809 charset, and a longer list means no appropriate charset."
811 ;; The return possibilities of this function are a mess...
812 (or (and (mm-multibyte-p)
813 mm-use-find-coding-systems-region
814 ;; Find the mime-charset of the most preferred coding
815 ;; system that has one.
816 (let ((systems (find-coding-systems-region b e)))
817 (when mm-coding-system-priorities
819 (sort systems 'mm-sort-coding-systems-predicate)))
820 (setq systems (delq 'compound-text systems))
821 (unless (equal systems '(undecided))
823 (let* ((head (pop systems))
824 (cs (or (coding-system-get head :mime-charset)
825 (coding-system-get head 'mime-charset))))
826 ;; The mime-charset (`x-ctext') of
827 ;; `compound-text' is not in the IANA list. We
828 ;; shouldn't normally use anything here with a
829 ;; mime-charset having an `x-' prefix.
830 ;; Fixme: Allow this to be overridden, since
831 ;; there is existing use of x-ctext.
832 ;; Also people apparently need the coding system
833 ;; `iso-2022-jp-3' (which Mule-UCS defines with
834 ;; mime-charset, though it's not valid).
836 (not (string-match "^[Xx]-" (symbol-name cs)))
837 ;; UTF-16 of any variety is invalid for
838 ;; text parts and, unfortunately, has
839 ;; mime-charset defined both in Mule-UCS
840 ;; and versions of Emacs. (The name
841 ;; might be `mule-utf-16...' or
843 (not (string-match "utf-16" (symbol-name cs))))
845 charsets (list cs))))))
847 ;; If we're XEmacs, and some coding system is appropriate,
848 ;; mm-xemacs-find-mime-charset will return an appropriate list.
849 ;; Otherwise, we'll get nil, and the next setq will get invoked.
850 (setq charsets (mm-xemacs-find-mime-charset b e))
852 ;; We're not multibyte, or a single coding system won't cover it.
854 (mm-delete-duplicates
855 (mapcar 'mm-mime-charset
857 (mm-find-charset-region b e))))))
858 (if (and (> (length charsets) 1)
859 (memq 'iso-8859-15 charsets)
860 (memq 'iso-8859-15 hack-charsets)
861 (save-excursion (mm-iso-8859-x-to-15-region b e)))
862 (mapcar (lambda (x) (setq charsets (delq (car x) charsets)))
863 mm-iso-8859-15-compatible))
864 (if (and (memq 'iso-2022-jp-2 charsets)
865 (memq 'iso-2022-jp-2 hack-charsets))
866 (setq charsets (delq 'iso-2022-jp charsets)))
867 ;; Attempt to reduce the number of charsets if utf-8 is available.
868 (if (and (featurep 'xemacs)
869 (> (length charsets) 1)
870 (mm-coding-system-p 'utf-8))
871 (let ((mm-coding-system-priorities
872 (cons 'utf-8 mm-coding-system-priorities)))
874 (mm-delete-duplicates
875 (mapcar 'mm-mime-charset
877 (mm-find-charset-region b e)))))))
880 (defmacro mm-with-unibyte-buffer (&rest forms)
881 "Create a temporary buffer, and evaluate FORMS there like `progn'.
882 Use unibyte mode for this."
883 `(let (default-enable-multibyte-characters)
884 (with-temp-buffer ,@forms)))
885 (put 'mm-with-unibyte-buffer 'lisp-indent-function 0)
886 (put 'mm-with-unibyte-buffer 'edebug-form-spec '(body))
888 (defmacro mm-with-multibyte-buffer (&rest forms)
889 "Create a temporary buffer, and evaluate FORMS there like `progn'.
890 Use multibyte mode for this."
891 `(let ((default-enable-multibyte-characters t))
892 (with-temp-buffer ,@forms)))
893 (put 'mm-with-multibyte-buffer 'lisp-indent-function 0)
894 (put 'mm-with-multibyte-buffer 'edebug-form-spec '(body))
896 (defmacro mm-with-unibyte-current-buffer (&rest forms)
897 "Evaluate FORMS with current buffer temporarily made unibyte.
898 Also bind `default-enable-multibyte-characters' to nil.
899 Equivalent to `progn' in XEmacs"
900 (let ((multibyte (make-symbol "multibyte"))
901 (buffer (make-symbol "buffer")))
903 (let ((,multibyte enable-multibyte-characters)
904 (,buffer (current-buffer)))
906 (let (default-enable-multibyte-characters)
907 (set-buffer-multibyte nil)
910 (set-buffer-multibyte ,multibyte)))
911 (let (default-enable-multibyte-characters)
913 (put 'mm-with-unibyte-current-buffer 'lisp-indent-function 0)
914 (put 'mm-with-unibyte-current-buffer 'edebug-form-spec '(body))
916 (defmacro mm-with-unibyte (&rest forms)
917 "Eval the FORMS with the default value of `enable-multibyte-characters' nil."
918 `(let (default-enable-multibyte-characters)
920 (put 'mm-with-unibyte 'lisp-indent-function 0)
921 (put 'mm-with-unibyte 'edebug-form-spec '(body))
923 (defmacro mm-with-multibyte (&rest forms)
924 "Eval the FORMS with the default value of `enable-multibyte-characters' t."
925 `(let ((default-enable-multibyte-characters t))
927 (put 'mm-with-multibyte 'lisp-indent-function 0)
928 (put 'mm-with-multibyte 'edebug-form-spec '(body))
930 (defun mm-find-charset-region (b e)
931 "Return a list of Emacs charsets in the region B to E."
933 ((and (mm-multibyte-p)
934 (fboundp 'find-charset-region))
935 ;; Remove composition since the base charsets have been included.
936 ;; Remove eight-bit-*, treat them as ascii.
937 (let ((css (find-charset-region b e)))
938 (mapcar (lambda (cs) (setq css (delq cs css)))
939 '(composition eight-bit-control eight-bit-graphic
943 ;; We are in a unibyte buffer or XEmacs non-mule, so we futz around a bit.
946 (narrow-to-region b e)
947 (goto-char (point-min))
948 (skip-chars-forward "\0-\177")
953 (and (boundp 'current-language-environment)
954 (car (last (assq 'charset
955 (assoc current-language-environment
956 language-info-alist))))))
957 (if (eq charset 'ascii) (setq charset nil))
960 (car (last (assq mail-parse-charset
961 mm-mime-mule-charset-alist)))))
962 (list 'ascii (or charset 'latin-iso8859-1)))))))))
964 (defun mm-auto-mode-alist ()
965 "Return an `auto-mode-alist' with only the .gz (etc) thingies."
966 (let ((alist auto-mode-alist)
969 (when (listp (cdar alist))
970 (push (car alist) out))
974 (defvar mm-inhibit-file-name-handlers
975 '(jka-compr-handler image-file-handler)
976 "A list of handlers doing (un)compression (etc) thingies.")
978 (defun mm-insert-file-contents (filename &optional visit beg end replace
980 "Like `insert-file-contents', but only reads in the file.
981 A buffer may be modified in several ways after reading into the buffer due
982 to advanced Emacs features, such as file-name-handlers, format decoding,
983 `find-file-hooks', etc.
984 If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'.
985 This function ensures that none of these modifications will take place."
986 (let* ((format-alist nil)
987 (auto-mode-alist (if inhibit nil (mm-auto-mode-alist)))
988 (default-major-mode 'fundamental-mode)
989 (enable-local-variables nil)
990 (after-insert-file-functions nil)
991 (enable-local-eval nil)
992 (inhibit-file-name-operation (if inhibit
993 'insert-file-contents
994 inhibit-file-name-operation))
995 (inhibit-file-name-handlers
997 (append mm-inhibit-file-name-handlers
998 inhibit-file-name-handlers)
999 inhibit-file-name-handlers))
1000 (ffh (if (boundp 'find-file-hook)
1003 (val (symbol-value ffh)))
1006 (insert-file-contents filename visit beg end replace)
1009 (defun mm-append-to-file (start end filename &optional codesys inhibit)
1010 "Append the contents of the region to the end of file FILENAME.
1011 When called from a function, expects three arguments,
1012 START, END and FILENAME. START and END are buffer positions
1013 saying what text to write.
1014 Optional fourth argument specifies the coding system to use when
1016 If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'."
1017 (let ((coding-system-for-write
1018 (or codesys mm-text-coding-system-for-write
1019 mm-text-coding-system))
1020 (inhibit-file-name-operation (if inhibit
1022 inhibit-file-name-operation))
1023 (inhibit-file-name-handlers
1025 (append mm-inhibit-file-name-handlers
1026 inhibit-file-name-handlers)
1027 inhibit-file-name-handlers)))
1028 (write-region start end filename t 'no-message)
1029 (message "Appended to %s" filename)))
1031 (defun mm-write-region (start end filename &optional append visit lockname
1032 coding-system inhibit)
1034 "Like `write-region'.
1035 If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'."
1036 (let ((coding-system-for-write
1037 (or coding-system mm-text-coding-system-for-write
1038 mm-text-coding-system))
1039 (inhibit-file-name-operation (if inhibit
1041 inhibit-file-name-operation))
1042 (inhibit-file-name-handlers
1044 (append mm-inhibit-file-name-handlers
1045 inhibit-file-name-handlers)
1046 inhibit-file-name-handlers)))
1047 (write-region start end filename append visit lockname)))
1049 ;; It is not a MIME function, but some MIME functions use it.
1050 (if (and (fboundp 'make-temp-file)
1052 (let ((def (symbol-function 'make-temp-file)))
1053 (and (byte-code-function-p def)
1054 (setq def (if (fboundp 'compiled-function-arglist)
1056 (eval (list 'compiled-function-arglist def))
1059 (eq (nth 3 def) 'suffix)))))
1060 (defalias 'mm-make-temp-file 'make-temp-file)
1061 ;; Stolen (and modified for XEmacs) from Emacs 22.
1062 (defun mm-make-temp-file (prefix &optional dir-flag suffix)
1063 "Create a temporary file.
1064 The returned file name (created by appending some random characters at the end
1065 of PREFIX, and expanding against `temporary-file-directory' if necessary),
1066 is guaranteed to point to a newly created empty file.
1067 You can then use `write-region' to write new data into the file.
1069 If DIR-FLAG is non-nil, create a new empty directory instead of a file.
1071 If SUFFIX is non-nil, add that at the end of the file name."
1072 (let ((umask (default-file-modes))
1076 ;; Create temp files with strict access rights. It's easy to
1077 ;; loosen them later, whereas it's impossible to close the
1078 ;; time-window of loose permissions otherwise.
1079 (set-default-file-modes 448)
1080 (while (condition-case ()
1086 (if (fboundp 'temp-directory)
1089 temporary-file-directory))))
1091 (setq file (concat file suffix)))
1093 (make-directory file)
1094 (if (featurep 'xemacs)
1095 ;; NOTE: This is unsafe if an XEmacs user
1096 ;; doesn't use a secure temp directory.
1097 (if (file-exists-p file)
1098 (signal 'file-already-exists
1099 (list "File exists" file))
1100 (write-region "" nil file nil 'silent))
1101 (write-region "" nil file nil 'silent
1104 (file-already-exists t)
1105 ;; The XEmacs version of `make-directory' issues it.
1107 ;; the file was somehow created by someone else between
1108 ;; `make-temp-name' and `write-region', let's try again.
1112 (set-default-file-modes umask)))))
1114 (defun mm-image-load-path (&optional package)
1116 (dolist (path load-path (nreverse result))
1119 (setq dir (concat (file-name-directory
1120 (directory-file-name path))
1121 "etc/images/" (or package "gnus/")))))
1123 (push path result))))
1125 ;; Fixme: This doesn't look useful where it's used.
1126 (if (fboundp 'detect-coding-region)
1127 (defun mm-detect-coding-region (start end)
1128 "Like `detect-coding-region' except returning the best one."
1129 (let ((coding-systems
1130 (detect-coding-region start end)))
1131 (or (car-safe coding-systems)
1133 (defun mm-detect-coding-region (start end)
1134 (let ((point (point)))
1136 (skip-chars-forward "\0-\177" end)
1138 (if (eq (point) end) 'ascii (mm-guess-charset))
1139 (goto-char point)))))
1141 (if (fboundp 'coding-system-get)
1142 (defun mm-detect-mime-charset-region (start end)
1143 "Detect MIME charset of the text in the region between START and END."
1144 (let ((cs (mm-detect-coding-region start end)))
1145 (or (coding-system-get cs :mime-charset)
1146 (coding-system-get cs 'mime-charset))))
1147 (defun mm-detect-mime-charset-region (start end)
1148 "Detect MIME charset of the text in the region between START and END."
1149 (let ((cs (mm-detect-coding-region start end)))
1153 (unless (fboundp 'coding-system-to-mime-charset)
1154 (defalias 'coding-system-to-mime-charset 'ignore)))
1156 (defun mm-coding-system-to-mime-charset (coding-system)
1157 "Return the MIME charset corresponding to CODING-SYSTEM.
1158 To make this function work with XEmacs, the APEL package is required."
1160 (or (and (fboundp 'coding-system-get)
1161 (or (coding-system-get coding-system :mime-charset)
1162 (coding-system-get coding-system 'mime-charset)))
1163 (and (featurep 'xemacs)
1164 (or (and (fboundp 'coding-system-to-mime-charset)
1165 (not (eq (symbol-function 'coding-system-to-mime-charset)
1167 (and (condition-case nil
1170 (fboundp 'coding-system-to-mime-charset)))
1171 (coding-system-to-mime-charset coding-system)))))
1174 (require 'jka-compr))
1176 (defun mm-decompress-buffer (filename &optional inplace force)
1177 "Decompress buffer's contents, depending on jka-compr.
1178 Only when FORCE is t or `auto-compression-mode' is enabled and FILENAME
1179 agrees with `jka-compr-compression-info-list', decompression is done.
1180 Signal an error if FORCE is neither nil nor t and compressed data are
1181 not decompressed because `auto-compression-mode' is disabled.
1182 If INPLACE is nil, return decompressed data or nil without modifying
1183 the buffer. Otherwise, replace the buffer's contents with the
1184 decompressed data. The buffer's multibyteness must be turned off."
1187 (prog1 t (require 'jka-compr))
1188 (and (fboundp 'jka-compr-installed-p)
1189 (jka-compr-installed-p))))
1190 (let ((info (jka-compr-get-compression-info filename)))
1192 (unless (or (memq force (list nil t))
1193 (jka-compr-installed-p))
1195 (let ((prog (jka-compr-info-uncompress-program info))
1196 (args (jka-compr-info-uncompress-args info))
1197 (msg (format "%s %s..."
1198 (jka-compr-info-uncompress-message info)
1200 (err-file (jka-compr-make-temp-name))
1201 (cur (current-buffer))
1202 (coding-system-for-read mm-binary-coding-system)
1203 (coding-system-for-write mm-binary-coding-system)
1207 (insert-buffer-substring cur)
1210 (unless (memq (apply 'call-process-region
1211 (point-min) (point-max)
1212 prog t (list t err-file) nil args)
1213 jka-compr-acceptable-retval-list)
1217 (delete "" (split-string
1219 (insert-file-contents err-file)
1225 (format "Error while executing \"%s %s < %s\""
1226 prog (mapconcat 'identity args " ")
1228 (setq retval (buffer-string)))
1230 (setq err-msg (error-message-string err)))))
1231 (when (file-exists-p err-file)
1232 (ignore-errors (jka-compr-delete-temp-file err-file)))
1235 (delete-region (point-min) (point-max))
1238 (message "%s" (or err-msg (concat msg "done")))
1242 (unless (fboundp 'coding-system-name)
1243 (defalias 'coding-system-name 'ignore))
1244 (unless (fboundp 'find-file-coding-system-for-read-from-filename)
1245 (defalias 'find-file-coding-system-for-read-from-filename 'ignore))
1246 (unless (fboundp 'find-operation-coding-system)
1247 (defalias 'find-operation-coding-system 'ignore)))
1249 (defun mm-find-buffer-file-coding-system (&optional filename)
1250 "Find coding system used to decode the contents of the current buffer.
1251 This function looks for the coding system magic cookie or examines the
1252 coding system specified by `file-coding-system-alist' being associated
1253 with FILENAME which defaults to `buffer-file-name'. Data compressed by
1254 gzip, bzip2, etc. are allowed."
1256 (setq filename buffer-file-name))
1258 (let ((decomp (unless ;; No worth to examine charset of tar files.
1261 "\\.\\(?:tar\\.[^.]+\\|tbz\\|tgz\\)\\'"
1263 (mm-decompress-buffer filename nil t))))
1265 (set-buffer (let (default-enable-multibyte-characters)
1266 (generate-new-buffer " *temp*")))
1268 (setq filename (file-name-sans-extension filename)))
1269 (goto-char (point-min))
1272 ((boundp 'set-auto-coding-function) ;; Emacs
1274 (or (funcall (symbol-value 'set-auto-coding-function)
1275 filename (- (point-max) (point-min)))
1276 (car (find-operation-coding-system 'insert-file-contents
1278 (let (auto-coding-alist)
1280 (funcall (symbol-value 'set-auto-coding-function)
1281 nil (- (point-max) (point-min)))
1283 ((featurep 'file-coding) ;; XEmacs
1284 (let ((case-fold-search t)
1285 (end (point-at-eol))
1288 (and (re-search-forward "-\\*-+[\t ]*" end t)
1290 (setq start (match-end 0))
1291 (re-search-forward "[\t ]*-+\\*-" end t))
1293 (setq end (match-beginning 0))
1295 (or (looking-at "coding:[\t ]*\\([^\t ;]+\\)")
1297 "[\t ;]+coding:[\t ]*\\([^\t ;]+\\)"
1299 (find-coding-system (setq codesys
1300 (intern (match-string 1))))
1302 (and (re-search-forward "^[\t ]*;+[\t ]*Local[\t ]+Variables:"
1305 (setq start (match-end 0))
1306 (re-search-forward "^[\t ]*;+[\t ]*End:" nil t))
1308 (setq end (match-beginning 0))
1311 "^[\t ]*;+[\t ]*coding:[\t ]*\\([^\t\n\r ]+\\)"
1313 (find-coding-system (setq codesys
1314 (intern (match-string 1))))
1317 (goto-char (point-min))
1318 (setq case-fold-search nil)
1319 (re-search-forward "^;;;coding system: "
1320 ;;(+ (point-min) 3000) t))
1322 (looking-at "[^\t\n\r ]+")
1324 (setq codesys (intern (match-string 0))))
1328 (find-file-coding-system-for-read-from-filename
1330 (coding-system-name (coding-system-base codesys)))))))
1332 (kill-buffer (current-buffer)))))))
1336 ;;; mm-util.el ends here