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