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