Mercurial > emacs
comparison lisp/international/mule-util.el @ 18200:c913160e34a7
(set-coding-system-alist): Deleted.
(string-to-sequence): Doc string modified.
(coding-system-list): Add optional arg BASE-ONLY.
(coding-system-base): New function.
(coding-system-plist): New function.
(coding-system-equal): New function.
(coding-system-unification-table): New function.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 10 Jun 1997 00:56:20 +0000 |
parents | e7920fdc4948 |
children | c6f35cac24b4 |
comparison
equal
deleted
inserted
replaced
18199:15177bdb2fcf | 18200:c913160e34a7 |
---|---|
28 ;;; characters. | 28 ;;; characters. |
29 | 29 |
30 ;;;###autoload | 30 ;;;###autoload |
31 (defun string-to-sequence (string type) | 31 (defun string-to-sequence (string type) |
32 "Convert STRING to a sequence of TYPE which contains characters in STRING. | 32 "Convert STRING to a sequence of TYPE which contains characters in STRING. |
33 TYPE should be `list' or `vector'. | 33 TYPE should be `list' or `vector'." |
34 Multibyte characters are conserned." | |
35 (or (eq type 'list) (eq type 'vector) | 34 (or (eq type 'list) (eq type 'vector) |
36 (error "Invalid type: %s" type)) | 35 (error "Invalid type: %s" type)) |
37 (let* ((len (length string)) | 36 (let* ((len (length string)) |
38 (i 0) | 37 (i 0) |
39 l ch) | 38 l ch) |
198 alist))) | 197 alist))) |
199 | 198 |
200 ;; Coding system related functions. | 199 ;; Coding system related functions. |
201 | 200 |
202 ;;;###autoload | 201 ;;;###autoload |
203 (defun set-coding-system-alist (target-type regexp coding-system | 202 (defun coding-system-list (&optional base-only) |
204 &optional operation) | 203 "Return a list of all existing coding systems. |
205 "Update `coding-system-alist' according to the arguments. | 204 If optional arg BASE-ONLY is non-nil, each element of the list |
206 TARGET-TYPE specifies a type of the target: `file', `process', or `network'. | 205 is a base coding system or a list of coding systems. |
207 TARGET-TYPE tells which slots of coding-system-alist should be affected. | 206 In the latter case, the first element is a base coding system, |
208 If `file', it affects slots for insert-file-contents and write-region. | 207 and the remainings are aliases of it." |
209 If `process', it affects slots for call-process, call-process-region, and | |
210 start-process. | |
211 If `network', it affects a slot for open-network-process. | |
212 REGEXP is a regular expression matching a target of I/O operation. | |
213 CODING-SYSTEM is a coding system to perform code conversion | |
214 on the I/O operation, or a cons of coding systems for decoding and | |
215 encoding respectively, or a function symbol which returns the cons. | |
216 Optional arg OPERATION if non-nil specifies directly one of slots above. | |
217 The valid value is: insert-file-contents, write-region, | |
218 call-process, call-process-region, start-process, or open-network-stream. | |
219 If OPERATION is specified, TARGET-TYPE is ignored. | |
220 See the documentation of `coding-system-alist' for more detail." | |
221 (or (stringp regexp) | |
222 (error "Invalid regular expression: %s" regexp)) | |
223 (or (memq target-type '(file process network)) | |
224 (error "Invalid target type: %s" target-type)) | |
225 (if (symbolp coding-system) | |
226 (if (not (fboundp coding-system)) | |
227 (progn | |
228 (check-coding-system coding-system) | |
229 (setq coding-system (cons coding-system coding-system)))) | |
230 (check-coding-system (car coding-system)) | |
231 (check-coding-system (cdr coding-system))) | |
232 (let ((op-list (if operation (list operation) | |
233 (cond ((eq target-type 'file) | |
234 '(insert-file-contents write-region)) | |
235 ((eq target-type 'process) | |
236 '(call-process call-process-region start-process)) | |
237 (t ; i.e. (eq target-type network) | |
238 '(open-network-stream))))) | |
239 slot) | |
240 (while op-list | |
241 (setq slot (assq (car op-list) coding-system-alist)) | |
242 (if slot | |
243 (let ((chain (cdr slot))) | |
244 (if (catch 'tag | |
245 (while chain | |
246 (if (string= regexp (car (car chain))) | |
247 (progn | |
248 (setcdr (car chain) coding-system) | |
249 (throw 'tag nil))) | |
250 (setq chain (cdr chain))) | |
251 t) | |
252 (setcdr slot (cons (cons regexp coding-system) (cdr slot))))) | |
253 (setq coding-system-alist | |
254 (cons (cons (car op-list) (list (cons regexp coding-system))) | |
255 coding-system-alist))) | |
256 (setq op-list (cdr op-list))))) | |
257 | |
258 ;;;###autoload | |
259 (defun coding-system-list () | |
260 "Return a list of all existing coding systems." | |
261 (let (l) | 208 (let (l) |
262 (mapatoms (lambda (x) (if (get x 'coding-system) (setq l (cons x l))))) | 209 (mapatoms (lambda (x) (if (get x 'coding-system) (setq l (cons x l))))) |
263 l)) | 210 (if (not base-only) |
211 l | |
212 (let* ((codings (sort l (function | |
213 (lambda (x y) | |
214 (<= (coding-system-mnemonic x) | |
215 (coding-system-mnemonic y)))))) | |
216 (tail (cons nil codings)) | |
217 (aliases nil) ; ((BASE ALIAS ...) ...) | |
218 base coding) | |
219 ;; At first, remove subsidiary coding systems (eol variants) and | |
220 ;; move alias coding systems to ALIASES. | |
221 (while (cdr tail) | |
222 (setq coding (car (cdr tail))) | |
223 (if (get coding 'eol-variant) | |
224 (setcdr tail (cdr (cdr tail))) | |
225 (setq base (coding-system-base coding)) | |
226 (if (and (not (eq coding base)) | |
227 (coding-system-equal coding base)) | |
228 (let ((slot (memq base aliases))) | |
229 (setcdr tail (cdr (cdr tail))) | |
230 (if slot | |
231 (setcdr slot (cons coding (cdr slot))) | |
232 (setq aliases (cons (list base coding) aliases)))) | |
233 (setq tail (cdr tail))))) | |
234 ;; Then, replace a coding system who has aliases with a list. | |
235 (setq tail codings) | |
236 (while tail | |
237 (let ((alias (assq (car tail) aliases))) | |
238 (if alias | |
239 (setcar tail alias))) | |
240 (setq tail (cdr tail))) | |
241 codings)))) | |
242 | |
243 ;;;###autoload | |
244 (defun coding-system-base (coding-system) | |
245 "Return a base of CODING-SYSTEM. | |
246 The base is a coding system of which coding-system property is a | |
247 coding-spec (see the function `make-coding-system')." | |
248 (let ((coding-spec (get coding-system 'coding-system))) | |
249 (if (vectorp coding-spec) | |
250 coding-system | |
251 (coding-system-base coding-spec)))) | |
252 | |
253 ;;;###autoload | |
254 (defun coding-system-plist (coding-system) | |
255 "Return property list of CODING-SYSTEM." | |
256 (let ((found nil) | |
257 coding-spec eol-type | |
258 post-read-conversion pre-write-conversion | |
259 unification-table) | |
260 (while (not found) | |
261 (or eol-type | |
262 (setq eol-type (get coding-system 'eol-type))) | |
263 (or post-read-conversion | |
264 (setq post-read-conversion | |
265 (get coding-system 'post-read-conversion))) | |
266 (or pre-write-conversion | |
267 (setq pre-write-conversion | |
268 (get coding-system 'pre-write-conversion))) | |
269 (or unification-table | |
270 (setq unification-table | |
271 (get coding-system 'unification-table))) | |
272 (setq coding-spec (get coding-system 'coding-system)) | |
273 (if (and coding-spec (symbolp coding-spec)) | |
274 (setq coding-system coding-spec) | |
275 (setq found t))) | |
276 (if (not coding-spec) | |
277 (error "Invalid coding system: %s" coding-system)) | |
278 (list 'coding-spec coding-spec | |
279 'eol-type eol-type | |
280 'post-read-conversion post-read-conversion | |
281 'pre-write-conversion pre-write-conversion | |
282 'unification-table unification-table))) | |
283 | |
284 ;;;###autoload | |
285 (defun coding-system-equal (coding-system-1 coding-system-2) | |
286 "Return t if and only of CODING-SYSTEM-1 and CODING-SYSTEM-2 are identical. | |
287 Two coding systems are identical if two symbols are equal | |
288 or one is an alias of the other." | |
289 (equal (coding-system-plist coding-system-1) | |
290 (coding-system-plist coding-system-2))) | |
291 | |
292 ;;;###autoload | |
293 (defun coding-system-eol-type-mnemonic (coding-system) | |
294 "Return mnemonic letter of eol-type of CODING-SYSTEM." | |
295 (let ((eol-type (coding-system-eol-type coding-system))) | |
296 (cond ((vectorp eol-type) eol-mnemonic-undecided) | |
297 ((eq eol-type 0) eol-mnemonic-unix) | |
298 ((eq eol-type 1) eol-mnemonic-unix) | |
299 ((eq eol-type 2) eol-mnemonic-unix) | |
300 (t ?-)))) | |
301 | |
302 ;;;###autoload | |
303 (defun coding-system-post-read-conversion (coding-system) | |
304 "Return post-read-conversion property of CODING-SYSTEM." | |
305 (and coding-system | |
306 (symbolp coding-system) | |
307 (or (get coding-system 'post-read-conversion) | |
308 (coding-system-post-read-conversion | |
309 (get coding-system 'coding-system))))) | |
310 | |
311 ;;;###autoload | |
312 (defun coding-system-pre-write-conversion (coding-system) | |
313 "Return pre-write-conversion property of CODING-SYSTEM." | |
314 (and coding-system | |
315 (symbolp coding-system) | |
316 (or (get coding-system 'pre-write-conversion) | |
317 (coding-system-pre-write-conversion | |
318 (get coding-system 'coding-system))))) | |
319 | |
320 ;;;###autoload | |
321 (defun coding-system-unification-table (coding-system) | |
322 "Return unification-table property of CODING-SYSTEM." | |
323 (and coding-system | |
324 (symbolp coding-system) | |
325 (or (get coding-system 'unification-table) | |
326 (coding-system-unification-table | |
327 (get coding-system 'coding-system))))) | |
264 | 328 |
265 | 329 |
266 ;;; Composite charcater manipulations. | 330 ;;; Composite charcater manipulations. |
267 | 331 |
268 ;;;###autoload | 332 ;;;###autoload |