1 ;;; mcs-xm.el --- MIME charset implementation for XEmacs-mule
3 ;; Copyright (C) 1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule
8 ;; This file is part of APEL (A Portable Emacs Library).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; 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., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; This module requires Emacs 20.0.93, XEmacs 20.3-b5 (with mule)
35 (defun encode-mime-charset-region (start end charset &optional lbt)
36 "Encode the text between START and END as MIME CHARSET."
37 (let ((cs (mime-charset-to-coding-system charset lbt)))
39 (encode-coding-region start end cs)
43 (defcustom mime-charset-decoder-alist
44 '((iso-2022-jp . decode-mime-charset-region-with-iso646-unification)
45 (iso-2022-jp-2 . decode-mime-charset-region-with-iso646-unification)
46 (x-ctext . decode-mime-charset-region-with-iso646-unification)
47 (hz-gb-2312 . decode-mime-charset-region-for-hz)
48 (t . decode-mime-charset-region-default))
49 "Alist MIME-charset vs. decoder function."
51 :type '(repeat (cons mime-charset function)))
53 (defsubst decode-mime-charset-region-default (start end charset lbt)
54 (let ((cs (mime-charset-to-coding-system charset lbt)))
56 (decode-coding-region start end cs)
59 (defcustom mime-iso646-character-unification-alist
65 (cons (cons (char-to-string (make-char 'latin-jisx0201 i))
72 (cons (cons (char-to-string (make-char 'latin-jisx0201 i))
77 "Alist unified string vs. canonical string."
79 :type '(repeat (cons string string)))
81 (defcustom mime-unified-character-face nil
82 "*Face of unified character."
86 (defcustom mime-character-unification-limit-size 2048
87 "*Limit size to unify characters."
91 (defun decode-mime-charset-region-with-iso646-unification (start end charset
93 (decode-mime-charset-region-default start end charset lbt)
94 (if (<= (- end start) mime-character-unification-limit-size)
96 (let ((rest mime-iso646-character-unification-alist))
98 (let ((pair (car rest)))
100 (while (search-forward (car pair) end t)
101 (let ((str (cdr pair)))
102 (put-text-property 0 (length str)
103 'face mime-unified-character-face str)
104 (replace-match str 'fixed-case 'literal)
107 (setq rest (cdr rest)))))
110 (defun decode-mime-charset-region-for-hz (start end charset lbt)
113 (narrow-to-region start end)
114 (decode-coding-region (point-min)(point-max)
115 (mime-charset-to-coding-system 'raw-text lbt))
116 (decode-hz-region (point-min)(point-max)))
117 (decode-hz-region start end)))
119 (defun decode-mime-charset-region (start end charset &optional lbt)
120 "Decode the text between START and END as MIME CHARSET."
121 (if (stringp charset)
122 (setq charset (intern (downcase charset)))
124 (let ((func (cdr (or (assq charset mime-charset-decoder-alist)
125 (assq t mime-charset-decoder-alist)))))
126 (funcall func start end charset lbt)))
128 (defsubst encode-mime-charset-string (string charset &optional lbt)
129 "Encode the STRING as MIME CHARSET."
130 (let ((cs (mime-charset-to-coding-system charset lbt)))
132 (encode-coding-string string cs)
135 ;; (defsubst decode-mime-charset-string (string charset)
136 ;; "Decode the STRING as MIME CHARSET."
137 ;; (let ((cs (mime-charset-to-coding-system charset)))
139 ;; (decode-coding-string string cs)
141 (defun decode-mime-charset-string (string charset &optional lbt)
142 "Decode the STRING as MIME CHARSET."
145 (decode-mime-charset-region (point-min)(point-max) charset lbt)
149 (defvar charsets-mime-charset-alist
150 '(((ascii) . us-ascii)
151 ((ascii latin-iso8859-1) . iso-8859-1)
152 ((ascii latin-iso8859-2) . iso-8859-2)
153 ((ascii latin-iso8859-3) . iso-8859-3)
154 ((ascii latin-iso8859-4) . iso-8859-4)
155 ((ascii cyrillic-iso8859-5) . iso-8859-5)
156 ;;; ((ascii cyrillic-iso8859-5) . koi8-r)
157 ((ascii arabic-iso8859-6) . iso-8859-6)
158 ((ascii greek-iso8859-7) . iso-8859-7)
159 ((ascii hebrew-iso8859-8) . iso-8859-8)
160 ((ascii latin-iso8859-9) . iso-8859-9)
161 ((ascii latin-jisx0201
162 japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
163 ((ascii latin-jisx0201
164 katakana-jisx0201 japanese-jisx0208) . shift_jis)
165 ((ascii korean-ksc5601) . euc-kr)
166 ((ascii chinese-gb2312) . gb2312)
167 ((ascii chinese-big5-1 chinese-big5-2) . big5)
168 ((ascii latin-iso8859-1 greek-iso8859-7
169 latin-jisx0201 japanese-jisx0208-1978
170 chinese-gb2312 japanese-jisx0208
171 korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
172 ;; ((ascii latin-iso8859-1 greek-iso8859-7
173 ;; latin-jisx0201 japanese-jisx0208-1978
174 ;; chinese-gb2312 japanese-jisx0208
175 ;; korean-ksc5601 japanese-jisx0212
176 ;; chinese-cns11643-1 chinese-cns11643-2) . iso-2022-int-1)
180 (defun coding-system-to-mime-charset (coding-system)
181 "Convert CODING-SYSTEM to a MIME-charset.
182 Return nil if corresponding MIME-charset is not found."
184 (coding-system-name (coding-system-base coding-system)))
185 (or (car (rassq coding-system mime-charset-coding-system-alist))
188 (defun mime-charset-list ()
189 "Return a list of all existing MIME-charset."
190 (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
191 (rest (coding-system-list))
194 (setq cs (coding-system-name (coding-system-base (car rest))))
195 (or (rassq cs mime-charset-coding-system-alist)
197 (setq dest (cons cs dest)))
198 (setq rest (cdr rest)))
207 ;;; mcs-xm.el ends here