70
|
1 ;;; mule-coding.el --- Coding-system functions for Mule.
|
|
2
|
|
3 ;; Copyright (C) 1992,93,94,95 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Amdahl Corporation.
|
|
5 ;; Copyright (C) 1995 Sun Microsystems.
|
|
6
|
|
7 ;; This file is part of XEmacs.
|
|
8
|
|
9 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
10 ;; under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
17 ;; General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;;; split off of mule.el.
|
|
27
|
|
28 ;;; Code:
|
|
29
|
102
|
30 (defun set-keyboard-coding-system (coding-system)
|
|
31 "Set the coding system used for TTY keyboard input. Currently broken."
|
|
32 (interactive "zkeyboard-coding-system: ")
|
|
33 (get-coding-system coding-system) ; correctness check
|
|
34 (setq keyboard-coding-system coding-system)
|
|
35 (redraw-modeline t))
|
|
36
|
70
|
37 (defun set-terminal-coding-system (coding-system)
|
102
|
38 "Set the coding system used for TTY display output. Currently broken."
|
70
|
39 (interactive "zterminal-coding-system: ")
|
102
|
40 (get-coding-system coding-system) ; correctness check
|
70
|
41 (setq terminal-coding-system coding-system)
|
|
42 (redraw-modeline t))
|
|
43
|
|
44 (defun set-pathname-coding-system (coding-system)
|
|
45 "Set the coding system used for file system path names."
|
|
46 (interactive "zPathname-coding-system: ")
|
102
|
47 (get-coding-system coding-system) ; correctness check
|
70
|
48 (setq pathname-coding-system coding-system))
|
|
49
|
|
50 (defun what-coding-system (start end &optional arg)
|
|
51 "Show the encoding of text in the region.
|
|
52 This function is meant to be called interactively;
|
|
53 from a Lisp program, use `detect-coding-region' instead."
|
|
54 (interactive "r\nP")
|
80
|
55 (princ (detect-coding-region start end)))
|
70
|
56
|
|
57 (defmacro with-string-as-buffer-contents (str &rest body)
|
|
58 "With the contents of the current buffer being STR, run BODY.
|
|
59 Returns the new contents of the buffer, as modified by BODY.
|
|
60 The original current buffer is restored afterwards."
|
|
61 `(let ((curbuf (current-buffer))
|
|
62 (tempbuf (get-buffer-create " *string-as-buffer-contents*")))
|
|
63 (unwind-protect
|
|
64 (progn
|
|
65 (set-buffer tempbuf)
|
|
66 (buffer-disable-undo (current-buffer))
|
|
67 (erase-buffer)
|
|
68 (insert ,str)
|
|
69 ,@body
|
|
70 (buffer-string))
|
|
71 (erase-buffer tempbuf)
|
|
72 (set-buffer curbuf))))
|
|
73
|
|
74 (defun decode-coding-string (str coding-system)
|
|
75 "Decode the string STR which is encoded in CODING-SYSTEM.
|
|
76 Does not modify STR. Returns the decoded string on successful conversion."
|
|
77 (with-string-as-buffer-contents
|
|
78 str (decode-coding-region (point-min) (point-max) coding-system)))
|
|
79
|
|
80 (defun encode-coding-string (str coding-system)
|
|
81 "Encode the string STR using CODING-SYSTEM.
|
|
82 Does not modify STR. Returns the encoded string on successful conversion."
|
|
83 (with-string-as-buffer-contents
|
|
84 str (encode-coding-region (point-min) (point-max) coding-system)))
|
|
85
|
|
86
|
|
87 ;;;; Coding system accessors
|
|
88
|
|
89 (defun coding-system-mnemonic (coding-system)
|
|
90 "Return the 'mnemonic property of CODING-SYSTEM."
|
|
91 (coding-system-property coding-system 'mnemonic))
|
|
92
|
|
93 (defun coding-system-eol-type (coding-system)
|
|
94 "Return the 'eol-type property of CODING-SYSTEM."
|
|
95 (coding-system-property coding-system 'eol-type))
|
|
96
|
|
97 (defun coding-system-eol-lf (coding-system)
|
|
98 "Return the 'eol-lf property of CODING-SYSTEM."
|
|
99 (coding-system-property coding-system 'eol-lf))
|
|
100
|
|
101 (defun coding-system-eol-crlf (coding-system)
|
|
102 "Return the 'eol-crlf property of CODING-SYSTEM."
|
|
103 (coding-system-property coding-system 'eol-crlf))
|
|
104
|
|
105 (defun coding-system-eol-cr (coding-system)
|
|
106 "Return the 'eol-cr property of CODING-SYSTEM."
|
|
107 (coding-system-property coding-system 'eol-cr))
|
|
108
|
|
109 (defun coding-system-post-read-conversion (coding-system)
|
|
110 "Return the 'post-read-conversion property of CODING-SYSTEM."
|
|
111 (coding-system-property coding-system 'post-read-conversion))
|
|
112
|
|
113 (defun coding-system-pre-write-conversion (coding-system)
|
|
114 "Return the 'pre-write-conversion property of CODING-SYSTEM."
|
|
115 (coding-system-property coding-system 'pre-write-conversion))
|
|
116
|
|
117 (defun coding-system-charset (coding-system register)
|
|
118 "Return the 'charset property of CODING-SYSTEM for the specified REGISTER."
|
102
|
119 (unless (integerp register)
|
|
120 (signal 'wrong-type-argument (list 'integerp register)))
|
|
121 (coding-system-property
|
|
122 coding-system
|
|
123 (case register
|
|
124 (0 'charset-g0)
|
|
125 (1 'charset-g1)
|
|
126 (2 'charset-g2)
|
|
127 (3 'charset-g3)
|
|
128 (t (signal 'args-out-of-range (list register 0 3))))))
|
70
|
129
|
|
130 (defun coding-system-force-on-output (coding-system register)
|
|
131 "Return the 'force-on-output property of CODING-SYSTEM for the specified REGISTER."
|
102
|
132 (unless (integerp register)
|
|
133 (signal 'wrong-type-argument (list 'integerp register)))
|
|
134 (coding-system-property
|
|
135 coding-system
|
|
136 (case register
|
|
137 (0 'force-g0-on-output)
|
|
138 (1 'force-g1-on-output)
|
|
139 (2 'force-g2-on-output)
|
|
140 (3 'force-g3-on-output)
|
|
141 (t (signal 'args-out-of-range (list register 0 3))))))
|
70
|
142
|
|
143 (defun coding-system-short (coding-system)
|
|
144 "Return the 'short property of CODING-SYSTEM."
|
|
145 (coding-system-property coding-system 'short))
|
|
146
|
|
147 (defun coding-system-no-ascii-eol (coding-system)
|
|
148 "Return the 'no-ascii-eol property of CODING-SYSTEM."
|
|
149 (coding-system-property coding-system 'no-ascii-eol))
|
|
150
|
|
151 (defun coding-system-no-ascii-cntl (coding-system)
|
|
152 "Return the 'no-ascii-cntl property of CODING-SYSTEM."
|
|
153 (coding-system-property coding-system 'no-ascii-cntl))
|
|
154
|
|
155 (defun coding-system-seven (coding-system)
|
|
156 "Return the 'seven property of CODING-SYSTEM."
|
|
157 (coding-system-property coding-system 'seven))
|
|
158
|
|
159 (defun coding-system-lock-shift (coding-system)
|
|
160 "Return the 'lock-shift property of CODING-SYSTEM."
|
|
161 (coding-system-property coding-system 'lock-shift))
|
|
162
|
102
|
163 ;;(defun coding-system-use-japanese-jisx0201-roman (coding-system)
|
|
164 ;; "Return the 'use-japanese-jisx0201-roman property of CODING-SYSTEM."
|
|
165 ;; (coding-system-property coding-system 'use-japanese-jisx0201-roman))
|
70
|
166
|
102
|
167 ;;(defun coding-system-use-japanese-jisx0208-1978 (coding-system)
|
|
168 ;; "Return the 'use-japanese-jisx0208-1978 property of CODING-SYSTEM."
|
|
169 ;; (coding-system-property coding-system 'use-japanese-jisx0208-2978))
|
70
|
170
|
|
171 (defun coding-system-no-iso6429 (coding-system)
|
|
172 "Return the 'no-iso6429 property of CODING-SYSTEM."
|
|
173 (coding-system-property coding-system 'no-iso6429))
|
|
174
|
|
175 (defun coding-system-ccl-encode (coding-system)
|
|
176 "Return the CCL 'encode property of CODING-SYSTEM."
|
|
177 (coding-system-property coding-system 'encode))
|
|
178
|
|
179 (defun coding-system-ccl-decode (coding-system)
|
|
180 "Return the CCL 'decode property of CODING-SYSTEM."
|
|
181 (coding-system-property coding-system 'decode))
|
|
182
|
|
183
|
|
184 ;;;; Definitions of predefined coding systems
|
|
185
|
|
186 (make-coding-system
|
|
187 'autodetect 'autodetect
|
|
188 "Automatic conversion."
|
|
189 '(mnemonic "Auto"))
|
|
190
|
|
191 (make-coding-system
|
|
192 'ctext 'iso2022
|
|
193 "Coding-system used in X as Compound Text Encoding."
|
|
194 '(charset-g0 ascii
|
74
|
195 charset-g1 latin-iso8859-1
|
70
|
196 eol-type lf
|
|
197 mnemonic "CText"
|
|
198 ))
|
|
199
|
102
|
200 ;;; iso-8859-1 and ctext are aliases.
|
|
201
|
|
202 (copy-coding-system 'ctext 'iso-8859-1)
|
|
203
|
70
|
204 (make-coding-system
|
|
205 'iso-2022-ss2-8 'iso2022
|
|
206 "ISO-2022 coding system using SS2 for 96-charset in 8-bit code."
|
|
207 '(charset-g0 ascii
|
74
|
208 charset-g1 latin-iso8859-1
|
70
|
209 charset-g2 t ;; unspecified but can be used later.
|
|
210 short t
|
|
211 mnemonic "ISO8/SS"
|
|
212 ))
|
|
213
|
|
214 (make-coding-system
|
|
215 'iso-2022-ss2-7 'iso2022
|
|
216 "ISO-2022 coding system using SS2 for 96-charset in 7-bit code."
|
|
217 '(charset-g0 ascii
|
|
218 charset-g2 t ;; unspecified but can be used later.
|
|
219 seven t
|
|
220 short t
|
|
221 mnemonic "ISO7/SS"
|
|
222 ))
|
|
223
|
|
224 (make-coding-system
|
|
225 'iso-2022-7 'iso2022
|
|
226 "ISO-2022 seven-bit coding system. No single-shift or locking-shift."
|
|
227 '(charset-g0 ascii
|
|
228 seven t
|
|
229 short t
|
|
230 mnemonic "ISO7"
|
|
231 ))
|
|
232
|
|
233 (make-coding-system
|
|
234 'iso-2022-8 'iso2022
|
|
235 "ISO-2022 eight-bit coding system. No single-shift or locking-shift."
|
|
236 '(charset-g0 ascii
|
74
|
237 charset-g1 latin-iso8859-1
|
70
|
238 short t
|
|
239 mnemonic "ISO8"
|
|
240 ))
|
|
241
|
|
242 (make-coding-system
|
|
243 'escape-quoted 'iso2022
|
|
244 "ISO-2022 eight-bit coding system with escape quoting; used for .ELC files."
|
|
245 '(charset-g0 ascii
|
74
|
246 charset-g1 latin-iso8859-1
|
70
|
247 eol-type lf
|
|
248 escape-quoted t
|
|
249 mnemonic "ESC/Quot"
|
|
250 ))
|
|
251
|
|
252 (make-coding-system
|
|
253 'iso-2022-lock 'iso2022
|
|
254 "ISO-2022 coding system using Locking-Shift for 96-charset."
|
|
255 '(charset-g0 ascii
|
|
256 charset-g1 t ;; unspecified but can be used later.
|
|
257 seven t
|
|
258 lock-shift t
|
|
259 mnemonic "ISO7/Lock"
|
|
260 ))
|
|
261
|
|
262 ;; initialize the coding categories to something semi-reasonable
|
|
263 ;; so that the remaining Lisp files can contain extended characters.
|
|
264 ;; (They will be in ISO-7 format)
|
|
265
|
86
|
266 (set-coding-priority-list '(iso-8-2 iso-8-designate iso-8-1
|
70
|
267 iso-7 iso-lock-shift no-conversion))
|
|
268
|
|
269 (set-coding-category-system 'iso-7 'iso-2022-7)
|
|
270 (set-coding-category-system 'iso-8-designate 'ctext)
|
|
271 (set-coding-category-system 'iso-8-1 'ctext)
|
|
272 (set-coding-category-system 'iso-lock-shift 'iso-2022-lock)
|
|
273 (set-coding-category-system 'no-conversion 'no-conversion)
|