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