(language-info-alist): Doc-string modified.
[bpt/emacs.git] / lisp / international / mule-cmds.el
1 ;;; mule-cmds.el --- Commands for mulitilingual environment
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5
6 ;; Keywords: mule, multilingual
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
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.
24
25 ;;; Code:
26
27 ;;; MULE related key bindings and menus.
28
29 (defvar mule-keymap (make-sparse-keymap)
30 "Keymap for MULE (Multilingual environment) specific commands.")
31
32 ;; Keep "C-x C-m ..." for mule specific commands.
33 (define-key ctl-x-map "\C-m" mule-keymap)
34
35 (define-key mule-keymap "f" 'set-buffer-file-coding-system)
36 (define-key mule-keymap "t" 'set-terminal-coding-system)
37 (define-key mule-keymap "k" 'set-keyboard-coding-system)
38 (define-key mule-keymap "p" 'set-buffer-process-coding-system)
39 (define-key mule-keymap "\C-\\" 'set-input-method)
40 (define-key mule-keymap "c" 'universal-coding-system-argument)
41 (define-key mule-keymap "l" 'set-language-environment)
42
43 (define-key help-map "\C-L" 'describe-language-environment)
44 (define-key help-map "L" 'describe-language-environment)
45 (define-key help-map "\C-\\" 'describe-input-method)
46 (define-key help-map "I" 'describe-input-method)
47 (define-key help-map "C" 'describe-coding-system)
48 (define-key help-map "h" 'view-hello-file)
49
50 (defvar mule-menu-keymap (make-sparse-keymap "Mule")
51 "Keymap for MULE (Multilingual environment) menu specific commands.")
52
53 (define-key global-map [menu-bar mule]
54 `(menu-item "Mule" ,mule-menu-keymap
55 :visible default-enable-multibyte-characters))
56
57 (setq menu-bar-final-items (cons 'mule menu-bar-final-items))
58
59 (defvar describe-language-environment-map nil)
60 (define-prefix-command 'describe-language-environment-map)
61
62 (defvar setup-language-environment-map nil)
63 (define-prefix-command 'setup-language-environment-map)
64
65 (defvar set-coding-system-map nil)
66 (define-prefix-command 'set-coding-system-map)
67
68 (define-key-after mule-menu-keymap [describe-language-environment]
69 '("Describe Language Environment" . describe-language-environment-map)
70 t)
71 (define-key-after mule-menu-keymap [set-language-environment]
72 '("Set Language Environment" . setup-language-environment-map)
73 t)
74 (define-key-after mule-menu-keymap [mouse-set-font]
75 '("Set Font/Fontset" . mouse-set-font)
76 t)
77 (define-key-after mule-menu-keymap [separator-mule]
78 '("--")
79 t)
80 (define-key-after mule-menu-keymap [toggle-input-method]
81 '("Toggle Input Method" . toggle-input-method)
82 t)
83 (define-key-after mule-menu-keymap [set-input-method]
84 '("Select Input Method" . set-input-method)
85 t)
86 (define-key-after mule-menu-keymap [describe-input-method]
87 '("Describe Input Method" . describe-input-method)
88 t)
89 (define-key-after mule-menu-keymap [separator-input-method]
90 '("--")
91 t)
92 (define-key-after mule-menu-keymap [describe-coding-system]
93 '("Describe Coding Systems" . describe-coding-system)
94 t)
95 (define-key-after mule-menu-keymap [set-various-coding-system]
96 '("Set Coding System" . set-coding-system-map)
97 t)
98 (define-key-after mule-menu-keymap [separator-coding-system]
99 '("--")
100 t)
101 (define-key-after mule-menu-keymap [mule-diag]
102 '("Show All of MULE Status" . mule-diag)
103 t)
104 (define-key-after mule-menu-keymap [view-hello-file]
105 '("Show Script Examples" . view-hello-file)
106 t)
107
108 (define-key-after set-coding-system-map [set-buffer-file-coding-system]
109 '("Buffer File" . set-buffer-file-coding-system)
110 t)
111 (define-key-after set-coding-system-map [universal-coding-system-argument]
112 '("Next Command" . universal-coding-system-argument)
113 t)
114 (define-key-after set-coding-system-map [set-terminal-coding-system]
115 '("Terminal" . set-terminal-coding-system)
116 t)
117 (define-key-after set-coding-system-map [set-keyboard-coding-system]
118 '("Keyboard" . set-keyboard-coding-system)
119 t)
120 (define-key-after set-coding-system-map [set-buffer-process-coding-system]
121 '("Buffer Process" . set-buffer-process-coding-system)
122 t)
123
124 (define-key setup-language-environment-map
125 [Default] '("Default" . setup-specified-language-environment))
126
127 ;; These are meaningless when running under X.
128 (put 'set-terminal-coding-system 'menu-enable
129 '(not (eq window-system 'x)))
130 (put 'set-keyboard-coding-system 'menu-enable
131 '(not (eq window-system 'x)))
132 ;; This is meaningless when the current buffer has no process.
133 (put 'set-buffer-process-coding-system 'menu-enable
134 '(get-buffer-process (current-buffer)))
135
136 ;; This should be a single character key binding because users use it
137 ;; very frequently while editing multilingual text. Now we can use
138 ;; only two such keys: "\C-\\" and "\C-^", but the latter is not
139 ;; convenient because it requires shifting on most keyboards. An
140 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit'
141 ;; but it won't be used that frequently.
142 (define-key global-map "\C-\\" 'toggle-input-method)
143
144 ;;; This is no good because people often type Shift-SPC
145 ;;; meaning to type SPC. -- rms.
146 ;;; ;; Here's an alternative key binding for X users (Shift-SPACE).
147 ;;; (define-key global-map [?\S- ] 'toggle-input-method)
148
149 (defun toggle-enable-multibyte-characters (&optional arg)
150 "Change whether this buffer uses multibyte characters.
151 With arg, use multibyte characters if the arg is positive.
152
153 Note that this command does not convert the byte contents of
154 the buffer; it only changes the way those bytes are interpreted.
155 In general, therefore, this command *changes* the sequence of
156 characters that the current buffer contains.
157
158 We suggest you avoid using use this command unless you know what you
159 are doing. If you use it by mistake, and the buffer is now displayed
160 wrong, use this command again to toggle back to the right mode."
161 (interactive "P")
162 (let ((new-flag
163 (if (null arg) (null enable-multibyte-characters)
164 (> (prefix-numeric-value arg) 0))))
165 (set-buffer-multibyte new-flag))
166 (force-mode-line-update))
167
168 (defun view-hello-file ()
169 "Display the HELLO file which list up many languages and characters."
170 (interactive)
171 ;; We have to decode the file in any environment.
172 (let ((default-enable-multibyte-characters t)
173 (coding-system-for-read 'iso-2022-7bit))
174 (find-file-read-only (expand-file-name "HELLO" data-directory))))
175
176 (defun universal-coding-system-argument ()
177 "Execute an I/O command using the specified coding system."
178 (interactive)
179 (let* ((default (and buffer-file-coding-system
180 (not (eq (coding-system-type buffer-file-coding-system)
181 t))
182 buffer-file-coding-system))
183 (coding-system (read-coding-system
184 (if default
185 (format "Coding system for following command (default, %s): " default)
186 "Coding system for following command: ")
187 default))
188 (keyseq (read-key-sequence
189 (format "Command to execute with %s:" coding-system)))
190 (cmd (key-binding keyseq)))
191 (let ((coding-system-for-read coding-system)
192 (coding-system-for-write coding-system))
193 (message "")
194 (call-interactively cmd))))
195
196 (defun set-default-coding-systems (coding-system)
197 "Set default value of various coding systems to CODING-SYSTEM.
198 This sets the following coding systems:
199 o coding system of a newly created buffer
200 o default coding system for subprocess I/O
201 This also sets the following values:
202 o default value used as file-name-coding-system for converting file names.
203 o default value for the command `set-terminal-coding-system'
204 o default value for the command `set-keyboard-coding-system'"
205 (check-coding-system coding-system)
206 (setq-default buffer-file-coding-system coding-system)
207 (if default-enable-multibyte-characters
208 (setq default-file-name-coding-system coding-system))
209 (setq default-terminal-coding-system coding-system)
210 (setq default-keyboard-coding-system coding-system)
211 (setq default-process-coding-system (cons coding-system coding-system)))
212
213 (defalias 'update-iso-coding-systems 'update-coding-systems-internal)
214 (make-obsolete 'update-iso-coding-systems 'update-coding-systems-internal)
215
216 (defun prefer-coding-system (coding-system)
217 "Add CODING-SYSTEM at the front of the priority list for automatic detection.
218 This also sets the following coding systems:
219 o coding system of a newly created buffer
220 o default coding system for subprocess I/O
221 This also sets the following values:
222 o default value used as file-name-coding-system for converting file names.
223 o default value for the command `set-terminal-coding-system'
224 o default value for the command `set-keyboard-coding-system'"
225 (interactive "zPrefer coding system: ")
226 (if (not (and coding-system (coding-system-p coding-system)))
227 (error "Invalid coding system `%s'" coding-system))
228 (let ((coding-category (coding-system-category coding-system))
229 (base (coding-system-base coding-system)))
230 (if (not coding-category)
231 ;; CODING-SYSTEM is no-conversion or undecided.
232 (error "Can't prefer the coding system `%s'" coding-system))
233 (set coding-category (or base coding-system))
234 (update-coding-systems-internal)
235 (if (not (eq coding-category (car coding-category-list)))
236 ;; We must change the order.
237 (setq coding-category-list
238 (cons coding-category
239 (delq coding-category coding-category-list))))
240 (if (and base (interactive-p))
241 (message "Highest priority is set to %s (base of %s)"
242 base coding-system))
243 (set-default-coding-systems (or base coding-system))))
244
245 (defun find-coding-systems-region-subset-p (list1 list2)
246 "Return non-nil if all elements in LIST1 are included in LIST2.
247 Comparison done with EQ."
248 (catch 'tag
249 (while list1
250 (or (memq (car list1) list2)
251 (throw 'tag nil))
252 (setq list1 (cdr list1)))
253 t))
254
255 (defun find-coding-systems-region (from to)
256 "Return a list of proper coding systems to encode a text between FROM and TO.
257 All coding systems in the list can safely encode any multibyte characters
258 in the text.
259
260 If the text contains no multibyte charcters, return a list of a single
261 element `undecided'."
262 (find-coding-systems-for-charsets (find-charset-region from to)))
263
264 (defun find-coding-systems-string (string)
265 "Return a list of proper coding systems to encode STRING.
266 All coding systems in the list can safely encode any multibyte characters
267 in STRING.
268
269 If STRING contains no multibyte charcters, return a list of a single
270 element `undecided'."
271 (find-coding-systems-for-charsets (find-charset-string string)))
272
273 (defun find-coding-systems-for-charsets (charsets)
274 "Return a list of proper coding systems to encode characters of CHARSETS.
275 CHARSETS is a list of character sets."
276 (if (or (null charsets)
277 (and (= (length charsets) 1)
278 (eq 'ascii (car charsets))))
279 '(undecided)
280 (let ((l coding-system-list)
281 (charset-prefered-codings
282 (mapcar (function
283 (lambda (x)
284 (get-charset-property x 'prefered-coding-system)))
285 charsets))
286 (priorities (mapcar (function (lambda (x) (symbol-value x)))
287 coding-category-list))
288 codings coding safe)
289 (while l
290 (setq coding (car l) l (cdr l))
291 (if (and (eq coding (coding-system-base coding))
292 (setq safe (coding-system-get coding 'safe-charsets))
293 (or (eq safe t)
294 (find-coding-systems-region-subset-p charsets safe)))
295 ;; We put the higher priority to coding systems included
296 ;; in CHARSET-PREFERED-CODINGS, and within them, put the
297 ;; higher priority to coding systems which support smaller
298 ;; number of charsets.
299 (let ((priority
300 (+ (if (coding-system-get coding 'mime-charset) 4096 0)
301 (lsh (length (memq coding priorities)) 7)
302 (if (memq coding charset-prefered-codings) 64 0)
303 (if (> (coding-system-type coding) 0) 32 0)
304 (if (consp safe) (- 32 (length safe)) 0))))
305 (setq codings (cons (cons priority coding) codings)))))
306 (mapcar 'cdr
307 (sort codings (function (lambda (x y) (> (car x) (car y))))))
308 )))
309
310 (defun find-multibyte-characters (from to &optional maxcount excludes)
311 "Find multibyte characters in the region specified by FROM and TO.
312 If FROM is a string, find multibyte characters in the string.
313 The return value is an alist of the following format:
314 ((CHARSET COUNT CHAR ...) ...)
315 where
316 CHARSET is a character set,
317 COUNT is a number of characters,
318 CHARs are found characters of the character set.
319 Optional 3rd arg MAXCOUNT limits how many CHARs are put in the above list.
320 Optioanl 4th arg EXCLUDE is a list of character sets to be ignored."
321 (let ((chars nil)
322 charset char)
323 (if (stringp from)
324 (let ((idx 0))
325 (while (setq idx (string-match "[^\000-\177]" from idx))
326 (setq char (aref from idx)
327 charset (char-charset char))
328 (if (not (memq charset excludes))
329 (let ((slot (assq charset chars)))
330 (if slot
331 (if (not (memq char (nthcdr 2 slot)))
332 (let ((count (nth 1 slot)))
333 (setcar (cdr slot) (1+ count))
334 (if (or (not maxcount) (< count maxcount))
335 (nconc slot (list char)))))
336 (setq chars (cons (list charset 1 char) chars)))))
337 (setq idx (1+ idx))))
338 (save-excursion
339 (goto-char from)
340 (while (re-search-forward "[^\000-\177]" to t)
341 (setq char (preceding-char)
342 charset (char-charset char))
343 (if (not (memq charset excludes))
344 (let ((slot (assq charset chars)))
345 (if slot
346 (if (not (memq char (nthcdr 2 slot)))
347 (let ((count (nth 1 slot)))
348 (setcar (cdr slot) (1+ count))
349 (if (or (not maxcount) (< count maxcount))
350 (nconc slot (list char)))))
351 (setq chars (cons (list charset 1 char) chars))))))))
352 (nreverse chars)))
353
354 (defvar last-coding-system-specified nil
355 "Most recent coding system explicitly specified by the user when asked.
356 This variable is set whenever Emacs asks the user which coding system
357 to use in order to write a file. If you set it to nil explicitly,
358 then call `write-region', then afterward this variable will be non-nil
359 only if the user was explicitly asked and specified a coding system.")
360
361 (defun select-safe-coding-system (from to &optional default-coding-system)
362 "Ask a user to select a safe coding system from candidates.
363 The candidates of coding systems which can safely encode a text
364 between FROM and TO are shown in a popup window.
365
366 Optional arg DEFAULT-CODING-SYSTEM specifies a coding system to be
367 checked at first. If omitted, buffer-file-coding-system of the
368 current buffer is used.
369
370 If the text can be encoded safely by DEFAULT-CODING-SYSTEM, it is
371 returned without any user interaction.
372
373 Kludgy feature: if FROM is a string, the string is the target text,
374 and TO is ignored."
375 (or default-coding-system
376 (setq default-coding-system buffer-file-coding-system))
377 (let* ((charsets (if (stringp from) (find-charset-string from)
378 (find-charset-region from to)))
379 (safe-coding-systems (find-coding-systems-for-charsets charsets)))
380 (if (or (eq (car safe-coding-systems) 'undecided)
381 (and default-coding-system
382 (memq (coding-system-base default-coding-system)
383 safe-coding-systems)))
384 default-coding-system
385
386 ;; At first, change each coding system to the corresponding
387 ;; mime-charset name if it is also a coding system.
388 (let ((l safe-coding-systems)
389 mime-charset)
390 (while l
391 (setq mime-charset (coding-system-get (car l) 'mime-charset))
392 (if (and mime-charset (coding-system-p mime-charset))
393 (setcar l mime-charset))
394 (setq l (cdr l))))
395
396 (let ((non-safe-chars (find-multibyte-characters
397 from to 3
398 (and default-coding-system
399 (coding-system-get default-coding-system
400 'safe-charsets))))
401 overlays)
402 (save-excursion
403 ;; Highlight characters that default-coding-system can't encode.
404 (when (integerp from)
405 (goto-char from)
406 (let ((found nil))
407 (while (and (not found)
408 (re-search-forward "[^\000-\177]" to t))
409 (setq found (assq (char-charset (preceding-char))
410 non-safe-chars))))
411 (beginning-of-line)
412 (set-window-start (selected-window) (point))
413 (save-excursion
414 (while (re-search-forward "[^\000-\177]" to t)
415 (let* ((char (preceding-char))
416 (charset (char-charset char)))
417 (when (assq charset non-safe-chars)
418 (setq overlays (cons (make-overlay (1- (point)) (point))
419 overlays))
420 (overlay-put (car overlays) 'face 'highlight))))))
421
422 ;; At last, ask a user to select a proper coding system.
423 (unwind-protect
424 (save-window-excursion
425 ;; At first, show a helpful message.
426 (with-output-to-temp-buffer "*Warning*"
427 (save-excursion
428 (set-buffer standard-output)
429 (insert "The target text contains the following non ASCII character(s):\n")
430 (let ((len (length non-safe-chars))
431 (shown 0))
432 (while (and non-safe-chars (< shown 3))
433 (when (> (length (car non-safe-chars)) 2)
434 (setq shown (1+ shown))
435 (insert (format "%25s: " (car (car non-safe-chars))))
436 (let ((l (nthcdr 2 (car non-safe-chars))))
437 (while l
438 (insert (car l))
439 (setq l (cdr l))))
440 (if (> (nth 1 (car non-safe-chars)) 3)
441 (insert "..."))
442 (insert "\n"))
443 (setq non-safe-chars (cdr non-safe-chars)))
444 (if (< shown len)
445 (insert (format "%27s\n" "..."))))
446 (insert (format "\
447 These can't be encoded safely by the coding system %s.
448
449 Please select one from the following safe coding systems:\n"
450 default-coding-system))
451 (let ((pos (point))
452 (fill-prefix " "))
453 (mapcar (function (lambda (x) (princ " ") (princ x)))
454 safe-coding-systems)
455 (fill-region-as-paragraph pos (point)))))
456
457 ;; Read a coding system.
458 (let* ((safe-names (mapcar (lambda (x) (list (symbol-name x)))
459 safe-coding-systems))
460 (name (completing-read
461 (format "Select coding system (default %s): "
462 (car safe-coding-systems))
463 safe-names nil t nil nil
464 (car (car safe-names)))))
465 (setq last-coding-system-specified (intern name))
466 (if (integerp (coding-system-eol-type default-coding-system))
467 (setq last-coding-system-specified
468 (coding-system-change-eol-conversion
469 last-coding-system-specified
470 (coding-system-eol-type default-coding-system))))
471 last-coding-system-specified))
472 (kill-buffer "*Warning*")
473 (while overlays
474 (delete-overlay (car overlays))
475 (setq overlays (cdr overlays)))))))))
476
477 (setq select-safe-coding-system-function 'select-safe-coding-system)
478
479 \f
480 ;;; Language support staffs.
481
482 (defvar language-info-alist nil
483 "Alist of language environment definitions.
484 Each element looks like:
485 (LANGUAGE-NAME . ((KEY . INFO) ...))
486 where LANGUAGE-NAME is a string, the name of the language environment,
487 KEY is a symbol denoting the kind of information, and
488 INFO is the data associated with KEY.
489 Meaningful values for KEY include
490
491 documentation value is documentation of what this language environment
492 is meant for, and how to use it.
493 charset value is a list of the character sets used by this
494 language environment.
495 sample-text value is one line of text,
496 written using those character sets,
497 appropriate for this language environment.
498 setup-function value is a function to call to switch to this
499 language environment.
500 exit-function value is a function to call to leave this
501 language environment.
502 coding-system value is a list of coding systems that are good
503 for saving text written in this language environment.
504 This list serves as suggestions to the user;
505 in effect, as a kind of documentation.
506 coding-priority value is a list of coding systems for this language
507 environment, in order of decreasing priority.
508 This is used to set up the coding system priority
509 list when you switch to this language environment.
510 nonascii-translation
511 value is a translation table to be set to the
512 variable `nonascii-translation-table' in this
513 language environment.
514 charset-origin-alist
515 value is an alist to be set to the variable
516 `charset-origin-alist' in this language environment.
517 input-method value is a default input method for this language
518 environment.
519
520 The following keys take effect only when multibyte characters are
521 globally disabled, i.e. the value of `default-enable-multibyte-characters'
522 is nil.
523
524 unibyte-syntax value is a library name to load to set
525 unibyte 8-bit charcater syntaxes for this
526 language environment.
527
528 unibyte-display value is a coding system to encode characters
529 for the terminal. Characters in the range
530 of 160 to 255 display not as octal escapes,
531 but as non-ASCII characters in this language
532 environment.")
533
534 (defun get-language-info (lang-env key)
535 "Return information listed under KEY for language environment LANG-ENV.
536 KEY is a symbol denoting the kind of information.
537 For a list of useful values for KEY and their meanings,
538 see `language-info-alist'."
539 (if (symbolp lang-env)
540 (setq lang-env (symbol-name lang-env)))
541 (let ((lang-slot (assoc-ignore-case lang-env language-info-alist)))
542 (if lang-slot
543 (cdr (assq key (cdr lang-slot))))))
544
545 (defun set-language-info (lang-env key info)
546 "Modify part of the definition of language environment LANG-ENV.
547 Specifically, this stores the information INFO under KEY
548 in the definition of this language environment.
549 KEY is a symbol denoting the kind of information.
550 INFO is the value for that information.
551
552 For a list of useful values for KEY and their meanings,
553 see `language-info-alist'."
554 (if (symbolp lang-env)
555 (setq lang-env (symbol-name lang-env)))
556 (let (lang-slot key-slot)
557 (setq lang-slot (assoc lang-env language-info-alist))
558 (if (null lang-slot) ; If no slot for the language, add it.
559 (setq lang-slot (list lang-env)
560 language-info-alist (cons lang-slot language-info-alist)))
561 (setq key-slot (assq key lang-slot))
562 (if (null key-slot) ; If no slot for the key, add it.
563 (progn
564 (setq key-slot (list key))
565 (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
566 (setcdr key-slot info)))
567
568 (defun set-language-info-alist (lang-env alist &optional parents)
569 "Store ALIST as the definition of language environment LANG-ENV.
570 ALIST is an alist of KEY and INFO values. See the documentation of
571 `set-langauge-info' for the meanings of KEY and INFO.
572
573 Optional arg PARENTS is a list of parent menu names; it specifies
574 where to put this language environment in the
575 Describe Language Environment and Set Language Environment menus.
576 For example, (\"European\") means to put this language environment
577 in the European submenu in each of those two menus."
578 (if (symbolp lang-env)
579 (setq lang-env (symbol-name lang-env)))
580 (let ((describe-map describe-language-environment-map)
581 (setup-map setup-language-environment-map))
582 (if parents
583 (let ((l parents)
584 map parent-symbol parent)
585 (while l
586 (if (symbolp (setq parent-symbol (car l)))
587 (setq parent (symbol-name parent))
588 (setq parent parent-symbol parent-symbol (intern parent)))
589 (setq map (lookup-key describe-map (vector parent-symbol)))
590 (if (not map)
591 (progn
592 (setq map (intern (format "describe-%s-environment-map"
593 (downcase parent))))
594 (define-prefix-command map)
595 (define-key-after describe-map (vector parent-symbol)
596 (cons parent map) t)))
597 (setq describe-map (symbol-value map))
598 (setq map (lookup-key setup-map (vector parent-symbol)))
599 (if (not map)
600 (progn
601 (setq map (intern (format "setup-%s-environment-map"
602 (downcase parent))))
603 (define-prefix-command map)
604 (define-key-after setup-map (vector parent-symbol)
605 (cons parent map) t)))
606 (setq setup-map (symbol-value map))
607 (setq l (cdr l)))))
608
609 ;; Set up menu items for this language env.
610 (let ((doc (assq 'documentation alist))
611 (setup-function (assq 'setup-function alist)))
612 (when doc
613 (define-key-after describe-map (vector (intern lang-env))
614 (cons lang-env 'describe-specified-language-support) t))
615 (when setup-function
616 (define-key-after setup-map (vector (intern lang-env))
617 (cons lang-env 'setup-specified-language-environment) t)))
618
619 (while alist
620 (set-language-info lang-env (car (car alist)) (cdr (car alist)))
621 (setq alist (cdr alist)))))
622
623 (defun read-language-name (key prompt &optional default)
624 "Read a language environment name which has information for KEY.
625 If KEY is nil, read any language environment.
626 Prompt with PROMPT. DEFAULT is the default choice of language environment.
627 This returns a language environment name as a string."
628 (let* ((completion-ignore-case t)
629 (name (completing-read prompt
630 language-info-alist
631 (and key
632 (function (lambda (elm) (assq key elm))))
633 t nil nil default)))
634 (if (and (> (length name) 0)
635 (or (not key)
636 (get-language-info name key)))
637 name)))
638 \f
639 ;;; Multilingual input methods.
640
641 (defconst leim-list-file-name "leim-list.el"
642 "Name of LEIM list file.
643 This file contains a list of libraries of Emacs input methods (LEIM)
644 in the format of Lisp expression for registering each input method.
645 Emacs loads this file at startup time.")
646
647 (defvar leim-list-header (format "\
648 ;;; %s -- list of LEIM (Library of Emacs Input Method)
649 ;;
650 ;; This file contains a list of LEIM (Library of Emacs Input Method)
651 ;; in the same directory as this file. Loading this file registeres
652 ;; the whole input methods in Emacs.
653 ;;
654 ;; Each entry has the form:
655 ;; (register-input-method
656 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC
657 ;; TITLE DESCRIPTION
658 ;; ARG ...)
659 ;; See the function `register-input-method' for the meanings of arguments.
660 ;;
661 ;; If this directory is included in load-path, Emacs automatically
662 ;; loads this file at startup time.
663
664 "
665 leim-list-file-name)
666 "Header to be inserted in LEIM list file.")
667
668 (defvar leim-list-entry-regexp "^(register-input-method"
669 "Regexp matching head of each entry in LEIM list file.
670 See also the variable `leim-list-header'")
671
672 (defvar update-leim-list-functions
673 '(quail-update-leim-list-file)
674 "List of functions to call to update LEIM list file.
675 Each function is called with one arg, LEIM directory name.")
676
677 (defun update-leim-list-file (&rest dirs)
678 "Update LEIM list file in directories DIRS."
679 (let ((functions update-leim-list-functions))
680 (while functions
681 (apply (car functions) dirs)
682 (setq functions (cdr functions)))))
683
684 (defvar current-input-method nil
685 "The current input method for multilingual text.
686 If nil, that means no input method is activated now.")
687 (make-variable-buffer-local 'current-input-method)
688 (put 'current-input-method 'permanent-local t)
689
690 (defvar current-input-method-title nil
691 "Title string of the current input method shown in mode line.")
692 (make-variable-buffer-local 'current-input-method-title)
693 (put 'current-input-method-title 'permanent-local t)
694
695 (defcustom default-input-method nil
696 "*Default input method for multilingual text (a string).
697 This is the input method activated automatically by the command
698 `toggle-input-method' (\\[toggle-input-method])."
699 :group 'mule
700 :type 'string)
701
702 (defvar input-method-history nil
703 "History list for some commands that read input methods.")
704 (make-variable-buffer-local 'input-method-history)
705 (put 'input-method-history 'permanent-local t)
706
707 (defvar inactivate-current-input-method-function nil
708 "Function to call for inactivating the current input method.
709 Every input method should set this to an appropriate value when activated.
710 This function is called with no argument.
711
712 This function should never change the value of `current-input-method'.
713 It is set to nil by the function `inactivate-input-method'.")
714 (make-variable-buffer-local 'inactivate-current-input-method-function)
715 (put 'inactivate-current-input-method-function 'permanent-local t)
716
717 (defvar describe-current-input-method-function nil
718 "Function to call for describing the current input method.
719 This function is called with no argument.")
720 (make-variable-buffer-local 'describe-current-input-method-function)
721 (put 'describe-current-input-method-function 'permanent-local t)
722
723 (defvar input-method-alist nil
724 "Alist of input method names vs how to use them.
725 Each element has the form:
726 (INPUT-METHOD LANGUAGE-ENV ACTIVATE-FUNC TITLE DESCRIPTION ARGS...)
727 See the function `register-input-method' for the meanings of the elements.")
728
729 (defun register-input-method (input-method lang-env &rest args)
730 "Register INPUT-METHOD as an input method for language environment ENV.
731 INPUT-METHOD and LANG-ENV are symbols or strings.
732
733 The remaining arguments are:
734 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARGS...
735 ACTIVATE-FUNC is a function to call to activate this method.
736 TITLE is a string to show in the mode line when this method is active.
737 DESCRIPTION is a string describing this method and what it is good for.
738 The ARGS, if any, are passed as arguments to ACTIVATE-FUNC.
739 All told, the arguments to ACTIVATE-FUNC are INPUT-METHOD and the ARGS."
740 (if (symbolp lang-env)
741 (setq lang-env (symbol-name lang-env)))
742 (if (symbolp input-method)
743 (setq input-method (symbol-name input-method)))
744 (let ((info (cons lang-env args))
745 (slot (assoc input-method input-method-alist)))
746 (if slot
747 (setcdr slot info)
748 (setq slot (cons input-method info))
749 (setq input-method-alist (cons slot input-method-alist)))))
750
751 (defun read-input-method-name (prompt &optional default inhibit-null)
752 "Read a name of input method from a minibuffer prompting with PROMPT.
753 If DEFAULT is non-nil, use that as the default,
754 and substitute it into PROMPT at the first `%s'.
755 If INHIBIT-NULL is non-nil, null input signals an error.
756
757 The return value is a string."
758 (if default
759 (setq prompt (format prompt default)))
760 (let* ((completion-ignore-case t)
761 ;; This binding is necessary because input-method-history is
762 ;; buffer local.
763 (input-method (completing-read prompt input-method-alist
764 nil t nil 'input-method-history
765 default)))
766 (if (> (length input-method) 0)
767 input-method
768 (if inhibit-null
769 (error "No valid input method is specified")))))
770
771 (defun activate-input-method (input-method)
772 "Switch to input method INPUT-METHOD for the current buffer.
773 If some other input method is already active, turn it off first.
774 If INPUT-METHOD is nil, deactivate any current input method."
775 (if (symbolp input-method)
776 (setq input-method (symbol-name input-method)))
777 (if (and current-input-method
778 (not (string= current-input-method input-method)))
779 (inactivate-input-method))
780 (unless (or current-input-method (null input-method))
781 (let ((slot (assoc input-method input-method-alist)))
782 (if (null slot)
783 (error "Can't activate input method `%s'" input-method))
784 (let ((func (nth 2 slot)))
785 (if (functionp func)
786 (apply (nth 2 slot) input-method (nthcdr 5 slot))
787 (if (and (consp func) (symbolp (car func)) (symbolp (cdr func)))
788 (progn
789 (require (cdr func))
790 (apply (car func) input-method (nthcdr 5 slot)))
791 (error "Can't activate input method `%s'" input-method))))
792 (setq current-input-method input-method)
793 (setq current-input-method-title (nth 3 slot))
794 (unwind-protect
795 (run-hooks 'input-method-activate-hook)
796 (force-mode-line-update)))))
797
798 (defun inactivate-input-method ()
799 "Turn off the current input method."
800 (when current-input-method
801 (if input-method-history
802 (unless (string= current-input-method (car input-method-history))
803 (setq input-method-history
804 (cons current-input-method
805 (delete current-input-method input-method-history))))
806 (setq input-method-history (list current-input-method)))
807 (unwind-protect
808 (funcall inactivate-current-input-method-function)
809 (unwind-protect
810 (run-hooks 'input-method-inactivate-hook)
811 (setq current-input-method nil
812 current-input-method-title nil)
813 (force-mode-line-update)))))
814
815 (defun set-input-method (input-method)
816 "Select and activate input method INPUT-METHOD for the current buffer.
817 This also sets the default input method to the one you specify."
818 (interactive
819 (let* ((default (or (car input-method-history) default-input-method)))
820 (list (read-input-method-name
821 (if default "Select input method (default %s): " "Select input method: ")
822 default t))))
823 (activate-input-method input-method)
824 (setq default-input-method input-method))
825
826 (defun toggle-input-method (&optional arg)
827 "Turn on or off a multilingual text input method for the current buffer.
828
829 With no prefix argument, if some input method is currently activated,
830 turn it off. Otherwise, activate an input method--the one most recently used,
831 or the one specified in `default-input-method', or one read from the
832 minibuffer.
833
834 With a prefix arg, read an input method from minibuffer and turn it on.
835 The default is the most recent input method specified
836 \(not including the currently active input method, if any).
837
838 When there's no input method to turn on, turn on what read from minibuffer."
839 (interactive "P")
840 (if (and current-input-method (not arg))
841 (inactivate-input-method)
842 (let ((default (or (car input-method-history) default-input-method)))
843 (if (and arg default (equal current-input-method default)
844 (> (length input-method-history) 1))
845 (setq default (nth 1 input-method-history)))
846 (activate-input-method
847 (if (or arg (not default))
848 (progn
849 (read-input-method-name
850 (if default "Input method (default %s): " "Input method: " )
851 default t))
852 default))
853 (or default-input-method
854 (setq default-input-method current-input-method)))))
855
856 (defun describe-input-method (input-method)
857 "Describe input method INPUT-METHOD."
858 (interactive
859 (list (read-input-method-name
860 "Describe input method (default, current choice): ")))
861 (if (and input-method (symbolp input-method))
862 (setq input-method (symbol-name input-method)))
863 (if (null input-method)
864 (describe-current-input-method)
865 (with-output-to-temp-buffer "*Help*"
866 (let ((elt (assoc input-method input-method-alist)))
867 (princ (format "Input method: %s (`%s' in mode line) for %s\n %s\n"
868 input-method (nth 3 elt) (nth 1 elt) (nth 4 elt)))))))
869
870 (defun describe-current-input-method ()
871 "Describe the input method currently in use."
872 (if current-input-method
873 (if (and (symbolp describe-current-input-method-function)
874 (fboundp describe-current-input-method-function))
875 (funcall describe-current-input-method-function)
876 (message "No way to describe the current input method `%s'"
877 (cdr current-input-method))
878 (ding))
879 (error "No input method is activated now")))
880
881 (defun read-multilingual-string (prompt &optional initial-input input-method)
882 "Read a multilingual string from minibuffer, prompting with string PROMPT.
883 The input method selected last time is activated in minibuffer.
884 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
885 initially.
886 Optional 3rd argument INPUT-METHOD specifies the input method
887 to be activated instead of the one selected last time. It is a symbol
888 or a string."
889 (setq input-method
890 (or input-method
891 current-input-method
892 default-input-method
893 (read-input-method-name "Input method: " nil t)))
894 (if (and input-method (symbolp input-method))
895 (setq input-method (symbol-name input-method)))
896 (let ((current-input-method input-method))
897 (read-string prompt initial-input nil nil t)))
898
899 ;; Variables to control behavior of input methods. All input methods
900 ;; should react to these variables.
901
902 (defcustom input-method-verbose-flag 'default
903 "*A flag to control extra guidance given by input methods.
904 The value should be nil, t, `complex-only', or `default'.
905
906 The extra guidance is done by showing list of available keys in echo
907 area. When you use the input method in the minibuffer, the guidance
908 is shown at the bottom short window (split from the existing window).
909
910 If the value is t, extra guidance is always given, if the value is
911 nil, extra guidance is always suppressed.
912
913 If the value is `complex-only', only complex input methods such as
914 `chinese-py' and `japanese' give extra guidance.
915
916 If the value is `default', complex input methods always give extra
917 guidance, but simple input methods give it only when you are not in
918 the minibuffer.
919
920 See also the variable `input-method-highlight-flag'."
921 :type '(choice (const t) (const nil) (const complex-only) (const default))
922 :group 'mule)
923
924 (defcustom input-method-highlight-flag t
925 "*If this flag is non-nil, input methods highlight partially-entered text.
926 For instance, while you are in the middle of a Quail input method sequence,
927 the text inserted so far is temporarily underlined.
928 The underlining goes away when you finish or abort the input method sequence.
929 See also the variable `input-method-verbose-flag'."
930 :type 'boolean
931 :group 'mule)
932
933 (defvar input-method-activate-hook nil
934 "Normal hook run just after an input method is activated.
935
936 The variable `current-input-method' keeps the input method name
937 just activated.")
938
939 (defvar input-method-inactivate-hook nil
940 "Normal hook run just after an input method is inactivated.
941
942 The variable `current-input-method' still keeps the input method name
943 just inactivated.")
944
945 (defvar input-method-after-insert-chunk-hook nil
946 "Normal hook run just after an input method insert some chunk of text.")
947
948 (defvar input-method-exit-on-first-char nil
949 "This flag controls a timing when an input method returns.
950 Usually, the input method does not return while there's a possibility
951 that it may find a different translation if a user types another key.
952 But, it this flag is non-nil, the input method returns as soon as
953 the current key sequence gets long enough to have some valid translation.")
954
955 (defvar input-method-use-echo-area nil
956 "This flag controls how an input method shows an intermediate key sequence.
957 Usually, the input method inserts the intermediate key sequence,
958 or candidate translations corresponding to the sequence,
959 at point in the current buffer.
960 But, if this flag is non-nil, it displays them in echo area instead.")
961
962 (defvar input-method-exit-on-invalid-key nil
963 "This flag controls the behaviour of an input method on invalid key input.
964 Usually, when a user types a key which doesn't start any character
965 handled by the input method, the key is handled by turning off the
966 input method temporarily. After that key, the input method is renabled.
967 But, if this flag is non-nil, the input method is never back on.")
968
969 \f
970 (defvar set-language-environment-hook nil
971 "Normal hook run after some language environment is set.
972
973 When you set some hook function here, that effect usually should not
974 be inherited to another language environment. So, you had better set
975 another function in `exit-language-environment-hook' (which see) to
976 cancel the effect.")
977
978 (defvar exit-language-environment-hook nil
979 "Normal hook run after exiting from some language environment.
980 When this hook is run, the variable `current-language-environment'
981 is still bound to the language environment being exited.
982
983 This hook is mainly used for cancelling the effect of
984 `set-language-environment-hook' (which-see).")
985
986 (defun setup-specified-language-environment ()
987 "Switch to a specified language environment."
988 (interactive)
989 (let (language-name)
990 (if (and (symbolp last-command-event)
991 (or (not (eq last-command-event 'Default))
992 (setq last-command-event 'English))
993 (setq language-name (symbol-name last-command-event)))
994 (set-language-environment language-name)
995 (error "Bogus calling sequence"))))
996
997 (defcustom current-language-environment "English"
998 "The last language environment specified with `set-language-environment'."
999 :set 'set-language-environment
1000 :initialize 'custom-initialize-default
1001 :group 'mule
1002 :type 'string)
1003
1004 (defun reset-language-environment ()
1005 "Reset multilingual environment of Emacs to the default status.
1006
1007 The default status is as follows:
1008
1009 The default value of buffer-file-coding-system is nil.
1010 The default coding system for process I/O is nil.
1011 The default value for the command `set-terminal-coding-system' is nil.
1012 The default value for the command `set-keyboard-coding-system' is nil.
1013
1014 The order of priorities of coding categories and the coding system
1015 bound to each category are as follows
1016 coding category coding system
1017 --------------------------------------------------
1018 coding-category-iso-8-2 iso-latin-1
1019 coding-category-iso-8-1 iso-latin-1
1020 coding-category-iso-7-tight iso-2022-jp
1021 coding-category-iso-7 iso-2022-7bit
1022 coding-category-iso-7-else iso-2022-7bit-lock
1023 coding-category-iso-8-else iso-2022-8bit-ss2
1024 coding-category-emacs-mule emacs-mule
1025 coding-category-raw-text raw-text
1026 coding-category-sjis japanese-shift-jis
1027 coding-category-big5 chinese-big5
1028 coding-category-ccl nil
1029 coding-category-binarry no-conversion
1030 "
1031 (interactive)
1032 ;; This function formerly set default-enable-multibyte-characters to t,
1033 ;; but that is incorrect. It should not alter the unibyte/multibyte choice.
1034
1035 (setq coding-category-iso-7-tight 'iso-2022-jp
1036 coding-category-iso-7 'iso-2022-7bit
1037 coding-category-iso-8-1 'iso-latin-1
1038 coding-category-iso-8-2 'iso-latin-1
1039 coding-category-iso-7-else 'iso-2022-7bit-lock
1040 coding-category-iso-8-else 'iso-2022-8bit-ss2
1041 coding-category-emacs-mule 'emacs-mule
1042 coding-category-raw-text 'raw-text
1043 coding-category-sjis 'japanese-shift-jis
1044 coding-category-big5 'chinese-big5
1045 coding-category-ccl nil
1046 coding-category-binary 'no-conversion)
1047
1048 (set-coding-priority
1049 '(coding-category-iso-8-1
1050 coding-category-iso-8-2
1051 coding-category-iso-7-tight
1052 coding-category-iso-7
1053 coding-category-iso-7-else
1054 coding-category-iso-8-else
1055 coding-category-emacs-mule
1056 coding-category-raw-text
1057 coding-category-sjis
1058 coding-category-big5
1059 coding-category-ccl
1060 coding-category-binary))
1061
1062 (set-default-coding-systems nil)
1063 ;; Don't alter the terminal and keyboard coding systems here.
1064 ;; The terminal still supports the same coding system
1065 ;; that it supported a minute ago.
1066 ;;; (set-terminal-coding-system-internal nil)
1067 ;;; (set-keyboard-coding-system-internal nil)
1068
1069 (setq nonascii-translation-table nil
1070 nonascii-insert-offset 0))
1071
1072 (defun set-language-environment (language-name)
1073 "Set up multi-lingual environment for using LANGUAGE-NAME.
1074 This sets the coding system priority and the default input method
1075 and sometimes other things. LANGUAGE-NAME should be a string
1076 which is the name of a language environment. For example, \"Latin-1\"
1077 specifies the character set for the major languages of Western Europe."
1078 (interactive (list (read-language-name
1079 nil
1080 "Set language environment (default, English): ")))
1081 (if language-name
1082 (if (symbolp language-name)
1083 (setq language-name (symbol-name language-name)))
1084 (setq language-name "English"))
1085 (or (assoc-ignore-case language-name language-info-alist)
1086 (error "Language environment not defined: %S" language-name))
1087 (if current-language-environment
1088 (let ((func (get-language-info current-language-environment
1089 'exit-function)))
1090 (run-hooks 'exit-language-environment-hook)
1091 (if (fboundp func) (funcall func))))
1092 (reset-language-environment)
1093
1094 (setq current-language-environment language-name)
1095 (set-language-environment-coding-systems language-name)
1096 (let ((input-method (get-language-info language-name 'input-method)))
1097 (when input-method
1098 (setq default-input-method input-method)
1099 (if input-method-history
1100 (setq input-method-history
1101 (cons input-method
1102 (delete input-method input-method-history))))))
1103 (let ((nonascii (get-language-info language-name 'nonascii-translation)))
1104 (if (char-table-p nonascii)
1105 (setq nonascii-translation-table nonascii)
1106 (if (charsetp nonascii)
1107 (setq nonascii-insert-offset (- (make-char nonascii) 128)))))
1108
1109 (setq charset-origin-alist
1110 (get-language-info language-name 'charset-origin-alist))
1111
1112 (unless default-enable-multibyte-characters
1113 ;; Unibyte setups.
1114 (let ((syntax (get-language-info language-name 'unibyte-syntax)))
1115 (if syntax
1116 (let ((set-case-syntax-set-multibyte nil))
1117 (load syntax nil t)
1118 (set-standard-case-table (standard-case-table))
1119 (let ((list (buffer-list)))
1120 (while list
1121 (with-current-buffer (car list)
1122 (set-case-table (standard-case-table)))
1123 (setq list (cdr list)))))))
1124 (let ((coding (get-language-info language-name 'unibyte-display)))
1125 (if coding
1126 (progn
1127 (standard-display-european-internal)
1128 (set-terminal-coding-system coding))
1129 (standard-display-default 160 255)
1130 (aset standard-display-table 146 nil)
1131 (set-terminal-coding-system nil))))
1132
1133 (let ((required-features (get-language-info language-name 'features)))
1134 (while required-features
1135 (require (car required-features))
1136 (setq required-features (cdr required-features))))
1137 (let ((func (get-language-info language-name 'setup-function)))
1138 (if (fboundp func)
1139 (funcall func)))
1140 (run-hooks 'set-language-environment-hook)
1141 (force-mode-line-update t))
1142
1143 (defun standard-display-european-internal ()
1144 ;; Actually set up direct output of non-ASCII characters.
1145 (standard-display-8bit 160 255)
1146 ;; Make non-line-break space display as a plain space.
1147 ;; Most X fonts do the wrong thing for code 160.
1148 (aset standard-display-table 160 [32])
1149 ;; Most Windows programs send out apostrophe's as \222. Most X fonts
1150 ;; don't contain a character at that position. Map it to the ASCII
1151 ;; apostrophe.
1152 (aset standard-display-table 146 [39]))
1153
1154 (defun set-language-environment-coding-systems (language-name)
1155 "Do various coding system setups for language environment LANGUAGE-NAME."
1156 (let* ((priority (get-language-info language-name 'coding-priority))
1157 (default-coding (car priority)))
1158 (if priority
1159 (let ((categories (mapcar 'coding-system-category priority)))
1160 (set-default-coding-systems default-coding)
1161 (set-coding-priority categories)
1162 (while priority
1163 (set (car categories) (car priority))
1164 (setq priority (cdr priority) categories (cdr categories)))
1165 (update-coding-systems-internal)))))
1166
1167 ;; Print all arguments with `princ', then print "\n".
1168 (defsubst princ-list (&rest args)
1169 (while args (princ (car args)) (setq args (cdr args)))
1170 (princ "\n"))
1171
1172 ;; Print a language specific information such as input methods,
1173 ;; charsets, and coding systems. This function is intended to be
1174 ;; called from the menu:
1175 ;; [menu-bar mule describe-language-environment LANGUAGE]
1176 ;; and should not run it by `M-x describe-current-input-method-function'.
1177 (defun describe-specified-language-support ()
1178 "Describe how Emacs supports the specified language environment."
1179 (interactive)
1180 (let (language-name)
1181 (if (not (and (symbolp last-command-event)
1182 (setq language-name (symbol-name last-command-event))))
1183 (error "Bogus calling sequence"))
1184 (describe-language-environment language-name)))
1185
1186 (defun describe-language-environment (language-name)
1187 "Describe how Emacs supports language environment LANGUAGE-NAME."
1188 (interactive
1189 (list (read-language-name
1190 'documentation
1191 "Describe language environment (default, current choice): ")))
1192 (if (null language-name)
1193 (setq language-name current-language-environment))
1194 (if (or (null language-name)
1195 (null (get-language-info language-name 'documentation)))
1196 (error "No documentation for the specified language"))
1197 (if (symbolp language-name)
1198 (setq language-name (symbol-name language-name)))
1199 (let ((doc (get-language-info language-name 'documentation)))
1200 (with-output-to-temp-buffer "*Help*"
1201 (princ-list language-name " language environment" "\n")
1202 (if (stringp doc)
1203 (progn
1204 (princ-list doc)
1205 (terpri)))
1206 (let ((str (get-language-info language-name 'sample-text)))
1207 (if (stringp str)
1208 (progn
1209 (princ "Sample text:\n")
1210 (princ-list " " str)
1211 (terpri))))
1212 (let ((input-method (get-language-info language-name 'input-method))
1213 (l input-method-alist))
1214 (princ "Input methods")
1215 (when input-method
1216 (princ (format " (default, %s)" input-method))
1217 (setq input-method (assoc input-method input-method-alist))
1218 (setq l (cons input-method (delete input-method l))))
1219 (princ ":\n")
1220 (while l
1221 (if (string= language-name (nth 1 (car l)))
1222 (princ-list " " (car (car l))
1223 (format " (`%s' in mode line)" (nth 3 (car l)))))
1224 (setq l (cdr l))))
1225 (terpri)
1226 (princ "Character sets:\n")
1227 (let ((l (get-language-info language-name 'charset)))
1228 (if (null l)
1229 (princ-list " nothing specific to " language-name)
1230 (while l
1231 (princ-list " " (car l) ": "
1232 (charset-description (car l)))
1233 (setq l (cdr l)))))
1234 (terpri)
1235 (princ "Coding systems:\n")
1236 (let ((l (get-language-info language-name 'coding-system)))
1237 (if (null l)
1238 (princ-list " nothing specific to " language-name)
1239 (while l
1240 (princ (format " %s (`%c' in mode line):\n\t%s\n"
1241 (car l)
1242 (coding-system-mnemonic (car l))
1243 (coding-system-doc-string (car l))))
1244 (let ((aliases (coding-system-get (car l) 'alias-coding-systems)))
1245 (when aliases
1246 (princ "\t")
1247 (princ (cons 'alias: (cdr aliases)))
1248 (terpri)))
1249 (setq l (cdr l))))))))
1250 \f
1251 ;;; Charset property
1252
1253 (defsubst get-charset-property (charset propname)
1254 "Return the value of CHARSET's PROPNAME property.
1255 This is the last value stored with
1256 (put-charset-property CHARSET PROPNAME VALUE)."
1257 (plist-get (charset-plist charset) propname))
1258
1259 (defsubst put-charset-property (charset propname value)
1260 "Store CHARSETS's PROPNAME property with value VALUE.
1261 It can be retrieved with `(get-charset-property CHARSET PROPNAME)'."
1262 (set-charset-plist charset
1263 (plist-put (charset-plist charset) propname value)))
1264
1265 ;;; Character code property
1266 (put 'char-code-property-table 'char-table-extra-slots 0)
1267
1268 (defvar char-code-property-table
1269 (make-char-table 'char-code-property-table)
1270 "Char-table containing a property list of each character code.
1271
1272 See also the documentation of `get-char-code-property' and
1273 `put-char-code-property'.")
1274
1275 (defun get-char-code-property (char propname)
1276 "Return the value of CHAR's PROPNAME property in `char-code-property-table'."
1277 (let ((plist (aref char-code-property-table char)))
1278 (if (listp plist)
1279 (car (cdr (memq propname plist))))))
1280
1281 (defun put-char-code-property (char propname value)
1282 "Store CHAR's PROPNAME property with VALUE in `char-code-property-table'.
1283 It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
1284 (let ((plist (aref char-code-property-table char)))
1285 (if plist
1286 (let ((slot (memq propname plist)))
1287 (if slot
1288 (setcar (cdr slot) value)
1289 (nconc plist (list propname value))))
1290 (aset char-code-property-table char (list propname value)))))
1291
1292 ;;; mule-cmds.el ends here