Mercurial > hg > xemacs-beta
comparison lisp/mule/mule-cmds.el @ 197:acd284d43ca1 r20-3b25
Import from CVS: tag r20-3b25
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:00:02 +0200 |
parents | b405438285a2 |
children | 850242ba4a81 |
comparison
equal
deleted
inserted
replaced
196:58e0786448ca | 197:acd284d43ca1 |
---|---|
1 ;;; mule-cmds.el --- Commands for multilingual environment | 1 ;;; mule-cmds.el --- Commands for multilingual environment |
2 | 2 |
3 ;; Copyright (C) 1995 Free Software Foundation, Inc. | |
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | 3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. |
4 ;; Licensed to the Free Software Foundation. | |
5 ;; Copyright (C) 1997 MORIOKA Tomohiko | 5 ;; Copyright (C) 1997 MORIOKA Tomohiko |
6 | 6 |
7 ;; Keywords: mule, multilingual | 7 ;; Keywords: mule, multilingual |
8 | 8 |
9 ;; This file is part of XEmacs. | 9 ;; This file is part of XEmacs. |
31 "Keymap for MULE (Multilingual environment) specific commands.") | 31 "Keymap for MULE (Multilingual environment) specific commands.") |
32 (fset 'mule-prefix mule-keymap) | 32 (fset 'mule-prefix mule-keymap) |
33 | 33 |
34 ;; Keep "C-x C-m ..." for mule specific commands. | 34 ;; Keep "C-x C-m ..." for mule specific commands. |
35 (define-key ctl-x-map "\C-m" 'mule-prefix) | 35 (define-key ctl-x-map "\C-m" 'mule-prefix) |
36 | |
37 ;; (defvar mule-describe-language-support-map | |
38 ;; (make-sparse-keymap "Describe Language Support")) | |
39 ;; (fset 'mule-describe-language-support-prefix | |
40 ;; mule-describe-language-support-map) | |
41 | |
42 ;; (defvar mule-set-language-environment-map | |
43 ;; (make-sparse-keymap "Set Language Environment")) | |
44 ;; (fset 'mule-set-language-environment-prefix | |
45 ;; mule-set-language-environment-map) | |
46 | 36 |
47 (define-key mule-keymap "f" 'set-buffer-file-coding-system) | 37 (define-key mule-keymap "f" 'set-buffer-file-coding-system) |
48 (define-key mule-keymap "F" 'set-default-buffer-file-coding-system) ; XEmacs | 38 (define-key mule-keymap "F" 'set-default-buffer-file-coding-system) ; XEmacs |
49 (define-key mule-keymap "t" 'set-terminal-coding-system) | 39 (define-key mule-keymap "t" 'set-terminal-coding-system) |
50 (define-key mule-keymap "k" 'set-keyboard-coding-system) | 40 (define-key mule-keymap "k" 'set-keyboard-coding-system) |
51 (define-key mule-keymap "p" 'set-current-process-coding-system) | 41 (define-key mule-keymap "p" 'set-current-process-coding-system) |
52 (define-key mule-keymap "P" 'set-default-process-coding-system) ; XEmacs | 42 (define-key mule-keymap "P" 'set-default-process-coding-system) ; XEmacs |
53 (define-key mule-keymap "i" 'select-input-method) | 43 (define-key mule-keymap "\C-\\" 'select-input-method) |
54 (define-key mule-keymap "c" 'list-coding-system-briefly) ; XEmacs | 44 (define-key mule-keymap "c" 'list-coding-system-briefly) ; XEmacs |
55 (define-key mule-keymap "C" 'list-coding-system) ; XEmacs | 45 (define-key mule-keymap "C" 'list-coding-system) ; XEmacs |
56 (define-key mule-keymap "r" 'toggle-display-direction) ; XEmacs | 46 (define-key mule-keymap "r" 'toggle-display-direction) ; XEmacs |
47 (define-key mule-keymap "l" 'set-language-environment) | |
57 | 48 |
58 (define-key help-map "\C-L" 'describe-language-support) | 49 (define-key help-map "\C-L" 'describe-language-support) |
50 (define-key help-map "L" 'describe-language-environment) | |
59 (define-key help-map "\C-\\" 'describe-input-method) | 51 (define-key help-map "\C-\\" 'describe-input-method) |
52 (define-key help-map "I" 'describe-input-method) | |
60 (define-key help-map "C" 'describe-current-coding-system) | 53 (define-key help-map "C" 'describe-current-coding-system) |
61 (define-key help-map "h" 'view-hello-file) | 54 (define-key help-map "h" 'view-hello-file) |
62 | 55 |
63 ;; Menu for XEmacs were moved to x11/x-menubar.el. | 56 ;; Menu for XEmacs were moved to x11/x-menubar.el. |
64 | 57 |
94 INFO is any Lisp object which contains the actual information related | 87 INFO is any Lisp object which contains the actual information related |
95 to KEY.") | 88 to KEY.") |
96 | 89 |
97 (defun get-language-info (language-name key) | 90 (defun get-language-info (language-name key) |
98 "Return the information for LANGUAGE-NAME of the kind KEY. | 91 "Return the information for LANGUAGE-NAME of the kind KEY. |
99 LANGUAGE-NAME is a string. | |
100 KEY is a symbol denoting the kind of required information." | 92 KEY is a symbol denoting the kind of required information." |
101 (let ((lang-slot (assoc language-name language-info-alist))) | 93 (if (symbolp language-name) |
94 (setq language-name (symbol-name language-name))) | |
95 (let ((lang-slot (assoc-ignore-case language-name language-info-alist))) | |
102 (if lang-slot | 96 (if lang-slot |
103 (cdr (assq key (cdr lang-slot)))))) | 97 (cdr (assq key (cdr lang-slot)))))) |
104 | 98 |
105 (defun set-language-info (language-name key info) | 99 (defun set-language-info (language-name key info) |
106 "Set for LANGUAGE-NAME the information INFO under KEY. | 100 "Set for LANGUAGE-NAME the information INFO under KEY. |
107 LANGUAGE-NAME is a string | |
108 KEY is a symbol denoting the kind of information. | 101 KEY is a symbol denoting the kind of information. |
109 INFO is any Lisp object which contains the actual information. | 102 INFO is any Lisp object which contains the actual information. |
110 | 103 |
111 Currently, the following KEYs are used by Emacs: | 104 Currently, the following KEYs are used by Emacs: |
105 | |
112 charset: list of symbols whose values are charsets specific to the language. | 106 charset: list of symbols whose values are charsets specific to the language. |
107 | |
113 coding-system: list of coding systems specific to the langauge. | 108 coding-system: list of coding systems specific to the langauge. |
109 | |
114 tutorial: a tutorial file name written in the language. | 110 tutorial: a tutorial file name written in the language. |
111 | |
115 sample-text: one line short text containing characters of the language. | 112 sample-text: one line short text containing characters of the language. |
116 input-method: alist of input method names for the language vs information | 113 |
117 for activating them. Use `register-input-method' (which see) | 114 documentation: t or a string describing how Emacs supports the language. |
118 to add a new input method to the alist. | 115 If a string is specified, it is shown before any other information |
119 documentation: a string describing how Emacs supports the langauge. | 116 of the language by the command `describe-language-environment'. |
120 describe-function: a function to call for descriebing how Emacs supports | 117 |
121 the language. The function uses information listed abobe. | |
122 setup-function: a function to call for setting up environment | 118 setup-function: a function to call for setting up environment |
123 convenient for the language. | 119 convenient for a user of the language. |
124 | 120 |
125 Emacs will use more KEYs in the future. To avoid conflict, users | 121 If KEY is documentation or setup-function, you can also specify |
126 should use prefix \"user-\" in the name of KEY if he wants to set | 122 a cons cell as INFO, in which case, the car part should be |
127 different kind of information." | 123 a normal value as INFO for KEY (as described above), |
124 and the cdr part should be a symbol whose value is a menu keymap | |
125 in which an entry for the language is defined. But, only the car part | |
126 is actually set as the information. | |
127 | |
128 We will define more KEYs in the future. To avoid conflict, | |
129 if you want to use your own KEY values, make them start with `user-'." | |
130 (if (symbolp language-name) | |
131 (setq language-name (symbol-name language-name))) | |
128 (let (lang-slot key-slot) | 132 (let (lang-slot key-slot) |
129 (setq lang-slot (assoc language-name language-info-alist)) | 133 (setq lang-slot (assoc language-name language-info-alist)) |
130 (if (null lang-slot) ; If no slot for the language, add it. | 134 (if (null lang-slot) ; If no slot for the language, add it. |
131 (setq lang-slot (list language-name) | 135 (setq lang-slot (list language-name) |
132 language-info-alist (cons lang-slot language-info-alist))) | 136 language-info-alist (cons lang-slot language-info-alist))) |
133 (setq key-slot (assq key lang-slot)) | 137 (setq key-slot (assq key lang-slot)) |
134 (if (null key-slot) ; If no slot for the key, add it. | 138 (if (null key-slot) ; If no slot for the key, add it. |
135 (progn | 139 (progn |
136 (setq key-slot (list key)) | 140 (setq key-slot (list key)) |
137 (setcdr lang-slot (cons key-slot (cdr lang-slot))))) | 141 (setcdr lang-slot (cons key-slot (cdr lang-slot))))) |
138 (setcdr key-slot info) | |
139 ;; Setup menu. | 142 ;; Setup menu. |
140 (cond ((eq key 'describe-function) | 143 (cond ((eq key 'documentation) |
141 ;; (define-key-after mule-describe-language-support-map | 144 ;; (define-key-after mule-describe-language-support-map |
142 ;; (vector (intern language-name)) | 145 ;; (vector (intern language-name)) |
143 ;; (cons language-name info) | 146 ;; (cons language-name info) |
144 ;; t) | 147 ;; t) |
145 (eval-after-load "x-menubar" | 148 (eval-after-load "x-menubar" |
159 | 162 |
160 (defun set-language-info-alist (language-name alist) | 163 (defun set-language-info-alist (language-name alist) |
161 "Set for LANGUAGE-NAME the information in ALIST. | 164 "Set for LANGUAGE-NAME the information in ALIST. |
162 ALIST is an alist of KEY and INFO. See the documentation of | 165 ALIST is an alist of KEY and INFO. See the documentation of |
163 `set-langauge-info' for the meanings of KEY and INFO." | 166 `set-langauge-info' for the meanings of KEY and INFO." |
167 (if (symbolp language-name) | |
168 (setq language-name (symbol-name language-name))) | |
164 (while alist | 169 (while alist |
165 (set-language-info language-name (car (car alist)) (cdr (car alist))) | 170 (set-language-info language-name (car (car alist)) (cdr (car alist))) |
166 (setq alist (cdr alist)))) | 171 (setq alist (cdr alist)))) |
167 | 172 |
168 (defun read-language-name (key prompt &optional initial-input) | 173 (defun read-language-name (key prompt &optional default) |
169 "Read language name which has information for KEY, prompting with PROMPT." | 174 "Read language name which has information for KEY, prompting with PROMPT. |
175 DEFAULT is the default choice of language. | |
176 This returns a language name as a string." | |
170 (let* ((completion-ignore-case t) | 177 (let* ((completion-ignore-case t) |
171 (name (completing-read prompt | 178 (name (completing-read prompt |
172 language-info-alist | 179 language-info-alist |
173 (function (lambda (elm) (assq key elm))) | 180 (function (lambda (elm) (assq key elm))) |
174 t | 181 t nil nil default))) |
175 initial-input))) | 182 (if (and (> (length name) 0) |
176 (and (> (length name) 0) | 183 (get-language-info name key)) |
177 (car (assoc-ignore-case (downcase name) language-info-alist))))) | 184 name))) |
178 | 185 |
179 ;;; Multilingual input methods. | 186 ;;; Multilingual input methods. |
180 | 187 |
188 (defconst leim-list-file-name "leim-list.el" | |
189 "Name of LEIM list file. | |
190 This file contains a list of libraries of Emacs input methods (LEIM) | |
191 in the format of Lisp expression for registering each input method. | |
192 Emacs loads this file at startup time.") | |
193 | |
194 (defvar leim-list-header (format "\ | |
195 ;;; %s -- list of LEIM (Library of Emacs Input Method) | |
196 ;; | |
197 ;; This file contains a list of LEIM (Library of Emacs Input Method) | |
198 ;; in the same directory as this file. Loading this file registeres | |
199 ;; the whole input methods in Emacs. | |
200 ;; | |
201 ;; Each entry has the form: | |
202 ;; (register-input-method | |
203 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC | |
204 ;; TITLE DESCRIPTION | |
205 ;; ARG ...) | |
206 ;; See the function `register-input-method' for the meanings of arguments. | |
207 ;; | |
208 ;; If this directory is included in load-path, Emacs automatically | |
209 ;; loads this file at startup time. | |
210 | |
211 " | |
212 leim-list-file-name) | |
213 "Header to be inserted in LEIM list file.") | |
214 | |
215 (defvar leim-list-entry-regexp "^(register-input-method" | |
216 "Regexp matching head of each entry in LEIM list file. | |
217 See also the variable `leim-list-header'") | |
218 | |
219 (defvar update-leim-list-functions | |
220 '(quail-update-leim-list-file) | |
221 "List of functions to call to update LEIM list file. | |
222 Each function is called with one arg, LEIM directory name.") | |
223 | |
224 (defun update-leim-list-file (&rest dirs) | |
225 "Update LEIM list file in directories DIRS." | |
226 (let ((functions update-leim-list-functions)) | |
227 (while functions | |
228 (apply (car functions) dirs) | |
229 (setq functions (cdr functions))))) | |
230 | |
181 (defvar current-input-method nil | 231 (defvar current-input-method nil |
182 "The current input method for multilingual text. | 232 "The current input method for multilingual text. |
183 The value is a cons of language name and input method name. | 233 If nil, that means no input method is activated now.") |
184 If nil, it means no input method is activated now.") | |
185 (make-variable-buffer-local 'current-input-method) | 234 (make-variable-buffer-local 'current-input-method) |
186 (put 'current-input-method 'permanent-local t) | 235 (put 'current-input-method 'permanent-local t) |
187 | 236 |
188 (defvar current-input-method-title nil | 237 (defvar current-input-method-title nil |
189 "Title string of the current input method shown in mode line. | 238 "Title string of the current input method shown in mode line.") |
190 Every input method should set this to an appropriate value when activated.") | |
191 (make-variable-buffer-local 'current-input-method-title) | 239 (make-variable-buffer-local 'current-input-method-title) |
192 (put 'current-input-method-title 'permanent-local t) | 240 (put 'current-input-method-title 'permanent-local t) |
193 | 241 |
194 (defvar default-input-method nil | 242 (defcustom default-input-method nil |
195 "Default input method. | 243 "*Default input method for multilingual text. |
196 The default input method is the one activated automatically by the command | 244 This is the input method activated automatically by the command |
197 `toggle-input-method' (\\[toggle-input-method]). | 245 `toggle-input-method' (\\[toggle-input-method])." |
198 The value is a cons of language name and input method name.") | 246 :group 'mule) |
199 | 247 |
200 (defvar default-input-method-title nil | 248 (defvar input-method-history nil |
201 "Title string of the default input method.") | 249 "History list for some commands that read input methods.") |
202 | 250 (make-variable-buffer-local 'input-method-history) |
203 (defvar previous-input-method nil | 251 (put 'input-method-history 'permanent-local t) |
204 "Input method selected previously. | |
205 This is the one selected before the current input method is selected. | |
206 See also the documentation of `default-input-method'.") | |
207 | 252 |
208 (defvar inactivate-current-input-method-function nil | 253 (defvar inactivate-current-input-method-function nil |
209 "Function to call for inactivating the current input method. | 254 "Function to call for inactivating the current input method. |
210 Every input method should set this to an appropriate value when activated. | 255 Every input method should set this to an appropriate value when activated. |
211 This function is called with no argument.") | 256 This function is called with no argument. |
257 | |
258 This function should never change the value of `current-input-method'. | |
259 It is set to nil by the function `inactivate-input-method'.") | |
212 (make-variable-buffer-local 'inactivate-current-input-method-function) | 260 (make-variable-buffer-local 'inactivate-current-input-method-function) |
213 (put 'inactivate-current-input-method-function 'permanent-local t) | 261 (put 'inactivate-current-input-method-function 'permanent-local t) |
214 | 262 |
215 (defvar describe-current-input-method-function nil | 263 (defvar describe-current-input-method-function nil |
216 "Function to call for describing the current input method. | 264 "Function to call for describing the current input method. |
217 This function is called with no argument.") | 265 This function is called with no argument.") |
218 (make-variable-buffer-local 'describe-current-input-method-function) | 266 (make-variable-buffer-local 'describe-current-input-method-function) |
219 (put 'describe-current-input-method-function 'permanent-local t) | 267 (put 'describe-current-input-method-function 'permanent-local t) |
220 | 268 |
221 (defun register-input-method (language-name input-method) | 269 (defvar input-method-alist nil |
222 "Register INPUT-METHOD as an input method of LANGUAGE-NAME. | 270 "Alist of input method names vs the corresponding information to use it. |
223 LANGUAGE-NAME is a string. | 271 Each element has the form: |
224 INPUT-METHOD is a list of the form: | 272 (INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC TITLE DESCRIPTION ...) |
225 (METHOD-NAME ACTIVATE-FUNC ARG ...) | 273 See the function `register-input-method' for the meanings of each elements.") |
226 where METHOD-NAME is the name of this method, | 274 |
227 ACTIVATE-FUNC is the function to call for activating this method. | 275 (defun register-input-method (input-method language-name &rest args) |
228 Arguments for the function are METHOD-NAME and ARGs." | 276 "Register INPUT-METHOD as an input method for LANGUAGE-NAME. |
229 (let ((slot (get-language-info language-name 'input-method)) | 277 INPUT-METHOD and LANGUAGE-NAME are symbols or strings. |
230 method-slot) | 278 The remaining arguments are: |
231 (if (null slot) | 279 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARG ... |
232 (set-language-info language-name 'input-method (list input-method)) | 280 where, |
233 (setq method-slot (assoc (car input-method) slot)) | 281 ACTIVATE-FUNC is a function to call for activating this method. |
234 (if method-slot | 282 TITLE is a string shown in mode-line while this method is active, |
235 (setcdr method-slot (cdr input-method)) | 283 DESCRIPTION is a string describing about this method, |
236 (set-language-info language-name 'input-method | 284 Arguments to ACTIVATE-FUNC are INPUT-METHOD and ARGs." |
237 (cons input-method slot)))))) | 285 (if (symbolp language-name) |
238 | 286 (setq language-name (symbol-name language-name))) |
239 (defun read-language-and-input-method-name () | 287 (if (symbolp input-method) |
240 "Read a language names and the corresponding input method from a minibuffer. | 288 (setq input-method (symbol-name input-method))) |
241 Return a cons of those names." | 289 (let ((info (cons language-name args)) |
242 (let ((language-name (read-language-name | 290 (slot (assoc input-method input-method-alist))) |
243 'input-method | 291 (if slot |
244 "Language: " | 292 (setcdr slot info) |
245 (if previous-input-method | 293 (setq slot (cons input-method info)) |
246 (cons (car previous-input-method) 0))))) | 294 (setq input-method-alist (cons slot input-method-alist))))) |
247 (if (null language-name) | 295 |
248 (error "No input method for the specified language")) | 296 (defun read-input-method-name (prompt &optional default inhibit-null) |
249 (let* ((completion-ignore-case t) | 297 "Read a name of input method from a minibuffer prompting with PROMPT. |
250 (key-slot (cdr (assq 'input-method | 298 If DEFAULT is non-nil, use that as the default, |
251 (assoc language-name language-info-alist)))) | 299 and substitute it into PROMPT at the first `%s'. |
252 (method-name | 300 If INHIBIT-NULL is non-nil, null input signals an error. |
253 (completing-read "Input method: " key-slot nil t | 301 |
254 (if (and previous-input-method | 302 The return value is a string." |
255 (string= language-name | 303 (if default |
256 (car previous-input-method))) | 304 (setq prompt (format prompt default))) |
257 (cons (cdr previous-input-method) 0))))) | 305 (let* ((completion-ignore-case t) |
258 (if (= (length method-name) 0) | 306 ;; This binding is necessary because input-method-history is |
259 (error "No input method specified")) | 307 ;; buffer local. |
260 (list language-name | 308 (input-method (completing-read prompt input-method-alist |
261 (car (assoc-ignore-case (downcase method-name) key-slot)))))) | 309 nil t nil 'input-method-history) |
262 | 310 ;;default) |
263 (defun set-default-input-method (language-name method-name) | 311 )) |
264 "Set the default input method to METHOD-NAME for inputting LANGUAGE-NAME. | 312 (if (> (length input-method) 0) |
265 The default input method is the one activated automatically by the command | 313 input-method |
266 `toggle-input-method' (\\[toggle-input-method]). | 314 (if inhibit-null |
267 This doesn't affect the currently activated input method." | 315 (error "No valid input method is specified"))))) |
268 (interactive (read-language-and-input-method-name)) | 316 |
269 (let* ((key-slot (get-language-info language-name 'input-method)) | 317 (defun activate-input-method (input-method) |
270 (method-slot (assoc method-name key-slot))) | 318 "Turn INPUT-METHOD on. |
271 (if (null method-slot) | 319 If some input method is already on, turn it off at first." |
272 (error "No input method `%s' for %s" method-name language-name)) | 320 (if (symbolp input-method) |
273 (setq default-input-method (cons language-name method-name)))) | 321 (setq input-method (symbol-name input-method))) |
274 | 322 (if (and current-input-method |
275 (defun select-input-method (language-name method-name) | 323 (not (string= current-input-method input-method))) |
276 "Select and activate input method METHOD-NAME for inputting LANGUAGE-NAME. | 324 (inactivate-input-method)) |
277 The information for activating METHOD-NAME is stored | 325 (unless current-input-method |
278 in `language-info-alist' under the key 'input-method. | 326 (let ((slot (assoc input-method input-method-alist))) |
279 The format of the information has the form: | 327 (if (null slot) |
280 ((METHOD-NAME ACTIVATE-FUNC ARG ...) ...) | 328 (error "Can't activate input method `%s'" input-method)) |
281 where ACTIVATE-FUNC is a function to call for activating this method. | 329 (apply (nth 2 slot) input-method (nthcdr 5 slot)) |
282 Arguments for the function are METHOD-NAME and ARGs." | 330 (setq current-input-method input-method) |
283 (interactive (read-language-and-input-method-name)) | 331 (setq current-input-method-title (nth 3 slot)) |
284 (let* ((key-slot (get-language-info language-name 'input-method)) | 332 (run-hooks 'input-method-activate-hook)))) |
285 (method-slot (assoc method-name key-slot))) | 333 |
286 (if (null method-slot) | 334 (defun inactivate-input-method () |
287 (error "No input method `%s' for %s" method-name language-name)) | 335 "Turn off the current input method." |
288 (if current-input-method | 336 (when current-input-method |
289 (progn | 337 (if input-method-history |
290 (if (not (equal previous-input-method current-input-method)) | 338 (unless (string= current-input-method (car input-method-history)) |
291 (setq previous-input-method current-input-method)) | 339 (setq input-method-history |
292 (funcall inactivate-current-input-method-function))) | 340 (cons current-input-method |
293 (setq method-slot (cdr method-slot)) | 341 (delete current-input-method input-method-history)))) |
294 (apply (car method-slot) method-name (cdr method-slot)) | 342 (setq input-method-history (list current-input-method))) |
295 (setq default-input-method | 343 (unwind-protect |
296 (setq current-input-method (cons language-name method-name))) | 344 (funcall inactivate-current-input-method-function) |
297 (setq default-input-method-title current-input-method-title) | 345 (unwind-protect |
298 (setq current-input-method default-input-method))) | 346 (run-hooks 'input-method-inactivate-hook) |
347 (setq current-input-method nil | |
348 current-input-method-title nil))))) | |
349 | |
350 (defun select-input-method (input-method) | |
351 "Select and turn on INPUT-METHOD. | |
352 This sets the default input method to what you specify, | |
353 and turn it on for the current buffer." | |
354 (interactive | |
355 (let* ((default (or (car input-method-history) default-input-method))) | |
356 (list (read-input-method-name | |
357 (if default "Select input method (default %s): " "Select input method: ") | |
358 default t)))) | |
359 (activate-input-method input-method) | |
360 (setq default-input-method input-method)) | |
299 | 361 |
300 (defun toggle-input-method (&optional arg) | 362 (defun toggle-input-method (&optional arg) |
301 "Toggle whether a multilingual input method is activated in this buffer. | 363 "Turn on or off a multilingual text input method for the current buffer. |
302 With arg, activate an input method specified interactively. | 364 |
303 Without arg, the method being activated is the one selected most recently, | 365 With arg, read an input method from minibuffer and turn it on. |
304 but if no input method has ever been selected, select one interactively." | 366 |
367 Without arg, if some input method is currently activated, turn it off, | |
368 else turn on an input method selected last time | |
369 or the default input method (see `default-input-method'). | |
370 | |
371 When there's no input method to turn on, turn on what read from minibuffer." | |
305 (interactive "P") | 372 (interactive "P") |
306 (if arg | 373 (if (eq arg 1) |
307 (call-interactively 'select-input-method) | 374 (setq arg nil)) |
308 (if (null current-input-method) | 375 (let* ((default (or (car input-method-history) default-input-method))) |
309 (if default-input-method | 376 (if (and current-input-method (not arg)) |
310 (select-input-method (car default-input-method) | 377 (inactivate-input-method) |
311 (cdr default-input-method)) | 378 (activate-input-method |
312 (call-interactively 'select-input-method)) | 379 (if (or arg (not default)) |
313 (funcall inactivate-current-input-method-function) | 380 (read-input-method-name |
314 (setq current-input-method nil)))) | 381 (if default "Input method (default %s): " "Input method: " ) |
315 | 382 default t) |
316 (defun describe-input-method () | 383 default)) |
317 "Describe the current input method." | 384 (or default-input-method |
318 (interactive) | 385 (setq default-input-method current-input-method))))) |
386 | |
387 (defun describe-input-method (input-method) | |
388 "Describe input method INPUT-METHOD." | |
389 (interactive | |
390 (list (read-input-method-name | |
391 "Describe input method (default, current choice): "))) | |
392 (if (and input-method (symbolp input-method)) | |
393 (setq input-method (symbol-name input-method))) | |
394 (if (null input-method) | |
395 (describe-current-input-method) | |
396 (with-output-to-temp-buffer "*Help*" | |
397 (let ((elt (assoc input-method input-method-alist))) | |
398 (princ (format "Input method: %s (`%s' in mode line) for %s\n %s\n" | |
399 input-method (nth 3 elt) (nth 1 elt) (nth 4 elt))))))) | |
400 | |
401 (defun describe-current-input-method () | |
402 "Describe the input method currently in use." | |
319 (if current-input-method | 403 (if current-input-method |
320 (if (and (symbolp describe-current-input-method-function) | 404 (if (and (symbolp describe-current-input-method-function) |
321 (fboundp describe-current-input-method-function)) | 405 (fboundp describe-current-input-method-function)) |
322 (funcall describe-current-input-method-function) | 406 (funcall describe-current-input-method-function) |
323 (message "No way to describe the current input method `%s'" | 407 (message "No way to describe the current input method `%s'" |
324 (cdr current-input-method)) | 408 (cdr current-input-method)) |
325 (ding)) | 409 (ding)) |
326 (message "No input method is activated now") | 410 (error "No input method is activated now"))) |
327 (ding))) | |
328 | 411 |
329 (defun read-multilingual-string (prompt &optional initial-input | 412 (defun read-multilingual-string (prompt &optional initial-input |
330 language-name method-name) | 413 input-method) |
331 "Read a multilingual string from minibuffer, prompting with string PROMPT. | 414 "Read a multilingual string from minibuffer, prompting with string PROMPT. |
332 The input method selected last time is activated in minibuffer. | 415 The input method selected last time is activated in minibuffer. |
333 If non-nil, second arg INITIAL-INPUT is a string to insert before reading. | 416 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer |
334 Optional 3rd and 4th arguments LANGUAGE-NAME and METHOD-NAME specify | 417 initially. |
335 the input method to be activated instead of the one selected last time." | 418 Optional 3rd argument INPUT-METHOD specifies the input method |
336 (let ((minibuffer-setup-hook '(toggle-input-method)) | 419 to be activated instead of the one selected last time. It is a symbol |
337 (default-input-method default-input-method)) | 420 or a string." |
338 (if (and language-name method-name) | 421 (setq input-method |
339 (set-default-input-method language-name method-name)) | 422 (or input-method |
340 (read-string prompt initial-input))) | 423 default-input-method |
424 (read-input-method-name "Input method: " nil t))) | |
425 (if (and input-method (symbolp input-method)) | |
426 (setq input-method (symbol-name input-method))) | |
427 (let ((current-input-method input-method)) | |
428 (read-string prompt initial-input nil nil t))) | |
341 | 429 |
342 ;; Variables to control behavior of input methods. All input methods | 430 ;; Variables to control behavior of input methods. All input methods |
343 ;; should react to these variables. | 431 ;; should react to these variables. |
344 | 432 |
345 (defvar input-method-tersely-flag nil | 433 (defcustom input-method-verbose-flag t |
346 "*If this flag is non-nil, input method works rather tersely. | 434 "*If this flag is non-nil, input methods give extra guidance. |
347 | 435 |
348 For instance, Quail input method does not show guidance buffer while | 436 The extra guidance is done by showing list of available keys in echo |
349 inputting at minibuffer if this flag is t.") | 437 area. |
438 | |
439 For complex input methods such as `chinese-py' and `japanese', | |
440 when you use the input method in the minibuffer, the guidance is | |
441 shown at the bottom short window (split from the existing window). | |
442 For simple input methods, guidance is not shown | |
443 when you are in the minibuffer." | |
444 :type 'boolean | |
445 :group 'mule) | |
446 | |
447 (defcustom input-method-highlight-flag t | |
448 "*If this flag is non-nil, input methods highlight partially-entered text. | |
449 For instance, while you are in the middle of a Quail input method sequence, | |
450 the text inserted so far is temporarily underlined. | |
451 The underlining goes away when you finish or abort the input method sequence." | |
452 :type 'boolean | |
453 :group 'mule) | |
350 | 454 |
351 (defvar input-method-activate-hook nil | 455 (defvar input-method-activate-hook nil |
352 "Normal hook run just after an input method is activated.") | 456 "Normal hook run just after an input method is activated. |
457 | |
458 The variable `current-input-method' keeps the input method name | |
459 just activated.") | |
353 | 460 |
354 (defvar input-method-inactivate-hook nil | 461 (defvar input-method-inactivate-hook nil |
355 "Normal hook run just after an input method is inactivated.") | 462 "Normal hook run just after an input method is inactivated. |
463 | |
464 The variable `current-input-method' still keeps the input method name | |
465 just inacitvated.") | |
356 | 466 |
357 (defvar input-method-after-insert-chunk-hook nil | 467 (defvar input-method-after-insert-chunk-hook nil |
358 "Normal hook run just after an input method insert some chunk of text.") | 468 "Normal hook run just after an input method insert some chunk of text.") |
469 | |
470 (defvar input-method-exit-on-invalid-key nil | |
471 "This flag controls the behaviour of an input method on invalid key input. | |
472 Usually, when a user types a key which doesn't start any character | |
473 handled by the input method, the key is handled by turning off the | |
474 input method temporalily. After the key is handled, the input method is | |
475 back on. | |
476 But, if this flag is non-nil, the input method is never back on.") | |
359 | 477 |
360 | 478 |
361 ;;; Language specific setup functions. | 479 ;;; Language specific setup functions. |
362 ;; (defun set-language-environment (language-name) | 480 ;; (defun set-language-environment (language-name) |
363 ;; "Setup a user's environment for LANGUAGE-NAME. | 481 ;; "Setup a user's environment for LANGUAGE-NAME. |