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
|
|
30 (defun set-terminal-coding-system (coding-system)
|
|
31 "Set the coding system used for TTY display output."
|
|
32 (interactive "zterminal-coding-system: ")
|
|
33 (get-coding-system coding-system) ;; correctness check
|
|
34 (setq terminal-coding-system coding-system)
|
|
35 (redraw-modeline t))
|
|
36
|
|
37 (defun set-pathname-coding-system (coding-system)
|
|
38 "Set the coding system used for file system path names."
|
|
39 (interactive "zPathname-coding-system: ")
|
|
40 (get-coding-system coding-system) ;; correctness check
|
|
41 (setq pathname-coding-system coding-system))
|
|
42
|
|
43 (defun what-coding-system (start end &optional arg)
|
|
44 "Show the encoding of text in the region.
|
|
45 This function is meant to be called interactively;
|
|
46 from a Lisp program, use `detect-coding-region' instead."
|
|
47 (interactive "r\nP")
|
80
|
48 (princ (detect-coding-region start end)))
|
70
|
49
|
|
50 (defmacro with-string-as-buffer-contents (str &rest body)
|
|
51 "With the contents of the current buffer being STR, run BODY.
|
|
52 Returns the new contents of the buffer, as modified by BODY.
|
|
53 The original current buffer is restored afterwards."
|
|
54 `(let ((curbuf (current-buffer))
|
|
55 (tempbuf (get-buffer-create " *string-as-buffer-contents*")))
|
|
56 (unwind-protect
|
|
57 (progn
|
|
58 (set-buffer tempbuf)
|
|
59 (buffer-disable-undo (current-buffer))
|
|
60 (erase-buffer)
|
|
61 (insert ,str)
|
|
62 ,@body
|
|
63 (buffer-string))
|
|
64 (erase-buffer tempbuf)
|
|
65 (set-buffer curbuf))))
|
|
66
|
|
67 (defun decode-coding-string (str coding-system)
|
|
68 "Decode the string STR which is encoded in CODING-SYSTEM.
|
|
69 Does not modify STR. Returns the decoded string on successful conversion."
|
|
70 (with-string-as-buffer-contents
|
|
71 str (decode-coding-region (point-min) (point-max) coding-system)))
|
|
72
|
|
73 (defun encode-coding-string (str coding-system)
|
|
74 "Encode the string STR using CODING-SYSTEM.
|
|
75 Does not modify STR. Returns the encoded string on successful conversion."
|
|
76 (with-string-as-buffer-contents
|
|
77 str (encode-coding-region (point-min) (point-max) coding-system)))
|
|
78
|
|
79
|
|
80 ;;;; Coding system accessors
|
|
81
|
|
82 (defun coding-system-mnemonic (coding-system)
|
|
83 "Return the 'mnemonic property of CODING-SYSTEM."
|
|
84 (coding-system-property coding-system 'mnemonic))
|
|
85
|
|
86 (defun coding-system-eol-type (coding-system)
|
|
87 "Return the 'eol-type property of CODING-SYSTEM."
|
|
88 (coding-system-property coding-system 'eol-type))
|
|
89
|
|
90 (defun coding-system-eol-lf (coding-system)
|
|
91 "Return the 'eol-lf property of CODING-SYSTEM."
|
|
92 (coding-system-property coding-system 'eol-lf))
|
|
93
|
|
94 (defun coding-system-eol-crlf (coding-system)
|
|
95 "Return the 'eol-crlf property of CODING-SYSTEM."
|
|
96 (coding-system-property coding-system 'eol-crlf))
|
|
97
|
|
98 (defun coding-system-eol-cr (coding-system)
|
|
99 "Return the 'eol-cr property of CODING-SYSTEM."
|
|
100 (coding-system-property coding-system 'eol-cr))
|
|
101
|
|
102 (defun coding-system-post-read-conversion (coding-system)
|
|
103 "Return the 'post-read-conversion property of CODING-SYSTEM."
|
|
104 (coding-system-property coding-system 'post-read-conversion))
|
|
105
|
|
106 (defun coding-system-pre-write-conversion (coding-system)
|
|
107 "Return the 'pre-write-conversion property of CODING-SYSTEM."
|
|
108 (coding-system-property coding-system 'pre-write-conversion))
|
|
109
|
|
110 (defun coding-system-charset (coding-system register)
|
|
111 "Return the 'charset property of CODING-SYSTEM for the specified REGISTER."
|
|
112 (cond ((not (integerp register))
|
|
113 (signal 'wrong-type-argument (list 'integerp register)))
|
|
114 ((= register 0)
|
|
115 (coding-system-property coding-system 'charset-g0))
|
|
116 ((= register 1)
|
|
117 (coding-system-property coding-system 'charset-g1))
|
|
118 ((= register 2)
|
|
119 (coding-system-property coding-system 'charset-g2))
|
|
120 ((= register 3)
|
|
121 (coding-system-property coding-system 'charset-g3))
|
|
122 (t
|
|
123 (signal 'args-out-of-range (list register 0 3)))))
|
|
124
|
|
125 (defun coding-system-force-on-output (coding-system register)
|
|
126 "Return the 'force-on-output property of CODING-SYSTEM for the specified REGISTER."
|
|
127 (cond ((not (integerp register))
|
|
128 (signal 'wrong-type-argument (list 'integerp register)))
|
|
129 ((= register 0)
|
|
130 (coding-system-property coding-system 'force-g0-on-output))
|
|
131 ((= register 1)
|
|
132 (coding-system-property coding-system 'force-g1-on-output))
|
|
133 ((= register 2)
|
|
134 (coding-system-property coding-system 'force-g2-on-output))
|
|
135 ((= register 3)
|
|
136 (coding-system-property coding-system 'force-g3-on-output))
|
|
137 (t
|
|
138 (signal 'args-out-of-range (list register 0 3)))))
|
|
139
|
|
140 (defun coding-system-short (coding-system)
|
|
141 "Return the 'short property of CODING-SYSTEM."
|
|
142 (coding-system-property coding-system 'short))
|
|
143
|
|
144 (defun coding-system-no-ascii-eol (coding-system)
|
|
145 "Return the 'no-ascii-eol property of CODING-SYSTEM."
|
|
146 (coding-system-property coding-system 'no-ascii-eol))
|
|
147
|
|
148 (defun coding-system-no-ascii-cntl (coding-system)
|
|
149 "Return the 'no-ascii-cntl property of CODING-SYSTEM."
|
|
150 (coding-system-property coding-system 'no-ascii-cntl))
|
|
151
|
|
152 (defun coding-system-seven (coding-system)
|
|
153 "Return the 'seven property of CODING-SYSTEM."
|
|
154 (coding-system-property coding-system 'seven))
|
|
155
|
|
156 (defun coding-system-lock-shift (coding-system)
|
|
157 "Return the 'lock-shift property of CODING-SYSTEM."
|
|
158 (coding-system-property coding-system 'lock-shift))
|
|
159
|
|
160 (defun coding-system-use-japanese-jisx0201-roman (coding-system)
|
|
161 "Return the 'use-japanese-jisx0201-roman property of CODING-SYSTEM."
|
|
162 (coding-system-property coding-system 'use-japanese-jisx0201-roman))
|
|
163
|
|
164 (defun coding-system-use-japanese-jisx0208-1978 (coding-system)
|
|
165 "Return the 'use-japanese-jisx0208-1978 property of CODING-SYSTEM."
|
|
166 (coding-system-property coding-system 'use-japanese-jisx0208-2978))
|
|
167
|
|
168 (defun coding-system-no-iso6429 (coding-system)
|
|
169 "Return the 'no-iso6429 property of CODING-SYSTEM."
|
|
170 (coding-system-property coding-system 'no-iso6429))
|
|
171
|
|
172 (defun coding-system-ccl-encode (coding-system)
|
|
173 "Return the CCL 'encode property of CODING-SYSTEM."
|
|
174 (coding-system-property coding-system 'encode))
|
|
175
|
|
176 (defun coding-system-ccl-decode (coding-system)
|
|
177 "Return the CCL 'decode property of CODING-SYSTEM."
|
|
178 (coding-system-property coding-system 'decode))
|
|
179
|
|
180
|
|
181 ;;;; Definitions of predefined coding systems
|
|
182
|
|
183 (make-coding-system
|
|
184 'autodetect 'autodetect
|
|
185 "Automatic conversion."
|
|
186 '(mnemonic "Auto"))
|
|
187
|
|
188 (make-coding-system
|
|
189 'ctext 'iso2022
|
|
190 "Coding-system used in X as Compound Text Encoding."
|
|
191 '(charset-g0 ascii
|
74
|
192 charset-g1 latin-iso8859-1
|
70
|
193 eol-type lf
|
|
194 mnemonic "CText"
|
|
195 ))
|
|
196
|
|
197 (make-coding-system
|
|
198 'iso-2022-ss2-8 'iso2022
|
|
199 "ISO-2022 coding system using SS2 for 96-charset in 8-bit code."
|
|
200 '(charset-g0 ascii
|
74
|
201 charset-g1 latin-iso8859-1
|
70
|
202 charset-g2 t ;; unspecified but can be used later.
|
|
203 short t
|
|
204 mnemonic "ISO8/SS"
|
|
205 ))
|
|
206
|
|
207 (make-coding-system
|
|
208 'iso-2022-ss2-7 'iso2022
|
|
209 "ISO-2022 coding system using SS2 for 96-charset in 7-bit code."
|
|
210 '(charset-g0 ascii
|
|
211 charset-g2 t ;; unspecified but can be used later.
|
|
212 seven t
|
|
213 short t
|
|
214 mnemonic "ISO7/SS"
|
|
215 ))
|
|
216
|
|
217 (make-coding-system
|
|
218 'iso-2022-7 'iso2022
|
|
219 "ISO-2022 seven-bit coding system. No single-shift or locking-shift."
|
|
220 '(charset-g0 ascii
|
|
221 seven t
|
|
222 short t
|
|
223 mnemonic "ISO7"
|
|
224 ))
|
|
225
|
|
226 (make-coding-system
|
|
227 'iso-2022-8 'iso2022
|
|
228 "ISO-2022 eight-bit coding system. No single-shift or locking-shift."
|
|
229 '(charset-g0 ascii
|
74
|
230 charset-g1 latin-iso8859-1
|
70
|
231 short t
|
|
232 mnemonic "ISO8"
|
|
233 ))
|
|
234
|
|
235 (make-coding-system
|
|
236 'escape-quoted 'iso2022
|
|
237 "ISO-2022 eight-bit coding system with escape quoting; used for .ELC files."
|
|
238 '(charset-g0 ascii
|
74
|
239 charset-g1 latin-iso8859-1
|
70
|
240 eol-type lf
|
|
241 escape-quoted t
|
|
242 mnemonic "ESC/Quot"
|
|
243 ))
|
|
244
|
|
245 (make-coding-system
|
|
246 'iso-2022-lock 'iso2022
|
|
247 "ISO-2022 coding system using Locking-Shift for 96-charset."
|
|
248 '(charset-g0 ascii
|
|
249 charset-g1 t ;; unspecified but can be used later.
|
|
250 seven t
|
|
251 lock-shift t
|
|
252 mnemonic "ISO7/Lock"
|
|
253 ))
|
|
254
|
|
255 ;; initialize the coding categories to something semi-reasonable
|
|
256 ;; so that the remaining Lisp files can contain extended characters.
|
|
257 ;; (They will be in ISO-7 format)
|
|
258
|
|
259 (set-coding-priority-list '(iso-8-2 shift-jis iso-8-designate iso-8-1 big5
|
|
260 iso-7 iso-lock-shift no-conversion))
|
|
261
|
|
262 (set-coding-category-system 'iso-7 'iso-2022-7)
|
|
263 (set-coding-category-system 'iso-8-designate 'ctext)
|
|
264 (set-coding-category-system 'iso-8-1 'ctext)
|
|
265 (set-coding-category-system 'iso-lock-shift 'iso-2022-lock)
|
|
266 (set-coding-category-system 'no-conversion 'no-conversion)
|