comparison lisp/tl/emu-x20.el @ 8:4b173ad71786 r19-15b5

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