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