(ascii_skip_code): New variable.
[bpt/emacs.git] / lisp / international / mule.el
CommitLineData
4ed46869
KH
1;;; mule.el --- basic commands for mulitilingual environment
2
4ed46869 3;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
58cfed09 4;; Licensed to the Free Software Foundation.
4ed46869
KH
5
6;; Keywords: mule, multilingual, character set, coding system
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
369314dc
KH
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
4ed46869
KH
24
25;;; Code:
26
27(defconst mule-version "3.0 (MOMIJINOGA)" "\
28Version number and name of this version of MULE (multilingual environment).")
29
30(defconst mule-version-date "1998.1.1" "\
31Distribution date of this version of MULE (multilingual environment).")
32
33(defun load-with-code-conversion (fullname file &optional noerror nomessage)
0f69cb38
KH
34 "Execute a file of Lisp code named FILE whose absolute name is FULLNAME.
35The file contents are decoded before evaluation if necessary.
4ed46869
KH
36If optional second arg NOERROR is non-nil,
37 report no error if FILE doesn't exist.
38Print messages at start and end of loading unless
39 optional third arg NOMESSAGE is non-nil.
40Return t if file exists."
41 (if (null (file-readable-p fullname))
42 (and (null noerror)
43 (signal 'file-error (list "Cannot open load file" file)))
44 ;; Read file with code conversion, and then eval.
45 (let* ((buffer
46 ;; To avoid any autoloading, set default-major-mode to
47 ;; fundamental-mode.
88162676
RS
48 ;; So that we don't get completely screwed if the
49 ;; file is encoded in some complicated character set,
50 ;; read it with real decoding, as a multibyte buffer,
51 ;; even if this is a --unibyte Emacs session.
52 (let ((default-major-mode 'fundamental-mode)
53 (default-enable-multibyte-characters t))
4ed46869
KH
54 ;; We can't use `generate-new-buffer' because files.el
55 ;; is not yet loaded.
56 (get-buffer-create (generate-new-buffer-name " *load*"))))
db5cae4b
SM
57 (load-in-progress t)
58 (source (save-match-data (string-match "\\.el\\'" fullname))))
59 (unless nomessage
60 (if source
61 (message "Loading %s (source)..." file)
62 (message "Loading %s..." file)))
63 (when purify-flag
64 (setq preloaded-file-list (cons file preloaded-file-list)))
4ed46869 65 (unwind-protect
a6acd8a2
KH
66 (let ((load-file-name fullname)
67 (inhibit-file-name-operation nil))
4ed46869
KH
68 (save-excursion
69 (set-buffer buffer)
70 (insert-file-contents fullname)
4ed46869
KH
71 ;; Make `kill-buffer' quiet.
72 (set-buffer-modified-p nil))
0f69cb38 73 ;; Have the original buffer current while we eval.
88162676
RS
74 (eval-buffer buffer nil file
75 ;; If this Emacs is running with --unibyte,
76 ;; convert multibyte strings to unibyte
77 ;; after reading them.
ba74e833
RS
78;; (not default-enable-multibyte-characters)
79 ))
cfc70cdf
RS
80 (let (kill-buffer-hook kill-buffer-query-functions)
81 (kill-buffer buffer)))
4ed46869 82 (let ((hook (assoc file after-load-alist)))
db5cae4b
SM
83 (when hook
84 (mapcar (function eval) (cdr hook))))
85 (unless (or nomessage noninteractive)
86 (if source
87 (message "Loading %s (source)...done" file)
88 (message "Loading %s...done" file)))
4ed46869
KH
89 t)))
90
91;; API (Application Program Interface) for charsets.
92
2e02a76f
RS
93;; Return t if OBJ is a quoted symbol
94;; and the symbol is the name of a standard charset.
95(defsubst charset-quoted-standard-p (obj)
96 (and (listp obj) (eq (car obj) 'quote)
97 (symbolp (car-safe (cdr obj)))
98 (let ((vector (get (car-safe (cdr obj)) 'charset)))
99 (and (vectorp vector)
100 (< (aref vector 0) 160)))))
4ed46869
KH
101
102(defsubst charsetp (object)
103 "T is OBJECT is a charset."
104 (and (symbolp object) (vectorp (get object 'charset))))
105
106(defsubst charset-info (charset)
107 "Return a vector of information of CHARSET.
108The elements of the vector are:
109 CHARSET-ID, BYTES, DIMENSION, CHARS, WIDTH, DIRECTION,
110 LEADING-CODE-BASE, LEADING-CODE-EXT,
111 ISO-FINAL-CHAR, ISO-GRAPHIC-PLANE,
112 REVERSE-CHARSET, SHORT-NAME, LONG-NAME, DESCRIPTION,
113 PLIST,
114where
115CHARSET-ID (integer) is the identification number of the charset.
116DIMENSION (integer) is the number of bytes to represent a character of
117the charset: 1 or 2.
118CHARS (integer) is the number of characters in a dimension: 94 or 96.
119BYTE (integer) is the length of multi-byte form of a character in
120 the charset: one of 1, 2, 3, and 4.
121WIDTH (integer) is the number of columns a character in the charset
122 occupies on the screen: one of 0, 1, and 2.
123DIRECTION (integer) is the rendering direction of characters in the
124 charset when rendering. If 0, render from right to left, else
125 render from left to right.
126LEADING-CODE-BASE (integer) is the base leading-code for the
127 charset.
128LEADING-CODE-EXT (integer) is the extended leading-code for the
129 charset. All charsets of less than 0xA0 has the value 0.
130ISO-FINAL-CHAR (character) is the final character of the
131 corresponding ISO 2022 charset.
132ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked
133 while encoding to variants of ISO 2022 coding system, one of the
134 following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR).
135REVERSE-CHARSET (integer) is the charset which differs only in
136 LEFT-TO-RIGHT value from the charset. If there's no such a
137 charset, the value is -1.
138SHORT-NAME (string) is the short name to refer to the charset.
139LONG-NAME (string) is the long name to refer to the charset
140DESCRIPTION (string) is the description string of the charset.
141PLIST (property list) may contain any type of information a user
142 want to put and get by functions `put-charset-property' and
143 `get-charset-property' respectively."
144 (get charset 'charset))
145
146(defmacro charset-id (charset)
147 "Return charset identification number of CHARSET."
2e02a76f 148 (if (charset-quoted-standard-p charset)
4ed46869
KH
149 (aref (charset-info (nth 1 charset)) 0)
150 `(aref (charset-info ,charset) 0)))
151
152(defmacro charset-bytes (charset)
900dc6e3
KH
153 "Return bytes of CHARSET.
154See the function `charset-info' for more detail."
2e02a76f 155 (if (charset-quoted-standard-p charset)
4ed46869
KH
156 (aref (charset-info (nth 1 charset)) 1)
157 `(aref (charset-info ,charset) 1)))
158
159(defmacro charset-dimension (charset)
900dc6e3
KH
160 "Return dimension of CHARSET.
161See the function `charset-info' for more detail."
2e02a76f 162 (if (charset-quoted-standard-p charset)
4ed46869
KH
163 (aref (charset-info (nth 1 charset)) 2)
164 `(aref (charset-info ,charset) 2)))
165
166(defmacro charset-chars (charset)
900dc6e3
KH
167 "Return character numbers contained in a dimension of CHARSET.
168See the function `charset-info' for more detail."
2e02a76f 169 (if (charset-quoted-standard-p charset)
4ed46869
KH
170 (aref (charset-info (nth 1 charset)) 3)
171 `(aref (charset-info ,charset) 3)))
172
173(defmacro charset-width (charset)
900dc6e3
KH
174 "Return width (how many column occupied on a screen) of CHARSET.
175See the function `charset-info' for more detail."
2e02a76f 176 (if (charset-quoted-standard-p charset)
4ed46869
KH
177 (aref (charset-info (nth 1 charset)) 4)
178 `(aref (charset-info ,charset) 4)))
179
180(defmacro charset-direction (charset)
900dc6e3
KH
181 "Return direction of CHARSET.
182See the function `charset-info' for more detail."
2e02a76f 183 (if (charset-quoted-standard-p charset)
4ed46869
KH
184 (aref (charset-info (nth 1 charset)) 5)
185 `(aref (charset-info ,charset) 5)))
186
187(defmacro charset-iso-final-char (charset)
900dc6e3
KH
188 "Return final char of CHARSET.
189See the function `charset-info' for more detail."
2e02a76f 190 (if (charset-quoted-standard-p charset)
4ed46869
KH
191 (aref (charset-info (nth 1 charset)) 8)
192 `(aref (charset-info ,charset) 8)))
193
194(defmacro charset-iso-graphic-plane (charset)
900dc6e3
KH
195 "Return graphic plane of CHARSET.
196See the function `charset-info' for more detail."
2e02a76f 197 (if (charset-quoted-standard-p charset)
4ed46869
KH
198 (aref (charset-info (nth 1 charset)) 9)
199 `(aref (charset-info ,charset) 9)))
200
201(defmacro charset-reverse-charset (charset)
900dc6e3
KH
202 "Return reverse charset of CHARSET.
203See the function `charset-info' for more detail."
2e02a76f 204 (if (charset-quoted-standard-p charset)
4ed46869
KH
205 (aref (charset-info (nth 1 charset)) 10)
206 `(aref (charset-info ,charset) 10)))
207
208(defmacro charset-short-name (charset)
900dc6e3
KH
209 "Return short name of CHARSET.
210See the function `charset-info' for more detail."
2e02a76f 211 (if (charset-quoted-standard-p charset)
4ed46869
KH
212 (aref (charset-info (nth 1 charset)) 11)
213 `(aref (charset-info ,charset) 11)))
214
215(defmacro charset-long-name (charset)
900dc6e3
KH
216 "Return long name of CHARSET.
217See the function `charset-info' for more detail."
2e02a76f 218 (if (charset-quoted-standard-p charset)
4ed46869
KH
219 (aref (charset-info (nth 1 charset)) 12)
220 `(aref (charset-info ,charset) 12)))
221
222(defmacro charset-description (charset)
900dc6e3
KH
223 "Return descriptoin of CHARSET.
224See the function `charset-info' for more detail."
2e02a76f 225 (if (charset-quoted-standard-p charset)
4ed46869
KH
226 (aref (charset-info (nth 1 charset)) 13)
227 `(aref (charset-info ,charset) 13)))
228
229(defmacro charset-plist (charset)
900dc6e3
KH
230 "Return list charset property of CHARSET.
231See the function `charset-info' for more detail."
2e02a76f 232 (if (charset-quoted-standard-p charset)
f98e2797 233 `(aref ,(charset-info (nth 1 charset)) 14)
4ed46869
KH
234 `(aref (charset-info ,charset) 14)))
235
236(defun set-charset-plist (charset plist)
900dc6e3 237 "Set CHARSET's property list to PLIST, and retrun PLIST."
4ed46869
KH
238 (aset (charset-info charset) 14 plist))
239
a6acd8a2 240(defun make-char (charset &optional c1 c2)
f98e2797
KH
241 "Return a character of CHARSET and position-codes CODE1 and CODE2.
242CODE1 and CODE2 are optional, but if you don't supply
900dc6e3 243sufficient position-codes, return a generic character which stands for
f98e2797 244all characters or group of characters in the character sets.
a73a8c89 245A generic character can be used to index a char table (e.g. syntax-table)."
a6acd8a2
KH
246 (make-char-internal (charset-id charset) c1 c2))
247
248(put 'make-char 'byte-compile
249 (function
250 (lambda (form)
251 (let ((charset (nth 1 form)))
252 (if (charset-quoted-standard-p charset)
253 (byte-compile-normal-call
254 (cons 'make-char-internal
255 (cons (charset-id (nth 1 charset)) (nthcdr 2 form))))
256 (byte-compile-normal-call
257 (cons 'make-char-internal
258 (cons (list 'charset-id charset) (nthcdr 2 form)))))))))
4ed46869 259
d3675a42 260(defun charset-list ()
900dc6e3
KH
261 "Return list of charsets ever defined.
262
d3675a42 263This function is provided for backward compatibility.
900dc6e3 264Now we have the variable `charset-list'."
d3675a42
KH
265 charset-list)
266
267(make-obsolete 'charset-list
268 "Use the variable charset-list instead.")
13d5617d
KH
269
270(defsubst generic-char-p (char)
271 "Return t if and only if CHAR is a generic character.
272See also the documentation of make-char."
1d935669
KH
273 (and (>= char 0400)
274 (let ((l (split-char char)))
275 (and (or (= (nth 1 l) 0) (eq (nth 2 l) 0))
276 (not (eq (car l) 'composition))))))
69eba008 277
0269ddfb 278\f
8057896b 279;; Coding system staffs
4ed46869 280
8057896b 281;; Coding system is a symbol that has the property `coding-system'.
4ed46869 282;;
8057896b
KH
283;; The value of the property `coding-system' is a vector of the
284;; following format:
d3675a42 285;; [TYPE MNEMONIC DOC-STRING PLIST FLAGS]
8057896b 286;; We call this vector as coding-spec. See comments in src/coding.c
d3675a42 287;; for more detail.
8057896b
KH
288
289(defconst coding-spec-type-idx 0)
290(defconst coding-spec-mnemonic-idx 1)
291(defconst coding-spec-doc-string-idx 2)
0269ddfb 292(defconst coding-spec-plist-idx 3)
8057896b
KH
293(defconst coding-spec-flags-idx 4)
294
a6acd8a2
KH
295;; PLIST is a property list of a coding system. To share PLIST among
296;; alias coding systems, a coding system has PLIST in coding-spec
297;; instead of having it in normal property list of Lisp symbol.
298;; Here's a list of coding system properties currently being used.
0269ddfb
KH
299;;
300;; o coding-category
301;;
302;; The value is a coding category the coding system belongs to. The
303;; function `make-coding-system' and `define-coding-system-alias' sets
304;; this value automatically.
4ed46869 305;;
0269ddfb 306;; o alias-coding-systems
4ed46869 307;;
0269ddfb
KH
308;; The value is a list of coding systems of the same alias group. The
309;; first element is the coding system made at first, which we call as
310;; `base coding system'. The function `make-coding-system' and
311;; `define-coding-system-alias' set this value automatically.
312;;
313;; o post-read-conversion
314;;
315;; The value is a function to call after some text is inserted and
316;; decoded by the coding system itself and before any functions in
317;; `after-insert-functions' are called. The arguments to this
318;; function is the same as those of a function in
4ed46869
KH
319;; `after-insert-functions', i.e. LENGTH of a text while putting point
320;; at the head of the text to be decoded
321;;
0269ddfb
KH
322;; o pre-write-conversion
323;;
324;; The value is a function to call after all functions in
325;; `write-region-annotate-functions' and `buffer-file-format' are
326;; called, and before the text is encoded by the coding system itself.
327;; The arguments to this function is the same as those of a function
328;; in `write-region-annotate-functions', i.e. FROM and TO specifying
329;; region of a text.
330;;
f967223b 331;; o translation-table-for-decode
0269ddfb 332;;
f967223b
KH
333;; The value is a translation table to be applied on decoding. See
334;; the function `make-translation-table' for the format of translation
335;; table.
0269ddfb 336;;
f967223b 337;; o translation-table-for-encode
0269ddfb 338;;
f967223b 339;; The value is a translation table to be applied on encoding.
a6acd8a2
KH
340;;
341;; o safe-charsets
342;;
343;; The value is a list of charsets safely supported by the coding
344;; system. The value t means that all charsets Emacs handles are
345;; supported. Even if some charset is not in this list, it doesn't
346;; mean that the charset can't be encoded in the coding system,
347;; instead, it just means that some other receiver of a text encoded
348;; in the coding system won't be able to handle that charset.
b25eef20
KH
349;;
350;; o mime-charset
351;;
352;; The value is a symbol of which name is `MIME-charset' parameter of
353;; the coding system.
0269ddfb
KH
354
355;; Return coding-spec of CODING-SYSTEM
356(defsubst coding-system-spec (coding-system)
357 (get (check-coding-system coding-system) 'coding-system))
4ed46869 358
4ed46869 359(defun coding-system-type (coding-system)
0269ddfb
KH
360 "Return the coding type of CODING-SYSTEM.
361A coding type is an integer value indicating the encoding method
362of CODING-SYSTEM. See the function `make-coding-system' for more detail."
363 (aref (coding-system-spec coding-system) coding-spec-type-idx))
4ed46869 364
4ed46869 365(defun coding-system-mnemonic (coding-system)
0269ddfb
KH
366 "Return the mnemonic character of CODING-SYSTEM.
367A mnemonic character of a coding system is used in mode line
368to indicate the coding system."
369 (or (aref (coding-system-spec coding-system) coding-spec-mnemonic-idx)
8057896b 370 ?-))
4ed46869 371
8057896b 372(defun coding-system-doc-string (coding-system)
0269ddfb
KH
373 "Return the documentation string for CODING-SYSTEM."
374 (aref (coding-system-spec coding-system) coding-spec-doc-string-idx))
4ed46869 375
d3675a42 376(defun coding-system-plist (coding-system)
0269ddfb
KH
377 "Return the property list of CODING-SYSTEM."
378 (aref (coding-system-spec coding-system) coding-spec-plist-idx))
d3675a42 379
4ed46869 380(defun coding-system-flags (coding-system)
0269ddfb
KH
381 "Return `flags' of CODING-SYSTEM.
382A `flags' of a coding system is a vector of length 32 indicating detailed
383information of a coding system. See the function `make-coding-system'
384for more detail."
385 (aref (coding-system-spec coding-system) coding-spec-flags-idx))
386
387(defun coding-system-get (coding-system prop)
388 "Extract a value from CODING-SYSTEM's property list for property PROP."
389 (plist-get (coding-system-plist coding-system) prop))
390
391(defun coding-system-put (coding-system prop val)
392 "Change value in CODING-SYSTEM's property list PROP to VAL."
393 (let ((plist (coding-system-plist coding-system)))
394 (if plist
395 (plist-put plist prop val)
396 (aset (coding-system-spec coding-system) coding-spec-plist-idx
397 (list prop val)))))
398
399(defun coding-system-category (coding-system)
400 "Return the coding category of CODING-SYSTEM."
401 (coding-system-get coding-system 'coding-category))
402
403(defun coding-system-base (coding-system)
404 "Return the base coding system of CODING-SYSTEM.
d9e3229d
KH
405A base coding system is what made by `make-coding-system'.
406Any alias nor subsidiary coding systems are not base coding system."
0269ddfb
KH
407 (car (coding-system-get coding-system 'alias-coding-systems)))
408
409(defalias 'coding-system-parent 'coding-system-base)
410(make-obsolete 'coding-system-parent 'coding-system-base)
411
412;; Coding system also has a property `eol-type'.
413;;
414;; This property indicates how the coding system handles end-of-line
415;; format. The value is integer 0, 1, 2, or a vector of three coding
416;; systems. Each integer value 0, 1, and 2 indicates the format of
417;; end-of-line LF, CRLF, and CR respectively. A vector value
418;; indicates that the format of end-of-line should be detected
419;; automatically. Nth element of the vector is the subsidiary coding
420;; system whose `eol-type' property is N.
4ed46869 421
8057896b 422(defun coding-system-eol-type (coding-system)
0269ddfb
KH
423 "Return eol-type of CODING-SYSTEM.
424An eol-type is integer 0, 1, 2, or a vector of coding systems.
4ed46869 425
0269ddfb
KH
426Integer values 0, 1, and 2 indicate a format of end-of-line; LF,
427CRLF, and CR respectively.
428
429A vector value indicates that a format of end-of-line should be
430detected automatically. Nth element of the vector is the subsidiary
431coding system whose eol-type is N."
432 (get coding-system 'eol-type))
bd882697 433
6e9722b0
KH
434;; Make subsidiary coding systems (eol-type variants) of CODING-SYSTEM.
435(defun make-subsidiary-coding-system (coding-system)
0269ddfb
KH
436 (let ((coding-spec (coding-system-spec coding-system))
437 (subsidiaries (vector (intern (format "%s-unix" coding-system))
8057896b
KH
438 (intern (format "%s-dos" coding-system))
439 (intern (format "%s-mac" coding-system))))
0269ddfb
KH
440 (i 0)
441 temp)
8057896b 442 (while (< i 3)
0269ddfb 443 (put (aref subsidiaries i) 'coding-system coding-spec)
8057896b 444 (put (aref subsidiaries i) 'eol-type i)
0269ddfb
KH
445 (setq coding-system-list
446 (cons (aref subsidiaries i) coding-system-list))
447 (setq coding-system-alist
448 (cons (list (symbol-name (aref subsidiaries i)))
449 coding-system-alist))
8057896b
KH
450 (setq i (1+ i)))
451 subsidiaries))
4ed46869 452
8057896b 453(defun make-coding-system (coding-system type mnemonic doc-string
d9e3229d 454 &optional flags properties)
3bb1accb 455 "Define a new coding system CODING-SYSTEM (symbol).
a6acd8a2 456Remaining arguments are TYPE, MNEMONIC, DOC-STRING, FLAGS (optional),
d9e3229d 457and PROPERTIES (optional) which construct a coding-spec of CODING-SYSTEM
a6acd8a2 458in the following format:
0269ddfb 459 [TYPE MNEMONIC DOC-STRING PLIST FLAGS]
3bb1accb
KH
460
461TYPE is an integer value indicating the type of the coding system as follows:
4ed46869
KH
462 0: Emacs internal format,
463 1: Shift-JIS (or MS-Kanji) used mainly on Japanese PC,
464 2: ISO-2022 including many variants,
465 3: Big5 used mainly on Chinese PC,
cd9c3177
KH
466 4: private, CCL programs provide encoding/decoding algorithm,
467 5: Raw-text, which means that text contains random 8-bit codes.
0269ddfb 468
3bb1accb 469MNEMONIC is a character to be displayed on mode line for the coding system.
0269ddfb 470
3bb1accb 471DOC-STRING is a documentation string for the coding system.
0269ddfb 472
3bb1accb 473FLAGS specifies more detailed information of the coding system as follows:
d6d6d592 474
3bb1accb 475 If TYPE is 2 (ISO-2022), FLAGS is a list of these elements:
4ed46869
KH
476 CHARSET0, CHARSET1, CHARSET2, CHARSET3, SHORT-FORM,
477 ASCII-EOL, ASCII-CNTL, SEVEN, LOCKING-SHIFT, SINGLE-SHIFT,
d6d6d592 478 USE-ROMAN, USE-OLDJIS, NO-ISO6429, INIT-BOL, DESIGNATION-BOL,
850101ed 479 SAFE, ACCEPT-LATIN-EXTRA-CODE.
4ed46869
KH
480 CHARSETn are character sets initially designated to Gn graphic registers.
481 If CHARSETn is nil, Gn is never used.
482 If CHARSETn is t, Gn can be used but nothing designated initially.
483 If CHARSETn is a list of character sets, those character sets are
484 designated to Gn on output, but nothing designated to Gn initially.
485 SHORT-FORM non-nil means use short designation sequence on output.
486 ASCII-EOL non-nil means designate ASCII to g0 at end of line on output.
487 ASCII-CNTL non-nil means designate ASCII to g0 before control codes and
488 SPACE on output.
489 SEVEN non-nil means use 7-bit code only on output.
490 LOCKING-SHIFT non-nil means use locking-shift.
491 SINGLE-SHIFT non-nil means use single-shift.
492 USE-ROMAN non-nil means designate JIS0201-1976-Roman instead of ASCII.
493 USE-OLDJIS non-nil means designate JIS0208-1976 instead of JIS0208-1983.
494 NO-ISO6429 non-nil means not use ISO6429's direction specification.
69eba008
KH
495 INIT-BOL non-nil means any designation state is assumed to be reset
496 to initial at each beginning of line on output.
497 DESIGNATION-BOL non-nil means designation sequences should be placed
498 at beginning of line on output.
a6acd8a2
KH
499 SAFE non-nil means convert unsafe characters to `?' on output.
500 Unsafe characters are what not specified in SAFE-CHARSET.
850101ed
RS
501 ACCEPT-LATIN-EXTRA-CODE non-nil means code-detection routine accepts
502 a code specified in `latin-extra-code-table' (which see) as a valid
503 code of the coding system.
d6d6d592 504
3bb1accb
KH
505 If TYPE is 4 (private), FLAGS should be a cons of CCL programs, for
506 decoding and encoding. CCL programs should be specified by their
507 symbols.
d9e3229d
KH
508
509PROPERTIES is an alist of properties vs the corresponding values.
510These properties are set in PLIST, a property list. This function
511also sets properties `coding-category' and `alias-coding-systems'
512automatically.
4ed46869 513
3bb1accb
KH
514Kludgy features for backward compatibility:
515
5161. If TYPE is 4 and car or cdr of FLAGS is a vector, the vector is
517treated as a compiled CCL code.
518
5192. If PROPERTIES is just a list of character sets, the list is set as
520a value of `safe-charsets' in PLIST."
0269ddfb 521 (if (memq coding-system coding-system-list)
d9e3229d 522 (error "Coding system %s already exists" coding-system))
0269ddfb
KH
523
524 ;; Set a value of `coding-system' property.
6e9722b0 525 (let ((coding-spec (make-vector 5 nil))
d9e3229d
KH
526 (no-initial-designation t)
527 (no-alternative-designation t)
6e9722b0 528 coding-category)
cd9c3177 529 (if (or (not (integerp type)) (< type 0) (> type 5))
0269ddfb 530 (error "TYPE argument must be 0..5"))
8057896b 531 (if (or (not (integerp mnemonic)) (<= mnemonic ? ) (> mnemonic 127))
0269ddfb
KH
532 (error "MNEMONIC arguemnt must be an ASCII printable character."))
533 (aset coding-spec coding-spec-type-idx type)
534 (aset coding-spec coding-spec-mnemonic-idx mnemonic)
535 (aset coding-spec coding-spec-doc-string-idx
536 (if (stringp doc-string) doc-string ""))
6e9722b0
KH
537 (cond ((= type 0)
538 (setq coding-category 'coding-category-emacs-mule))
539 ((= type 1)
540 (setq coding-category 'coding-category-sjis))
541 ((= type 2) ; ISO2022
4ed46869 542 (let ((i 0)
6e9722b0 543 (vec (make-vector 32 nil))
6e9722b0 544 (g1-designation nil))
4ed46869
KH
545 (while (< i 4)
546 (let ((charset (car flags)))
6e9722b0
KH
547 (if (and no-initial-designation
548 (> i 0)
549 (or (charsetp charset)
550 (and (consp charset)
551 (charsetp (car charset)))))
552 (setq no-initial-designation nil))
553 (if (charsetp charset)
554 (if (= i 1) (setq g1-designation charset))
555 (if (consp charset)
556 (let ((tail charset)
557 elt)
558 (while tail
559 (setq elt (car tail))
d9e3229d
KH
560 (if (eq elt t)
561 (setq no-alternative-designation nil)
562 (if (and elt (not (charsetp elt)))
563 (error "Invalid charset: %s" elt)))
6e9722b0
KH
564 (setq tail (cdr tail)))
565 (setq g1-designation (car charset)))
d9e3229d
KH
566 (if charset
567 (if (eq charset t)
568 (setq no-alternative-designation nil)
569 (error "Invalid charset: %s" charset)))))
4ed46869
KH
570 (aset vec i charset))
571 (setq flags (cdr flags) i (1+ i)))
572 (while (and (< i 32) flags)
573 (aset vec i (car flags))
574 (setq flags (cdr flags) i (1+ i)))
6e9722b0 575 (aset coding-spec 4 vec)
6e9722b0
KH
576 (setq coding-category
577 (if (aref vec 8) ; Use locking-shift.
dc64cd19
KH
578 (or (and (aref vec 7) 'coding-category-iso-7-else)
579 'coding-category-iso-8-else)
6e9722b0
KH
580 (if (aref vec 7) ; 7-bit only.
581 (if (aref vec 9) ; Use single-shift.
dc64cd19 582 'coding-category-iso-7-else
d9e3229d
KH
583 (if no-alternative-designation
584 'coding-category-iso-7-tight
585 'coding-category-iso-7))
3ad911d8
KH
586 (if (or no-initial-designation
587 (not no-alternative-designation))
dc64cd19 588 'coding-category-iso-8-else
6e9722b0
KH
589 (if (and (charsetp g1-designation)
590 (= (charset-dimension g1-designation) 2))
591 'coding-category-iso-8-2
592 'coding-category-iso-8-1)))))))
593 ((= type 3)
594 (setq coding-category 'coding-category-big5))
595 ((= type 4) ; private
596 (setq coding-category 'coding-category-binary)
3bb1accb
KH
597 (if (not (consp flags))
598 (error "Invalid FLAGS argument for TYPE 4 (CCL)")
599 (let ((decoder (check-ccl-program
600 (car flags)
601 (intern (format "%s-decoder" coding-system))))
602 (encoder (check-ccl-program
603 (cdr flags)
604 (intern (format "%s-encoder" coding-system)))))
605 (if (and decoder encoder)
606 (aset coding-spec 4 (cons decoder encoder))
607 (error "Invalid FLAGS argument for TYPE 4 (CCL)")))))
cd9c3177
KH
608 (t ; i.e. (= type 5)
609 (setq coding-category 'coding-category-raw-text)))
0269ddfb
KH
610
611 (let ((plist (list 'coding-category coding-category
d9e3229d 612 'alias-coding-systems (list coding-system))))
0269ddfb 613 (if no-initial-designation
d9e3229d
KH
614 (plist-put plist 'no-initial-designation t))
615 (if (and properties
616 (or (eq properties t)
617 (not (consp (car properties)))))
618 ;; In the old version, the arg PROPERTIES is a list to be
619 ;; set in PLIST as a value of property `safe-charsets'.
620 (plist-put plist 'safe-charsets properties)
621 (while properties
622 (plist-put plist (car (car properties)) (cdr (car properties)))
623 (setq properties (cdr properties))))
0269ddfb 624 (aset coding-spec coding-spec-plist-idx plist))
6e9722b0 625 (put coding-system 'coding-system coding-spec)
6e9722b0
KH
626 (put coding-category 'coding-systems
627 (cons coding-system (get coding-category 'coding-systems))))
4ed46869
KH
628
629 ;; Next, set a value of `eol-type' property. The value is a vector
6e9722b0 630 ;; of subsidiary coding systems, each corresponds to a coding system
4ed46869 631 ;; for the detected end-of-line format.
8057896b 632 (put coding-system 'eol-type
cd9c3177 633 (if (or (<= type 3) (= type 5))
6e9722b0 634 (make-subsidiary-coding-system coding-system)
0269ddfb
KH
635 0))
636
637 ;; At last, register CODING-SYSTEM in `coding-system-list' and
638 ;; `coding-system-alist'.
639 (setq coding-system-list (cons coding-system coding-system-list))
640 (setq coding-system-alist (cons (list (symbol-name coding-system))
d9e3229d
KH
641 coding-system-alist))
642 coding-system)
8057896b 643
a42763dc 644(defun define-coding-system-alias (alias coding-system)
358d28fb 645 "Define ALIAS as an alias for coding system CODING-SYSTEM."
0269ddfb
KH
646 (put alias 'coding-system (coding-system-spec coding-system))
647 (nconc (coding-system-get alias 'alias-coding-systems) (list alias))
648 (setq coding-system-list (cons alias coding-system-list))
649 (setq coding-system-alist (cons (list (symbol-name alias))
650 coding-system-alist))
651 (let ((eol-type (coding-system-eol-type coding-system)))
652 (if (vectorp eol-type)
653 (put alias 'eol-type (make-subsidiary-coding-system alias))
654 (put alias 'eol-type eol-type))))
4ed46869
KH
655
656(defun set-buffer-file-coding-system (coding-system &optional force)
358d28fb
RS
657 "Set the file coding-system of the current buffer to CODING-SYSTEM.
658This means that when you save the buffer, it will be converted
659according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM,
660use \\[list-coding-systems].
661
662If the buffer's previous file coding-system value specifies end-of-line
663conversion, and CODING-SYSTEM does not specify one, CODING-SYSTEM is
664merged with the already-specified end-of-line conversion.
665However, if the optional prefix argument FORCE is non-nil,
0269ddfb 666then CODING-SYSTEM is used exactly as specified."
d9e3229d 667 (interactive "zCoding system for visited file (default, nil): \nP")
4ed46869
KH
668 (check-coding-system coding-system)
669 (if (null force)
8057896b
KH
670 (let ((x (coding-system-eol-type buffer-file-coding-system))
671 (y (coding-system-eol-type coding-system)))
4ed46869
KH
672 (if (and (numberp x) (>= x 0) (<= x 2) (vectorp y))
673 (setq coding-system (aref y x)))))
674 (setq buffer-file-coding-system coding-system)
675 (set-buffer-modified-p t)
676 (force-mode-line-update))
677
358d28fb
RS
678(defvar default-terminal-coding-system nil
679 "Default value for the terminal coding system.
680This is normally set according to the selected language environment.
681See also the command `set-terminal-coding-system'.")
682
df100398
KH
683(defun set-terminal-coding-system (coding-system)
684 "Set coding system of your terminal to CODING-SYSTEM.
358d28fb
RS
685All text output to the terminal will be encoded
686with the specified coding system.
687For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
688The default is determined by the selected language environment
689or by the previous use of this command."
690 (interactive
2e02a76f
RS
691 (list (let ((default (if (and (not (terminal-coding-system))
692 default-terminal-coding-system)
693 default-terminal-coding-system)))
694 (read-coding-system
695 (format "Coding system for terminal display (default, %s): "
696 default)
697 default))))
358d28fb
RS
698 (if (and (not coding-system)
699 (not (terminal-coding-system)))
700 (setq coding-system default-terminal-coding-system))
701 (if coding-system
702 (setq default-terminal-coding-system coding-system))
df100398
KH
703 (set-terminal-coding-system-internal coding-system)
704 (redraw-frame (selected-frame)))
705
358d28fb
RS
706(defvar default-keyboard-coding-system nil
707 "Default value of the keyboard coding system.
708This is normally set according to the selected language environment.
709See also the command `set-keyboard-coding-system'.")
710
df100398 711(defun set-keyboard-coding-system (coding-system)
358d28fb
RS
712 "Set coding system for keyboard input to CODING-SYSTEM.
713In addition, this command enables Encoded-kbd minor mode.
714\(If CODING-SYSTEM is nil, Encoded-bkd mode is turned off.)
715For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
716The default is determined by the selected language environment
717or by the previous use of this command."
718 (interactive
2e02a76f
RS
719 (list (let ((default (if (and (not (keyboard-coding-system))
720 default-keyboard-coding-system)
721 default-keyboard-coding-system)))
722 (read-coding-system
723 (format "Coding system for keyboard input (default, %s): "
724 default)
725 default))))
358d28fb
RS
726 (if (and (not coding-system)
727 (not (keyboard-coding-system)))
728 (setq coding-system default-keyboard-coding-system))
729 (if coding-system
730 (setq default-keyboard-coding-system coding-system))
df100398
KH
731 (set-keyboard-coding-system-internal coding-system)
732 (encoded-kbd-mode (if coding-system 1 0)))
733
734(defun set-buffer-process-coding-system (decoding encoding)
358d28fb 735 "Set coding systems for the process associated with the current buffer.
df100398 736DECODING is the coding system to be used to decode input from the process,
358d28fb
RS
737ENCODING is the coding system to be used to encode output to the process.
738
739For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems]."
4ed46869
KH
740 (interactive
741 "zCoding-system for process input: \nzCoding-system for process output: ")
742 (let ((proc (get-buffer-process (current-buffer))))
743 (if (null proc)
744 (error "no process")
df100398
KH
745 (check-coding-system decoding)
746 (check-coding-system encoding)
747 (set-process-coding-system proc decoding encoding)))
4ed46869
KH
748 (force-mode-line-update))
749
b25eef20
KH
750(defun set-clipboard-coding-system (coding-system)
751 "Make CODING-SYSTEM used for communicating with other X clients .
752When sending or receiving text via cut_buffer, selection, and clipboard,
753the text is encoded or decoded by CODING-SYSTEM."
754 (check-coding-system coding-system)
755 (setq clipboard-coding-system coding-system))
756
4ed46869 757(defun set-coding-priority (arg)
d9e3229d
KH
758 "Set priority of coding categories according to LIST.
759LIST is a list of coding categories ordered by priority."
760 (let ((l arg)
761 (current-list (copy-sequence coding-category-list)))
762 ;; Check the varidity of ARG while deleting coding categories in
763 ;; ARG from CURRENT-LIST. We assume that CODING-CATEGORY-LIST
764 ;; contains all coding categories.
765 (while l
766 (if (or (null (get (car l) 'coding-category-index))
767 (null (memq (car l) current-list)))
768 (error "Invalid or duplicated element in argument: %s" arg))
769 (setq current-list (delq (car l) current-list))
770 (setq l (cdr l)))
4ed46869 771 ;; Update `coding-category-list' and return it.
d9e3229d 772 (setq coding-category-list (append arg current-list))))
4ed46869
KH
773
774;;; FILE I/O
775
63561304
KH
776(defun set-auto-coding (string)
777 "Return coding system for a file which has STRING at the head and tail.
778STRING is a concatination of the first 1K-byte and
779 the last 3K-byte of the file.
780
781It checks for a -*- coding: tag in the first one or two lines of STRING.
782If there's no coding: tag in the head, it checks local variables spec
783in the tailing 3K-byte oof STRING.
784
785The return value is the specified coding system,
786or nil if nothing specified.
87aba788 787
ba74e833 788The variable `set-auto-coding-function' (which see) is set to this
87aba788 789function by default."
63561304
KH
790 (condition-case nil
791 (let ((case-fold-search t)
792 (len (length string))
793 (limit (string-match "\n" string))
794 (coding-system nil))
795
796 ;; At first check the head.
797 (if limit
798 (when (string-match "^#!" string)
799 ;; If the file begins with "#!" (exec interpreter
800 ;; magic), look for coding frobs in the first two lines.
801 ;; You cannot necessarily put them in the first line of
802 ;; such a file without screwing up the interpreter
803 ;; invocation.
804 (setq limit (string-match "\n" string limit))
805 (or limit
806 (setq limit len)))
807 (setq limit len))
35ce8cd7
RS
808 (when (and (string-match "-\\*-\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)" string)
809 (< (match-beginning 2) limit))
63561304 810 (setq coding-system
35ce8cd7 811 (intern (substring string (match-beginning 2) (match-end 2))))
63561304
KH
812 (if (not (coding-system-p coding-system))
813 (setq coding-system nil)))
814
815 ;; If no coding system is specified in the head, check the tail.
816 (when (and (not coding-system)
817 (let ((idx (if (> len 3000) (- len 3000) 0))
818 start)
819 (while (setq start (string-match "\n\^L" string idx))
820 (setq idx (+ start 2)))
821 (string-match
822 "^\\(.*\\)[ \t]*Local Variables:[ \t]*\\(.*\\)$"
823 string idx)))
824 ;; The prefix is what comes before "local variables:" in its line.
825 ;; The suffix is what comes after "local variables:" in its line.
826 (let* ((idx (1+ (match-end 0)))
827 (prefix (regexp-quote
828 (substring string
829 (match-beginning 1) (match-end 1))))
830 (suffix (regexp-quote
831 (substring string
832 (match-beginning 2) (match-end 2))))
833 (re-coding (concat "^" prefix
82d6c19f 834 "coding[ \t]*:[ \t]*\\([^ \t\n]+\\)[ \t]*"
63561304
KH
835 suffix "$"))
836 (re-end (concat "^" prefix "end *:[ \t]*" suffix "$"))
837 (limit (or (string-match re-end string idx) len)))
838 (when (and (setq idx (string-match re-coding string idx))
839 (< idx limit))
840 (setq coding-system
841 (intern (substring string
842 (match-beginning 1) (match-end 1))))
843 (or (coding-system-p coding-system)
844 (setq coding-system nil)))))
845
846 coding-system)
847 (error nil)))
848
849(setq set-auto-coding-function 'set-auto-coding)
87aba788 850
4ed46869
KH
851;; Set buffer-file-coding-system of the current buffer after some text
852;; is inserted.
853(defun after-insert-file-set-buffer-file-coding-system (inserted)
854 (if last-coding-system-used
855 (let ((coding-system
856 (find-new-buffer-file-coding-system last-coding-system-used))
857 (modified-p (buffer-modified-p)))
0269ddfb
KH
858 (when coding-system
859 (set-buffer-file-coding-system coding-system)
ccb77b4e
RS
860 (if (and (or (eq coding-system 'no-conversion)
861 (eq (coding-system-type coding-system) 5))
862 ;; If buffer was unmodified, we must be visiting it.
863 (not modified-p))
864 ;; For coding systems no-conversion and raw-text...,
865 ;; edit the buffer as unibyte.
a2b4abc1 866 (set-buffer-multibyte nil))
0269ddfb 867 (set-buffer-modified-p modified-p))))
4ed46869
KH
868 nil)
869
84c9d215
KH
870(add-hook 'after-insert-file-functions
871 'after-insert-file-set-buffer-file-coding-system)
4ed46869 872
8057896b 873;; The coding-spec and eol-type of coding-system returned is decided
4ed46869
KH
874;; independently in the following order.
875;; 1. That of buffer-file-coding-system locally bound.
876;; 2. That of CODING.
877
878(defun find-new-buffer-file-coding-system (coding)
879 "Return a coding system for a buffer when a file of CODING is inserted.
a73a8c89
KH
880The local variable `buffer-file-coding-system' of the current buffer
881is set to the returned value.
df100398 882Return nil if there's no need of setting new buffer-file-coding-system."
4ed46869 883 (let (local-coding local-eol
b685f8d6 884 found-coding found-eol
4ed46869
KH
885 new-coding new-eol)
886 (if (null coding)
887 ;; Nothing found about coding.
888 nil
889
b685f8d6
RS
890 ;; Get information of `buffer-file-coding-system' in LOCAL-EOL
891 ;; and LOCAL-CODING.
892 (setq local-eol (coding-system-eol-type buffer-file-coding-system))
893 (if (null (numberp local-eol))
894 ;; But eol-type is not yet set.
895 (setq local-eol nil))
0269ddfb
KH
896 (if (and buffer-file-coding-system
897 (not (eq (coding-system-type buffer-file-coding-system) t)))
898 ;; This is not `undecided'.
899 (setq local-coding (coding-system-base buffer-file-coding-system)))
b685f8d6
RS
900
901 (if (and (local-variable-p 'buffer-file-coding-system)
902 local-eol local-coding)
4ed46869
KH
903 ;; The current buffer has already set full coding-system, we
904 ;; had better not change it.
905 nil
906
8057896b 907 (setq found-eol (coding-system-eol-type coding))
4ed46869
KH
908 (if (null (numberp found-eol))
909 ;; But eol-type is not found.
910 (setq found-eol nil))
0269ddfb
KH
911 (if (not (eq (coding-system-type coding) t))
912 ;; This is not `undecided'.
913 (setq found-coding (coding-system-base coding)))
4ed46869
KH
914
915 ;; The local setting takes precedence over the found one.
b685f8d6
RS
916 (setq new-coding (or (and (local-variable-p 'buffer-file-coding-system)
917 local-coding)
918 found-coding
919 local-coding))
920 (setq new-eol (or (and (local-variable-p 'buffer-file-coding-system)
921 local-eol)
922 found-eol
923 local-eol))
924 (when (numberp new-eol)
925 (or new-coding
926 (setq new-coding 'undecided))
927 (if (vectorp (coding-system-eol-type new-coding))
928 (setq new-coding
929 (aref (coding-system-eol-type new-coding) new-eol))))
930 ;; Return a new coding system only when it is different from
931 ;; the current one.
932 (if (not (eq buffer-file-coding-system new-coding))
933 new-coding)))))
4ed46869 934
fe831d33
GV
935(defun modify-coding-system-alist (target-type regexp coding-system)
936 "Modify one of look up tables for finding a coding system on I/O operation.
8c453b46
RS
937There are three of such tables, `file-coding-system-alist',
938`process-coding-system-alist', and `network-coding-system-alist'.
fe831d33
GV
939
940TARGET-TYPE specifies which of them to modify.
8c453b46
RS
941If it is `file', it affects `file-coding-system-alist' (which see).
942If it is `process', it affects `process-coding-system-alist' (which see).
943If it is `network', it affects `network-codign-system-alist' (which see).
fe831d33
GV
944
945REGEXP is a regular expression matching a target of I/O operation.
946The target is a file name if TARGET-TYPE is `file', a program name if
947TARGET-TYPE is `process', or a network service name or a port number
948to connect to if TARGET-TYPE is `network'.
949
950CODING-SYSTEM is a coding system to perform code conversion on the I/O
8c453b46
RS
951operation, or a cons cell (DECODING . ENCODING) specifying the coding systems
952for decoding and encoding respectively,
953or a function symbol which, when called, returns such a cons cell."
fe831d33
GV
954 (or (memq target-type '(file process network))
955 (error "Invalid target type: %s" target-type))
956 (or (stringp regexp)
957 (and (eq target-type 'network) (integerp regexp))
958 (error "Invalid regular expression: %s" regexp))
959 (if (symbolp coding-system)
960 (if (not (fboundp coding-system))
961 (progn
962 (check-coding-system coding-system)
963 (setq coding-system (cons coding-system coding-system))))
964 (check-coding-system (car coding-system))
965 (check-coding-system (cdr coding-system)))
966 (cond ((eq target-type 'file)
967 (let ((slot (assoc regexp file-coding-system-alist)))
968 (if slot
969 (setcdr slot coding-system)
970 (setq file-coding-system-alist
971 (cons (cons regexp coding-system)
972 file-coding-system-alist)))))
973 ((eq target-type 'process)
974 (let ((slot (assoc regexp process-coding-system-alist)))
975 (if slot
976 (setcdr slot coding-system)
977 (setq process-coding-system-alist
978 (cons (cons regexp coding-system)
979 process-coding-system-alist)))))
980 (t
981 (let ((slot (assoc regexp network-coding-system-alist)))
982 (if slot
983 (setcdr slot coding-system)
984 (setq network-coding-system-alist
985 (cons (cons regexp coding-system)
986 network-coding-system-alist)))))))
987
b25eef20 988(defun make-translation-table (&rest args)
f967223b 989 "Make a translation table (char table) from arguments.
13d5617d 990Each argument is a list of the form (FROM . TO),
b25eef20 991where FROM is a character to be translated to TO.
13d5617d 992
452fdb31
RS
993FROM can be a generic character (see `make-char'). In this case, TO is
994a generic character containing the same number of characters, or a
995ordinary character. If FROM and TO are both generic characters, all
b25eef20 996characters belonging to FROM are translated to characters belonging to TO
13d5617d 997without changing their position code(s)."
f967223b 998 (let ((table (make-char-table 'translation-table))
a73a8c89
KH
999 revlist)
1000 (while args
1001 (let ((elts (car args)))
1002 (while elts
13d5617d
KH
1003 (let* ((from (car (car elts)))
1004 (from-i 0) ; degree of freedom of FROM
1005 (from-rev (nreverse (split-char from)))
1006 (to (cdr (car elts)))
1007 (to-i 0) ; degree of freedom of TO
1008 (to-rev (nreverse (split-char to))))
1009 ;; Check numbers of heading 0s in FROM-REV and TO-REV.
1010 (while (eq (car from-rev) 0)
1011 (setq from-i (1+ from-i) from-rev (cdr from-rev)))
1012 (while (eq (car to-rev) 0)
1013 (setq to-i (1+ to-i) to-rev (cdr to-rev)))
1014 (if (and (/= from-i to-i) (/= to-i 0))
1015 (error "Invalid character pair (%d . %d)" from to))
b25eef20
KH
1016 ;; If we have already translated TO to TO-ALT, FROM should
1017 ;; also be translated to TO-ALT. But, this is only if TO
1018 ;; is a generic character or TO-ALT is not a generic
13d5617d
KH
1019 ;; character.
1020 (let ((to-alt (aref table to)))
1021 (if (and to-alt
1022 (or (> to-i 0) (not (generic-char-p to-alt))))
1023 (setq to to-alt)))
1024 (if (> from-i 0)
1025 (set-char-table-default table from to)
1026 (aset table from to))
b25eef20
KH
1027 ;; If we have already translated some chars to FROM, they
1028 ;; should also be translated to TO.
a73a8c89
KH
1029 (let ((l (assq from revlist)))
1030 (if l
1031 (let ((ch (car l)))
1032 (setcar l to)
1033 (setq l (cdr l))
1034 (while l
1035 (aset table ch to)
1036 (setq l (cdr l)) ))))
1037 ;; Now update REVLIST.
1038 (let ((l (assq to revlist)))
1039 (if l
1040 (setcdr l (cons from (cdr l)))
1041 (setq revlist (cons (list to from) revlist)))))
1042 (setq elts (cdr elts))))
1043 (setq args (cdr args)))
1044 ;; Return TABLE just created.
1045 table))
1046
f967223b
KH
1047(defun define-translation-table (symbol &rest args)
1048 "Define SYMBOL as a name of translation table makde by ARGS.
b25eef20
KH
1049
1050See the documentation of the function `make-translation-table' for the
1051meaning of ARGS.
1052
452fdb31
RS
1053This function sets properties `translation-table' and
1054`translation-table-id' of SYMBOL to the created table itself and
f967223b 1055identification number of the table respectively."
b25eef20 1056 (let ((table (apply 'make-translation-table args))
f967223b 1057 (len (length translation-table-vector))
d9e3229d 1058 (id 0)
b25eef20 1059 (done nil))
f967223b 1060 (put symbol 'translation-table table)
b25eef20
KH
1061 (while (not done)
1062 (if (>= id len)
f967223b
KH
1063 (setq translation-table-vector
1064 (vconcat translation-table-vector (make-vector len nil))))
1065 (let ((slot (aref translation-table-vector id)))
b25eef20
KH
1066 (if (or (not slot)
1067 (eq (car slot) symbol))
1068 (progn
f967223b 1069 (aset translation-table-vector id (cons symbol table))
b25eef20 1070 (setq done t))))
d9e3229d 1071 (setq id (1+ id)))
f967223b 1072 (put symbol 'translation-table-id id)
d9e3229d
KH
1073 id))
1074
69eba008
KH
1075;;; Initialize some variables.
1076
1077(put 'use-default-ascent 'char-table-extra-slots 0)
1078(setq use-default-ascent (make-char-table 'use-default-ascent))
d6d6d592
KH
1079(put 'ignore-relative-composition 'char-table-extra-slots 0)
1080(setq ignore-relative-composition
1081 (make-char-table 'ignore-relative-composition))
69eba008
KH
1082
1083;;;
4ed46869
KH
1084(provide 'mule)
1085
1086;;; mule.el ends here