Mercurial > emacs
annotate lisp/international/mule-cmds.el @ 17735:f379e219ed8e
(Fbury_buffer): If buffer is in selected window, remove it.
Otherwise, remove it from other windows.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 10 May 1997 21:44:11 +0000 |
parents | 6501aac82580 |
children | 8c67c2e2cc29 |
rev | line source |
---|---|
17052 | 1 ;;; mule-cmds.el --- Commands for mulitilingual environment |
2 | |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
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 | |
17071 | 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. | |
17052 | 24 |
25 ;;; Code: | |
26 | |
27 ;;; MULE related key bindings and menus. | |
28 | |
29 (defvar mule-keymap (make-sparse-keymap "MULE") | |
30 "Keymap for MULE (Multilingual environment) specific commands.") | |
31 (fset 'mule-prefix mule-keymap) | |
32 | |
17294
d7ae63db9e6e
Prefix for Mule related commands is changed.
Kenichi Handa <handa@m17n.org>
parents:
17090
diff
changeset
|
33 ;; Keep "C-x C-m ..." for mule specific commands. |
d7ae63db9e6e
Prefix for Mule related commands is changed.
Kenichi Handa <handa@m17n.org>
parents:
17090
diff
changeset
|
34 (define-key ctl-x-map "\C-m" 'mule-prefix) |
17052 | 35 |
36 (define-key global-map [menu-bar mule] (cons "Mule" mule-keymap)) | |
37 | |
38 (setq menu-bar-final-items (cons 'mule menu-bar-final-items)) | |
39 | |
40 (defvar mule-describe-language-support-map | |
41 (make-sparse-keymap "Describe Language Support")) | |
42 (fset 'mule-describe-language-support-prefix | |
43 mule-describe-language-support-map) | |
44 | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
45 (defvar mule-set-language-environment-map |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
46 (make-sparse-keymap "Set Language Environment")) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
47 (fset 'mule-set-language-environment-prefix |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
48 mule-set-language-environment-map) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
49 |
17052 | 50 (define-key mule-keymap "m" 'toggle-enable-multibyte-characters) |
51 (define-key mule-keymap "f" 'set-buffer-file-coding-system) | |
52 (define-key mule-keymap "t" 'set-terminal-coding-system) | |
53 (define-key mule-keymap "k" 'set-keyboard-coding-system) | |
54 (define-key mule-keymap "p" 'set-current-process-coding-system) | |
55 (define-key mule-keymap "i" 'select-input-method) | |
17526
6501aac82580
(mule-keymap): Add C-x RET C-\ for select-input-method.
Richard M. Stallman <rms@gnu.org>
parents:
17294
diff
changeset
|
56 (define-key mule-keymap "\C-\\" 'select-input-method) |
17052 | 57 |
58 (define-key help-map "\C-L" 'describe-language-support) | |
59 (define-key help-map "\C-\\" 'describe-input-method) | |
60 (define-key help-map "C" 'describe-current-coding-system) | |
61 (define-key help-map "h" 'view-hello-file) | |
62 | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
63 (define-key mule-keymap [view-hello-file] |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
64 '("Show many languages" . view-hello-file)) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
65 (define-key mule-keymap [mule-diag] |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
66 '("Show diagnosis for MULE" . mule-diag)) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
67 (define-key mule-keymap [separator-coding-system] |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
68 '("--")) |
17052 | 69 (define-key mule-keymap [set-process-coding-system] |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
70 '("Set coding system of process" . set-current-process-coding-system)) |
17052 | 71 (define-key mule-keymap [set-keyboard-coding-system] |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
72 '("Set coding system of keyboard" . set-keyboard-coding-system)) |
17052 | 73 (define-key mule-keymap [set-terminal-coding-system] |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
74 '("Set coding system of terminal" . set-terminal-coding-system)) |
17052 | 75 (define-key mule-keymap [set-buffer-file-coding-system] |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
76 '("Set coding system of buffer file" . set-buffer-file-coding-system)) |
17052 | 77 (define-key mule-keymap [describe-current-coding-system] |
78 '("Describe current coding systems" . describe-current-coding-system)) | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
79 (define-key mule-keymap [separator-input-method] |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
80 '("--")) |
17052 | 81 (define-key mule-keymap [describe-input-method] |
82 '("Describe input method" . describe-input-method)) | |
83 (define-key mule-keymap [select-input-method] | |
84 '("Select input method" . select-input-method)) | |
85 (define-key mule-keymap [toggle-input-method] | |
86 '("Toggle input method" . toggle-input-method)) | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
87 (define-key mule-keymap [separator-mule] |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
88 '("--")) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
89 (define-key mule-keymap [set-language-environment] |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
90 '("Set language environment" . mule-set-language-environment-prefix)) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
91 (define-key mule-keymap [describe-language-support] |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
92 '("Describe language support" . mule-describe-language-support-prefix)) |
17052 | 93 (define-key mule-keymap [toggle-mule] |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
94 '("Disable/enable multibyte character" . toggle-enable-multibyte-characters)) |
17052 | 95 |
96 ;; These are meaningless when running under X. | |
97 (put 'set-keyboard-coding-system 'menu-enable | |
98 '(null window-system)) | |
99 (put 'set-terminal-coding-system 'menu-enable | |
100 '(null window-system)) | |
101 | |
102 | |
103 ;; This should be a single character key binding because users use it | |
104 ;; very frequently while editing multilingual text. Now we can use | |
105 ;; only two such keys: "\C-\\" and "\C-^", but the latter is not | |
106 ;; convenient because it requires shifting on most keyboards. An | |
107 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit' | |
108 ;; but it won't be used that frequently. | |
109 (define-key global-map "\C-\\" 'toggle-input-method) | |
110 | |
111 (defun toggle-enable-multibyte-characters (&optional arg) | |
112 "Change whether this buffer enables multibyte characters. | |
113 With arg, make them enable iff arg is positive." | |
114 (interactive "P") | |
115 (setq enable-multibyte-characters | |
116 (if (null arg) (null enable-multibyte-characters) | |
117 (> (prefix-numeric-value arg) 0))) | |
118 (force-mode-line-update)) | |
119 | |
120 (defun view-hello-file () | |
121 "Display the HELLO file which list up many languages and characters." | |
122 (interactive) | |
17294
d7ae63db9e6e
Prefix for Mule related commands is changed.
Kenichi Handa <handa@m17n.org>
parents:
17090
diff
changeset
|
123 ;; We have to decode the file in any environment. |
d7ae63db9e6e
Prefix for Mule related commands is changed.
Kenichi Handa <handa@m17n.org>
parents:
17090
diff
changeset
|
124 (let ((default-enable-multibyte-characters t) |
d7ae63db9e6e
Prefix for Mule related commands is changed.
Kenichi Handa <handa@m17n.org>
parents:
17090
diff
changeset
|
125 (coding-system-for-read 'iso-2022-7)) |
d7ae63db9e6e
Prefix for Mule related commands is changed.
Kenichi Handa <handa@m17n.org>
parents:
17090
diff
changeset
|
126 (find-file-read-only (expand-file-name "HELLO" data-directory)))) |
17052 | 127 |
128 | |
129 ;;; Language support staffs. | |
130 | |
131 (defvar primary-language "English" | |
132 "Name of a user's primary language. | |
133 Emacs provide various language supports based on this variable.") | |
134 | |
135 (defvar language-info-alist nil | |
136 "Alist of language names vs the corresponding information of various kind. | |
137 Each element looks like: | |
138 (LANGUAGE-NAME . ((KEY . INFO) ...)) | |
139 where LANGUAGE-NAME is a string, | |
140 KEY is a symbol denoting the kind of information, | |
141 INFO is any Lisp object which contains the actual information related | |
142 to KEY.") | |
143 | |
144 (defun get-language-info (language-name key) | |
145 "Return the information for LANGUAGE-NAME of the kind KEY. | |
146 LANGUAGE-NAME is a string. | |
147 KEY is a symbol denoting the kind of required information." | |
148 (let ((lang-slot (assoc language-name language-info-alist))) | |
149 (if lang-slot | |
150 (cdr (assq key (cdr lang-slot)))))) | |
151 | |
152 ;; Return a lambda form which calls `describe-language-support' with | |
153 ;; argument LANG. | |
154 (defun build-describe-language-support-function (lang) | |
155 `(lambda () | |
156 (interactive) | |
157 (describe-language-support ,lang))) | |
158 | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
159 ;; Return a lambda form which calls `set-language-environment' with |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
160 ;; argument LANG. |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
161 (defun build-set-language-environment-function (lang) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
162 `(lambda () |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
163 (interactive) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
164 (set-language-environment ,lang))) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
165 |
17052 | 166 (defun set-language-info (language-name key info) |
167 "Set for LANGUAGE-NAME the information INFO under KEY. | |
168 LANGUAGE-NAME is a string | |
169 KEY is a symbol denoting the kind of information. | |
170 INFO is any Lisp object which contains the actual information. | |
171 | |
172 Currently, the following KEYs are used by Emacs: | |
173 charset: list of symbols whose values are charsets specific to the language. | |
174 coding-system: list of coding systems specific to the langauge. | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
175 setup-function: see the documentation of `set-language-environment'. |
17052 | 176 tutorial: a tutorial file name written in the language. |
177 sample-text: one line short text containing characters of the language. | |
178 documentation: a docstring describing how the language is supported, | |
179 or a fuction to call to describe it, | |
180 or t which means call `describe-language-support' to describe it. | |
181 input-method: alist of input method names for the language vs information | |
182 for activating them. Use `register-input-method' (which see) | |
183 to add a new input method to the alist. | |
184 | |
185 Emacs will use more KEYs in the future. To avoid the conflition, users | |
186 should use prefix \"user-\" in the name of KEY." | |
187 (let (lang-slot key-slot) | |
188 (setq lang-slot (assoc language-name language-info-alist)) | |
189 (if (null lang-slot) ; If no slot for the language, add it. | |
190 (setq lang-slot (list language-name) | |
191 language-info-alist (cons lang-slot language-info-alist))) | |
192 (setq key-slot (assq key lang-slot)) | |
193 (if (null key-slot) ; If no slot for the key, add it. | |
194 (progn | |
195 (setq key-slot (list key)) | |
196 (setcdr lang-slot (cons key-slot (cdr lang-slot))))) | |
197 (setcdr key-slot info) | |
198 ;; Setup menu. | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
199 (cond ((eq key 'documentation) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
200 (define-key mule-describe-language-support-map |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
201 (vector (intern language-name)) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
202 (cons language-name |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
203 (build-describe-language-support-function language-name)))) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
204 ((eq key 'setup-function) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
205 (define-key mule-set-language-environment-map |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
206 (vector (intern language-name)) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
207 (cons language-name |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
208 (build-set-language-environment-function language-name))))) |
17052 | 209 )) |
210 | |
211 (defun set-language-info-alist (language-name alist) | |
212 "Set for LANGUAGE-NAME the information in ALIST. | |
213 ALIST is an alist of KEY and INFO. See the documentation of | |
214 `set-langauge-info' for the meanings of KEY and INFO." | |
215 (while alist | |
216 (set-language-info language-name (car (car alist)) (cdr (car alist))) | |
217 (setq alist (cdr alist)))) | |
218 | |
219 (defun read-language-name (key prompt &optional initial-input) | |
220 "Read language name which has information for KEY, prompting with PROMPT." | |
221 (let* ((completion-ignore-case t) | |
222 (name (completing-read prompt | |
223 language-info-alist | |
224 (function (lambda (elm) (assq key elm))) | |
225 t | |
226 initial-input))) | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
227 (and (> (length name) 0) |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
228 (car (assoc-ignore-case (downcase name) language-info-alist))))) |
17052 | 229 |
230 ;;; Multilingual input methods. | |
231 | |
232 (defvar current-input-method nil | |
233 "The current input method for multilingual text. | |
234 The value is a cons of language name and input method name. | |
235 If nil, it means no input method is activated now.") | |
236 (make-variable-buffer-local 'current-input-method) | |
237 (put 'current-input-method 'permanent-local t) | |
238 | |
239 (defvar current-input-method-title nil | |
240 "Title string of the current input method shown in mode line. | |
241 Every input method should set this an appropriate value when activated.") | |
242 (make-variable-buffer-local 'current-input-method-title) | |
243 (put 'current-input-method-title 'permanent-local t) | |
244 | |
245 (defvar default-input-method nil | |
246 "Default input method. | |
247 The default input method is the one activated automatically by the command | |
248 `toggle-input-method' (\\[toggle-input-method]). | |
249 The value is a cons of language name and input method name.") | |
250 | |
251 (defvar default-input-method-title nil | |
252 "Title string of the default input method.") | |
253 | |
254 (defvar previous-input-method nil | |
255 "Input method selected previously. | |
256 This is the one selected before the current input method is selected. | |
257 See also the documentation of `default-input-method'.") | |
258 | |
259 (defvar inactivate-current-input-method-function nil | |
260 "Function to call for inactivating the current input method. | |
261 Every input method should set this to an appropriate value when activated. | |
262 This function is called with no argument.") | |
263 (make-variable-buffer-local 'inactivate-current-input-method-function) | |
264 (put 'inactivate-current-input-method-function 'permanent-local t) | |
265 | |
266 (defvar describe-current-input-method-function nil | |
267 "Function to call for describing the current input method. | |
268 This function is called with no argument.") | |
269 (make-variable-buffer-local 'describe-current-input-method-function) | |
270 (put 'describe-current-input-method-function 'permanent-local t) | |
271 | |
272 (defun register-input-method (language-name input-method) | |
273 "Register INPUT-METHOD as an input method of LANGUAGE-NAME. | |
274 LANGUAGE-NAME is a string. | |
275 INPUT-METHOD is a list of the form: | |
276 (METHOD-NAME ACTIVATE-FUNC ARG ...) | |
277 where METHOD-NAME is the name of this method, | |
278 ACTIVATE-FUNC is the function to call for activating this method. | |
279 Arguments for the function are METHOD-NAME and ARGs." | |
280 (let ((slot (get-language-info language-name 'input-method)) | |
281 method-slot) | |
282 (if (null slot) | |
283 (set-language-info language-name 'input-method (list input-method)) | |
284 (setq method-slot (assoc (car input-method) slot)) | |
285 (if method-slot | |
286 (setcdr method-slot (cdr input-method)) | |
287 (set-language-info language-name 'input-method | |
288 (cons input-method slot)))))) | |
289 | |
290 (defun read-language-and-input-method-name () | |
291 "Read a language names and the corresponding input method from a minibuffer. | |
292 Return a cons of those names." | |
293 (let ((language-name (read-language-name | |
294 'input-method | |
295 "Language: " | |
296 (if previous-input-method | |
297 (cons (car previous-input-method) 0))))) | |
298 (if (null language-name) | |
299 (error "No input method for the specified language")) | |
300 (let* ((completion-ignore-case t) | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
301 (key-slot (cdr (assq 'input-method |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
302 (assoc language-name language-info-alist)))) |
17052 | 303 (method-name |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
304 (completing-read "Input method: " key-slot nil t |
17052 | 305 (if (and previous-input-method |
306 (string= language-name | |
307 (car previous-input-method))) | |
308 (cons (cdr previous-input-method) 0))))) | |
309 (if (= (length method-name) 0) | |
310 (error "No input method specified")) | |
17090
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
311 (list language-name |
8085a8690c87
(mule-keymap): Re-arranged.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
312 (car (assoc-ignore-case (downcase method-name) key-slot)))))) |
17052 | 313 |
314 (defun set-default-input-method (language-name method-name) | |
315 "Set the default input method to METHOD-NAME for inputting LANGUAGE-NAME. | |
316 The default input method is the one activated automatically by the command | |
317 `toggle-input-method' (\\[toggle-input-method]). | |
318 This doesn't affect the currently activated input method." | |
319 (interactive (read-language-and-input-method-name)) | |
320 (let* ((key-slot (get-language-info language-name 'input-method)) | |
321 (method-slot (assoc method-name key-slot))) | |
322 (if (null method-slot) | |
323 (error "No input method `%s' for %s" method-name language-name)) | |
324 (setq default-input-method (cons language-name method-name)))) | |
325 | |
326 (defun select-input-method (language-name method-name) | |
327 "Select and activate input method METHOD-NAME for inputting LANGUAGE-NAME. | |
328 The information for activating METHOD-NAME is stored | |
329 in `language-info-alist' under the key 'input-method. | |
330 The format of the information has the form: | |
331 ((METHOD-NAME ACTIVATE-FUNC ARG ...) ...) | |
332 where ACTIVATE-FUNC is a function to call for activating this method. | |
333 Arguments for the function are METHOD-NAME and ARGs." | |
334 (interactive (read-language-and-input-method-name)) | |
335 (let* ((key-slot (get-language-info language-name 'input-method)) | |
336 (method-slot (assoc method-name key-slot))) | |
337 (if (null method-slot) | |
338 (error "No input method `%s' for %s" method-name language-name)) | |
339 (if current-input-method | |
340 (progn | |
341 (if (not (equal previous-input-method current-input-method)) | |
342 (setq previous-input-method current-input-method)) | |
343 (funcall inactivate-current-input-method-function))) | |
344 (setq method-slot (cdr method-slot)) | |
345 (apply (car method-slot) method-name (cdr method-slot)) | |
346 (setq default-input-method | |
347 (setq current-input-method (cons language-name method-name))) | |
348 (setq default-input-method-title current-input-method-title) | |
349 (setq current-input-method default-input-method))) | |
350 | |
351 (defun toggle-input-method (&optional arg) | |
352 "Toggle whether a multilingual input method is activated in this buffer. | |
353 With arg, activate an input method specified interactively. | |
354 Without arg, the method being activated is the one selected most recently, | |
355 but if no input method has ever been selected, select one interactively." | |
356 (interactive "P") | |
357 (if arg | |
358 (call-interactively 'select-input-method) | |
359 (if (null current-input-method) | |
360 (if default-input-method | |
361 (select-input-method (car default-input-method) | |
362 (cdr default-input-method)) | |
363 (call-interactively 'select-input-method)) | |
364 (funcall inactivate-current-input-method-function) | |
365 (setq current-input-method nil)))) | |
366 | |
367 (defun describe-input-method () | |
368 "Describe the current input method." | |
369 (interactive) | |
370 (if current-input-method | |
371 (if (and (symbolp describe-current-input-method-function) | |
372 (fboundp describe-current-input-method-function)) | |
373 (funcall describe-current-input-method-function) | |
374 (message "No way to describe the current input method `%s'" | |
375 (cdr current-input-method)) | |
376 (ding)) | |
377 (message "No input method is activated now") | |
378 (ding))) | |
379 | |
380 (defun read-multilingual-string (prompt &optional initial-input | |
381 language-name method-name) | |
382 "Read a multilingual string from minibuffer, prompting with string PROMPT. | |
383 The input method selected last time is activated in minibuffer. | |
384 If non-nil, second arg INITIAL-INPUT is a string to insert before reading. | |
385 Optional 3rd and 4th arguments LANGUAGE-NAME and METHOD-NAME specify | |
386 the input method to be activated instead of the one selected last time." | |
387 (let ((minibuffer-setup-hook '(toggle-input-method)) | |
388 (default-input-method default-input-method)) | |
389 (if (and language-name method-name) | |
390 (set-default-input-method language-name method-name)) | |
391 (read-string prompt initial-input))) | |
392 | |
393 ;; Variables to control behavior of input methods. All input methods | |
394 ;; should react to these variables. | |
395 | |
396 (defvar input-method-tersely-flag nil | |
397 "*If this flag is non-nil, input method works rather tersely. | |
398 | |
399 For instance, Quail input method does not show guidance buffer while | |
400 inputting at minibuffer if this flag is t.") | |
401 | |
402 (defvar input-method-activate-hook nil | |
403 "Normal hook run just after an input method is activated.") | |
404 | |
405 (defvar input-method-inactivate-hook nil | |
406 "Normal hook run just after an input method is inactivated.") | |
407 | |
408 (defvar input-method-after-insert-chunk-hook nil | |
409 "Normal hook run just after an input method insert some chunk of text.") | |
410 | |
411 | |
412 ;;; Language specific setup functions. | |
413 (defun set-language-environment (language-name) | |
414 "Setup a user's environment for LANGUAGE-NAME. | |
415 | |
416 To setup, a fucntion returned by: | |
417 (get-language-info LANGUAGE-NAME 'setup-function) | |
418 is called." | |
419 (interactive (list (read-language-name 'setup-function "Language: "))) | |
420 (let (func) | |
421 (if (or (null language-name) | |
422 (null (setq func | |
423 (get-language-info language-name 'setup-function)))) | |
424 (error "No way to setup environment for the specified language")) | |
425 (funcall func))) | |
426 | |
427 ;; Print all arguments with `princ', then print "\n". | |
428 (defsubst princ-list (&rest args) | |
429 (while args (princ (car args)) (setq args (cdr args))) | |
430 (princ "\n")) | |
431 | |
432 (defun describe-language-support (language-name) | |
433 "Show documentation about how Emacs supports LANGUAGE-NAME." | |
434 (interactive (list (read-language-name 'documentation "Language: "))) | |
435 (let (doc) | |
436 (if (or (null language-name) | |
437 (null (setq doc | |
438 (get-language-info language-name 'documentation)))) | |
439 (error "No documentation for the specified language")) | |
440 (with-output-to-temp-buffer "*Help*" | |
441 (if (not (eq doc t)) | |
442 (cond ((stringp doc) | |
443 (princ doc)) | |
444 ((and (symbolp doc) (fboundp doc)) | |
445 (funcall doc)) | |
446 (t | |
447 (error "Invalid documentation data for %s" language-name))) | |
448 (princ-list "List of items specific to " | |
449 language-name | |
450 " environment") | |
451 (princ "-----------------------------------------------------------\n") | |
452 (let ((str (get-language-info language-name 'sample-text))) | |
453 (if (stringp str) | |
454 (progn | |
455 (princ "<sample text>\n") | |
456 (princ-list " " str)))) | |
457 (princ "<input methods>\n") | |
458 (let ((l (get-language-info language-name 'input-method))) | |
459 (while l | |
460 (princ-list " " (car (car l))) | |
461 (setq l (cdr l)))) | |
462 (princ "<character sets>\n") | |
463 (let ((l (get-language-info language-name 'charset))) | |
464 (if (null l) | |
465 (princ-list " nothing specific to " language-name) | |
466 (while l | |
467 (princ-list " " (car l) | |
468 (format ":%3d:\n\t" (charset-id (car l))) | |
469 (charset-description (car l))) | |
470 (setq l (cdr l))))) | |
471 (princ "<coding systems>\n") | |
472 (let ((l (get-language-info language-name 'coding-system))) | |
473 (if (null l) | |
474 (princ-list " nothing specific to " language-name) | |
475 (while l | |
476 (princ-list " " (car l) ":\n\t" | |
477 (coding-system-docstring (car l))) | |
478 (setq l (cdr l))))))))) | |
479 | |
480 ;;; Charset property | |
481 | |
482 (defsubst get-charset-property (charset propname) | |
483 "Return the value of CHARSET's PROPNAME property. | |
484 This is the last value stored with | |
485 `(put-charset-property CHARSET PROPNAME VALUE)'." | |
486 (plist-get (charset-plist charset) propname)) | |
487 | |
488 (defsubst put-charset-property (charset propname value) | |
489 "Store CHARSETS's PROPNAME property with value VALUE. | |
490 It can be retrieved with `(get-charset-property CHARSET PROPNAME)'." | |
491 (set-charset-plist charset | |
492 (plist-put (charset-plist charset) propname value))) | |
493 | |
494 ;;; Character code property | |
495 (put 'char-code-property-table 'char-table-extra-slots 0) | |
496 | |
497 (defvar char-code-property-table | |
498 (make-char-table 'char-code-property-table) | |
499 "Char-table containing a property list of each character code. | |
500 | |
501 See also the documentation of `get-char-code-property' and | |
502 `put-char-code-property'") | |
503 | |
504 (defun get-char-code-property (char propname) | |
505 "Return the value of CHAR's PROPNAME property in `char-code-property-table'." | |
506 (let ((plist (aref char-code-property-table char))) | |
507 (if (listp plist) | |
508 (car (cdr (memq propname plist)))))) | |
509 | |
510 (defun put-char-code-property (char propname value) | |
511 "Store CHAR's PROPNAME property with VALUE in `char-code-property-table'. | |
512 It can be retrieved with `(get-char-code-property CHAR PROPNAME)'." | |
513 (let ((plist (aref char-code-property-table char))) | |
514 (if plist | |
515 (let ((slot (memq propname plist))) | |
516 (if slot | |
517 (setcar (cdr slot) value) | |
518 (nconc plist (list propname value)))) | |
519 (aset char-code-property-table char (list propname value))))) | |
520 | |
521 ;;; mule-cmds.el ends here |