70
|
1 ;;; emu-x20.el --- emu API implementation for XEmacs 20 with mule
|
|
2
|
86
|
3 ;; Copyright (C) 1994,1995,1996,1997 MORIOKA Tomohiko
|
70
|
4
|
|
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
|
86
|
6 ;; Version: $Id: emu-x20.el,v 1.3 1997/01/30 02:22:46 steve Exp $
|
70
|
7 ;; Keywords: emulation, compatibility, Mule, XEmacs
|
|
8
|
86
|
9 ;; This file is part of XEmacs.
|
70
|
10
|
|
11 ;; This program is free software; you can redistribute it and/or
|
|
12 ;; modify it under the terms of the GNU General Public License as
|
|
13 ;; published by the Free Software Foundation; either version 2, or (at
|
|
14 ;; your option) any later version.
|
|
15
|
|
16 ;; This program is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with GNU XEmacs; see the file COPYING. If not, write to the
|
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
24 ;; Boston, MA 02111-1307, USA.
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 (require 'cyrillic)
|
|
29 (require 'emu-xemacs)
|
|
30
|
|
31 (defvar xemacs-beta-version
|
|
32 (if (string-match "(beta\\([0-9]+\\))" emacs-version)
|
|
33 (string-to-number
|
|
34 (substring emacs-version (match-beginning 1)(match-end 1))
|
|
35 )))
|
|
36
|
|
37
|
|
38 ;;; @ coding-system
|
|
39 ;;;
|
|
40
|
|
41 (defconst *noconv* 'no-conversion)
|
|
42 (defconst *ctext* 'ctext)
|
|
43 (defconst *hz* 'hz)
|
|
44 (defconst *big5* 'big5)
|
|
45 (defconst *euc-kr* 'euc-kr)
|
|
46 (defconst *koi8* 'koi8)
|
|
47
|
|
48 (defalias 'set-buffer-file-coding-system 'set-file-coding-system)
|
|
49
|
|
50 (defmacro as-binary-process (&rest body)
|
|
51 `(let (selective-display ; Disable ^M to nl translation.
|
|
52 process-input-coding-system
|
|
53 process-output-coding-system)
|
|
54 ,@body))
|
|
55
|
|
56 (defmacro as-binary-input-file (&rest body)
|
|
57 `(let ((file-coding-system-for-read 'no-conversion))
|
|
58 ,@body))
|
|
59
|
|
60
|
|
61 ;;; @ MIME charset
|
|
62 ;;;
|
|
63
|
|
64 (defvar charsets-mime-charset-alist
|
|
65 '(((ascii) . us-ascii)
|
74
|
66 ((ascii latin-iso8859-1) . iso-8859-1)
|
|
67 ((ascii latin-iso8859-2) . iso-8859-2)
|
|
68 ((ascii latin-iso8859-3) . iso-8859-3)
|
|
69 ((ascii latin-iso8859-4) . iso-8859-4)
|
|
70 ;;; ((ascii cyrillic-iso8859-5) . iso-8859-5)
|
|
71 ((ascii cyrillic-iso8859-5) . koi8-r)
|
|
72 ((ascii arabic-iso8859-6) . iso-8859-6)
|
|
73 ((ascii greek-iso8859-7) . iso-8859-7)
|
|
74 ((ascii hebrew-iso8859-8) . iso-8859-8)
|
|
75 ((ascii latin-iso8859-9) . iso-8859-9)
|
86
|
76 ((ascii latin-jisx0201
|
|
77 japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
|
70
|
78 ((ascii korean-ksc5601) . euc-kr)
|
86
|
79 ((ascii chinese-gb2312) . cn-gb-2312)
|
|
80 ((ascii chinese-big5-1 chinese-big5-2) . cn-big5)
|
|
81 ((ascii latin-iso8859-1 greek-iso8859-7
|
|
82 latin-jisx0201 japanese-jisx0208-1978
|
|
83 chinese-gb2312 japanese-jisx0208
|
|
84 korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
|
|
85 ((ascii latin-iso8859-1 greek-iso8859-7
|
|
86 latin-jisx0201 japanese-jisx0208-1978
|
|
87 chinese-gb2312 japanese-jisx0208
|
|
88 korean-ksc5601 japanese-jisx0212
|
|
89 chinese-cns11643-1 chinese-cns11643-2) . iso-2022-int-1)
|
|
90 ((ascii latin-iso8859-1 latin-iso8859-2
|
|
91 cyrillic-iso8859-5 greek-iso8859-7
|
|
92 latin-jisx0201 japanese-jisx0208-1978
|
|
93 chinese-gb2312 japanese-jisx0208
|
|
94 korean-ksc5601 japanese-jisx0212
|
74
|
95 chinese-cns11643-1 chinese-cns11643-2
|
86
|
96 chinese-cns11643-3 chinese-cns11643-4
|
|
97 chinese-cns11643-5 chinese-cns11643-6
|
|
98 chinese-cns11643-7) . iso-2022-int-1)
|
70
|
99 ))
|
|
100
|
86
|
101 (defvar default-mime-charset 'x-ctext)
|
70
|
102
|
|
103 (defvar mime-charset-coding-system-alist
|
86
|
104 '((iso-8859-1 . ctext)
|
|
105 (x-ctext . ctext)
|
|
106 (hz-gb-2312 . hz)
|
|
107 (cn-gb-2312 . euc-china)
|
|
108 (gb2312 . euc-china)
|
|
109 (cn-big5 . big5)
|
|
110 (koi8-r . koi8)
|
|
111 (iso-2022-jp-2 . iso-2022-ss2-7)
|
70
|
112 ))
|
|
113
|
|
114 (defun mime-charset-to-coding-system (charset)
|
|
115 "Return coding-system by MIME charset. [emu-x20.el]"
|
|
116 (if (stringp charset)
|
|
117 (setq charset (intern (downcase charset)))
|
|
118 )
|
|
119 (or (cdr (assq charset mime-charset-coding-system-alist))
|
|
120 (and (memq charset (coding-system-list)) charset)
|
|
121 ))
|
|
122
|
|
123 (defun detect-mime-charset-region (start end)
|
|
124 "Return MIME charset for region between START and END.
|
|
125 \[emu-x20.el]"
|
|
126 (charsets-to-mime-charset (charsets-in-region start end)))
|
|
127
|
|
128 (defun encode-mime-charset-region (start end charset)
|
|
129 "Encode the text between START and END as MIME CHARSET.
|
|
130 \[emu-x20.el]"
|
|
131 (let ((cs (mime-charset-to-coding-system charset)))
|
|
132 (if cs
|
|
133 (encode-coding-region start end cs)
|
|
134 )))
|
|
135
|
|
136 (defun decode-mime-charset-region (start end charset)
|
|
137 "Decode the text between START and END as MIME CHARSET.
|
|
138 \[emu-x20.el]"
|
|
139 (let ((cs (mime-charset-to-coding-system charset)))
|
|
140 (if cs
|
|
141 (decode-coding-region start end cs)
|
|
142 )))
|
|
143
|
|
144 (defun encode-mime-charset-string (string charset)
|
|
145 "Encode the STRING as MIME CHARSET. [emu-x20.el]"
|
|
146 (let ((cs (mime-charset-to-coding-system charset)))
|
|
147 (if cs
|
|
148 (encode-coding-string string cs)
|
|
149 string)))
|
|
150
|
|
151 (defun decode-mime-charset-string (string charset)
|
|
152 "Decode the STRING as MIME CHARSET. [emu-x20.el]"
|
|
153 (let ((cs (mime-charset-to-coding-system charset)))
|
|
154 (if cs
|
|
155 (decode-coding-string string cs)
|
|
156 string)))
|
|
157
|
|
158
|
|
159 ;;; @ character
|
|
160 ;;;
|
|
161
|
86
|
162 ;; (defun char-bytes (chr) 1)
|
70
|
163
|
86
|
164 ;; (defun char-length (character)
|
|
165 ;; "Return number of elements a CHARACTER occupies in a string or buffer.
|
|
166 ;; \[emu-x20.el]"
|
|
167 ;; 1)
|
70
|
168
|
86
|
169 ;; (defun char-columns (character)
|
|
170 ;; "Return number of columns a CHARACTER occupies when displayed.
|
|
171 ;; \[emu-x20.el]"
|
|
172 ;; (charset-columns (char-charset character))
|
|
173 ;; )
|
70
|
174
|
|
175 ;;; @@ Mule emulating aliases
|
|
176 ;;;
|
|
177 ;;; You should not use them.
|
|
178
|
86
|
179 ;;(defalias 'char-width 'char-columns)
|
70
|
180
|
|
181 (defalias 'char-leading-char 'char-charset)
|
|
182
|
|
183 (defun char-category (character)
|
|
184 "Return string of category mnemonics for CHAR in TABLE.
|
|
185 CHAR can be any multilingual character
|
|
186 TABLE defaults to the current buffer's category table.
|
|
187 \[emu-x20.el; Mule emulating function]"
|
|
188 (mapconcat (lambda (chr)
|
|
189 (char-to-string (int-char chr))
|
|
190 )
|
|
191 (char-category-list character)
|
|
192 ""))
|
|
193
|
|
194
|
|
195 ;;; @ string
|
|
196 ;;;
|
|
197
|
86
|
198 ;; (defun string-columns (string)
|
|
199 ;; "Return number of columns STRING occupies when displayed.
|
|
200 ;; \[emu-x20.el]"
|
|
201 ;; (let ((col 0)
|
|
202 ;; (len (length string))
|
|
203 ;; (i 0))
|
|
204 ;; (while (< i len)
|
|
205 ;; (setq col (+ col (char-columns (aref string i))))
|
|
206 ;; (setq i (1+ i))
|
|
207 ;; )
|
|
208 ;; col))
|
70
|
209
|
86
|
210 ;;(defalias 'string-width 'string-columns)
|
70
|
211
|
|
212 (defun string-to-int-list (str)
|
|
213 (mapcar #'char-int str)
|
|
214 )
|
|
215
|
86
|
216 ;;(defalias 'sref 'aref)
|
70
|
217
|
86
|
218 ;; (defun truncate-string (str width &optional start-column)
|
|
219 ;; "Truncate STR to fit in WIDTH columns.
|
|
220 ;; Optional non-nil arg START-COLUMN specifies the starting column.
|
|
221 ;; \[emu-x20.el; Mule 2.3 emulating function]"
|
|
222 ;; (or start-column
|
|
223 ;; (setq start-column 0))
|
|
224 ;; (substring str start-column width)
|
|
225 ;; )
|
70
|
226
|
|
227
|
|
228 ;;; @ end
|
|
229 ;;;
|
|
230
|
|
231 (provide 'emu-x20)
|
|
232
|
|
233 ;;; emu-x20.el ends here
|