(select-safe-coding-system): If default-coding-system is no-conversion,
[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 (eq default-coding-system 'no-conversion)
382 (and default-coding-system
383 (memq (coding-system-base default-coding-system)
384 safe-coding-systems)))
385 default-coding-system
386
387 ;; At first, change each coding system to the corresponding
388 ;; mime-charset name if it is also a coding system.
389 (let ((l safe-coding-systems)
390 mime-charset)
391 (while l
392 (setq mime-charset (coding-system-get (car l) 'mime-charset))
393 (if (and mime-charset (coding-system-p mime-charset))
394 (setcar l mime-charset))
395 (setq l (cdr l))))
396
397 (let ((non-safe-chars (find-multibyte-characters
398 from to 3
399 (and default-coding-system
400 (coding-system-get default-coding-system
401 'safe-charsets))))
402 overlays)
403 (save-excursion
404 ;; Highlight characters that default-coding-system can't encode.
405 (when (integerp from)
406 (goto-char from)
407 (let ((found nil))
408 (while (and (not found)
409 (re-search-forward "[^\000-\177]" to t))
410 (setq found (assq (char-charset (preceding-char))
411 non-safe-chars))))
412 (beginning-of-line)
413 (set-window-start (selected-window) (point))
414 (save-excursion
415 (while (re-search-forward "[^\000-\177]" to t)
416 (let* ((char (preceding-char))
417 (charset (char-charset char)))
418 (when (assq charset non-safe-chars)
419 (setq overlays (cons (make-overlay (1- (point)) (point))
420 overlays))
421 (overlay-put (car overlays) 'face 'highlight))))))
422
423 ;; At last, ask a user to select a proper coding system.
424 (unwind-protect
425 (save-window-excursion
426 ;; At first, show a helpful message.
427 (with-output-to-temp-buffer "*Warning*"
428 (save-excursion
429 (set-buffer standard-output)
430 (insert "The target text contains the following non ASCII character(s):\n")
431 (let ((len (length non-safe-chars))
432 (shown 0))
433 (while (and non-safe-chars (< shown 3))
434 (when (> (length (car non-safe-chars)) 2)
435 (setq shown (1+ shown))
436 (insert (format "%25s: " (car (car non-safe-chars))))
437 (let ((l (nthcdr 2 (car non-safe-chars))))
438 (while l
439 (insert (car l))
440 (setq l (cdr l))))
441 (if (> (nth 1 (car non-safe-chars)) 3)
442 (insert "..."))
443 (insert "\n"))
444 (setq non-safe-chars (cdr non-safe-chars)))
445 (if (< shown len)
446 (insert (format "%27s\n" "..."))))
447 (insert (format "\
448 These can't be encoded safely by the coding system %s.
449
450 Please select one from the following safe coding systems:\n"
451 default-coding-system))
452 (let ((pos (point))
453 (fill-prefix " "))
454 (mapcar (function (lambda (x) (princ " ") (princ x)))
455 safe-coding-systems)
456 (fill-region-as-paragraph pos (point)))))
457
458 ;; Read a coding system.
459 (let* ((safe-names (mapcar (lambda (x) (list (symbol-name x)))
460 safe-coding-systems))
461 (name (completing-read
462 (format "Select coding system (default %s): "
463 (car safe-coding-systems))
464 safe-names nil t nil nil
465 (car (car safe-names)))))
466 (setq last-coding-system-specified (intern name))
467 (if (integerp (coding-system-eol-type default-coding-system))
468 (setq last-coding-system-specified
469 (coding-system-change-eol-conversion
470 last-coding-system-specified
471 (coding-system-eol-type default-coding-system))))
472 last-coding-system-specified))
473 (kill-buffer "*Warning*")
474 (while overlays
475 (delete-overlay (car overlays))
476 (setq overlays (cdr overlays)))))))))
477
478 (setq select-safe-coding-system-function 'select-safe-coding-system)
479
480 \f
481 ;;; Language support staffs.
482
483 (defvar language-info-alist nil
484 "Alist of language environment definitions.
485 Each element looks like:
486 (LANGUAGE-NAME . ((KEY . INFO) ...))
487 where LANGUAGE-NAME is a string, the name of the language environment,
488 KEY is a symbol denoting the kind of information, and
489 INFO is the data associated with KEY.
490 Meaningful values for KEY include
491
492 documentation value is documentation of what this language environment
493 is meant for, and how to use it.
494 charset value is a list of the character sets used by this
495 language environment.
496 sample-text value is one line of text,
497 written using those character sets,
498 appropriate for this language environment.
499 setup-function value is a function to call to switch to this
500 language environment.
501 exit-function value is a function to call to leave this
502 language environment.
503 coding-system value is a list of coding systems that are good
504 for saving text written in this language environment.
505 This list serves as suggestions to the user;
506 in effect, as a kind of documentation.
507 coding-priority value is a list of coding systems for this language
508 environment, in order of decreasing priority.
509 This is used to set up the coding system priority
510 list when you switch to this language environment.
511 nonascii-translation
512 value is a translation table to be set to the
513 variable `nonascii-translation-table' in this
514 language environment.
515 charset-origin-alist
516 value is an alist to be set to the variable
517 `charset-origin-alist' in this language environment.
518 input-method value is a default input method for this language
519 environment.
520
521 The following keys take effect only when multibyte characters are
522 globally disabled, i.e. the value of `default-enable-multibyte-characters'
523 is nil.
524
525 unibyte-syntax value is a library name to load to set
526 unibyte 8-bit charcater syntaxes for this
527 language environment.
528
529 unibyte-display value is a coding system to encode characters
530 for the terminal. Characters in the range
531 of 160 to 255 display not as octal escapes,
532 but as non-ASCII characters in this language
533 environment.")
534
535 (defun get-language-info (lang-env key)
536 "Return information listed under KEY for language environment LANG-ENV.
537 KEY is a symbol denoting the kind of information.
538 For a list of useful values for KEY and their meanings,
539 see `language-info-alist'."
540 (if (symbolp lang-env)
541 (setq lang-env (symbol-name lang-env)))
542 (let ((lang-slot (assoc-ignore-case lang-env language-info-alist)))
543 (if lang-slot
544 (cdr (assq key (cdr lang-slot))))))
545
546 (defun set-language-info (lang-env key info)
547 "Modify part of the definition of language environment LANG-ENV.
548 Specifically, this stores the information INFO under KEY
549 in the definition of this language environment.
550 KEY is a symbol denoting the kind of information.
551 INFO is the value for that information.
552
553 For a list of useful values for KEY and their meanings,
554 see `language-info-alist'."
555 (if (symbolp lang-env)
556 (setq lang-env (symbol-name lang-env)))
557 (let (lang-slot key-slot)
558 (setq lang-slot (assoc lang-env language-info-alist))
559 (if (null lang-slot) ; If no slot for the language, add it.
560 (setq lang-slot (list lang-env)
561 language-info-alist (cons lang-slot language-info-alist)))
562 (setq key-slot (assq key lang-slot))
563 (if (null key-slot) ; If no slot for the key, add it.
564 (progn
565 (setq key-slot (list key))
566 (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
567 (setcdr key-slot info)))
568
569 (defun set-language-info-alist (lang-env alist &optional parents)
570 "Store ALIST as the definition of language environment LANG-ENV.
571 ALIST is an alist of KEY and INFO values. See the documentation of
572 `set-langauge-info' for the meanings of KEY and INFO.
573
574 Optional arg PARENTS is a list of parent menu names; it specifies
575 where to put this language environment in the
576 Describe Language Environment and Set Language Environment menus.
577 For example, (\"European\") means to put this language environment
578 in the European submenu in each of those two menus."
579 (if (symbolp lang-env)
580 (setq lang-env (symbol-name lang-env)))
581 (let ((describe-map describe-language-environment-map)
582 (setup-map setup-language-environment-map))
583 (if parents
584 (let ((l parents)
585 map parent-symbol parent)
586 (while l
587 (if (symbolp (setq parent-symbol (car l)))
588 (setq parent (symbol-name parent))
589 (setq parent parent-symbol parent-symbol (intern parent)))
590 (setq map (lookup-key describe-map (vector parent-symbol)))
591 (if (not map)
592 (progn
593 (setq map (intern (format "describe-%s-environment-map"
594 (downcase parent))))
595 (define-prefix-command map)
596 (define-key-after describe-map (vector parent-symbol)
597 (cons parent map) t)))
598 (setq describe-map (symbol-value map))
599 (setq map (lookup-key setup-map (vector parent-symbol)))
600 (if (not map)
601 (progn
602 (setq map (intern (format "setup-%s-environment-map"
603 (downcase parent))))
604 (define-prefix-command map)
605 (define-key-after setup-map (vector parent-symbol)
606 (cons parent map) t)))
607 (setq setup-map (symbol-value map))
608 (setq l (cdr l)))))
609
610 ;; Set up menu items for this language env.
611 (let ((doc (assq 'documentation alist))
612 (setup-function (assq 'setup-function alist)))
613 (when doc
614 (define-key-after describe-map (vector (intern lang-env))
615 (cons lang-env 'describe-specified-language-support) t))
616 (when setup-function
617 (define-key-after setup-map (vector (intern lang-env))
618 (cons lang-env 'setup-specified-language-environment) t)))
619
620 (while alist
621 (set-language-info lang-env (car (car alist)) (cdr (car alist)))
622 (setq alist (cdr alist)))))
623
624 (defun read-language-name (key prompt &optional default)
625 "Read a language environment name which has information for KEY.
626 If KEY is nil, read any language environment.
627 Prompt with PROMPT. DEFAULT is the default choice of language environment.
628 This returns a language environment name as a string."
629 (let* ((completion-ignore-case t)
630 (name (completing-read prompt
631 language-info-alist
632 (and key
633 (function (lambda (elm) (assq key elm))))
634 t nil nil default)))
635 (if (and (> (length name) 0)
636 (or (not key)
637 (get-language-info name key)))
638 name)))
639 \f
640 ;;; Multilingual input methods.
641
642 (defconst leim-list-file-name "leim-list.el"
643 "Name of LEIM list file.
644 This file contains a list of libraries of Emacs input methods (LEIM)
645 in the format of Lisp expression for registering each input method.
646 Emacs loads this file at startup time.")
647
648 (defvar leim-list-header (format "\
649 ;;; %s -- list of LEIM (Library of Emacs Input Method)
650 ;;
651 ;; This file contains a list of LEIM (Library of Emacs Input Method)
652 ;; in the same directory as this file. Loading this file registeres
653 ;; the whole input methods in Emacs.
654 ;;
655 ;; Each entry has the form:
656 ;; (register-input-method
657 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC
658 ;; TITLE DESCRIPTION
659 ;; ARG ...)
660 ;; See the function `register-input-method' for the meanings of arguments.
661 ;;
662 ;; If this directory is included in load-path, Emacs automatically
663 ;; loads this file at startup time.
664
665 "
666 leim-list-file-name)
667 "Header to be inserted in LEIM list file.")
668
669 (defvar leim-list-entry-regexp "^(register-input-method"
670 "Regexp matching head of each entry in LEIM list file.
671 See also the variable `leim-list-header'")
672
673 (defvar update-leim-list-functions
674 '(quail-update-leim-list-file)
675 "List of functions to call to update LEIM list file.
676 Each function is called with one arg, LEIM directory name.")
677
678 (defun update-leim-list-file (&rest dirs)
679 "Update LEIM list file in directories DIRS."
680 (let ((functions update-leim-list-functions))
681 (while functions
682 (apply (car functions) dirs)
683 (setq functions (cdr functions)))))
684
685 (defvar current-input-method nil
686 "The current input method for multilingual text.
687 If nil, that means no input method is activated now.")
688 (make-variable-buffer-local 'current-input-method)
689 (put 'current-input-method 'permanent-local t)
690
691 (defvar current-input-method-title nil
692 "Title string of the current input method shown in mode line.")
693 (make-variable-buffer-local 'current-input-method-title)
694 (put 'current-input-method-title 'permanent-local t)
695
696 (defcustom default-input-method nil
697 "*Default input method for multilingual text (a string).
698 This is the input method activated automatically by the command
699 `toggle-input-method' (\\[toggle-input-method])."
700 :group 'mule
701 :type 'string)
702
703 (defvar input-method-history nil
704 "History list for some commands that read input methods.")
705 (make-variable-buffer-local 'input-method-history)
706 (put 'input-method-history 'permanent-local t)
707
708 (defvar inactivate-current-input-method-function nil
709 "Function to call for inactivating the current input method.
710 Every input method should set this to an appropriate value when activated.
711 This function is called with no argument.
712
713 This function should never change the value of `current-input-method'.
714 It is set to nil by the function `inactivate-input-method'.")
715 (make-variable-buffer-local 'inactivate-current-input-method-function)
716 (put 'inactivate-current-input-method-function 'permanent-local t)
717
718 (defvar describe-current-input-method-function nil
719 "Function to call for describing the current input method.
720 This function is called with no argument.")
721 (make-variable-buffer-local 'describe-current-input-method-function)
722 (put 'describe-current-input-method-function 'permanent-local t)
723
724 (defvar input-method-alist nil
725 "Alist of input method names vs how to use them.
726 Each element has the form:
727 (INPUT-METHOD LANGUAGE-ENV ACTIVATE-FUNC TITLE DESCRIPTION ARGS...)
728 See the function `register-input-method' for the meanings of the elements.")
729
730 (defun register-input-method (input-method lang-env &rest args)
731 "Register INPUT-METHOD as an input method for language environment ENV.
732 INPUT-METHOD and LANG-ENV are symbols or strings.
733
734 The remaining arguments are:
735 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARGS...
736 ACTIVATE-FUNC is a function to call to activate this method.
737 TITLE is a string to show in the mode line when this method is active.
738 DESCRIPTION is a string describing this method and what it is good for.
739 The ARGS, if any, are passed as arguments to ACTIVATE-FUNC.
740 All told, the arguments to ACTIVATE-FUNC are INPUT-METHOD and the ARGS."
741 (if (symbolp lang-env)
742 (setq lang-env (symbol-name lang-env)))
743 (if (symbolp input-method)
744 (setq input-method (symbol-name input-method)))
745 (let ((info (cons lang-env args))
746 (slot (assoc input-method input-method-alist)))
747 (if slot
748 (setcdr slot info)
749 (setq slot (cons input-method info))
750 (setq input-method-alist (cons slot input-method-alist)))))
751
752 (defun read-input-method-name (prompt &optional default inhibit-null)
753 "Read a name of input method from a minibuffer prompting with PROMPT.
754 If DEFAULT is non-nil, use that as the default,
755 and substitute it into PROMPT at the first `%s'.
756 If INHIBIT-NULL is non-nil, null input signals an error.
757
758 The return value is a string."
759 (if default
760 (setq prompt (format prompt default)))
761 (let* ((completion-ignore-case t)
762 ;; This binding is necessary because input-method-history is
763 ;; buffer local.
764 (input-method (completing-read prompt input-method-alist
765 nil t nil 'input-method-history
766 default)))
767 (if (> (length input-method) 0)
768 input-method
769 (if inhibit-null
770 (error "No valid input method is specified")))))
771
772 (defun activate-input-method (input-method)
773 "Switch to input method INPUT-METHOD for the current buffer.
774 If some other input method is already active, turn it off first.
775 If INPUT-METHOD is nil, deactivate any current input method."
776 (if (symbolp input-method)
777 (setq input-method (symbol-name input-method)))
778 (if (and current-input-method
779 (not (string= current-input-method input-method)))
780 (inactivate-input-method))
781 (unless (or current-input-method (null input-method))
782 (let ((slot (assoc input-method input-method-alist)))
783 (if (null slot)
784 (error "Can't activate input method `%s'" input-method))
785 (let ((func (nth 2 slot)))
786 (if (functionp func)
787 (apply (nth 2 slot) input-method (nthcdr 5 slot))
788 (if (and (consp func) (symbolp (car func)) (symbolp (cdr func)))
789 (progn
790 (require (cdr func))
791 (apply (car func) input-method (nthcdr 5 slot)))
792 (error "Can't activate input method `%s'" input-method))))
793 (setq current-input-method input-method)
794 (setq current-input-method-title (nth 3 slot))
795 (unwind-protect
796 (run-hooks 'input-method-activate-hook)
797 (force-mode-line-update)))))
798
799 (defun inactivate-input-method ()
800 "Turn off the current input method."
801 (when current-input-method
802 (if input-method-history
803 (unless (string= current-input-method (car input-method-history))
804 (setq input-method-history
805 (cons current-input-method
806 (delete current-input-method input-method-history))))
807 (setq input-method-history (list current-input-method)))
808 (unwind-protect
809 (funcall inactivate-current-input-method-function)
810 (unwind-protect
811 (run-hooks 'input-method-inactivate-hook)
812 (setq current-input-method nil
813 current-input-method-title nil)
814 (force-mode-line-update)))))
815
816 (defun set-input-method (input-method)
817 "Select and activate input method INPUT-METHOD for the current buffer.
818 This also sets the default input method to the one you specify."
819 (interactive
820 (let* ((default (or (car input-method-history) default-input-method)))
821 (list (read-input-method-name
822 (if default "Select input method (default %s): " "Select input method: ")
823 default t))))
824 (activate-input-method input-method)
825 (setq default-input-method input-method))
826
827 (defun toggle-input-method (&optional arg)
828 "Turn on or off a multilingual text input method for the current buffer.
829
830 With no prefix argument, if some input method is currently activated,
831 turn it off. Otherwise, activate an input method--the one most recently used,
832 or the one specified in `default-input-method', or one read from the
833 minibuffer.
834
835 With a prefix arg, read an input method from minibuffer and turn it on.
836 The default is the most recent input method specified
837 \(not including the currently active input method, if any).
838
839 When there's no input method to turn on, turn on what read from minibuffer."
840 (interactive "P")
841 (if (and current-input-method (not arg))
842 (inactivate-input-method)
843 (let ((default (or (car input-method-history) default-input-method)))
844 (if (and arg default (equal current-input-method default)
845 (> (length input-method-history) 1))
846 (setq default (nth 1 input-method-history)))
847 (activate-input-method
848 (if (or arg (not default))
849 (progn
850 (read-input-method-name
851 (if default "Input method (default %s): " "Input method: " )
852 default t))
853 default))
854 (or default-input-method
855 (setq default-input-method current-input-method)))))
856
857 (defun describe-input-method (input-method)
858 "Describe input method INPUT-METHOD."
859 (interactive
860 (list (read-input-method-name
861 "Describe input method (default, current choice): ")))
862 (if (and input-method (symbolp input-method))
863 (setq input-method (symbol-name input-method)))
864 (if (null input-method)
865 (describe-current-input-method)
866 (with-output-to-temp-buffer "*Help*"
867 (let ((elt (assoc input-method input-method-alist)))
868 (princ (format "Input method: %s (`%s' in mode line) for %s\n %s\n"
869 input-method (nth 3 elt) (nth 1 elt) (nth 4 elt)))))))
870
871 (defun describe-current-input-method ()
872 "Describe the input method currently in use."
873 (if current-input-method
874 (if (and (symbolp describe-current-input-method-function)
875 (fboundp describe-current-input-method-function))
876 (funcall describe-current-input-method-function)
877 (message "No way to describe the current input method `%s'"
878 (cdr current-input-method))
879 (ding))
880 (error "No input method is activated now")))
881
882 (defun read-multilingual-string (prompt &optional initial-input input-method)
883 "Read a multilingual string from minibuffer, prompting with string PROMPT.
884 The input method selected last time is activated in minibuffer.
885 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
886 initially.
887 Optional 3rd argument INPUT-METHOD specifies the input method
888 to be activated instead of the one selected last time. It is a symbol
889 or a string."
890 (setq input-method
891 (or input-method
892 current-input-method
893 default-input-method
894 (read-input-method-name "Input method: " nil t)))
895 (if (and input-method (symbolp input-method))
896 (setq input-method (symbol-name input-method)))
897 (let ((current-input-method input-method))
898 (read-string prompt initial-input nil nil t)))
899
900 ;; Variables to control behavior of input methods. All input methods
901 ;; should react to these variables.
902
903 (defcustom input-method-verbose-flag 'default
904 "*A flag to control extra guidance given by input methods.
905 The value should be nil, t, `complex-only', or `default'.
906
907 The extra guidance is done by showing list of available keys in echo
908 area. When you use the input method in the minibuffer, the guidance
909 is shown at the bottom short window (split from the existing window).
910
911 If the value is t, extra guidance is always given, if the value is
912 nil, extra guidance is always suppressed.
913
914 If the value is `complex-only', only complex input methods such as
915 `chinese-py' and `japanese' give extra guidance.
916
917 If the value is `default', complex input methods always give extra
918 guidance, but simple input methods give it only when you are not in
919 the minibuffer.
920
921 See also the variable `input-method-highlight-flag'."
922 :type '(choice (const t) (const nil) (const complex-only) (const default))
923 :group 'mule)
924
925 (defcustom input-method-highlight-flag t
926 "*If this flag is non-nil, input methods highlight partially-entered text.
927 For instance, while you are in the middle of a Quail input method sequence,
928 the text inserted so far is temporarily underlined.
929 The underlining goes away when you finish or abort the input method sequence.
930 See also the variable `input-method-verbose-flag'."
931 :type 'boolean
932 :group 'mule)
933
934 (defvar input-method-activate-hook nil
935 "Normal hook run just after an input method is activated.
936
937 The variable `current-input-method' keeps the input method name
938 just activated.")
939
940 (defvar input-method-inactivate-hook nil
941 "Normal hook run just after an input method is inactivated.
942
943 The variable `current-input-method' still keeps the input method name
944 just inactivated.")
945
946 (defvar input-method-after-insert-chunk-hook nil
947 "Normal hook run just after an input method insert some chunk of text.")
948
949 (defvar input-method-exit-on-first-char nil
950 "This flag controls a timing when an input method returns.
951 Usually, the input method does not return while there's a possibility
952 that it may find a different translation if a user types another key.
953 But, it this flag is non-nil, the input method returns as soon as
954 the current key sequence gets long enough to have some valid translation.")
955
956 (defvar input-method-use-echo-area nil
957 "This flag controls how an input method shows an intermediate key sequence.
958 Usually, the input method inserts the intermediate key sequence,
959 or candidate translations corresponding to the sequence,
960 at point in the current buffer.
961 But, if this flag is non-nil, it displays them in echo area instead.")
962
963 (defvar input-method-exit-on-invalid-key nil
964 "This flag controls the behaviour of an input method on invalid key input.
965 Usually, when a user types a key which doesn't start any character
966 handled by the input method, the key is handled by turning off the
967 input method temporarily. After that key, the input method is renabled.
968 But, if this flag is non-nil, the input method is never back on.")
969
970 \f
971 (defvar set-language-environment-hook nil
972 "Normal hook run after some language environment is set.
973
974 When you set some hook function here, that effect usually should not
975 be inherited to another language environment. So, you had better set
976 another function in `exit-language-environment-hook' (which see) to
977 cancel the effect.")
978
979 (defvar exit-language-environment-hook nil
980 "Normal hook run after exiting from some language environment.
981 When this hook is run, the variable `current-language-environment'
982 is still bound to the language environment being exited.
983
984 This hook is mainly used for cancelling the effect of
985 `set-language-environment-hook' (which-see).")
986
987 (defun setup-specified-language-environment ()
988 "Switch to a specified language environment."
989 (interactive)
990 (let (language-name)
991 (if (and (symbolp last-command-event)
992 (or (not (eq last-command-event 'Default))
993 (setq last-command-event 'English))
994 (setq language-name (symbol-name last-command-event)))
995 (set-language-environment language-name)
996 (error "Bogus calling sequence"))))
997
998 (defcustom current-language-environment "English"
999 "The last language environment specified with `set-language-environment'."
1000 :set 'set-language-environment
1001 :initialize 'custom-initialize-default
1002 :group 'mule
1003 :type 'string)
1004
1005 (defun reset-language-environment ()
1006 "Reset multilingual environment of Emacs to the default status.
1007
1008 The default status is as follows:
1009
1010 The default value of buffer-file-coding-system is nil.
1011 The default coding system for process I/O is nil.
1012 The default value for the command `set-terminal-coding-system' is nil.
1013 The default value for the command `set-keyboard-coding-system' is nil.
1014
1015 The order of priorities of coding categories and the coding system
1016 bound to each category are as follows
1017 coding category coding system
1018 --------------------------------------------------
1019 coding-category-iso-8-2 iso-latin-1
1020 coding-category-iso-8-1 iso-latin-1
1021 coding-category-iso-7-tight iso-2022-jp
1022 coding-category-iso-7 iso-2022-7bit
1023 coding-category-iso-7-else iso-2022-7bit-lock
1024 coding-category-iso-8-else iso-2022-8bit-ss2
1025 coding-category-emacs-mule emacs-mule
1026 coding-category-raw-text raw-text
1027 coding-category-sjis japanese-shift-jis
1028 coding-category-big5 chinese-big5
1029 coding-category-ccl nil
1030 coding-category-binarry no-conversion
1031 "
1032 (interactive)
1033 ;; This function formerly set default-enable-multibyte-characters to t,
1034 ;; but that is incorrect. It should not alter the unibyte/multibyte choice.
1035
1036 (setq coding-category-iso-7-tight 'iso-2022-jp
1037 coding-category-iso-7 'iso-2022-7bit
1038 coding-category-iso-8-1 'iso-latin-1
1039 coding-category-iso-8-2 'iso-latin-1
1040 coding-category-iso-7-else 'iso-2022-7bit-lock
1041 coding-category-iso-8-else 'iso-2022-8bit-ss2
1042 coding-category-emacs-mule 'emacs-mule
1043 coding-category-raw-text 'raw-text
1044 coding-category-sjis 'japanese-shift-jis
1045 coding-category-big5 'chinese-big5
1046 coding-category-ccl nil
1047 coding-category-binary 'no-conversion)
1048
1049 (set-coding-priority
1050 '(coding-category-iso-8-1
1051 coding-category-iso-8-2
1052 coding-category-iso-7-tight
1053 coding-category-iso-7
1054 coding-category-iso-7-else
1055 coding-category-iso-8-else
1056 coding-category-emacs-mule
1057 coding-category-raw-text
1058 coding-category-sjis
1059 coding-category-big5
1060 coding-category-ccl
1061 coding-category-binary))
1062
1063 (set-default-coding-systems nil)
1064 ;; Don't alter the terminal and keyboard coding systems here.
1065 ;; The terminal still supports the same coding system
1066 ;; that it supported a minute ago.
1067 ;;; (set-terminal-coding-system-internal nil)
1068 ;;; (set-keyboard-coding-system-internal nil)
1069
1070 (setq nonascii-translation-table nil
1071 nonascii-insert-offset 0))
1072
1073 (defun set-language-environment (language-name)
1074 "Set up multi-lingual environment for using LANGUAGE-NAME.
1075 This sets the coding system priority and the default input method
1076 and sometimes other things. LANGUAGE-NAME should be a string
1077 which is the name of a language environment. For example, \"Latin-1\"
1078 specifies the character set for the major languages of Western Europe."
1079 (interactive (list (read-language-name
1080 nil
1081 "Set language environment (default, English): ")))
1082 (if language-name
1083 (if (symbolp language-name)
1084 (setq language-name (symbol-name language-name)))
1085 (setq language-name "English"))
1086 (or (assoc-ignore-case language-name language-info-alist)
1087 (error "Language environment not defined: %S" language-name))
1088 (if current-language-environment
1089 (let ((func (get-language-info current-language-environment
1090 'exit-function)))
1091 (run-hooks 'exit-language-environment-hook)
1092 (if (fboundp func) (funcall func))))
1093 (reset-language-environment)
1094
1095 (setq current-language-environment language-name)
1096 (set-language-environment-coding-systems language-name)
1097 (let ((input-method (get-language-info language-name 'input-method)))
1098 (when input-method
1099 (setq default-input-method input-method)
1100 (if input-method-history
1101 (setq input-method-history
1102 (cons input-method
1103 (delete input-method input-method-history))))))
1104 (let ((nonascii (get-language-info language-name 'nonascii-translation)))
1105 (if (char-table-p nonascii)
1106 (setq nonascii-translation-table nonascii)
1107 (if (charsetp nonascii)
1108 (setq nonascii-insert-offset (- (make-char nonascii) 128)))))
1109
1110 (setq charset-origin-alist
1111 (get-language-info language-name 'charset-origin-alist))
1112
1113 (unless default-enable-multibyte-characters
1114 ;; Unibyte setups.
1115 (let ((syntax (get-language-info language-name 'unibyte-syntax)))
1116 (if syntax
1117 (let ((set-case-syntax-set-multibyte nil))
1118 (load syntax nil t)
1119 (set-standard-case-table (standard-case-table))
1120 (let ((list (buffer-list)))
1121 (while list
1122 (with-current-buffer (car list)
1123 (set-case-table (standard-case-table)))
1124 (setq list (cdr list)))))))
1125 (let ((coding (get-language-info language-name 'unibyte-display)))
1126 (if coding
1127 (progn
1128 (standard-display-european-internal)
1129 (set-terminal-coding-system coding))
1130 (standard-display-default 160 255)
1131 (aset standard-display-table 146 nil)
1132 (set-terminal-coding-system nil))))
1133
1134 (let ((required-features (get-language-info language-name 'features)))
1135 (while required-features
1136 (require (car required-features))
1137 (setq required-features (cdr required-features))))
1138 (let ((func (get-language-info language-name 'setup-function)))
1139 (if (fboundp func)
1140 (funcall func)))
1141 (run-hooks 'set-language-environment-hook)
1142 (force-mode-line-update t))
1143
1144 (defun standard-display-european-internal ()
1145 ;; Actually set up direct output of non-ASCII characters.
1146 (standard-display-8bit 160 255)
1147 ;; Make non-line-break space display as a plain space.
1148 ;; Most X fonts do the wrong thing for code 160.
1149 (aset standard-display-table 160 [32])
1150 ;; Most Windows programs send out apostrophe's as \222. Most X fonts
1151 ;; don't contain a character at that position. Map it to the ASCII
1152 ;; apostrophe.
1153 (aset standard-display-table 146 [39]))
1154
1155 (defun set-language-environment-coding-systems (language-name)
1156 "Do various coding system setups for language environment LANGUAGE-NAME."
1157 (let* ((priority (get-language-info language-name 'coding-priority))
1158 (default-coding (car priority)))
1159 (if priority
1160 (let ((categories (mapcar 'coding-system-category priority)))
1161 (set-default-coding-systems default-coding)
1162 (set-coding-priority categories)
1163 (while priority
1164 (set (car categories) (car priority))
1165 (setq priority (cdr priority) categories (cdr categories)))
1166 (update-coding-systems-internal)))))
1167
1168 ;; Print all arguments with `princ', then print "\n".
1169 (defsubst princ-list (&rest args)
1170 (while args (princ (car args)) (setq args (cdr args)))
1171 (princ "\n"))
1172
1173 ;; Print a language specific information such as input methods,
1174 ;; charsets, and coding systems. This function is intended to be
1175 ;; called from the menu:
1176 ;; [menu-bar mule describe-language-environment LANGUAGE]
1177 ;; and should not run it by `M-x describe-current-input-method-function'.
1178 (defun describe-specified-language-support ()
1179 "Describe how Emacs supports the specified language environment."
1180 (interactive)
1181 (let (language-name)
1182 (if (not (and (symbolp last-command-event)
1183 (setq language-name (symbol-name last-command-event))))
1184 (error "Bogus calling sequence"))
1185 (describe-language-environment language-name)))
1186
1187 (defun describe-language-environment (language-name)
1188 "Describe how Emacs supports language environment LANGUAGE-NAME."
1189 (interactive
1190 (list (read-language-name
1191 'documentation
1192 "Describe language environment (default, current choice): ")))
1193 (if (null language-name)
1194 (setq language-name current-language-environment))
1195 (if (or (null language-name)
1196 (null (get-language-info language-name 'documentation)))
1197 (error "No documentation for the specified language"))
1198 (if (symbolp language-name)
1199 (setq language-name (symbol-name language-name)))
1200 (let ((doc (get-language-info language-name 'documentation)))
1201 (with-output-to-temp-buffer "*Help*"
1202 (princ-list language-name " language environment" "\n")
1203 (if (stringp doc)
1204 (progn
1205 (princ-list doc)
1206 (terpri)))
1207 (let ((str (get-language-info language-name 'sample-text)))
1208 (if (stringp str)
1209 (progn
1210 (princ "Sample text:\n")
1211 (princ-list " " str)
1212 (terpri))))
1213 (let ((input-method (get-language-info language-name 'input-method))
1214 (l input-method-alist))
1215 (princ "Input methods")
1216 (when input-method
1217 (princ (format " (default, %s)" input-method))
1218 (setq input-method (assoc input-method input-method-alist))
1219 (setq l (cons input-method (delete input-method l))))
1220 (princ ":\n")
1221 (while l
1222 (if (string= language-name (nth 1 (car l)))
1223 (princ-list " " (car (car l))
1224 (format " (`%s' in mode line)" (nth 3 (car l)))))
1225 (setq l (cdr l))))
1226 (terpri)
1227 (princ "Character sets:\n")
1228 (let ((l (get-language-info language-name 'charset)))
1229 (if (null l)
1230 (princ-list " nothing specific to " language-name)
1231 (while l
1232 (princ-list " " (car l) ": "
1233 (charset-description (car l)))
1234 (setq l (cdr l)))))
1235 (terpri)
1236 (princ "Coding systems:\n")
1237 (let ((l (get-language-info language-name 'coding-system)))
1238 (if (null l)
1239 (princ-list " nothing specific to " language-name)
1240 (while l
1241 (princ (format " %s (`%c' in mode line):\n\t%s\n"
1242 (car l)
1243 (coding-system-mnemonic (car l))
1244 (coding-system-doc-string (car l))))
1245 (let ((aliases (coding-system-get (car l) 'alias-coding-systems)))
1246 (when aliases
1247 (princ "\t")
1248 (princ (cons 'alias: (cdr aliases)))
1249 (terpri)))
1250 (setq l (cdr l))))))))
1251 \f
1252 ;;; Charset property
1253
1254 (defsubst get-charset-property (charset propname)
1255 "Return the value of CHARSET's PROPNAME property.
1256 This is the last value stored with
1257 (put-charset-property CHARSET PROPNAME VALUE)."
1258 (plist-get (charset-plist charset) propname))
1259
1260 (defsubst put-charset-property (charset propname value)
1261 "Store CHARSETS's PROPNAME property with value VALUE.
1262 It can be retrieved with `(get-charset-property CHARSET PROPNAME)'."
1263 (set-charset-plist charset
1264 (plist-put (charset-plist charset) propname value)))
1265
1266 ;;; Character code property
1267 (put 'char-code-property-table 'char-table-extra-slots 0)
1268
1269 (defvar char-code-property-table
1270 (make-char-table 'char-code-property-table)
1271 "Char-table containing a property list of each character code.
1272
1273 See also the documentation of `get-char-code-property' and
1274 `put-char-code-property'.")
1275
1276 (defun get-char-code-property (char propname)
1277 "Return the value of CHAR's PROPNAME property in `char-code-property-table'."
1278 (let ((plist (aref char-code-property-table char)))
1279 (if (listp plist)
1280 (car (cdr (memq propname plist))))))
1281
1282 (defun put-char-code-property (char propname value)
1283 "Store CHAR's PROPNAME property with VALUE in `char-code-property-table'.
1284 It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
1285 (let ((plist (aref char-code-property-table char)))
1286 (if plist
1287 (let ((slot (memq propname plist)))
1288 (if slot
1289 (setcar (cdr slot) value)
1290 (nconc plist (list propname value))))
1291 (aset char-code-property-table char (list propname value)))))
1292
1293 ;;; mule-cmds.el ends here