428
|
1 ;;; coding.el --- Coding-system functions for XEmacs.
|
|
2
|
|
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
|
4 ;; Licensed to the Free Software Foundation.
|
|
5 ;; Copyright (C) 1995 Amdahl Corporation.
|
|
6 ;; Copyright (C) 1995 Sun Microsystems.
|
|
7 ;; Copyright (C) 1997 MORIOKA Tomohiko
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; This file is very similar to mule-coding.el
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 ;; General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
440
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
428
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;;; split off of mule.el.
|
|
31
|
|
32 ;;; Code:
|
|
33
|
502
|
34 (globally-declare-fboundp
|
|
35 '(coding-system-lock-shift
|
|
36 coding-system-seven coding-system-charset charset-dimension))
|
|
37
|
428
|
38 (defalias 'check-coding-system 'get-coding-system)
|
|
39
|
|
40 (defconst modeline-multibyte-status '("%C")
|
|
41 "Modeline control for showing multibyte extension status.")
|
|
42
|
|
43 ;; override the default value defined in loaddefs.el.
|
|
44 (setq-default modeline-format
|
444
|
45 (cons ""
|
|
46 (cons 'modeline-multibyte-status
|
|
47 (cdr modeline-format))))
|
428
|
48
|
|
49 (defun modify-coding-system-alist (target-type regexp coding-system)
|
|
50 "Modify one of look up tables for finding a coding system on I/O operation.
|
|
51 There are three of such tables, `file-coding-system-alist',
|
|
52 `process-coding-system-alist', and `network-coding-system-alist'.
|
|
53
|
|
54 TARGET-TYPE specifies which of them to modify.
|
|
55 If it is `file', it affects `file-coding-system-alist' (which see).
|
|
56 If it is `process', it affects `process-coding-system-alist' (which see).
|
599
|
57 If it is `network', it affects `network-coding-system-alist' (which see).
|
428
|
58
|
|
59 REGEXP is a regular expression matching a target of I/O operation.
|
|
60 The target is a file name if TARGET-TYPE is `file', a program name if
|
|
61 TARGET-TYPE is `process', or a network service name or a port number
|
|
62 to connect to if TARGET-TYPE is `network'.
|
|
63
|
|
64 CODING-SYSTEM is a coding system to perform code conversion on the I/O
|
|
65 operation, or a cons cell (DECODING . ENCODING) specifying the coding systems
|
|
66 for decoding and encoding respectively,
|
|
67 or a function symbol which, when called, returns such a cons cell."
|
|
68 (or (memq target-type '(file process network))
|
|
69 (error "Invalid target type: %s" target-type))
|
|
70 (or (stringp regexp)
|
|
71 (and (eq target-type 'network) (integerp regexp))
|
|
72 (error "Invalid regular expression: %s" regexp))
|
|
73 (if (symbolp coding-system)
|
|
74 (if (not (fboundp coding-system))
|
|
75 (progn
|
|
76 (check-coding-system coding-system)
|
|
77 (setq coding-system (cons coding-system coding-system))))
|
|
78 (check-coding-system (car coding-system))
|
|
79 (check-coding-system (cdr coding-system)))
|
|
80 (cond ((eq target-type 'file)
|
|
81 (let ((slot (assoc regexp file-coding-system-alist)))
|
|
82 (if slot
|
|
83 (setcdr slot coding-system)
|
|
84 (setq file-coding-system-alist
|
|
85 (cons (cons regexp coding-system)
|
|
86 file-coding-system-alist)))))
|
|
87 ((eq target-type 'process)
|
|
88 (let ((slot (assoc regexp process-coding-system-alist)))
|
|
89 (if slot
|
|
90 (setcdr slot coding-system)
|
|
91 (setq process-coding-system-alist
|
|
92 (cons (cons regexp coding-system)
|
|
93 process-coding-system-alist)))))
|
|
94 (t
|
|
95 (let ((slot (assoc regexp network-coding-system-alist)))
|
|
96 (if slot
|
|
97 (setcdr slot coding-system)
|
|
98 (setq network-coding-system-alist
|
|
99 (cons (cons regexp coding-system)
|
|
100 network-coding-system-alist)))))))
|
|
101
|
|
102 (defsubst keyboard-coding-system ()
|
|
103 "Return coding-system of what is sent from terminal keyboard."
|
|
104 keyboard-coding-system)
|
|
105
|
|
106 (defun set-keyboard-coding-system (coding-system)
|
|
107 "Set the coding system used for TTY keyboard input. Currently broken."
|
|
108 (interactive "zkeyboard-coding-system: ")
|
|
109 (get-coding-system coding-system) ; correctness check
|
|
110 (setq keyboard-coding-system coding-system)
|
442
|
111 (if (eq (device-type) 'tty)
|
502
|
112 (declare-fboundp (set-console-tty-input-coding-system
|
|
113 (device-console) keyboard-coding-system)))
|
428
|
114 (redraw-modeline t))
|
|
115
|
|
116 (defsubst terminal-coding-system ()
|
|
117 "Return coding-system of your terminal."
|
|
118 terminal-coding-system)
|
|
119
|
|
120 (defun set-terminal-coding-system (coding-system)
|
|
121 "Set the coding system used for TTY display output. Currently broken."
|
|
122 (interactive "zterminal-coding-system: ")
|
|
123 (get-coding-system coding-system) ; correctness check
|
|
124 (setq terminal-coding-system coding-system)
|
|
125 ; #### should this affect all current tty consoles ?
|
|
126 (if (eq (device-type) 'tty)
|
502
|
127 (declare-fboundp (set-console-tty-output-coding-system
|
|
128 (device-console) terminal-coding-system)))
|
428
|
129 (redraw-modeline t))
|
|
130
|
|
131 (defun set-pathname-coding-system (coding-system)
|
|
132 "Set the coding system used for file system path names."
|
|
133 (interactive "zPathname-coding-system: ")
|
|
134 (get-coding-system coding-system) ; correctness check
|
|
135 (setq file-name-coding-system coding-system))
|
|
136
|
|
137 (defun what-coding-system (start end &optional arg)
|
|
138 "Show the encoding of text in the region.
|
|
139 This function is meant to be called interactively;
|
|
140 from a Lisp program, use `detect-coding-region' instead."
|
|
141 (interactive "r\nP")
|
|
142 (princ (detect-coding-region start end)))
|
|
143
|
|
144 (defun decode-coding-string (str coding-system)
|
|
145 "Decode the string STR which is encoded in CODING-SYSTEM.
|
|
146 Does not modify STR. Returns the decoded string on successful conversion."
|
|
147 (with-string-as-buffer-contents
|
|
148 str (decode-coding-region (point-min) (point-max) coding-system)))
|
|
149
|
|
150 (defun encode-coding-string (str coding-system)
|
|
151 "Encode the string STR using CODING-SYSTEM.
|
|
152 Does not modify STR. Returns the encoded string on successful conversion."
|
|
153 (with-string-as-buffer-contents
|
|
154 str (encode-coding-region (point-min) (point-max) coding-system)))
|
|
155
|
|
156
|
|
157 ;;;; Coding system accessors
|
|
158
|
|
159 (defun coding-system-mnemonic (coding-system)
|
|
160 "Return the 'mnemonic property of CODING-SYSTEM."
|
|
161 (coding-system-property coding-system 'mnemonic))
|
|
162
|
|
163 (defalias 'coding-system-docstring 'coding-system-doc-string)
|
|
164
|
|
165 (defun coding-system-eol-type (coding-system)
|
|
166 "Return the 'eol-type property of CODING-SYSTEM."
|
|
167 (coding-system-property coding-system 'eol-type))
|
|
168
|
|
169 (defun coding-system-eol-lf (coding-system)
|
|
170 "Return the 'eol-lf property of CODING-SYSTEM."
|
|
171 (coding-system-property coding-system 'eol-lf))
|
|
172
|
|
173 (defun coding-system-eol-crlf (coding-system)
|
|
174 "Return the 'eol-crlf property of CODING-SYSTEM."
|
|
175 (coding-system-property coding-system 'eol-crlf))
|
|
176
|
|
177 (defun coding-system-eol-cr (coding-system)
|
|
178 "Return the 'eol-cr property of CODING-SYSTEM."
|
|
179 (coding-system-property coding-system 'eol-cr))
|
|
180
|
|
181 (defun coding-system-post-read-conversion (coding-system)
|
|
182 "Return the 'post-read-conversion property of CODING-SYSTEM."
|
|
183 (coding-system-property coding-system 'post-read-conversion))
|
|
184
|
|
185 (defun coding-system-pre-write-conversion (coding-system)
|
|
186 "Return the 'pre-write-conversion property of CODING-SYSTEM."
|
|
187 (coding-system-property coding-system 'pre-write-conversion))
|
|
188
|
|
189 (defun coding-system-base (coding-system)
|
|
190 "Return the base coding system of CODING-SYSTEM."
|
|
191 (if (not (coding-system-eol-type coding-system))
|
|
192 coding-system
|
440
|
193 (find-coding-system
|
428
|
194 (intern
|
440
|
195 (substring
|
428
|
196 (symbol-name (coding-system-name coding-system))
|
|
197 0
|
|
198 (string-match "-unix$\\|-dos$\\|-mac$"
|
|
199 (symbol-name (coding-system-name coding-system))))))))
|
502
|
200
|
|
201
|
|
202 ;;; #### bleagh!!!!!!!
|
|
203
|
|
204 (defun coding-system-get (coding-system prop)
|
|
205 "Extract a value from CODING-SYSTEM's property list for property PROP."
|
|
206 (or (plist-get
|
|
207 (get (coding-system-name coding-system) 'coding-system-property)
|
|
208 prop)
|
|
209 (condition-case nil
|
|
210 (coding-system-property coding-system prop)
|
|
211 (error nil))))
|
|
212
|
|
213 (defun coding-system-put (coding-system prop value)
|
|
214 "Change value in CODING-SYSTEM's property list PROP to VALUE."
|
|
215 (put (coding-system-name coding-system)
|
|
216 'coding-system-property
|
|
217 (plist-put (get (coding-system-name coding-system)
|
|
218 'coding-system-property)
|
|
219 prop value)))
|
|
220
|
|
221 (defun coding-system-category (coding-system)
|
|
222 "Return the coding category of CODING-SYSTEM."
|
|
223 (or (coding-system-get coding-system 'category)
|
|
224 (let ((type (coding-system-type coding-system)))
|
|
225 (cond ((eq type 'no-conversion)
|
|
226 'no-conversion)
|
|
227 ((eq type 'shift-jis)
|
|
228 'shift-jis)
|
|
229 ((eq type 'ucs-4)
|
|
230 'ucs-4)
|
|
231 ((eq type 'utf-8)
|
|
232 'utf-8)
|
|
233 ((eq type 'big5)
|
|
234 'big5)
|
|
235 ((eq type 'iso2022)
|
|
236 (cond ((coding-system-lock-shift coding-system)
|
|
237 'iso-lock-shift)
|
|
238 ((coding-system-seven coding-system)
|
|
239 'iso-7)
|
|
240 (t
|
|
241 (let ((dim 0)
|
|
242 ccs
|
|
243 (i 0))
|
|
244 (while (< i 4)
|
|
245 (setq ccs (coding-system-charset coding-system i))
|
|
246 (if (and ccs
|
|
247 (> (charset-dimension ccs) dim))
|
|
248 (setq dim (charset-dimension ccs))
|
|
249 )
|
|
250 (setq i (1+ i)))
|
|
251 (cond ((= dim 1) 'iso-8-1)
|
|
252 ((= dim 2) 'iso-8-2)
|
|
253 (t 'iso-8-designate))
|
|
254 ))))))))
|
|
255
|
428
|
256
|
|
257 ;;;; Definitions of predefined coding systems
|
|
258
|
|
259 (make-coding-system
|
|
260 'undecided 'undecided
|
|
261 "Automatic conversion."
|
|
262 '(mnemonic "Auto"))
|
|
263
|
440
|
264 ;;; Make certain variables equivalent to coding-system aliases
|
|
265 (defun dontusethis-set-value-file-name-coding-system-handler (sym args fun harg handlers)
|
|
266 (define-coding-system-alias 'file-name (or (car args) 'binary)))
|
|
267
|
|
268 (dontusethis-set-symbol-value-handler
|
|
269 'file-name-coding-system
|
|
270 'set-value
|
|
271 'dontusethis-set-value-file-name-coding-system-handler)
|
|
272
|
|
273 (defun dontusethis-set-value-terminal-coding-system-handler (sym args fun harg handlers)
|
|
274 (define-coding-system-alias 'terminal (or (car args) 'binary)))
|
|
275
|
|
276 (dontusethis-set-symbol-value-handler
|
|
277 'terminal-coding-system
|
|
278 'set-value
|
|
279 'dontusethis-set-value-terminal-coding-system-handler)
|
|
280
|
|
281 (defun dontusethis-set-value-keyboard-coding-system-handler (sym args fun harg handlers)
|
|
282 (define-coding-system-alias 'keyboard (or (car args) 'binary)))
|
|
283
|
|
284 (dontusethis-set-symbol-value-handler
|
|
285 'keyboard-coding-system
|
|
286 'set-value
|
|
287 'dontusethis-set-value-keyboard-coding-system-handler)
|
|
288
|
|
289 (unless (boundp 'file-name-coding-system)
|
|
290 (setq file-name-coding-system nil))
|
|
291
|
|
292 (when (not (featurep 'mule))
|
|
293 ;; these are so that gnus and friends work when not mule
|
|
294 (copy-coding-system 'undecided 'iso-8859-1)
|
|
295 (copy-coding-system 'undecided 'iso-8859-2)
|
|
296
|
|
297 (define-coding-system-alias 'ctext 'binary))
|
|
298
|
428
|
299
|
|
300 ;; compatibility for old XEmacsen (don't use it)
|
|
301 (copy-coding-system 'undecided 'automatic-conversion)
|
|
302
|
|
303 (make-compatible-variable 'enable-multibyte-characters "Unimplemented")
|
|
304
|
|
305 (define-obsolete-variable-alias
|
|
306 'pathname-coding-system 'file-name-coding-system)
|
|
307
|
728
|
308 ;;; coding.el ends here
|