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.27 1996/07/11 09:02:01 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.
32 (defvar xemacs-beta-version
33 (if (string-match "(beta\\([0-9]+\\))" emacs-version)
35 (substring emacs-version (match-beginning 1)(match-end 1))
42 (defalias 'charset-description 'charset-doc-string)
44 (defun find-charset-string (string)
45 "Return a list of charsets in the STRING except ascii.
46 \[emu-x20.el; Mule emulating function]"
47 (delq 'ascii (charsets-in-string string))
50 (defun find-charset-region (start end)
51 "Return a list of charsets except ascii
52 in the region between START and END.
53 \[emu-x20.el; Mule emulating function]"
54 (delq 'ascii (charsets-in-region start end))
57 ;;; @@ for Mule emulation
60 (defconst lc-ascii 'ascii)
61 (defconst lc-ltn1 'latin-1)
62 (defconst lc-ltn2 'latin-2)
63 (defconst lc-ltn3 'latin-3)
64 (defconst lc-ltn4 'latin-4)
65 (defconst lc-crl 'cyrillic)
66 (defconst lc-arb 'arabic)
67 (defconst lc-grk 'greek)
68 (defconst lc-hbw 'hebrew)
69 (defconst lc-ltn5 'latin-5)
70 (defconst lc-jp 'japanese)
71 (defconst lc-jp2 'japanese-2)
72 (defconst lc-kr 'korean)
73 (defconst lc-big5-1 'chinese-big5-1)
74 (defconst lc-big5-2 'chinese-big5-2)
75 (defconst lc-cn 'chinese-gb)
76 (defconst lc-cns1 'chinese-cns-1)
77 (defconst lc-cns2 'chinese-cns-2)
78 (defconst lc-cns3 'chinese-cns-3)
79 (defconst lc-cns4 'chinese-cns-4)
80 (defconst lc-cns5 'chinese-cns-5)
81 (defconst lc-cns6 'chinese-cns-6)
82 (defconst lc-cns7 'chinese-cns-7)
88 (defconst *noconv* 'noconv)
89 (defconst *ctext* 'ctext)
91 (defconst *big5* 'big5)
92 (defconst *euc-kr* 'euc-kr)
95 (defvar code-converter-is-broken
96 (and xemacs-beta-version (<= xemacs-beta-version 26)))
98 (if code-converter-is-broken
101 (defun decode-coding-region (start end coding-system &optional buffer)
102 "Decode the text between START and END which is encoded in CODING-SYSTEM.
103 \[emu-x20.el; XEmacs 20 emulating function]"
109 (narrow-to-region start end)
110 (let ((process-output-coding-system 'noconv)
111 (process-input-coding-system coding-system))
112 (call-process-region start end "cat" t t nil)
115 (defun encode-coding-region (start end coding-system &optional buffer)
116 "Encode the text between START and END which is encoded in CODING-SYSTEM.
117 \[emu-x20.el; XEmacs 20 emulating function]"
123 (narrow-to-region start end)
124 (let ((process-output-coding-system coding-system)
125 (process-input-coding-system 'noconv))
126 (call-process-region start end "cat" t t nil)
131 (defalias 'character-encode-string 'encode-coding-string)
132 (defalias 'character-decode-string 'decode-coding-string)
133 (defalias 'character-encode-region 'encode-coding-region)
134 (defalias 'character-decode-region 'decode-coding-region)
136 (defmacro as-binary-process (&rest body)
137 `(let (selective-display ; Disable ^M to nl translation.
138 process-input-coding-system
139 process-output-coding-system)
146 (defvar charsets-mime-charset-alist
147 '(((ascii) . us-ascii)
148 ((ascii latin-1) . iso-8859-1)
149 ((ascii latin-2) . iso-8859-2)
150 ((ascii latin-3) . iso-8859-3)
151 ((ascii latin-4) . iso-8859-4)
152 ;;; ((ascii cyrillic) . iso-8859-5)
153 ((ascii cyrillic) . koi8-r)
154 ((ascii arabic) . iso-8859-6)
155 ((ascii greek) . iso-8859-7)
156 ((ascii hebrew) . iso-8859-8)
157 ((ascii latin-5) . iso-8859-9)
158 ((ascii japanese-old japanese) . iso-2022-jp)
159 ((ascii korean) . euc-kr)
160 ((ascii chinese-big5-1 chinese-big5-2) . big5)
161 ((ascii japanese-old chinese-gb japanese korean
162 japanese-2 latin-1 greek) . iso-2022-jp-2)
163 ((ascii japanese-old chinese-gb japanese korean
164 japanese-2 chinese-cns-1 chinese-cns-2
165 latin-1 greek) . iso-2022-int-1)
168 (defvar default-mime-charset 'iso-2022-int-1)
170 (defvar mime-charset-coding-system-alist
171 '((iso-8859-1 . ctext)
174 (iso-2022-jp-2 . iso-2022-ss2-7)
175 (x-iso-2022-jp-2 . iso-2022-ss2-7)
180 (defun mime-charset-to-coding-system (charset)
181 "Return coding-system by MIME charset. [emu-x20.el]"
182 (if (stringp charset)
183 (setq charset (intern (downcase charset)))
185 (or (cdr (assq charset mime-charset-coding-system-alist))
186 (and (memq charset (coding-system-list)) charset)
189 (defun detect-mime-charset-region (start end)
190 "Return MIME charset for region between START and END.
192 (charsets-to-mime-charset (charsets-in-region start end)))
194 (defun encode-mime-charset-region (start end charset)
195 "Encode the text between START and END which is
196 encoded in MIME CHARSET. [emu-x20.el]"
197 (let ((cs (mime-charset-to-coding-system charset)))
199 (encode-coding-region start end cs)
202 (defun encode-mime-charset-string (string charset)
203 "Encode the STRING which is encoded in MIME CHARSET. [emu-x20.el]"
204 (let ((cs (mime-charset-to-coding-system charset)))
206 (encode-coding-string string cs)
213 (defun char-bytes (chr) 1)
215 (defun char-length (character)
216 "Return number of elements a CHARACTER occupies in a string or buffer.
220 (defun char-columns (character)
221 "Return number of columns a CHARACTER occupies when displayed.
223 (charset-columns (char-charset character))
226 ;;; @@ Mule emulating aliases
228 ;;; You should not use them.
230 (defalias 'char-width 'char-columns)
232 (defalias 'char-leading-char 'char-charset)
234 (defun char-category (character)
235 "Return string of category mnemonics for CHAR in TABLE.
236 CHAR can be any multilingual character
237 TABLE defaults to the current buffer's category table.
238 \[emu-x20.el; Mule emulating function]"
239 (mapconcat (lambda (chr)
240 (char-to-string (int-char chr))
242 (char-category-list character)
249 (defun string-columns (string)
250 "Return number of columns STRING occupies when displayed.
253 (len (length string))
256 (setq col (+ col (char-columns (aref string i))))
261 (defalias 'string-width 'string-column)
263 (defun string-to-int-list (str)
264 (mapcar #'char-int str)
267 (defalias 'sref 'aref)
269 (defun truncate-string (str width &optional start-column)
270 "Truncate STR to fit in WIDTH columns.
271 Optional non-nil arg START-COLUMN specifies the starting column.
272 \[emu-x20.el; Mule 2.3 emulating function]"
274 (setq start-column 0))
275 (substring str start-column width)
284 ;;; emu-x20.el ends here