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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
46d71cfa2272 (mm-mime-mule-charset-alist)
Dave Love <fx@gnu.org>
parents: 35618
diff changeset
2 ;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; any later version.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; Boston, MA 02111-1307, USA.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;;; Commentary:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;; Code:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 (require 'mail-prsvr)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29
36557
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
30 (defun mm-coding-system-p (sym)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
31 "Return non-nil if SYM is a coding system."
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
32 (or (and (fboundp 'coding-system-p) (coding-system-p sym))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 (defvar mm-mime-mule-charset-alist
35793
46d71cfa2272 (mm-mime-mule-charset-alist)
Dave Love <fx@gnu.org>
parents: 35618
diff changeset
36 `((us-ascii ascii)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 (iso-8859-1 latin-iso8859-1)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 (iso-8859-2 latin-iso8859-2)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 (iso-8859-3 latin-iso8859-3)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 (iso-8859-4 latin-iso8859-4)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 (iso-8859-5 cyrillic-iso8859-5)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; Non-mule (X)Emacs uses the last mule-charset for 8bit characters.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; The fake mule-charset, gnus-koi8-r, tells Gnus that the default
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; charset is koi8-r, not iso-8859-5.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 (koi8-r cyrillic-iso8859-5 gnus-koi8-r)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 (iso-8859-6 arabic-iso8859-6)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (iso-8859-7 greek-iso8859-7)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 (iso-8859-8 hebrew-iso8859-8)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (viscii vietnamese-viscii-lower)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (iso-2022-jp latin-jisx0201 japanese-jisx0208 japanese-jisx0208-1978)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (tibetan tibetan)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 (thai-tis620 thai-tis620)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 (iso-2022-7bit ethiopic arabic-1-column arabic-2-column)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 (iso-2022-jp-2 latin-iso8859-1 greek-iso8859-7
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 latin-jisx0201 japanese-jisx0208-1978
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 chinese-gb2312 japanese-jisx0208
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 korean-ksc5601 japanese-jisx0212
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 katakana-jisx0201)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 (iso-2022-int-1 latin-iso8859-1 greek-iso8859-7
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 latin-jisx0201 japanese-jisx0208-1978
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 chinese-gb2312 japanese-jisx0208
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 korean-ksc5601 japanese-jisx0212
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 chinese-cns11643-1 chinese-cns11643-2)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (iso-2022-int-1 latin-iso8859-1 latin-iso8859-2
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 cyrillic-iso8859-5 greek-iso8859-7
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 latin-jisx0201 japanese-jisx0208-1978
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 chinese-gb2312 japanese-jisx0208
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 korean-ksc5601 japanese-jisx0212
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 chinese-cns11643-1 chinese-cns11643-2
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 chinese-cns11643-3 chinese-cns11643-4
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 chinese-cns11643-5 chinese-cns11643-6
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 "Alist of MIME-charset/MULE-charsets.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 (eval-and-compile
36557
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
88 (mapcar
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
89 (lambda (elem)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
90 (let ((nfunc (intern (format "mm-%s" (car elem)))))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
91 (if (fboundp (car elem))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
92 (defalias nfunc (car elem))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
93 (defalias nfunc (cdr elem)))))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
94 '((decode-coding-string . (lambda (s a) s))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
95 (encode-coding-string . (lambda (s a) s))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
96 (encode-coding-region . ignore)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
97 (coding-system-list . ignore)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
98 (decode-coding-region . ignore)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
99 (char-int . identity)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
100 (device-type . ignore)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
101 (coding-system-equal . equal)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
102 (annotationp . ignore)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
103 (set-buffer-file-coding-system . ignore)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
104 (make-char
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
105 . (lambda (charset int)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
106 (int-to-char int)))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
107 (read-coding-system
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
108 . (lambda (prompt)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
109 "Prompt the user for a coding system."
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
110 (completing-read
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
111 prompt (mapcar (lambda (s) (list (symbol-name (car s))))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
112 mm-mime-mule-charset-alist))))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
113 (read-charset
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
114 . (lambda (prompt)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
115 "Return a charset."
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
116 (intern
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
117 (completing-read
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
118 prompt
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
119 (mapcar (lambda (e) (list (symbol-name (car e))))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
120 mm-mime-mule-charset-alist)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
121 nil t))))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
122 (string-as-unibyte . identity)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
123 (multibyte-string-p . ignore)
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
124 )))
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
125
ecd00da553af Fix last change.
Dave Love <fx@gnu.org>
parents: 36556
diff changeset
126 (eval-and-compile
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (defalias 'mm-char-or-char-int-p
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 ((fboundp 'char-or-char-int-p) 'char-or-char-int-p)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 ((fboundp 'char-valid-p) 'char-valid-p)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (t 'identity))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (defvar mm-coding-system-list nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (defun mm-get-coding-system-list ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 "Get the coding system list."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (or mm-coding-system-list
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (setq mm-coding-system-list (mm-coding-system-list))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (x-ctext . ctext))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 "A mapping from invalid charset names to the real charset names.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (defvar mm-binary-coding-system
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 ((mm-coding-system-p 'binary) 'binary)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 ((mm-coding-system-p 'no-conversion) 'no-conversion)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (t nil))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 "100% binary coding system.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (defvar mm-text-coding-system
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (or (if (memq system-type '(windows-nt ms-dos ms-windows))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (and (mm-coding-system-p 'raw-text-dos) 'raw-text-dos)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (and (mm-coding-system-p 'raw-text) 'raw-text))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 mm-binary-coding-system)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 "Text-safe coding system (For removing ^M).")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (defvar mm-text-coding-system-for-write nil
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 "Text coding system for write.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (defvar mm-auto-save-coding-system
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 ((mm-coding-system-p 'emacs-mule)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (if (memq system-type '(windows-nt ms-dos ms-windows))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (if (mm-coding-system-p 'emacs-mule-dos)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 'emacs-mule-dos mm-binary-coding-system)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 'emacs-mule))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 ((mm-coding-system-p 'escape-quoted) 'escape-quoted)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (t mm-binary-coding-system))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 "Coding system of auto save file.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 ;;; Internal variables:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 ;;; Functions:
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (defun mm-mule-charset-to-mime-charset (charset)
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
182 "Return the MIME charset corresponding to the given Mule CHARSET."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (let ((alist mm-mime-mule-charset-alist)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 out)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (while alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (when (memq charset (cdar alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (setq out (caar alist)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 alist nil))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (pop alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 out))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (defun mm-charset-to-coding-system (charset &optional lbt)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 "Return coding-system corresponding to CHARSET.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 CHARSET is a symbol naming a MIME charset.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 If optional argument LBT (`unix', `dos' or `mac') is specified, it is
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 used as the line break code type of the coding system."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (when (stringp charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (setq charset (intern (downcase charset))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (setq charset
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (or (cdr (assq charset mm-charset-synonym-alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (when lbt
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (setq charset (intern (format "%s-%s" charset lbt))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 ;; Running in a non-MULE environment.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 ((null (mm-get-coding-system-list))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 ;; ascii
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 ((eq charset 'us-ascii)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 'ascii)
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
211 ;; Check to see whether we can handle this charset. (This depends
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
212 ;; on there being some coding system matching each `mime-charset'
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
213 ;; coding sysytem property defined, as there should be.)
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 ((memq charset (mm-get-coding-system-list))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 ;; Nope.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (t
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 nil)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (if (fboundp 'subst-char-in-string)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (defsubst mm-replace-chars-in-string (string from to)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (subst-char-in-string from to string))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (defun mm-replace-chars-in-string (string from to)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 "Replace characters in STRING from FROM to TO."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (let ((string (substring string 0)) ;Copy string.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (len (length string))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (idx 0))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 ;; Replace all occurrences of FROM with TO.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (while (< idx len)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (when (= (aref string idx) from)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (aset string idx to))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (setq idx (1+ idx)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 string)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (defsubst mm-enable-multibyte ()
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
236 "Set the multibyte flag of the current buffer.
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
237 Only do this if the default value of `enable-multibyte-characters' is
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
238 non-nil. This is a no-op in XEmacs."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 (when (and (fboundp 'set-buffer-multibyte)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (boundp 'enable-multibyte-characters)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (default-value 'enable-multibyte-characters))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (set-buffer-multibyte t)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (defsubst mm-disable-multibyte ()
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
245 "Unset the multibyte flag of in the current buffer.
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
246 This is a no-op in XEmacs."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (when (fboundp 'set-buffer-multibyte)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (set-buffer-multibyte nil)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (defun mm-preferred-coding-system (charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 ;; A typo in some Emacs versions.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (or (get-charset-property charset 'prefered-coding-system)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (get-charset-property charset 'preferred-coding-system)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (defun mm-charset-after (&optional pos)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 "Return charset of a character in current buffer at position POS.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 If POS is nil, it defauls to the current point.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 If POS is out of range, the value is nil.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
46d71cfa2272 (mm-mime-mule-charset-alist)
Dave Love <fx@gnu.org>
parents: 35618
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 (defun mm-mime-charset (charset)
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 ;; This exists in Emacs 20.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (or
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (and (mm-preferred-coding-system charset)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (coding-system-get
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 (mm-preferred-coding-system charset) 'mime-charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (and (eq charset 'ascii)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 'us-ascii)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (mm-mule-charset-to-mime-charset charset))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 ;; This is for XEmacs.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 (mm-mule-charset-to-mime-charset charset)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (defun mm-delete-duplicates (list)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 "Simple substitute for CL `delete-duplicates', testing with `equal'."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (let (result head)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (while list
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (setq head (car list))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 (setq list (delete head list))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (setq result (cons head result)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (nreverse result)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (defun mm-find-mime-charset-region (b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 "Return the MIME charsets needed to encode the region between B and E."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (let ((charsets (mapcar 'mm-mime-charset
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (delq 'ascii
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (mm-find-charset-region b e)))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (when (memq 'iso-2022-jp-2 charsets)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (setq charsets (delq 'iso-2022-jp charsets)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (setq charsets (mm-delete-duplicates charsets))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (if (and (> (length charsets) 1)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (fboundp 'find-coding-systems-region)
35793
46d71cfa2272 (mm-mime-mule-charset-alist)
Dave Love <fx@gnu.org>
parents: 35618
diff changeset
338 (let ((cs (find-coding-systems-region b e)))
46d71cfa2272 (mm-mime-mule-charset-alist)
Dave Love <fx@gnu.org>
parents: 35618
diff changeset
339 (or (memq 'utf-8 cs) (memq 'mule-utf-8 cs))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 '(utf-8)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 charsets)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (defsubst mm-multibyte-p ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (defmacro mm-with-unibyte-buffer (&rest forms)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 "Create a temporary buffer, and evaluate FORMS there like `progn'.
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
352 Use unibyte mode for this."
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
353 `(let (default-enable-multibyte-characters)
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
354 (with-temp-buffer ,@forms)))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (put 'mm-with-unibyte-buffer 'lisp-indent-function 0)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (put 'mm-with-unibyte-buffer 'edebug-form-spec '(body))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (defmacro mm-with-unibyte-current-buffer (&rest forms)
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
359 "Evaluate FORMS with current current buffer temporarily made unibyte.
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
360 Also bind `default-enable-multibyte-characters' to nil.
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
361 Equivalent to `progn' in XEmacs"
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (let ((multibyte (make-symbol "multibyte")))
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
363 `(if (fboundp 'set-buffer-multibyte)
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
364 (let ((,multibyte enable-multibyte-characters))
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
365 (unwind-protect
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
366 (let (default-enable-multibyte-characters)
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
367 (set-buffer-multibyte nil)
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
368 ,@forms)
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
369 (set-buffer-multibyte ,multibyte)))
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
370 (progn
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
371 ,@forms))))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (put 'mm-with-unibyte-current-buffer 'lisp-indent-function 0)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (put 'mm-with-unibyte-current-buffer 'edebug-form-spec '(body))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (defmacro mm-with-unibyte (&rest forms)
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
398 "Eval the FORMS with the default value of `enable-multibyte-characters' nil, ."
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
399 `(let (default-enable-multibyte-characters)
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
400 ,@forms))
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (put 'mm-with-unibyte 'lisp-indent-function 0)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (put 'mm-with-unibyte 'edebug-form-spec '(body))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (defun mm-find-charset-region (b e)
33378
ab964e52e0ba Doc fixes.
Dave Love <fx@gnu.org>
parents: 33342
diff changeset
405 "Return a list of Emacs charsets in the region B to E."
31717
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (cond
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 ((and (mm-multibyte-p)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (fboundp 'find-charset-region))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 ;; Remove composition since the base charsets have been included.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (save-excursion
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (save-restriction
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (narrow-to-region b e)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (goto-char (point-min))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (skip-chars-forward "\0-\177")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (if (eobp)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (if (fboundp 'shell-quote-argument)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (defalias 'mm-quote-arg 'shell-quote-argument)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (defun mm-quote-arg (arg)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 "Return a version of ARG that is safe to evaluate in a shell."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (let ((pos 0) new-pos accum)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 ;; *** bug: we don't handle newline characters properly
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (while (setq new-pos (string-match "[]*[;!'`\"$\\& \t{} |()<>]" arg pos))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (push (substring arg pos new-pos) accum)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (push "\\" accum)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (push (list (aref arg new-pos)) accum)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 (setq pos (1+ new-pos)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (if (= pos 0)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 arg
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (apply 'concat (nconc (nreverse accum) (list (substring arg pos))))))))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (defun mm-auto-mode-alist ()
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 "Return an `auto-mode-alist' with only the .gz (etc) thingies."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (let ((alist auto-mode-alist)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 out)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (while alist
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 (when (listp (cdar alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (push (car alist) out))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (pop alist))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (nreverse out)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
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
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460 "A list of handlers doing (un)compression (etc) thingies.")
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (defun mm-insert-file-contents (filename &optional visit beg end replace
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 inhibit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 "Like `insert-file-contents', q.v., but only reads in the file.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 A buffer may be modified in several ways after reading into the buffer due
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 to advanced Emacs features, such as file-name-handlers, format decoding,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 find-file-hooks, etc.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 If INHIBIT is non-nil, inhibit mm-inhibit-file-name-handlers.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 This function ensures that none of these modifications will take place."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (let ((format-alist nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 (auto-mode-alist (if inhibit nil (mm-auto-mode-alist)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (default-major-mode 'fundamental-mode)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (enable-local-variables nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (after-insert-file-functions nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 (enable-local-eval nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (find-file-hooks nil)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (inhibit-file-name-operation (if inhibit
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 'insert-file-contents
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 inhibit-file-name-operation))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 (inhibit-file-name-handlers
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (if inhibit
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (append mm-inhibit-file-name-handlers
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 inhibit-file-name-handlers)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 inhibit-file-name-handlers)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (insert-file-contents filename visit beg end replace)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (defun mm-append-to-file (start end filename &optional codesys inhibit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 "Append the contents of the region to the end of file FILENAME.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 When called from a function, expects three arguments,
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 START, END and FILENAME. START and END are buffer positions
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 saying what text to write.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 Optional fourth argument specifies the coding system to use when
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 encoding the file.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 If INHIBIT is non-nil, inhibit mm-inhibit-file-name-handlers."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 (let ((coding-system-for-write
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (or codesys mm-text-coding-system-for-write
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 mm-text-coding-system))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 (inhibit-file-name-operation (if inhibit
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 'append-to-file
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 inhibit-file-name-operation))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (inhibit-file-name-handlers
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (if inhibit
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (append mm-inhibit-file-name-handlers
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 inhibit-file-name-handlers)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 inhibit-file-name-handlers)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (append-to-file start end filename)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 (defun mm-write-region (start end filename &optional append visit lockname
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 coding-system inhibit)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 "Like `write-region'.
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 If INHIBIT is non-nil, inhibit mm-inhibit-file-name-handlers."
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (let ((coding-system-for-write
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (or coding-system mm-text-coding-system-for-write
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 mm-text-coding-system))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 (inhibit-file-name-operation (if inhibit
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 'write-region
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 inhibit-file-name-operation))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (inhibit-file-name-handlers
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (if inhibit
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 (append mm-inhibit-file-name-handlers
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 inhibit-file-name-handlers)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 inhibit-file-name-handlers)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 (write-region start end filename append visit lockname)))
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (provide 'mm-util)
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527
6b20b7e85e3c *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 ;;; mm-util.el ends here