(read-input-method-name): Replace INITIAL-INPUT arg with DEFAULT arg.
[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 nil
30 "Keymap for MULE (Multilingual environment) specific commands.")
31 (define-prefix-command 'mule-keymap)
32
33 ;; Keep "C-x C-m ..." for mule specific commands.
34 (define-key ctl-x-map "\C-m" 'mule-keymap)
35
36 (define-key mule-keymap "m" 'toggle-enable-multibyte-characters)
37 (define-key mule-keymap "f" 'set-buffer-file-coding-system)
38 (define-key mule-keymap "t" 'set-terminal-coding-system)
39 (define-key mule-keymap "k" 'set-keyboard-coding-system)
40 (define-key mule-keymap "p" 'set-buffer-process-coding-system)
41 (define-key mule-keymap "\C-\\" 'select-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 nil
53 "Keymap for MULE (Multilingual environment) menu specific commands.")
54 (define-prefix-command 'mule-menu-keymap)
55
56 (define-key global-map [menu-bar mule] (cons "Mule" mule-menu-keymap))
57
58 (setq menu-bar-final-items (cons 'mule menu-bar-final-items))
59
60 (defvar describe-language-environment-map nil)
61 (define-prefix-command 'describe-language-environment-map)
62
63 (defvar setup-language-environment-map nil)
64 (define-prefix-command 'setup-language-environment-map)
65
66 (defvar set-coding-system-map nil)
67 (define-prefix-command 'set-coding-system-map)
68
69 (define-key-after mule-menu-keymap [toggle-mule]
70 '("Toggle Multibyte Characters" . toggle-enable-multibyte-characters)
71 t)
72 (define-key-after mule-menu-keymap [describe-language-environment]
73 '("Describe Language Environment" . describe-language-environment-map)
74 t)
75 (define-key-after mule-menu-keymap [set-language-environment]
76 '("Set Language Environment" . setup-language-environment-map)
77 t)
78 (define-key-after mule-menu-keymap [mouse-set-font]
79 '("Set Font/Fontset" . mouse-set-font)
80 t)
81 (define-key-after mule-menu-keymap [separator-mule]
82 '("--")
83 t)
84 (define-key-after mule-menu-keymap [toggle-input-method]
85 '("Toggle Input Method" . toggle-input-method)
86 t)
87 (define-key-after mule-menu-keymap [select-input-method]
88 '("Select Input Method" . select-input-method)
89 t)
90 (define-key-after mule-menu-keymap [describe-input-method]
91 '("Describe Input Method" . describe-input-method)
92 t)
93 (define-key-after mule-menu-keymap [separator-input-method]
94 '("--")
95 t)
96 (define-key-after mule-menu-keymap [describe-coding-system]
97 '("Describe Coding Systems" . describe-coding-system)
98 t)
99 (define-key-after mule-menu-keymap [set-various-coding-system]
100 '("Set Coding System" . set-coding-system-map)
101 t)
102 (define-key-after mule-menu-keymap [separator-coding-system]
103 '("--")
104 t)
105 (define-key-after mule-menu-keymap [mule-diag]
106 '("Show All of MULE Status" . mule-diag)
107 t)
108 (define-key-after mule-menu-keymap [view-hello-file]
109 '("Show Script Examples" . view-hello-file)
110 t)
111
112 (define-key-after set-coding-system-map [set-buffer-file-coding-system]
113 '("Buffer File" . set-buffer-file-coding-system)
114 t)
115 (define-key-after set-coding-system-map [set-terminal-coding-system]
116 '("Terminal" . set-terminal-coding-system)
117 t)
118 (define-key-after set-coding-system-map [set-keyboard-coding-system]
119 '("Keyboard" . set-keyboard-coding-system)
120 t)
121 (define-key-after set-coding-system-map [set-buffer-process-coding-system]
122 '("Buffer Process" . set-buffer-process-coding-system)
123 t)
124
125 (define-key setup-language-environment-map
126 [Default] '("Default" . setup-specified-language-environment))
127
128 ;; These are meaningless when running under X.
129 (put 'set-terminal-coding-system 'menu-enable
130 '(null window-system))
131 (put 'set-keyboard-coding-system 'menu-enable
132 '(null window-system))
133 ;; This is meaningless when the current buffer has no process.
134 (put 'set-buffer-process-coding-system 'menu-enable
135 '(get-buffer-process (current-buffer)))
136
137 ;; This should be a single character key binding because users use it
138 ;; very frequently while editing multilingual text. Now we can use
139 ;; only two such keys: "\C-\\" and "\C-^", but the latter is not
140 ;; convenient because it requires shifting on most keyboards. An
141 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit'
142 ;; but it won't be used that frequently.
143 (define-key global-map "\C-\\" 'toggle-input-method)
144
145 ;;; This is no good because people often type Shift-SPC
146 ;;; meaning to type SPC. -- rms.
147 ;;; ;; Here's an alternative key binding for X users (Shift-SPACE).
148 ;;; (define-key global-map [?\S- ] 'toggle-input-method)
149
150 (defun toggle-enable-multibyte-characters (&optional arg)
151 "Change whether this buffer enables multibyte characters.
152 With arg, make them enable iff arg is positive."
153 (interactive "P")
154 (setq enable-multibyte-characters
155 (if (null arg) (null enable-multibyte-characters)
156 (> (prefix-numeric-value arg) 0)))
157 (force-mode-line-update))
158
159 (defun view-hello-file ()
160 "Display the HELLO file which list up many languages and characters."
161 (interactive)
162 ;; We have to decode the file in any environment.
163 (let ((default-enable-multibyte-characters t)
164 (coding-system-for-read 'iso-2022-7bit))
165 (find-file-read-only (expand-file-name "HELLO" data-directory))))
166
167 (defun universal-coding-system-argument ()
168 "Execute an I/O command using the specified coding system."
169 (interactive)
170 (let* ((coding-system (read-coding-system "Coding system: "))
171 (keyseq (read-key-sequence
172 (format "With coding system %s:" coding-system)))
173 (cmd (key-binding keyseq)))
174 (let ((coding-system-for-read coding-system)
175 (coding-system-for-write coding-system))
176 (message "")
177 (call-interactively cmd))))
178
179 (defun set-default-coding-systems (coding-system)
180 "Set default value of various coding systems to CODING-SYSTEM.
181 The follwing coding systems are set:
182 o coding system of a newly created buffer
183 o default coding system for terminal output
184 o default coding system for keyboard input
185 o default coding system for subprocess I/O"
186 (check-coding-system coding-system)
187 (setq-default buffer-file-coding-system coding-system)
188 (setq default-terminal-coding-system coding-system)
189 (setq default-keyboard-coding-system coding-system)
190 (setq default-process-coding-system (cons coding-system coding-system)))
191
192 (defun prefer-coding-system (coding-system)
193 "Add CODING-SYSTEM at the front of the priority list for automatic detection.
194 This also sets the following coding systems to CODING-SYSTEM:
195 o coding system of a newly created buffer
196 o default coding system for terminal output
197 o default coding system for keyboard input
198 o default coding system for subprocess I/O"
199 (interactive "zPrefer coding system: ")
200 (if (not (and coding-system (coding-system-p coding-system)))
201 (error "Invalid coding system `%s'" coding-system))
202 (let ((coding-category (coding-system-category coding-system))
203 (parent (coding-system-parent coding-system)))
204 (if (not coding-category)
205 ;; CODING-SYSTEM is no-conversion or undecided.
206 (error "Can't prefer the coding system `%s'" coding-system))
207 (set coding-category (or parent coding-system))
208 (if (not (eq coding-category (car coding-category-list)))
209 ;; We must change the order.
210 (setq coding-category-list
211 (cons coding-category
212 (delq coding-category coding-category-list))))
213 (if (and parent (interactive-p))
214 (message "Highest priority is set to %s (parent of %s)"
215 parent coding-system))
216 (set-default-coding-systems (or parent coding-system))))
217
218 \f
219 ;;; Language support staffs.
220
221 (defvar primary-language "English"
222 "Name of a user's primary language.
223 Emacs provide various language supports based on this variable.")
224
225 (defvar language-info-alist nil
226 "Alist of language names vs the corresponding information of various kind.
227 Each element looks like:
228 (LANGUAGE-NAME . ((KEY . INFO) ...))
229 where LANGUAGE-NAME is a string,
230 KEY is a symbol denoting the kind of information,
231 INFO is any Lisp object which contains the actual information related
232 to KEY.")
233
234 (defun get-language-info (language-name key)
235 "Return the information for LANGUAGE-NAME of the kind KEY.
236 LANGUAGE-NAME is a string.
237 KEY is a symbol denoting the kind of required information."
238 (let ((lang-slot (assoc-ignore-case language-name language-info-alist)))
239 (if lang-slot
240 (cdr (assq key (cdr lang-slot))))))
241
242 (defun set-language-info (language-name key info)
243 "Set for LANGUAGE-NAME the information INFO under KEY.
244 LANGUAGE-NAME is a string
245 KEY is a symbol denoting the kind of information.
246 INFO is any Lisp object which contains the actual information.
247
248 Currently, the following KEYs are used by Emacs:
249
250 charset: list of symbols whose values are charsets specific to the language.
251
252 coding-system: list of coding systems specific to the langauge.
253
254 tutorial: a tutorial file name written in the language.
255
256 sample-text: one line short text containing characters of the language.
257
258 documentation: t or a string describing how Emacs supports the language.
259 If a string is specified, it is shown before any other information
260 of the language by the command `describe-language-environment'.
261
262 setup-function: a function to call for setting up environment
263 convenient for a user of the language.
264
265 If KEY is documentation or setup-function, you can also specify
266 a cons cell as INFO, in which case, the car part should be
267 a normal value as INFO for KEY (as described above),
268 and the cdr part should be a symbol whose value is a menu keymap
269 in which an entry for the language is defined. But, only the car part
270 is actually set as the information.
271
272 We will define more KEYs in the future. To avoid conflict,
273 if you want to use your own KEY values, make them start with `user-'."
274 (let (lang-slot key-slot)
275 (setq lang-slot (assoc language-name language-info-alist))
276 (if (null lang-slot) ; If no slot for the language, add it.
277 (setq lang-slot (list language-name)
278 language-info-alist (cons lang-slot language-info-alist)))
279 (setq key-slot (assq key lang-slot))
280 (if (null key-slot) ; If no slot for the key, add it.
281 (progn
282 (setq key-slot (list key))
283 (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
284 ;; Setup menu.
285 (cond ((eq key 'documentation)
286 (define-key-after
287 (if (consp info)
288 (prog1 (symbol-value (cdr info))
289 (setq info (car info)))
290 describe-language-environment-map)
291 (vector (intern language-name))
292 (cons language-name 'describe-specified-language-support)
293 t))
294 ((eq key 'setup-function)
295 (define-key-after
296 (if (consp info)
297 (prog1 (symbol-value (cdr info))
298 (setq info (car info)))
299 setup-language-environment-map)
300 (vector (intern language-name))
301 (cons language-name 'setup-specified-language-environment)
302 t)))
303
304 (setcdr key-slot info)
305 ))
306
307 (defun set-language-info-alist (language-name alist)
308 "Set for LANGUAGE-NAME the information in ALIST.
309 ALIST is an alist of KEY and INFO. See the documentation of
310 `set-langauge-info' for the meanings of KEY and INFO."
311 (while alist
312 (set-language-info language-name (car (car alist)) (cdr (car alist)))
313 (setq alist (cdr alist))))
314
315 (defun read-language-name (key prompt &optional initial-input)
316 "Read language name which has information for KEY, prompting with PROMPT."
317 (let* ((completion-ignore-case t)
318 (name (completing-read prompt
319 language-info-alist
320 (function (lambda (elm) (assq key elm)))
321 t
322 initial-input)))
323 (if (and (> (length name) 0)
324 (get-language-info name key))
325 name)))
326 \f
327 ;;; Multilingual input methods.
328
329 (defconst leim-list-file-name "leim-list.el"
330 "Name of LEIM list file.
331 This file contains a list of libraries of Emacs input methods (LEIM)
332 in the format of Lisp expression for registering each input method.
333 Emacs loads this file at startup time.")
334
335 (defvar leim-list-header (format "\
336 ;;; %s -- list of LEIM (Library of Emacs Input Method)
337 ;;
338 ;; This file contains a list of LEIM (Library of Emacs Input Method)
339 ;; in the same directory as this file. Loading this file registeres
340 ;; the whole input methods in Emacs.
341 ;;
342 ;; Each entry has the form:
343 ;; (register-input-method
344 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC
345 ;; TITLE DESCRIPTION
346 ;; ARG ...)
347 ;; See the function `register-input-method' for the meanings of arguments.
348 ;;
349 ;; If this directory is included in load-path, Emacs automatically
350 ;; loads this file at startup time.
351
352 "
353 leim-list-file-name)
354 "Header to be inserted in LEIM list file.")
355
356 (defvar leim-list-entry-regexp "^(register-input-method"
357 "Regexp matching head of each entry in LEIM list file.
358 See also the variable `leim-list-header'")
359
360 (defvar update-leim-list-functions
361 '(quail-update-leim-list-file)
362 "List of functions to call to update LEIM list file.
363 Each function is called with one arg, LEIM directory name.")
364
365 (defun update-leim-list-file (dir)
366 "Update LEIM list file in directory DIR."
367 (let ((functions update-leim-list-functions))
368 (while functions
369 (funcall (car functions) (expand-file-name dir))
370 (setq functions (cdr functions)))))
371
372 (defun update-all-leim-list-files ()
373 "Update all the LEIM list files."
374 (interactive)
375 (let ((l load-path))
376 (while l
377 (if (string-match "leim" (car l))
378 (update-leim-list-file (car l)))
379 (setq l (cdr l)))))
380
381 (defvar current-input-method nil
382 "The current input method for multilingual text.
383 If nil, that means no input method is activated now.")
384 (make-variable-buffer-local 'current-input-method)
385 (put 'current-input-method 'permanent-local t)
386
387 (defvar current-input-method-title nil
388 "Title string of the current input method shown in mode line.")
389 (make-variable-buffer-local 'current-input-method-title)
390 (put 'current-input-method-title 'permanent-local t)
391
392 (defcustom default-input-method nil
393 "*Default input method for multilingual text.
394 This is the input method activated automatically by the command
395 `toggle-input-method' (\\[toggle-input-method]).
396 Automatically local in all buffers."
397 :group 'mule)
398
399 (make-variable-buffer-local 'default-input-method)
400 (put 'default-input-method 'permanent-local t)
401
402 (defvar previous-input-method nil
403 "Input method selected previously in the current buffer.
404 This is the one selected before the current input method is selected.
405 See also the documentation of `default-input-method'.")
406 (make-variable-buffer-local 'previous-input-method)
407 (put 'previous-input-method 'permanent-local t)
408
409 (defvar inactivate-current-input-method-function nil
410 "Function to call for inactivating the current input method.
411 Every input method should set this to an appropriate value when activated.
412 This function is called with no argument.")
413 (make-variable-buffer-local 'inactivate-current-input-method-function)
414 (put 'inactivate-current-input-method-function 'permanent-local t)
415
416 (defvar describe-current-input-method-function nil
417 "Function to call for describing the current input method.
418 This function is called with no argument.")
419 (make-variable-buffer-local 'describe-current-input-method-function)
420 (put 'describe-current-input-method-function 'permanent-local t)
421
422 (defvar input-method-alist nil
423 "Alist of input method names vs the corresponding information to use it.
424 Each element has the form:
425 (INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC TITLE DESCRIPTION ...)
426 See the function `register-input-method' for the meanings of each elements.")
427
428 (defun register-input-method (input-method language-name &rest args)
429 "Register INPUT-METHOD as an input method for LANGUAGE-NAME.
430 INPUT-METHOD and LANGUAGE-NAME are strings.
431 The remaining arguments are:
432 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARG ...
433 where,
434 ACTIVATE-FUNC is a function to call for activating this method.
435 TITLE is a string shown in mode-line while this method is active,
436 DESCRIPTION is a string describing about this method,
437 Arguments to ACTIVATE-FUNC are INPUT-METHOD and ARGs."
438 (let ((info (cons language-name args))
439 (slot (assoc input-method input-method-alist)))
440 (if slot
441 (setcdr slot info)
442 (setq slot (cons input-method info))
443 (setq input-method-alist (cons slot input-method-alist)))))
444
445 (defun read-input-method-name (prompt &optional default inhibit-null)
446 "Read a name of input method from a minibuffer prompting with PROMPT.
447 If DEFAULT is non-nil, use that as the default,
448 and substitute it into PROMPT at the first `%s'.
449 If INHIBIT-NULL is non-nil, null input signals an error."
450 (if default
451 (setq prompt (format prompt default)))
452 (let* ((completion-ignore-case t)
453 (input-method (completing-read prompt input-method-alist
454 nil t nil nil default)))
455 (if (> (length input-method) 0)
456 input-method
457 (if inhibit-null
458 (error "No valid input method is specified")))))
459
460 ;; Actvate INPUT-METHOD.
461 (defun activate-input-method (input-method)
462 (if (and current-input-method
463 (not (string= current-input-method input-method)))
464 (inactivate-input-method))
465 (if current-input-method
466 nil ; We have nothing to do.
467 (let ((slot (assoc input-method input-method-alist)))
468 (if (null slot)
469 (error "Invalid input method `%s'" input-method))
470 (apply (nth 2 slot) input-method (nthcdr 5 slot))
471 (setq current-input-method input-method)
472 (setq current-input-method-title (nth 3 slot))
473 (if (not (string= default-input-method current-input-method))
474 (setq previous-input-method default-input-method
475 default-input-method current-input-method)))))
476
477 ;; Inactivate the current input method.
478 (defun inactivate-input-method ()
479 (if current-input-method
480 (unwind-protect
481 (funcall inactivate-current-input-method-function)
482 (setq current-input-method nil))))
483
484 (defun select-input-method (input-method)
485 "Select and activate INPUT-METHOD.
486 This sets both the default and local values of `default-input-method'
487 to the input method you specify.
488 See also the function `register-input-method'."
489 (interactive
490 (let* ((default (or previous-input-method default-input-method)))
491 (if (not enable-multibyte-characters)
492 (error "Can't activate an input method while multibyte characters are disabled"))
493 (list (read-input-method-name "Input method (default %s): " default t))))
494 (activate-input-method input-method)
495 (setq-default default-input-method default-input-method))
496
497 (defun toggle-input-method (&optional arg)
498 "Turn on or off a multilingual text input method for the current buffer.
499 With arg, read an input method from minibuffer and turn it on.
500 Without arg, if some input method is currently activated, turn it off,
501 else turn on the default input method (see `default-input-method').
502 In the latter case, if default-input-method is nil, select an input method
503 interactively."
504 (interactive "P")
505 (let* ((default (or previous-input-method default-input-method)))
506 (if (and current-input-method (not arg))
507 (inactivate-input-method)
508 (if (not enable-multibyte-characters)
509 (error "Can't activate any input method while multibyte characters are disabled"))
510 (activate-input-method
511 (if (or arg (not default-input-method))
512 (read-input-method-name "Input method (default %s): " default t)
513 default-input-method)))))
514
515 (defun describe-input-method (input-method)
516 "Describe the current input method."
517 (interactive
518 (list (read-input-method-name
519 "Describe input method (default, current choice): ")))
520 (if (null input-method)
521 (describe-current-input-method)
522 (with-output-to-temp-buffer "*Help*"
523 (let ((elt (assoc input-method input-method-alist)))
524 (princ (format "Input method: %s (`%s' in mode line) for %s\n %s\n"
525 input-method (nth 3 elt) (nth 1 elt) (nth 4 elt)))))))
526
527 (defun describe-current-input-method ()
528 "Describe the input method currently in use."
529 (if current-input-method
530 (if (and (symbolp describe-current-input-method-function)
531 (fboundp describe-current-input-method-function))
532 (funcall describe-current-input-method-function)
533 (message "No way to describe the current input method `%s'"
534 (cdr current-input-method))
535 (ding))
536 (error "No input method is activated now")))
537
538 (defun read-multilingual-string (prompt &optional initial-input
539 input-method)
540 "Read a multilingual string from minibuffer, prompting with string PROMPT.
541 The input method selected last time is activated in minibuffer.
542 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
543 initially.
544 Optional 3rd argument INPUT-METHOD specifies the input method
545 to be activated instead of the one selected last time."
546 (setq input-method
547 (or input-method
548 default-input-method
549 (read-input-method-name "Input method: " nil t)))
550 (save-excursion
551 (set-buffer (window-buffer (minibuffer-window)))
552 (let ((default-input-method input-method)
553 (minibuffer-setup-hook '(toggle-input-method)))
554 (read-string prompt initial-input))))
555
556 ;; Variables to control behavior of input methods. All input methods
557 ;; should react to these variables.
558
559 (defvar input-method-tersely-flag nil
560 "*If this flag is non-nil, input method works rather tersely.
561
562 For instance, Quail input method does not show guidance buffer while
563 inputting at minibuffer if this flag is t.")
564
565 (defvar input-method-activate-hook nil
566 "Normal hook run just after an input method is activated.")
567
568 (defvar input-method-inactivate-hook nil
569 "Normal hook run just after an input method is inactivated.")
570
571 (defvar input-method-after-insert-chunk-hook nil
572 "Normal hook run just after an input method insert some chunk of text.")
573
574 \f
575 (defun setup-specified-language-environment ()
576 "Set up multi-lingual environment convenient for the specified language."
577 (interactive)
578 (let (language-name)
579 (if (and (symbolp last-command-event)
580 (or (not (eq last-command-event 'Default))
581 (setq last-command-event 'English))
582 (setq language-name (symbol-name last-command-event)))
583 (set-language-environment language-name)
584 (error "Bogus calling sequence"))))
585
586 (defvar current-language-environment "English"
587 "The last language environment specified with `set-language-environment'.")
588
589 (defun set-language-environment (language-name)
590 "Set up multi-lingual environment for using LANGUAGE-NAME.
591 This sets the coding system priority and the default input method
592 and sometimes other things."
593 (interactive (list (read-language-name 'setup-function
594 "Language (null for default): ")))
595 (or language-name
596 (setq language-name "English"))
597 (if (null (get-language-info language-name 'setup-function))
598 (error "Language environment not defined: %S" language-name))
599 (funcall (get-language-info language-name 'setup-function))
600 (setq current-language-environment language-name)
601 (force-mode-line-update t))
602
603 ;; Print all arguments with `princ', then print "\n".
604 (defsubst princ-list (&rest args)
605 (while args (princ (car args)) (setq args (cdr args)))
606 (princ "\n"))
607
608 ;; Print a language specific information such as input methods,
609 ;; charsets, and coding systems. This function is intended to be
610 ;; called from the menu:
611 ;; [menu-bar mule describe-language-environment LANGUAGE]
612 ;; and should not run it by `M-x describe-current-input-method-function'.
613 (defun describe-specified-language-support ()
614 "Describe how Emacs supports the specified language environment."
615 (interactive)
616 (let (language-name)
617 (if (not (and (symbolp last-command-event)
618 (setq language-name (symbol-name last-command-event))))
619 (error "Bogus calling sequence"))
620 (describe-language-environment language-name)))
621
622 (defun describe-language-environment (language-name)
623 "Describe how Emacs supports language environment LANGUAGE-NAME."
624 (interactive (list (read-language-name 'documentation "Language: ")))
625 (if (null language-name)
626 (setq language-name current-language-environment))
627 (if (or (null language-name)
628 (null (get-language-info language-name 'documentation)))
629 (error "No documentation for the specified language"))
630 (let ((doc (get-language-info language-name 'documentation)))
631 (with-output-to-temp-buffer "*Help*"
632 (if (stringp doc)
633 (progn
634 (princ-list doc)
635 (terpri)))
636 (let ((str (get-language-info language-name 'sample-text)))
637 (if (stringp str)
638 (progn
639 (princ "Sample text:\n")
640 (princ-list " " str)
641 (terpri))))
642 (princ "Input methods:\n")
643 (let ((l input-method-alist))
644 (while l
645 (if (string= language-name (nth 1 (car l)))
646 (princ-list " " (car (car l))
647 (format " (`%s' in mode line)" (nth 3 (car l)))))
648 (setq l (cdr l))))
649 (terpri)
650 (princ "Character sets:\n")
651 (let ((l (get-language-info language-name 'charset)))
652 (if (null l)
653 (princ-list " nothing specific to " language-name)
654 (while l
655 (princ-list " " (car l) ": "
656 (charset-description (car l)))
657 (setq l (cdr l)))))
658 (terpri)
659 (princ "Coding systems:\n")
660 (let ((l (get-language-info language-name 'coding-system)))
661 (if (null l)
662 (princ-list " nothing specific to " language-name)
663 (while l
664 (princ (format " %s (`%c' in mode line):\n\t%s\n"
665 (car l)
666 (coding-system-mnemonic (car l))
667 (coding-system-doc-string (car l))))
668 (setq l (cdr l))))))))
669 \f
670 ;;; Charset property
671
672 (defsubst get-charset-property (charset propname)
673 "Return the value of CHARSET's PROPNAME property.
674 This is the last value stored with
675 (put-charset-property CHARSET PROPNAME VALUE)."
676 (plist-get (charset-plist charset) propname))
677
678 (defsubst put-charset-property (charset propname value)
679 "Store CHARSETS's PROPNAME property with value VALUE.
680 It can be retrieved with `(get-charset-property CHARSET PROPNAME)'."
681 (set-charset-plist charset
682 (plist-put (charset-plist charset) propname value)))
683
684 ;;; Character code property
685 (put 'char-code-property-table 'char-table-extra-slots 0)
686
687 (defvar char-code-property-table
688 (make-char-table 'char-code-property-table)
689 "Char-table containing a property list of each character code.
690
691 See also the documentation of `get-char-code-property' and
692 `put-char-code-property'.")
693
694 (defun get-char-code-property (char propname)
695 "Return the value of CHAR's PROPNAME property in `char-code-property-table'."
696 (let ((plist (aref char-code-property-table char)))
697 (if (listp plist)
698 (car (cdr (memq propname plist))))))
699
700 (defun put-char-code-property (char propname value)
701 "Store CHAR's PROPNAME property with VALUE in `char-code-property-table'.
702 It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
703 (let ((plist (aref char-code-property-table char)))
704 (if plist
705 (let ((slot (memq propname plist)))
706 (if slot
707 (setcar (cdr slot) value)
708 (nconc plist (list propname value))))
709 (aset char-code-property-table char (list propname value)))))
710
711 ;;; mule-cmds.el ends here