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 ;; Returns list absolute file name and length of data inserted.
92 (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)))
178 (decode-hz-region start end)))
180 (defun decode-mime-charset-region (start end charset &optional lbt)
181 "Decode the text between START and END as MIME CHARSET."
182 (if (stringp charset)
183 (setq charset (intern (downcase charset)))
185 (let ((func (cdr (or (assq charset mime-charset-decoder-alist)
186 (assq t mime-charset-decoder-alist)))))
187 (funcall func start end charset lbt)))
189 (defsubst encode-mime-charset-string (string charset)
190 "Encode the STRING as MIME CHARSET."
191 (let ((cs (mime-charset-to-coding-system charset)))
193 (encode-coding-string string cs)
196 ;; (defsubst decode-mime-charset-string (string charset)
197 ;; "Decode the STRING as MIME CHARSET."
198 ;; (let ((cs (mime-charset-to-coding-system charset)))
200 ;; (decode-coding-string string cs)
202 (defun decode-mime-charset-string (string charset &optional lbt)
203 "Decode the STRING as MIME CHARSET."
206 (decode-mime-charset-region (point-min)(point-max) charset lbt)
210 (defvar charsets-mime-charset-alist
211 '(((ascii) . us-ascii)
212 ((ascii latin-iso8859-1) . iso-8859-1)
213 ((ascii latin-iso8859-2) . iso-8859-2)
214 ((ascii latin-iso8859-3) . iso-8859-3)
215 ((ascii latin-iso8859-4) . iso-8859-4)
216 ((ascii cyrillic-iso8859-5) . iso-8859-5)
217 ;;; ((ascii cyrillic-iso8859-5) . koi8-r)
218 ((ascii arabic-iso8859-6) . iso-8859-6)
219 ((ascii greek-iso8859-7) . iso-8859-7)
220 ((ascii hebrew-iso8859-8) . iso-8859-8)
221 ((ascii latin-iso8859-9) . iso-8859-9)
222 ((ascii latin-jisx0201
223 japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
224 ((ascii latin-jisx0201
225 katakana-jisx0201 japanese-jisx0208) . shift_jis)
226 ((ascii korean-ksc5601) . euc-kr)
227 ((ascii chinese-gb2312) . cn-gb-2312)
228 ((ascii chinese-big5-1 chinese-big5-2) . cn-big5)
229 ((ascii latin-iso8859-1 greek-iso8859-7
230 latin-jisx0201 japanese-jisx0208-1978
231 chinese-gb2312 japanese-jisx0208
232 korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
233 ((ascii latin-iso8859-1 greek-iso8859-7
234 latin-jisx0201 japanese-jisx0208-1978
235 chinese-gb2312 japanese-jisx0208
236 korean-ksc5601 japanese-jisx0212
237 chinese-cns11643-1 chinese-cns11643-2) . iso-2022-int-1)
238 ((ascii latin-iso8859-1 latin-iso8859-2
239 cyrillic-iso8859-5 greek-iso8859-7
240 latin-jisx0201 japanese-jisx0208-1978
241 chinese-gb2312 japanese-jisx0208
242 korean-ksc5601 japanese-jisx0212
243 chinese-cns11643-1 chinese-cns11643-2
244 chinese-cns11643-3 chinese-cns11643-4
245 chinese-cns11643-5 chinese-cns11643-6
246 chinese-cns11643-7) . iso-2022-int-1)
250 ;;; @ buffer representation
253 (defsubst-maybe set-buffer-multibyte (flag)
254 "Set the multibyte flag of the current buffer to FLAG.
255 If FLAG is t, this makes the buffer a multibyte buffer.
256 If FLAG is nil, this makes the buffer a single-byte buffer.
257 The buffer contents remain unchanged as a sequence of bytes
258 but the contents viewed as characters do change.
259 \[Emacs 20.3 emulating function]"
266 ;; avoid bug of XEmacs
267 (or (integerp (cdr (split-char ?a)))
268 (defun split-char (char)
269 "Return list of charset and one or two position-codes of CHAR."
270 (let ((charset (char-charset char)))
271 (if (eq charset 'ascii)
272 (list charset (char-int char))
274 (len (charset-dimension charset))
275 (code (if (integerp char)
280 (setq dest (cons (logand code 127) dest)
283 (cons charset dest)))))
286 (defmacro char-next-index (char index)
287 "Return index of character succeeding CHAR whose index is INDEX."
290 ;;; @@ Mule emulating aliases
292 ;;; You should not use them.
294 ;;(defalias 'char-leading-char 'char-charset)
296 (defun char-category (character)
297 "Return string of category mnemonics for CHAR in TABLE.
298 CHAR can be any multilingual character
299 TABLE defaults to the current buffer's category table."
300 (mapconcat (lambda (chr)
301 (char-to-string (int-char chr)))
302 (char-category-list character)
309 (defun string-to-int-list (str)
310 (mapcar #'char-int str))
312 (defalias 'looking-at-as-unibyte 'looking-at)
320 ;;; emu-x20.el ends here