1 ;;; emu-x20.el --- emu API implementation for XEmacs 20 with mule
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Copyright (C) 1994,1995,1996 MORIOKA Tomohiko
6 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Version: $Id: emu-x20.el,v 7.40 1996/10/19 14:35:37 morioka Exp $
8 ;; Keywords: emulation, compatibility, Mule, XEmacs
10 ;; This file is part of tl (Tiny Library).
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU XEmacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, 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 (defalias 'find-charset-string 'charsets-in-string)
45 (defalias 'find-charset-region 'charsets-in-region)
47 (defun find-non-ascii-charset-string (string)
48 "Return a list of charsets in the STRING except ascii.
49 \[emu-x20.el; Mule emulating function]"
50 (delq 'ascii (charsets-in-string string))
53 (defun find-non-ascii-charset-region (start end)
54 "Return a list of charsets except ascii
55 in the region between START and END.
56 \[emu-x20.el; Mule emulating function]"
57 (delq 'ascii (charsets-in-region start end))
60 ;;; @@ for Mule emulation
63 (defconst lc-ascii 'ascii)
64 (defconst lc-ltn1 'latin-1)
65 (defconst lc-ltn2 'latin-2)
66 (defconst lc-ltn3 'latin-3)
67 (defconst lc-ltn4 'latin-4)
68 (defconst lc-crl 'cyrillic)
69 (defconst lc-arb 'arabic)
70 (defconst lc-grk 'greek)
71 (defconst lc-hbw 'hebrew)
72 (defconst lc-ltn5 'latin-5)
73 (defconst lc-jp 'japanese)
74 (defconst lc-jp2 'japanese-2)
75 (defconst lc-kr 'korean)
76 (defconst lc-big5-1 'chinese-big5-1)
77 (defconst lc-big5-2 'chinese-big5-2)
78 (defconst lc-cn 'chinese-gb)
79 (defconst lc-cns1 'chinese-cns-1)
80 (defconst lc-cns2 'chinese-cns-2)
81 (defconst lc-cns3 'chinese-cns-3)
82 (defconst lc-cns4 'chinese-cns-4)
83 (defconst lc-cns5 'chinese-cns-5)
84 (defconst lc-cns6 'chinese-cns-6)
85 (defconst lc-cns7 'chinese-cns-7)
91 (defconst *noconv* 'noconv)
92 (defconst *ctext* 'ctext)
94 (defconst *big5* 'big5)
95 (defconst *euc-kr* 'euc-kr)
96 (defconst *koi8* 'koi8)
98 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
100 (defmacro as-binary-process (&rest body)
101 `(let (selective-display ; Disable ^M to nl translation.
102 process-input-coding-system
103 process-output-coding-system)
106 (defmacro as-binary-input-file (&rest body)
107 `(let ((file-coding-system-for-read 'noconv))
114 (defvar charsets-mime-charset-alist
115 '(((ascii) . us-ascii)
116 ((ascii latin-1) . iso-8859-1)
117 ((ascii latin-2) . iso-8859-2)
118 ((ascii latin-3) . iso-8859-3)
119 ((ascii latin-4) . iso-8859-4)
120 ;;; ((ascii cyrillic) . iso-8859-5)
121 ((ascii cyrillic) . koi8-r)
122 ((ascii arabic) . iso-8859-6)
123 ((ascii greek) . iso-8859-7)
124 ((ascii hebrew) . iso-8859-8)
125 ((ascii latin-5) . iso-8859-9)
126 ((ascii japanese-old japanese) . iso-2022-jp)
127 ((ascii korean) . euc-kr)
128 ((ascii chinese-big5-1 chinese-big5-2) . big5)
129 ((ascii japanese-old chinese-gb japanese korean
130 japanese-2 latin-1 greek) . iso-2022-jp-2)
131 ((ascii japanese-old chinese-gb japanese korean
132 japanese-2 chinese-cns-1 chinese-cns-2
133 latin-1 greek) . iso-2022-int-1)
136 (defvar default-mime-charset 'iso-2022-int-1)
138 (defvar mime-charset-coding-system-alist
139 '((iso-8859-1 . ctext)
142 (iso-2022-jp-2 . iso-2022-ss2-7)
143 (x-iso-2022-jp-2 . iso-2022-ss2-7)
148 (defun mime-charset-to-coding-system (charset)
149 "Return coding-system by MIME charset. [emu-x20.el]"
150 (if (stringp charset)
151 (setq charset (intern (downcase charset)))
153 (or (cdr (assq charset mime-charset-coding-system-alist))
154 (and (memq charset (coding-system-list)) charset)
157 (defun detect-mime-charset-region (start end)
158 "Return MIME charset for region between START and END.
160 (charsets-to-mime-charset (charsets-in-region start end)))
162 (defun encode-mime-charset-region (start end charset)
163 "Encode the text between START and END as MIME CHARSET.
165 (let ((cs (mime-charset-to-coding-system charset)))
167 (encode-coding-region start end cs)
170 (defun decode-mime-charset-region (start end charset)
171 "Decode the text between START and END as MIME CHARSET.
173 (let ((cs (mime-charset-to-coding-system charset)))
175 (decode-coding-region start end cs)
178 (defun encode-mime-charset-string (string charset)
179 "Encode the STRING as MIME CHARSET. [emu-x20.el]"
180 (let ((cs (mime-charset-to-coding-system charset)))
182 (encode-coding-string string cs)
185 (defun decode-mime-charset-string (string charset)
186 "Decode the STRING as MIME CHARSET. [emu-x20.el]"
187 (let ((cs (mime-charset-to-coding-system charset)))
189 (decode-coding-string string cs)
196 (defun char-bytes (chr) 1)
198 (defun char-length (character)
199 "Return number of elements a CHARACTER occupies in a string or buffer.
203 (defun char-columns (character)
204 "Return number of columns a CHARACTER occupies when displayed.
206 (charset-columns (char-charset character))
209 ;;; @@ Mule emulating aliases
211 ;;; You should not use them.
213 (defalias 'char-width 'char-columns)
215 (defalias 'char-leading-char 'char-charset)
217 (defun char-category (character)
218 "Return string of category mnemonics for CHAR in TABLE.
219 CHAR can be any multilingual character
220 TABLE defaults to the current buffer's category table.
221 \[emu-x20.el; Mule emulating function]"
222 (mapconcat (lambda (chr)
223 (char-to-string (int-char chr))
225 (char-category-list character)
232 (defun string-columns (string)
233 "Return number of columns STRING occupies when displayed.
236 (len (length string))
239 (setq col (+ col (char-columns (aref string i))))
244 (defalias 'string-width 'string-columns)
246 (defun string-to-int-list (str)
247 (mapcar #'char-int str)
250 (defalias 'sref 'aref)
252 (defun truncate-string (str width &optional start-column)
253 "Truncate STR to fit in WIDTH columns.
254 Optional non-nil arg START-COLUMN specifies the starting column.
255 \[emu-x20.el; Mule 2.3 emulating function]"
257 (setq start-column 0))
258 (substring str start-column width)
267 ;;; emu-x20.el ends here