2 ;;; emu-x20.el --- emu API implementation for XEmacs 20 with mule
4 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
5 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
7 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
9 ;;; $Id: emu-x20.el,v 7.34 1996/07/22 17:48:45 morioka Exp $
10 ;;; Keywords: emulation, compatibility, Mule, XEmacs
12 ;;; This file is part of tl (Tiny Library).
14 ;;; This program is free software; you can redistribute it and/or
15 ;;; modify it under the terms of the GNU General Public License as
16 ;;; published by the Free Software Foundation; either version 2, or
17 ;;; (at your option) any later version.
19 ;;; This program is distributed in the hope that it will be useful,
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;;; General Public License for more details.
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with This program. If not, write to the Free Software
26 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
33 (defvar xemacs-beta-version
34 (if (string-match "(beta\\([0-9]+\\))" emacs-version)
36 (substring emacs-version (match-beginning 1)(match-end 1))
43 (defalias 'charset-description 'charset-doc-string)
45 (defun find-charset-string (string)
46 "Return a list of charsets in the STRING except ascii.
47 \[emu-x20.el; Mule emulating function]"
48 (delq 'ascii (charsets-in-string string))
51 (defun find-charset-region (start end)
52 "Return a list of charsets except ascii
53 in the region between START and END.
54 \[emu-x20.el; Mule emulating function]"
55 (delq 'ascii (charsets-in-region start end))
58 ;;; @@ for Mule emulation
61 (defconst lc-ascii 'ascii)
62 (defconst lc-ltn1 'latin-1)
63 (defconst lc-ltn2 'latin-2)
64 (defconst lc-ltn3 'latin-3)
65 (defconst lc-ltn4 'latin-4)
66 (defconst lc-crl 'cyrillic)
67 (defconst lc-arb 'arabic)
68 (defconst lc-grk 'greek)
69 (defconst lc-hbw 'hebrew)
70 (defconst lc-ltn5 'latin-5)
71 (defconst lc-jp 'japanese)
72 (defconst lc-jp2 'japanese-2)
73 (defconst lc-kr 'korean)
74 (defconst lc-big5-1 'chinese-big5-1)
75 (defconst lc-big5-2 'chinese-big5-2)
76 (defconst lc-cn 'chinese-gb)
77 (defconst lc-cns1 'chinese-cns-1)
78 (defconst lc-cns2 'chinese-cns-2)
79 (defconst lc-cns3 'chinese-cns-3)
80 (defconst lc-cns4 'chinese-cns-4)
81 (defconst lc-cns5 'chinese-cns-5)
82 (defconst lc-cns6 'chinese-cns-6)
83 (defconst lc-cns7 'chinese-cns-7)
89 (defconst *noconv* 'noconv)
90 (defconst *ctext* 'ctext)
92 (defconst *big5* 'big5)
93 (defconst *euc-kr* 'euc-kr)
94 (defconst *koi8* 'koi8)
96 (defvar code-converter-is-broken
97 (and xemacs-beta-version (<= xemacs-beta-version 26)))
99 (if code-converter-is-broken
102 (defun decode-coding-region (start end coding-system &optional buffer)
103 "Decode the text between START and END which is encoded in CODING-SYSTEM.
104 \[emu-x20.el; XEmacs 20 emulating function]"
110 (narrow-to-region start end)
111 (let ((process-output-coding-system 'noconv)
112 (process-input-coding-system coding-system))
113 (call-process-region start end "cat" t t nil)
116 (defun encode-coding-region (start end coding-system &optional buffer)
117 "Encode the text between START and END which is encoded in CODING-SYSTEM.
118 \[emu-x20.el; XEmacs 20 emulating function]"
124 (narrow-to-region start end)
125 (let ((process-output-coding-system coding-system)
126 (process-input-coding-system 'noconv))
127 (call-process-region start end "cat" t t nil)
132 (defmacro as-binary-process (&rest body)
133 `(let (selective-display ; Disable ^M to nl translation.
134 process-input-coding-system
135 process-output-coding-system)
142 (defvar charsets-mime-charset-alist
143 '(((ascii) . us-ascii)
144 ((ascii latin-1) . iso-8859-1)
145 ((ascii latin-2) . iso-8859-2)
146 ((ascii latin-3) . iso-8859-3)
147 ((ascii latin-4) . iso-8859-4)
148 ;;; ((ascii cyrillic) . iso-8859-5)
149 ((ascii cyrillic) . koi8-r)
150 ((ascii arabic) . iso-8859-6)
151 ((ascii greek) . iso-8859-7)
152 ((ascii hebrew) . iso-8859-8)
153 ((ascii latin-5) . iso-8859-9)
154 ((ascii japanese-old japanese) . iso-2022-jp)
155 ((ascii korean) . euc-kr)
156 ((ascii chinese-big5-1 chinese-big5-2) . big5)
157 ((ascii japanese-old chinese-gb japanese korean
158 japanese-2 latin-1 greek) . iso-2022-jp-2)
159 ((ascii japanese-old chinese-gb japanese korean
160 japanese-2 chinese-cns-1 chinese-cns-2
161 latin-1 greek) . iso-2022-int-1)
164 (defvar default-mime-charset 'iso-2022-int-1)
166 (defvar mime-charset-coding-system-alist
167 '((iso-8859-1 . ctext)
170 (iso-2022-jp-2 . iso-2022-ss2-7)
171 (x-iso-2022-jp-2 . iso-2022-ss2-7)
176 (defun mime-charset-to-coding-system (charset)
177 "Return coding-system by MIME charset. [emu-x20.el]"
178 (if (stringp charset)
179 (setq charset (intern (downcase charset)))
181 (or (cdr (assq charset mime-charset-coding-system-alist))
182 (and (memq charset (coding-system-list)) charset)
185 (defun detect-mime-charset-region (start end)
186 "Return MIME charset for region between START and END.
188 (charsets-to-mime-charset (charsets-in-region start end)))
190 (defun encode-mime-charset-region (start end charset)
191 "Encode the text between START and END as MIME CHARSET.
193 (let ((cs (mime-charset-to-coding-system charset)))
195 (encode-coding-region start end cs)
198 (defun decode-mime-charset-region (start end charset)
199 "Decode the text between START and END as MIME CHARSET.
201 (let ((cs (mime-charset-to-coding-system charset)))
203 (decode-coding-region start end cs)
206 (defun encode-mime-charset-string (string charset)
207 "Encode the STRING as MIME CHARSET. [emu-x20.el]"
208 (let ((cs (mime-charset-to-coding-system charset)))
210 (encode-coding-string string cs)
213 (defun decode-mime-charset-string (string charset)
214 "Decode the STRING as MIME CHARSET. [emu-x20.el]"
215 (let ((cs (mime-charset-to-coding-system charset)))
217 (decode-coding-string string cs)
224 (defun char-bytes (chr) 1)
226 (defun char-length (character)
227 "Return number of elements a CHARACTER occupies in a string or buffer.
231 (defun char-columns (character)
232 "Return number of columns a CHARACTER occupies when displayed.
234 (charset-columns (char-charset character))
237 ;;; @@ Mule emulating aliases
239 ;;; You should not use them.
241 (defalias 'char-width 'char-columns)
243 (defalias 'char-leading-char 'char-charset)
245 (defun char-category (character)
246 "Return string of category mnemonics for CHAR in TABLE.
247 CHAR can be any multilingual character
248 TABLE defaults to the current buffer's category table.
249 \[emu-x20.el; Mule emulating function]"
250 (mapconcat (lambda (chr)
251 (char-to-string (int-char chr))
253 (char-category-list character)
260 (defun string-columns (string)
261 "Return number of columns STRING occupies when displayed.
264 (len (length string))
267 (setq col (+ col (char-columns (aref string i))))
272 (defalias 'string-width 'string-column)
274 (defun string-to-int-list (str)
275 (mapcar #'char-int str)
278 (defalias 'sref 'aref)
280 (defun truncate-string (str width &optional start-column)
281 "Truncate STR to fit in WIDTH columns.
282 Optional non-nil arg START-COLUMN specifies the starting column.
283 \[emu-x20.el; Mule 2.3 emulating function]"
285 (setq start-column 0))
286 (substring str start-column width)
295 ;;; emu-x20.el ends here