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