70
|
1 ;;; mule-coding.el --- Coding-system functions for Mule.
|
|
2
|
197
|
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
|
4 ;; Licensed to the Free Software Foundation.
|
70
|
5 ;; Copyright (C) 1995 Amdahl Corporation.
|
|
6 ;; Copyright (C) 1995 Sun Microsystems.
|
197
|
7 ;; Copyright (C) 1997 MORIOKA Tomohiko
|
70
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs 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 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 ;;; Commentary:
|
|
27
|
|
28 ;;; split off of mule.el.
|
|
29
|
|
30 ;;; Code:
|
|
31
|
197
|
32 (defalias 'check-coding-system 'get-coding-system)
|
|
33
|
|
34 (defun modify-coding-system-alist (target-type regexp coding-system)
|
|
35 "Modify one of look up tables for finding a coding system on I/O operation.
|
|
36 There are three of such tables, `file-coding-system-alist',
|
|
37 `process-coding-system-alist', and `network-coding-system-alist'.
|
|
38
|
|
39 TARGET-TYPE specifies which of them to modify.
|
|
40 If it is `file', it affects `file-coding-system-alist' (which see).
|
|
41 If it is `process', it affects `process-coding-system-alist' (which see).
|
|
42 If it is `network', it affects `network-codign-system-alist' (which see).
|
|
43
|
|
44 REGEXP is a regular expression matching a target of I/O operation.
|
|
45 The target is a file name if TARGET-TYPE is `file', a program name if
|
|
46 TARGET-TYPE is `process', or a network service name or a port number
|
|
47 to connect to if TARGET-TYPE is `network'.
|
|
48
|
|
49 CODING-SYSTEM is a coding system to perform code conversion on the I/O
|
|
50 operation, or a cons cell (DECODING . ENCODING) specifying the coding systems
|
|
51 for decoding and encoding respectively,
|
|
52 or a function symbol which, when called, returns such a cons cell."
|
|
53 (or (memq target-type '(file process network))
|
|
54 (error "Invalid target type: %s" target-type))
|
|
55 (or (stringp regexp)
|
|
56 (and (eq target-type 'network) (integerp regexp))
|
|
57 (error "Invalid regular expression: %s" regexp))
|
|
58 (if (symbolp coding-system)
|
|
59 (if (not (fboundp coding-system))
|
|
60 (progn
|
|
61 (check-coding-system coding-system)
|
|
62 (setq coding-system (cons coding-system coding-system))))
|
|
63 (check-coding-system (car coding-system))
|
|
64 (check-coding-system (cdr coding-system)))
|
|
65 (cond ((eq target-type 'file)
|
|
66 (let ((slot (assoc regexp file-coding-system-alist)))
|
|
67 (if slot
|
|
68 (setcdr slot coding-system)
|
|
69 (setq file-coding-system-alist
|
|
70 (cons (cons regexp coding-system)
|
|
71 file-coding-system-alist)))))
|
|
72 ((eq target-type 'process)
|
|
73 (let ((slot (assoc regexp process-coding-system-alist)))
|
|
74 (if slot
|
|
75 (setcdr slot coding-system)
|
|
76 (setq process-coding-system-alist
|
|
77 (cons (cons regexp coding-system)
|
|
78 process-coding-system-alist)))))
|
|
79 (t
|
|
80 (let ((slot (assoc regexp network-coding-system-alist)))
|
|
81 (if slot
|
|
82 (setcdr slot coding-system)
|
|
83 (setq network-coding-system-alist
|
|
84 (cons (cons regexp coding-system)
|
|
85 network-coding-system-alist)))))))
|
|
86
|
102
|
87 (defun set-keyboard-coding-system (coding-system)
|
|
88 "Set the coding system used for TTY keyboard input. Currently broken."
|
|
89 (interactive "zkeyboard-coding-system: ")
|
|
90 (get-coding-system coding-system) ; correctness check
|
|
91 (setq keyboard-coding-system coding-system)
|
|
92 (redraw-modeline t))
|
|
93
|
70
|
94 (defun set-terminal-coding-system (coding-system)
|
102
|
95 "Set the coding system used for TTY display output. Currently broken."
|
70
|
96 (interactive "zterminal-coding-system: ")
|
102
|
97 (get-coding-system coding-system) ; correctness check
|
70
|
98 (setq terminal-coding-system coding-system)
|
|
99 (redraw-modeline t))
|
|
100
|
|
101 (defun set-pathname-coding-system (coding-system)
|
|
102 "Set the coding system used for file system path names."
|
|
103 (interactive "zPathname-coding-system: ")
|
102
|
104 (get-coding-system coding-system) ; correctness check
|
197
|
105 (setq file-name-coding-system coding-system))
|
70
|
106
|
|
107 (defun what-coding-system (start end &optional arg)
|
|
108 "Show the encoding of text in the region.
|
|
109 This function is meant to be called interactively;
|
|
110 from a Lisp program, use `detect-coding-region' instead."
|
|
111 (interactive "r\nP")
|
80
|
112 (princ (detect-coding-region start end)))
|
70
|
113
|
|
114 (defun decode-coding-string (str coding-system)
|
|
115 "Decode the string STR which is encoded in CODING-SYSTEM.
|
|
116 Does not modify STR. Returns the decoded string on successful conversion."
|
|
117 (with-string-as-buffer-contents
|
|
118 str (decode-coding-region (point-min) (point-max) coding-system)))
|
|
119
|
|
120 (defun encode-coding-string (str coding-system)
|
|
121 "Encode the string STR using CODING-SYSTEM.
|
|
122 Does not modify STR. Returns the encoded string on successful conversion."
|
|
123 (with-string-as-buffer-contents
|
|
124 str (encode-coding-region (point-min) (point-max) coding-system)))
|
|
125
|
|
126
|
|
127 ;;;; Coding system accessors
|
|
128
|
|
129 (defun coding-system-mnemonic (coding-system)
|
|
130 "Return the 'mnemonic property of CODING-SYSTEM."
|
|
131 (coding-system-property coding-system 'mnemonic))
|
|
132
|
165
|
133 (defalias 'coding-system-docstring 'coding-system-doc-string)
|
|
134
|
70
|
135 (defun coding-system-eol-type (coding-system)
|
|
136 "Return the 'eol-type property of CODING-SYSTEM."
|
|
137 (coding-system-property coding-system 'eol-type))
|
|
138
|
|
139 (defun coding-system-eol-lf (coding-system)
|
|
140 "Return the 'eol-lf property of CODING-SYSTEM."
|
|
141 (coding-system-property coding-system 'eol-lf))
|
|
142
|
|
143 (defun coding-system-eol-crlf (coding-system)
|
|
144 "Return the 'eol-crlf property of CODING-SYSTEM."
|
|
145 (coding-system-property coding-system 'eol-crlf))
|
|
146
|
|
147 (defun coding-system-eol-cr (coding-system)
|
|
148 "Return the 'eol-cr property of CODING-SYSTEM."
|
|
149 (coding-system-property coding-system 'eol-cr))
|
|
150
|
|
151 (defun coding-system-post-read-conversion (coding-system)
|
|
152 "Return the 'post-read-conversion property of CODING-SYSTEM."
|
|
153 (coding-system-property coding-system 'post-read-conversion))
|
|
154
|
|
155 (defun coding-system-pre-write-conversion (coding-system)
|
|
156 "Return the 'pre-write-conversion property of CODING-SYSTEM."
|
|
157 (coding-system-property coding-system 'pre-write-conversion))
|
|
158
|
|
159 (defun coding-system-charset (coding-system register)
|
|
160 "Return the 'charset property of CODING-SYSTEM for the specified REGISTER."
|
102
|
161 (unless (integerp register)
|
|
162 (signal 'wrong-type-argument (list 'integerp register)))
|
|
163 (coding-system-property
|
|
164 coding-system
|
|
165 (case register
|
|
166 (0 'charset-g0)
|
|
167 (1 'charset-g1)
|
|
168 (2 'charset-g2)
|
|
169 (3 'charset-g3)
|
|
170 (t (signal 'args-out-of-range (list register 0 3))))))
|
70
|
171
|
|
172 (defun coding-system-force-on-output (coding-system register)
|
|
173 "Return the 'force-on-output property of CODING-SYSTEM for the specified REGISTER."
|
102
|
174 (unless (integerp register)
|
|
175 (signal 'wrong-type-argument (list 'integerp register)))
|
|
176 (coding-system-property
|
|
177 coding-system
|
|
178 (case register
|
|
179 (0 'force-g0-on-output)
|
|
180 (1 'force-g1-on-output)
|
|
181 (2 'force-g2-on-output)
|
|
182 (3 'force-g3-on-output)
|
|
183 (t (signal 'args-out-of-range (list register 0 3))))))
|
70
|
184
|
|
185 (defun coding-system-short (coding-system)
|
|
186 "Return the 'short property of CODING-SYSTEM."
|
|
187 (coding-system-property coding-system 'short))
|
|
188
|
|
189 (defun coding-system-no-ascii-eol (coding-system)
|
|
190 "Return the 'no-ascii-eol property of CODING-SYSTEM."
|
|
191 (coding-system-property coding-system 'no-ascii-eol))
|
|
192
|
|
193 (defun coding-system-no-ascii-cntl (coding-system)
|
|
194 "Return the 'no-ascii-cntl property of CODING-SYSTEM."
|
|
195 (coding-system-property coding-system 'no-ascii-cntl))
|
|
196
|
|
197 (defun coding-system-seven (coding-system)
|
|
198 "Return the 'seven property of CODING-SYSTEM."
|
|
199 (coding-system-property coding-system 'seven))
|
|
200
|
|
201 (defun coding-system-lock-shift (coding-system)
|
|
202 "Return the 'lock-shift property of CODING-SYSTEM."
|
|
203 (coding-system-property coding-system 'lock-shift))
|
|
204
|
102
|
205 ;;(defun coding-system-use-japanese-jisx0201-roman (coding-system)
|
|
206 ;; "Return the 'use-japanese-jisx0201-roman property of CODING-SYSTEM."
|
|
207 ;; (coding-system-property coding-system 'use-japanese-jisx0201-roman))
|
70
|
208
|
102
|
209 ;;(defun coding-system-use-japanese-jisx0208-1978 (coding-system)
|
|
210 ;; "Return the 'use-japanese-jisx0208-1978 property of CODING-SYSTEM."
|
|
211 ;; (coding-system-property coding-system 'use-japanese-jisx0208-2978))
|
70
|
212
|
|
213 (defun coding-system-no-iso6429 (coding-system)
|
|
214 "Return the 'no-iso6429 property of CODING-SYSTEM."
|
|
215 (coding-system-property coding-system 'no-iso6429))
|
|
216
|
|
217 (defun coding-system-ccl-encode (coding-system)
|
|
218 "Return the CCL 'encode property of CODING-SYSTEM."
|
|
219 (coding-system-property coding-system 'encode))
|
|
220
|
|
221 (defun coding-system-ccl-decode (coding-system)
|
|
222 "Return the CCL 'decode property of CODING-SYSTEM."
|
|
223 (coding-system-property coding-system 'decode))
|
|
224
|
|
225
|
|
226 ;;;; Definitions of predefined coding systems
|
|
227
|
|
228 (make-coding-system
|
120
|
229 'automatic-conversion 'automatic-conversion
|
70
|
230 "Automatic conversion."
|
|
231 '(mnemonic "Auto"))
|
|
232
|
|
233 (make-coding-system
|
|
234 'ctext 'iso2022
|
|
235 "Coding-system used in X as Compound Text Encoding."
|
|
236 '(charset-g0 ascii
|
74
|
237 charset-g1 latin-iso8859-1
|
70
|
238 eol-type lf
|
|
239 mnemonic "CText"
|
|
240 ))
|
|
241
|
102
|
242 ;;; iso-8859-1 and ctext are aliases.
|
|
243
|
|
244 (copy-coding-system 'ctext 'iso-8859-1)
|
|
245
|
70
|
246 (make-coding-system
|
185
|
247 'iso-2022-8bit-ss2 'iso2022
|
70
|
248 "ISO-2022 coding system using SS2 for 96-charset in 8-bit code."
|
|
249 '(charset-g0 ascii
|
74
|
250 charset-g1 latin-iso8859-1
|
70
|
251 charset-g2 t ;; unspecified but can be used later.
|
|
252 short t
|
|
253 mnemonic "ISO8/SS"
|
|
254 ))
|
|
255
|
|
256 (make-coding-system
|
185
|
257 'iso-2022-7bit-ss2 'iso2022
|
70
|
258 "ISO-2022 coding system using SS2 for 96-charset in 7-bit code."
|
|
259 '(charset-g0 ascii
|
|
260 charset-g2 t ;; unspecified but can be used later.
|
|
261 seven t
|
|
262 short t
|
|
263 mnemonic "ISO7/SS"
|
|
264 ))
|
|
265
|
185
|
266 (copy-coding-system 'iso-2022-7bit-ss2 'iso-2022-jp-2)
|
|
267
|
70
|
268 (make-coding-system
|
197
|
269 'iso-2022-7bit 'iso2022
|
|
270 "ISO 2022 based 7-bit encoding using only G0"
|
70
|
271 '(charset-g0 ascii
|
|
272 seven t
|
|
273 short t
|
197
|
274 mnemonic "ISO7"))
|
|
275
|
|
276 ;; compatibility for old XEmacsen
|
|
277 (copy-coding-system 'iso-2022-7bit 'iso-2022-7)
|
70
|
278
|
|
279 (make-coding-system
|
|
280 'iso-2022-8 'iso2022
|
|
281 "ISO-2022 eight-bit coding system. No single-shift or locking-shift."
|
|
282 '(charset-g0 ascii
|
74
|
283 charset-g1 latin-iso8859-1
|
70
|
284 short t
|
|
285 mnemonic "ISO8"
|
|
286 ))
|
|
287
|
|
288 (make-coding-system
|
|
289 'escape-quoted 'iso2022
|
|
290 "ISO-2022 eight-bit coding system with escape quoting; used for .ELC files."
|
|
291 '(charset-g0 ascii
|
74
|
292 charset-g1 latin-iso8859-1
|
70
|
293 eol-type lf
|
|
294 escape-quoted t
|
|
295 mnemonic "ESC/Quot"
|
|
296 ))
|
|
297
|
|
298 (make-coding-system
|
|
299 'iso-2022-lock 'iso2022
|
|
300 "ISO-2022 coding system using Locking-Shift for 96-charset."
|
|
301 '(charset-g0 ascii
|
|
302 charset-g1 t ;; unspecified but can be used later.
|
|
303 seven t
|
|
304 lock-shift t
|
|
305 mnemonic "ISO7/Lock"
|
|
306 ))
|
|
307
|
|
308 ;; initialize the coding categories to something semi-reasonable
|
|
309 ;; so that the remaining Lisp files can contain extended characters.
|
|
310 ;; (They will be in ISO-7 format)
|
|
311
|
86
|
312 (set-coding-priority-list '(iso-8-2 iso-8-designate iso-8-1
|
70
|
313 iso-7 iso-lock-shift no-conversion))
|
|
314
|
|
315 (set-coding-category-system 'iso-7 'iso-2022-7)
|
|
316 (set-coding-category-system 'iso-8-designate 'ctext)
|
|
317 (set-coding-category-system 'iso-8-1 'ctext)
|
|
318 (set-coding-category-system 'iso-lock-shift 'iso-2022-lock)
|
|
319 (set-coding-category-system 'no-conversion 'no-conversion)
|
114
|
320
|
|
321 (make-compatible-variable 'enable-multibyte-characters "Unimplemented")
|
|
322
|
197
|
323 (define-obsolete-variable-alias
|
|
324 'pathname-coding-system 'file-name-coding-system)
|
|
325
|
114
|
326 ;;; mule-coding.el ends here
|