1 ;;; emu-x20.el --- emu API implementation for XEmacs with mule
3 ;; Copyright (C) 1994,1995,1996,1997,1998 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule, XEmacs
8 ;; This file is part of emu.
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 XEmacs 20.3-b5 or later with mule.
34 ;;; @ fix coding-system definition
37 ;; It seems not bug, but I can not permit it...
38 (and (coding-system-property 'iso-2022-jp 'input-charset-conversion)
39 (copy-coding-system 'iso-2022-7bit 'iso-2022-jp))
41 ;; Redefine if -{dos|mac|unix} is not found.
42 (or (find-coding-system 'raw-text-dos)
43 (copy-coding-system 'no-conversion-dos 'raw-text-dos))
44 (or (find-coding-system 'raw-text-mac)
45 (copy-coding-system 'no-conversion-mac 'raw-text-mac))
46 (or (find-coding-system 'raw-text-unix)
47 (copy-coding-system 'no-conversion-unix 'raw-text-unix))
49 (or (find-coding-system 'ctext-dos)
52 "Coding-system used in X as Compound Text Encoding."
53 '(charset-g0 ascii charset-g1 latin-iso8859-1
57 (or (find-coding-system 'iso-2022-jp-2-dos)
59 'iso-2022-jp-2 'iso2022
60 "ISO-2022 coding system using SS2 for 96-charset in 7-bit code."
62 charset-g2 t ;; unspecified but can be used later.
68 (or (find-coding-system 'euc-kr-dos)
71 "Coding-system of Korean EUC (Extended Unix Code)."
72 '(charset-g0 ascii charset-g1 korean-ksc5601
77 ;;; @ without code-conversion
80 (define-obsolete-function-alias 'insert-binary-file-contents
81 'insert-file-contents-as-binary)
83 (defun insert-binary-file-contents-literally (filename
84 &optional visit beg end replace)
85 "Like `insert-file-contents-literally', q.v., but don't code conversion.
86 A buffer may be modified in several ways after reading into the buffer due
87 to advanced Emacs features, such as file-name-handlers, format decoding,
89 This function ensures that none of these modifications will take place."
90 (let ((coding-system-for-read 'binary))
91 (insert-file-contents-literally filename visit beg end replace)
98 (defun encode-mime-charset-region (start end charset)
99 "Encode the text between START and END as MIME CHARSET."
100 (let ((cs (mime-charset-to-coding-system charset)))
102 (encode-coding-region start end cs)
105 (defcustom mime-charset-decoder-alist
106 '((iso-2022-jp . decode-mime-charset-region-with-iso646-unification)
107 (iso-2022-jp-2 . decode-mime-charset-region-with-iso646-unification)
108 (x-ctext . decode-mime-charset-region-with-iso646-unification)
109 (hz-gb-2312 . decode-mime-charset-region-for-hz)
110 (t . decode-mime-charset-region-default))
111 "Alist MIME-charset vs. decoder function."
113 :type '(repeat (cons mime-charset function)))
115 (defsubst decode-mime-charset-region-default (start end charset lbt)
116 (let ((cs (mime-charset-to-coding-system charset lbt)))
118 (decode-coding-region start end cs)
121 (defcustom mime-iso646-character-unification-alist
126 (cons (cons (char-to-string (make-char 'latin-jisx0201 i))
133 (cons (cons (char-to-string (make-char 'latin-jisx0201 i))
138 "Alist unified string vs. canonical string."
140 :type '(repeat (cons string string)))
142 (defcustom mime-unified-character-face nil
143 "*Face of unified character."
147 (defcustom mime-character-unification-limit-size 2048
148 "*Limit size to unify characters."
152 (defun decode-mime-charset-region-with-iso646-unification (start end charset
154 (decode-mime-charset-region-default start end charset lbt)
155 (if (<= (- end start) mime-character-unification-limit-size)
157 (let ((rest mime-iso646-character-unification-alist))
159 (let ((pair (car rest)))
160 (goto-char (point-min))
161 (while (search-forward (car pair) nil t)
162 (let ((str (cdr pair)))
163 (put-text-property 0 (length str)
164 'face mime-unified-character-face str)
165 (replace-match str 'fixed-case 'literal)
168 (setq rest (cdr rest)))))
171 (defun decode-mime-charset-region-for-hz (start end charset lbt)
174 (narrow-to-region start end)
175 (decode-coding-region (point-min)(point-max)
176 (mime-charset-to-coding-system 'raw-text lbt))
177 (decode-hz-region (point-min)(point-max))
179 (decode-hz-region start end)
182 (defun decode-mime-charset-region (start end charset &optional lbt)
183 "Decode the text between START and END as MIME CHARSET."
184 (if (stringp charset)
185 (setq charset (intern (downcase charset)))
187 (let ((func (cdr (or (assq charset mime-charset-decoder-alist)
188 (assq t mime-charset-decoder-alist)))))
189 (funcall func start end charset lbt)
192 (defsubst encode-mime-charset-string (string charset)
193 "Encode the STRING as MIME CHARSET."
194 (let ((cs (mime-charset-to-coding-system charset)))
196 (encode-coding-string string cs)
199 ;; (defsubst decode-mime-charset-string (string charset)
200 ;; "Decode the STRING as MIME CHARSET."
201 ;; (let ((cs (mime-charset-to-coding-system charset)))
203 ;; (decode-coding-string string cs)
205 (defun decode-mime-charset-string (string charset &optional lbt)
206 "Decode the STRING as MIME CHARSET."
209 (decode-mime-charset-region (point-min)(point-max) charset lbt)
214 (defvar charsets-mime-charset-alist
215 '(((ascii) . us-ascii)
216 ((ascii latin-iso8859-1) . iso-8859-1)
217 ((ascii latin-iso8859-2) . iso-8859-2)
218 ((ascii latin-iso8859-3) . iso-8859-3)
219 ((ascii latin-iso8859-4) . iso-8859-4)
220 ((ascii cyrillic-iso8859-5) . iso-8859-5)
221 ;;; ((ascii cyrillic-iso8859-5) . koi8-r)
222 ((ascii arabic-iso8859-6) . iso-8859-6)
223 ((ascii greek-iso8859-7) . iso-8859-7)
224 ((ascii hebrew-iso8859-8) . iso-8859-8)
225 ((ascii latin-iso8859-9) . iso-8859-9)
226 ((ascii latin-jisx0201
227 japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
228 ((ascii latin-jisx0201
229 katakana-jisx0201 japanese-jisx0208) . shift_jis)
230 ((ascii korean-ksc5601) . euc-kr)
231 ((ascii chinese-gb2312) . cn-gb-2312)
232 ((ascii chinese-big5-1 chinese-big5-2) . cn-big5)
233 ((ascii latin-iso8859-1 greek-iso8859-7
234 latin-jisx0201 japanese-jisx0208-1978
235 chinese-gb2312 japanese-jisx0208
236 korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
237 ((ascii latin-iso8859-1 greek-iso8859-7
238 latin-jisx0201 japanese-jisx0208-1978
239 chinese-gb2312 japanese-jisx0208
240 korean-ksc5601 japanese-jisx0212
241 chinese-cns11643-1 chinese-cns11643-2) . iso-2022-int-1)
242 ((ascii latin-iso8859-1 latin-iso8859-2
243 cyrillic-iso8859-5 greek-iso8859-7
244 latin-jisx0201 japanese-jisx0208-1978
245 chinese-gb2312 japanese-jisx0208
246 korean-ksc5601 japanese-jisx0212
247 chinese-cns11643-1 chinese-cns11643-2
248 chinese-cns11643-3 chinese-cns11643-4
249 chinese-cns11643-5 chinese-cns11643-6
250 chinese-cns11643-7) . iso-2022-int-1)
254 ;;; @ buffer representation
257 (defsubst-maybe set-buffer-multibyte (flag)
258 "Set the multibyte flag of the current buffer to FLAG.
259 If FLAG is t, this makes the buffer a multibyte buffer.
260 If FLAG is nil, this makes the buffer a single-byte buffer.
261 The buffer contents remain unchanged as a sequence of bytes
262 but the contents viewed as characters do change.
263 \[Emacs 20.3 emulating function]"
270 ;; avoid bug of XEmacs
271 (or (integerp (cdr (split-char ?a)))
272 (defun split-char (char)
273 "Return list of charset and one or two position-codes of CHAR."
274 (let ((charset (char-charset char)))
275 (if (eq charset 'ascii)
276 (list charset (char-int char))
278 (len (charset-dimension charset))
279 (code (if (integerp char)
284 (setq dest (cons (logand code 127) dest)
291 (defmacro char-next-index (char index)
292 "Return index of character succeeding CHAR whose index is INDEX."
295 ;;; @@ Mule emulating aliases
297 ;;; You should not use them.
299 ;;(defalias 'char-leading-char 'char-charset)
301 (defun char-category (character)
302 "Return string of category mnemonics for CHAR in TABLE.
303 CHAR can be any multilingual character
304 TABLE defaults to the current buffer's category table."
305 (mapconcat (lambda (chr)
306 (char-to-string (int-char chr))
308 (char-category-list character)
315 (defun string-to-int-list (str)
316 (mapcar #'char-int str)
319 (defalias 'looking-at-as-unibyte 'looking-at)
327 ;;; emu-x20.el ends here