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