187
|
1 ;;; mule-cmds.el --- Commands for multilingual environment
|
155
|
2
|
|
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
197
|
4 ;; Licensed to the Free Software Foundation.
|
155
|
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
|
|
6
|
|
7 ;; Keywords: mule, multilingual
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
24 ;; 02111-1307, USA.
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 ;;; MULE related key bindings and menus.
|
|
29
|
|
30 (defvar mule-keymap (make-sparse-keymap "MULE")
|
|
31 "Keymap for MULE (Multilingual environment) specific commands.")
|
|
32
|
165
|
33 ;; Keep "C-x C-m ..." for mule specific commands.
|
207
|
34 (define-key ctl-x-map "\C-m" mule-keymap)
|
155
|
35
|
|
36 (define-key mule-keymap "f" 'set-buffer-file-coding-system)
|
|
37 (define-key mule-keymap "F" 'set-default-buffer-file-coding-system) ; XEmacs
|
|
38 (define-key mule-keymap "t" 'set-terminal-coding-system)
|
|
39 (define-key mule-keymap "k" 'set-keyboard-coding-system)
|
207
|
40 (define-key mule-keymap "p" 'set-buffer-process-coding-system)
|
197
|
41 (define-key mule-keymap "\C-\\" 'select-input-method)
|
207
|
42 (define-key mule-keymap "c" 'universal-coding-system-argument)
|
|
43 ;;(define-key mule-keymap "c" 'list-coding-system-briefly) ; XEmacs
|
155
|
44 (define-key mule-keymap "C" 'list-coding-system) ; XEmacs
|
|
45 (define-key mule-keymap "r" 'toggle-display-direction) ; XEmacs
|
197
|
46 (define-key mule-keymap "l" 'set-language-environment)
|
155
|
47
|
|
48 (define-key help-map "\C-L" 'describe-language-support)
|
197
|
49 (define-key help-map "L" 'describe-language-environment)
|
155
|
50 (define-key help-map "\C-\\" 'describe-input-method)
|
197
|
51 (define-key help-map "I" 'describe-input-method)
|
207
|
52 (define-key help-map "C" 'describe-coding-system)
|
155
|
53 (define-key help-map "h" 'view-hello-file)
|
|
54
|
|
55 ;; Menu for XEmacs were moved to x11/x-menubar.el.
|
|
56
|
|
57
|
|
58 ;; This should be a single character key binding because users use it
|
|
59 ;; very frequently while editing multilingual text. Now we can use
|
|
60 ;; only two such keys: "\C-\\" and "\C-^", but the latter is not
|
|
61 ;; convenient because it requires shifting on most keyboards. An
|
|
62 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit'
|
|
63 ;; but it won't be used that frequently.
|
|
64 (define-key global-map "\C-\\" 'toggle-input-method)
|
|
65
|
|
66 (defun view-hello-file ()
|
|
67 "Display the HELLO file which list up many languages and characters."
|
|
68 (interactive)
|
165
|
69 ;; We have to decode the file in any environment.
|
|
70 (let ((coding-system-for-read 'iso-2022-7))
|
|
71 (find-file-read-only (expand-file-name "HELLO" data-directory))))
|
155
|
72
|
207
|
73 (defun universal-coding-system-argument ()
|
|
74 "Execute an I/O command using the specified coding system."
|
|
75 (interactive)
|
|
76 (let* ((coding-system
|
|
77 (read-coding-system "Coding system for following command: "))
|
|
78 (keyseq (read-key-sequence
|
|
79 (format "Command to execute with %s:" coding-system)))
|
|
80 (cmd (key-binding keyseq)))
|
|
81 (let ((coding-system-for-read coding-system)
|
|
82 (coding-system-for-write coding-system))
|
|
83 (message "")
|
|
84 (call-interactively cmd))))
|
|
85
|
|
86 (defun set-default-coding-systems (coding-system)
|
|
87 "Set default value of various coding systems to CODING-SYSTEM.
|
|
88 The follwing coding systems are set:
|
|
89 o coding system of a newly created buffer
|
|
90 o default coding system for terminal output
|
|
91 o default coding system for keyboard input
|
|
92 o default coding system for subprocess I/O"
|
|
93 (check-coding-system coding-system)
|
|
94 ;;(setq-default buffer-file-coding-system coding-system)
|
|
95 (set-default-buffer-file-coding-system coding-system)
|
|
96 ;;(setq default-terminal-coding-system coding-system)
|
|
97 (setq terminal-coding-system coding-system)
|
|
98 ;;(setq default-keyboard-coding-system coding-system)
|
|
99 (setq keyboard-coding-system coding-system)
|
|
100 ;;(setq default-process-coding-system (cons coding-system coding-system))
|
|
101 (add-hook 'comint-exec-hook
|
|
102 (lambda ()
|
|
103 (let ((proc (get-buffer-process (current-buffer))))
|
|
104 (set-process-input-coding-system proc coding-system)
|
|
105 (set-process-output-coding-system proc coding-system)
|
|
106 )))
|
|
107 (setq file-name-coding-system coding-system)
|
|
108 )
|
|
109
|
|
110 (defun prefer-coding-system (coding-system)
|
|
111 "Add CODING-SYSTEM at the front of the priority list for automatic detection.
|
|
112 This also sets the following coding systems to CODING-SYSTEM:
|
|
113 o coding system of a newly created buffer
|
|
114 o default coding system for terminal output
|
|
115 o default coding system for keyboard input
|
|
116 o default coding system for subprocess I/O"
|
|
117 (interactive "zPrefer coding system: ")
|
|
118 (if (not (and coding-system (coding-system-p coding-system)))
|
|
119 (error "Invalid coding system `%s'" coding-system))
|
|
120 (let ((coding-category (coding-system-category coding-system))
|
|
121 (parent (coding-system-parent coding-system)))
|
|
122 (if (not coding-category)
|
|
123 ;; CODING-SYSTEM is no-conversion or undecided.
|
|
124 (error "Can't prefer the coding system `%s'" coding-system))
|
|
125 (set coding-category (or parent coding-system))
|
|
126 (if (not (eq coding-category (car coding-category-list)))
|
|
127 ;; We must change the order.
|
|
128 (setq coding-category-list
|
|
129 (cons coding-category
|
|
130 (delq coding-category coding-category-list))))
|
|
131 (if (and parent (interactive-p))
|
|
132 (message "Highest priority is set to %s (parent of %s)"
|
|
133 parent coding-system))
|
|
134 (set-default-coding-systems (or parent coding-system))))
|
|
135
|
155
|
136
|
|
137 ;;; Language support staffs.
|
|
138
|
|
139 (defvar language-info-alist nil
|
|
140 "Alist of language names vs the corresponding information of various kind.
|
|
141 Each element looks like:
|
165
|
142 (LANGUAGE-NAME . ((KEY . INFO) ...))
|
155
|
143 where LANGUAGE-NAME is a string,
|
|
144 KEY is a symbol denoting the kind of information,
|
|
145 INFO is any Lisp object which contains the actual information related
|
|
146 to KEY.")
|
|
147
|
|
148 (defun get-language-info (language-name key)
|
|
149 "Return the information for LANGUAGE-NAME of the kind KEY.
|
|
150 KEY is a symbol denoting the kind of required information."
|
197
|
151 (if (symbolp language-name)
|
|
152 (setq language-name (symbol-name language-name)))
|
|
153 (let ((lang-slot (assoc-ignore-case language-name language-info-alist)))
|
155
|
154 (if lang-slot
|
165
|
155 (cdr (assq key (cdr lang-slot))))))
|
155
|
156
|
|
157 (defun set-language-info (language-name key info)
|
|
158 "Set for LANGUAGE-NAME the information INFO under KEY.
|
|
159 KEY is a symbol denoting the kind of information.
|
|
160 INFO is any Lisp object which contains the actual information.
|
|
161
|
|
162 Currently, the following KEYs are used by Emacs:
|
197
|
163
|
155
|
164 charset: list of symbols whose values are charsets specific to the language.
|
197
|
165
|
155
|
166 coding-system: list of coding systems specific to the langauge.
|
197
|
167
|
155
|
168 tutorial: a tutorial file name written in the language.
|
197
|
169
|
155
|
170 sample-text: one line short text containing characters of the language.
|
197
|
171
|
|
172 documentation: t or a string describing how Emacs supports the language.
|
|
173 If a string is specified, it is shown before any other information
|
|
174 of the language by the command `describe-language-environment'.
|
|
175
|
165
|
176 setup-function: a function to call for setting up environment
|
197
|
177 convenient for a user of the language.
|
155
|
178
|
197
|
179 If KEY is documentation or setup-function, you can also specify
|
|
180 a cons cell as INFO, in which case, the car part should be
|
|
181 a normal value as INFO for KEY (as described above),
|
|
182 and the cdr part should be a symbol whose value is a menu keymap
|
|
183 in which an entry for the language is defined. But, only the car part
|
|
184 is actually set as the information.
|
|
185
|
|
186 We will define more KEYs in the future. To avoid conflict,
|
|
187 if you want to use your own KEY values, make them start with `user-'."
|
|
188 (if (symbolp language-name)
|
|
189 (setq language-name (symbol-name language-name)))
|
155
|
190 (let (lang-slot key-slot)
|
|
191 (setq lang-slot (assoc language-name language-info-alist))
|
165
|
192 (if (null lang-slot) ; If no slot for the language, add it.
|
|
193 (setq lang-slot (list language-name)
|
|
194 language-info-alist (cons lang-slot language-info-alist)))
|
155
|
195 (setq key-slot (assq key lang-slot))
|
165
|
196 (if (null key-slot) ; If no slot for the key, add it.
|
|
197 (progn
|
|
198 (setq key-slot (list key))
|
|
199 (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
|
155
|
200 ;; Setup menu.
|
197
|
201 (cond ((eq key 'documentation)
|
207
|
202 ;; (define-key-after
|
|
203 ;; (if (consp info)
|
|
204 ;; (prog1 (symbol-value (cdr info))
|
|
205 ;; (setq info (car info)))
|
|
206 ;; describe-language-environment-map)
|
165
|
207 ;; (vector (intern language-name))
|
207
|
208 ;; (cons language-name 'describe-specified-language-support)
|
165
|
209 ;; t)
|
207
|
210 (if (consp info)
|
|
211 (setq info (car info)))
|
165
|
212 (eval-after-load "x-menubar"
|
207
|
213 `(add-menu-button
|
|
214 '("Mule" "Describe Language Support")
|
|
215 (vector ,language-name
|
|
216 '(describe-language-environment ,language-name)
|
|
217 t)))
|
165
|
218 )
|
|
219 ((eq key 'setup-function)
|
207
|
220 ;; (define-key-after
|
|
221 ;; (if (consp info)
|
|
222 ;; (prog1 (symbol-value (cdr info))
|
|
223 ;; (setq info (car info)))
|
|
224 ;; setup-language-environment-map)
|
165
|
225 ;; (vector (intern language-name))
|
207
|
226 ;; (cons language-name 'setup-specified-language-environment)
|
165
|
227 ;; t)
|
207
|
228 (if (consp info)
|
|
229 (setq info (car info)))
|
165
|
230 (eval-after-load "x-menubar"
|
207
|
231 `(add-menu-button
|
|
232 '("Mule" "Set Language Environment")
|
|
233 (vector ,language-name
|
|
234 '(set-language-environment ,language-name)
|
|
235 t)))
|
165
|
236 ))
|
207
|
237
|
|
238 (setcdr key-slot info)
|
155
|
239 ))
|
|
240
|
|
241 (defun set-language-info-alist (language-name alist)
|
|
242 "Set for LANGUAGE-NAME the information in ALIST.
|
|
243 ALIST is an alist of KEY and INFO. See the documentation of
|
|
244 `set-langauge-info' for the meanings of KEY and INFO."
|
197
|
245 (if (symbolp language-name)
|
|
246 (setq language-name (symbol-name language-name)))
|
155
|
247 (while alist
|
|
248 (set-language-info language-name (car (car alist)) (cdr (car alist)))
|
|
249 (setq alist (cdr alist))))
|
|
250
|
197
|
251 (defun read-language-name (key prompt &optional default)
|
|
252 "Read language name which has information for KEY, prompting with PROMPT.
|
|
253 DEFAULT is the default choice of language.
|
|
254 This returns a language name as a string."
|
155
|
255 (let* ((completion-ignore-case t)
|
165
|
256 (name (completing-read prompt
|
|
257 language-info-alist
|
|
258 (function (lambda (elm) (assq key elm)))
|
207
|
259 t nil default)))
|
197
|
260 (if (and (> (length name) 0)
|
|
261 (get-language-info name key))
|
|
262 name)))
|
155
|
263
|
|
264 ;;; Multilingual input methods.
|
|
265
|
197
|
266 (defconst leim-list-file-name "leim-list.el"
|
|
267 "Name of LEIM list file.
|
|
268 This file contains a list of libraries of Emacs input methods (LEIM)
|
|
269 in the format of Lisp expression for registering each input method.
|
|
270 Emacs loads this file at startup time.")
|
|
271
|
|
272 (defvar leim-list-header (format "\
|
|
273 ;;; %s -- list of LEIM (Library of Emacs Input Method)
|
|
274 ;;
|
|
275 ;; This file contains a list of LEIM (Library of Emacs Input Method)
|
|
276 ;; in the same directory as this file. Loading this file registeres
|
|
277 ;; the whole input methods in Emacs.
|
|
278 ;;
|
|
279 ;; Each entry has the form:
|
|
280 ;; (register-input-method
|
|
281 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC
|
|
282 ;; TITLE DESCRIPTION
|
|
283 ;; ARG ...)
|
|
284 ;; See the function `register-input-method' for the meanings of arguments.
|
|
285 ;;
|
|
286 ;; If this directory is included in load-path, Emacs automatically
|
|
287 ;; loads this file at startup time.
|
|
288
|
|
289 "
|
|
290 leim-list-file-name)
|
|
291 "Header to be inserted in LEIM list file.")
|
|
292
|
|
293 (defvar leim-list-entry-regexp "^(register-input-method"
|
|
294 "Regexp matching head of each entry in LEIM list file.
|
|
295 See also the variable `leim-list-header'")
|
|
296
|
|
297 (defvar update-leim-list-functions
|
|
298 '(quail-update-leim-list-file)
|
|
299 "List of functions to call to update LEIM list file.
|
|
300 Each function is called with one arg, LEIM directory name.")
|
|
301
|
|
302 (defun update-leim-list-file (&rest dirs)
|
|
303 "Update LEIM list file in directories DIRS."
|
|
304 (let ((functions update-leim-list-functions))
|
|
305 (while functions
|
|
306 (apply (car functions) dirs)
|
|
307 (setq functions (cdr functions)))))
|
|
308
|
155
|
309 (defvar current-input-method nil
|
|
310 "The current input method for multilingual text.
|
197
|
311 If nil, that means no input method is activated now.")
|
155
|
312 (make-variable-buffer-local 'current-input-method)
|
|
313 (put 'current-input-method 'permanent-local t)
|
|
314
|
|
315 (defvar current-input-method-title nil
|
197
|
316 "Title string of the current input method shown in mode line.")
|
155
|
317 (make-variable-buffer-local 'current-input-method-title)
|
|
318 (put 'current-input-method-title 'permanent-local t)
|
|
319
|
197
|
320 (defcustom default-input-method nil
|
|
321 "*Default input method for multilingual text.
|
|
322 This is the input method activated automatically by the command
|
|
323 `toggle-input-method' (\\[toggle-input-method])."
|
|
324 :group 'mule)
|
155
|
325
|
197
|
326 (defvar input-method-history nil
|
|
327 "History list for some commands that read input methods.")
|
|
328 (make-variable-buffer-local 'input-method-history)
|
|
329 (put 'input-method-history 'permanent-local t)
|
155
|
330
|
|
331 (defvar inactivate-current-input-method-function nil
|
|
332 "Function to call for inactivating the current input method.
|
|
333 Every input method should set this to an appropriate value when activated.
|
197
|
334 This function is called with no argument.
|
|
335
|
|
336 This function should never change the value of `current-input-method'.
|
|
337 It is set to nil by the function `inactivate-input-method'.")
|
155
|
338 (make-variable-buffer-local 'inactivate-current-input-method-function)
|
|
339 (put 'inactivate-current-input-method-function 'permanent-local t)
|
|
340
|
|
341 (defvar describe-current-input-method-function nil
|
|
342 "Function to call for describing the current input method.
|
|
343 This function is called with no argument.")
|
|
344 (make-variable-buffer-local 'describe-current-input-method-function)
|
|
345 (put 'describe-current-input-method-function 'permanent-local t)
|
|
346
|
197
|
347 (defvar input-method-alist nil
|
|
348 "Alist of input method names vs the corresponding information to use it.
|
|
349 Each element has the form:
|
|
350 (INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC TITLE DESCRIPTION ...)
|
|
351 See the function `register-input-method' for the meanings of each elements.")
|
|
352
|
|
353 (defun register-input-method (input-method language-name &rest args)
|
|
354 "Register INPUT-METHOD as an input method for LANGUAGE-NAME.
|
|
355 INPUT-METHOD and LANGUAGE-NAME are symbols or strings.
|
|
356 The remaining arguments are:
|
|
357 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARG ...
|
|
358 where,
|
|
359 ACTIVATE-FUNC is a function to call for activating this method.
|
|
360 TITLE is a string shown in mode-line while this method is active,
|
|
361 DESCRIPTION is a string describing about this method,
|
|
362 Arguments to ACTIVATE-FUNC are INPUT-METHOD and ARGs."
|
|
363 (if (symbolp language-name)
|
|
364 (setq language-name (symbol-name language-name)))
|
|
365 (if (symbolp input-method)
|
|
366 (setq input-method (symbol-name input-method)))
|
|
367 (let ((info (cons language-name args))
|
|
368 (slot (assoc input-method input-method-alist)))
|
|
369 (if slot
|
|
370 (setcdr slot info)
|
|
371 (setq slot (cons input-method info))
|
|
372 (setq input-method-alist (cons slot input-method-alist)))))
|
|
373
|
|
374 (defun read-input-method-name (prompt &optional default inhibit-null)
|
|
375 "Read a name of input method from a minibuffer prompting with PROMPT.
|
|
376 If DEFAULT is non-nil, use that as the default,
|
|
377 and substitute it into PROMPT at the first `%s'.
|
|
378 If INHIBIT-NULL is non-nil, null input signals an error.
|
155
|
379
|
197
|
380 The return value is a string."
|
|
381 (if default
|
|
382 (setq prompt (format prompt default)))
|
|
383 (let* ((completion-ignore-case t)
|
|
384 ;; This binding is necessary because input-method-history is
|
|
385 ;; buffer local.
|
|
386 (input-method (completing-read prompt input-method-alist
|
|
387 nil t nil 'input-method-history)
|
|
388 ;;default)
|
|
389 ))
|
|
390 (if (> (length input-method) 0)
|
|
391 input-method
|
207
|
392 (if inhibit-null
|
|
393 (error "No valid input method is specified")))))
|
155
|
394
|
197
|
395 (defun activate-input-method (input-method)
|
|
396 "Turn INPUT-METHOD on.
|
|
397 If some input method is already on, turn it off at first."
|
|
398 (if (symbolp input-method)
|
|
399 (setq input-method (symbol-name input-method)))
|
|
400 (if (and current-input-method
|
|
401 (not (string= current-input-method input-method)))
|
|
402 (inactivate-input-method))
|
|
403 (unless current-input-method
|
|
404 (let ((slot (assoc input-method input-method-alist)))
|
|
405 (if (null slot)
|
|
406 (error "Can't activate input method `%s'" input-method))
|
|
407 (apply (nth 2 slot) input-method (nthcdr 5 slot))
|
|
408 (setq current-input-method input-method)
|
|
409 (setq current-input-method-title (nth 3 slot))
|
|
410 (run-hooks 'input-method-activate-hook))))
|
155
|
411
|
197
|
412 (defun inactivate-input-method ()
|
|
413 "Turn off the current input method."
|
|
414 (when current-input-method
|
|
415 (if input-method-history
|
|
416 (unless (string= current-input-method (car input-method-history))
|
|
417 (setq input-method-history
|
|
418 (cons current-input-method
|
|
419 (delete current-input-method input-method-history))))
|
|
420 (setq input-method-history (list current-input-method)))
|
|
421 (unwind-protect
|
|
422 (funcall inactivate-current-input-method-function)
|
|
423 (unwind-protect
|
|
424 (run-hooks 'input-method-inactivate-hook)
|
|
425 (setq current-input-method nil
|
|
426 current-input-method-title nil)))))
|
|
427
|
|
428 (defun select-input-method (input-method)
|
|
429 "Select and turn on INPUT-METHOD.
|
|
430 This sets the default input method to what you specify,
|
|
431 and turn it on for the current buffer."
|
|
432 (interactive
|
|
433 (let* ((default (or (car input-method-history) default-input-method)))
|
|
434 (list (read-input-method-name
|
|
435 (if default "Select input method (default %s): " "Select input method: ")
|
|
436 default t))))
|
|
437 (activate-input-method input-method)
|
|
438 (setq default-input-method input-method))
|
155
|
439
|
|
440 (defun toggle-input-method (&optional arg)
|
197
|
441 "Turn on or off a multilingual text input method for the current buffer.
|
|
442
|
|
443 With arg, read an input method from minibuffer and turn it on.
|
|
444
|
|
445 Without arg, if some input method is currently activated, turn it off,
|
|
446 else turn on an input method selected last time
|
|
447 or the default input method (see `default-input-method').
|
|
448
|
|
449 When there's no input method to turn on, turn on what read from minibuffer."
|
155
|
450 (interactive "P")
|
197
|
451 (let* ((default (or (car input-method-history) default-input-method)))
|
|
452 (if (and current-input-method (not arg))
|
|
453 (inactivate-input-method)
|
|
454 (activate-input-method
|
|
455 (if (or arg (not default))
|
|
456 (read-input-method-name
|
|
457 (if default "Input method (default %s): " "Input method: " )
|
|
458 default t)
|
|
459 default))
|
|
460 (or default-input-method
|
|
461 (setq default-input-method current-input-method)))))
|
155
|
462
|
197
|
463 (defun describe-input-method (input-method)
|
|
464 "Describe input method INPUT-METHOD."
|
|
465 (interactive
|
|
466 (list (read-input-method-name
|
|
467 "Describe input method (default, current choice): ")))
|
|
468 (if (and input-method (symbolp input-method))
|
|
469 (setq input-method (symbol-name input-method)))
|
|
470 (if (null input-method)
|
|
471 (describe-current-input-method)
|
|
472 (with-output-to-temp-buffer "*Help*"
|
|
473 (let ((elt (assoc input-method input-method-alist)))
|
|
474 (princ (format "Input method: %s (`%s' in mode line) for %s\n %s\n"
|
|
475 input-method (nth 3 elt) (nth 1 elt) (nth 4 elt)))))))
|
|
476
|
|
477 (defun describe-current-input-method ()
|
|
478 "Describe the input method currently in use."
|
155
|
479 (if current-input-method
|
|
480 (if (and (symbolp describe-current-input-method-function)
|
165
|
481 (fboundp describe-current-input-method-function))
|
155
|
482 (funcall describe-current-input-method-function)
|
|
483 (message "No way to describe the current input method `%s'"
|
|
484 (cdr current-input-method))
|
|
485 (ding))
|
197
|
486 (error "No input method is activated now")))
|
155
|
487
|
165
|
488 (defun read-multilingual-string (prompt &optional initial-input
|
197
|
489 input-method)
|
165
|
490 "Read a multilingual string from minibuffer, prompting with string PROMPT.
|
|
491 The input method selected last time is activated in minibuffer.
|
197
|
492 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
|
|
493 initially.
|
|
494 Optional 3rd argument INPUT-METHOD specifies the input method
|
|
495 to be activated instead of the one selected last time. It is a symbol
|
|
496 or a string."
|
|
497 (setq input-method
|
|
498 (or input-method
|
|
499 default-input-method
|
|
500 (read-input-method-name "Input method: " nil t)))
|
|
501 (if (and input-method (symbolp input-method))
|
|
502 (setq input-method (symbol-name input-method)))
|
|
503 (let ((current-input-method input-method))
|
207
|
504 ;; FSFmacs
|
|
505 ;; (read-string prompt initial-input nil nil t)))
|
|
506 (read-string prompt initial-input nil)))
|
155
|
507
|
|
508 ;; Variables to control behavior of input methods. All input methods
|
|
509 ;; should react to these variables.
|
|
510
|
197
|
511 (defcustom input-method-verbose-flag t
|
|
512 "*If this flag is non-nil, input methods give extra guidance.
|
|
513
|
|
514 The extra guidance is done by showing list of available keys in echo
|
|
515 area.
|
155
|
516
|
197
|
517 For complex input methods such as `chinese-py' and `japanese',
|
|
518 when you use the input method in the minibuffer, the guidance is
|
|
519 shown at the bottom short window (split from the existing window).
|
|
520 For simple input methods, guidance is not shown
|
|
521 when you are in the minibuffer."
|
|
522 :type 'boolean
|
|
523 :group 'mule)
|
|
524
|
|
525 (defcustom input-method-highlight-flag t
|
|
526 "*If this flag is non-nil, input methods highlight partially-entered text.
|
|
527 For instance, while you are in the middle of a Quail input method sequence,
|
|
528 the text inserted so far is temporarily underlined.
|
|
529 The underlining goes away when you finish or abort the input method sequence."
|
|
530 :type 'boolean
|
|
531 :group 'mule)
|
155
|
532
|
165
|
533 (defvar input-method-activate-hook nil
|
197
|
534 "Normal hook run just after an input method is activated.
|
|
535
|
|
536 The variable `current-input-method' keeps the input method name
|
|
537 just activated.")
|
155
|
538
|
165
|
539 (defvar input-method-inactivate-hook nil
|
197
|
540 "Normal hook run just after an input method is inactivated.
|
|
541
|
|
542 The variable `current-input-method' still keeps the input method name
|
|
543 just inacitvated.")
|
155
|
544
|
165
|
545 (defvar input-method-after-insert-chunk-hook nil
|
|
546 "Normal hook run just after an input method insert some chunk of text.")
|
155
|
547
|
197
|
548 (defvar input-method-exit-on-invalid-key nil
|
|
549 "This flag controls the behaviour of an input method on invalid key input.
|
|
550 Usually, when a user types a key which doesn't start any character
|
|
551 handled by the input method, the key is handled by turning off the
|
|
552 input method temporalily. After the key is handled, the input method is
|
|
553 back on.
|
|
554 But, if this flag is non-nil, the input method is never back on.")
|
|
555
|
155
|
556
|
207
|
557 (defun setup-specified-language-environment ()
|
|
558 "Set up multi-lingual environment convenient for the specified language."
|
|
559 (interactive)
|
|
560 (let (language-name)
|
|
561 (if (and (symbolp last-command-event)
|
|
562 (or (not (eq last-command-event 'Default))
|
|
563 (setq last-command-event 'English))
|
|
564 (setq language-name (symbol-name last-command-event)))
|
|
565 (set-language-environment language-name)
|
|
566 (error "Bogus calling sequence"))))
|
|
567
|
|
568 (defvar current-language-environment "English"
|
|
569 "The last language environment specified with `set-language-environment'.")
|
|
570
|
|
571 (defun set-language-environment (language-name)
|
|
572 "Set up multi-lingual environment for using LANGUAGE-NAME.
|
|
573 This sets the coding system priority and the default input method
|
|
574 and sometimes other things."
|
|
575 (interactive (list (read-language-name 'setup-function
|
|
576 "Set language environment: ")))
|
|
577 (if language-name
|
|
578 (if (symbolp language-name)
|
|
579 (setq language-name (symbol-name language-name)))
|
|
580 (setq language-name "English"))
|
|
581 (if (null (get-language-info language-name 'setup-function))
|
|
582 (error "Language environment not defined: %S" language-name))
|
|
583 (funcall (get-language-info language-name 'setup-function))
|
|
584 (setq current-language-environment language-name)
|
|
585 (force-mode-line-update t))
|
155
|
586
|
|
587 ;; Print all arguments with `princ', then print "\n".
|
|
588 (defsubst princ-list (&rest args)
|
|
589 (while args (princ (car args)) (setq args (cdr args)))
|
|
590 (princ "\n"))
|
|
591
|
207
|
592 ;; Print a language specific information such as input methods,
|
|
593 ;; charsets, and coding systems. This function is intended to be
|
|
594 ;; called from the menu:
|
|
595 ;; [menu-bar mule describe-language-environment LANGUAGE]
|
|
596 ;; and should not run it by `M-x describe-current-input-method-function'.
|
|
597 (defun describe-specified-language-support ()
|
|
598 "Describe how Emacs supports the specified language environment."
|
|
599 (interactive)
|
|
600 (let (language-name)
|
|
601 (if (not (and (symbolp last-command-event)
|
|
602 (setq language-name (symbol-name last-command-event))))
|
|
603 (error "Bogus calling sequence"))
|
|
604 (describe-language-environment language-name)))
|
165
|
605
|
207
|
606 (defun describe-language-environment (language-name)
|
|
607 "Describe how Emacs supports language environment LANGUAGE-NAME."
|
|
608 (interactive
|
|
609 (list (read-language-name
|
|
610 'documentation
|
|
611 "Describe language environment (default, current choise): ")))
|
|
612 (if (null language-name)
|
|
613 (setq language-name current-language-environment))
|
|
614 (if (or (null language-name)
|
|
615 (null (get-language-info language-name 'documentation)))
|
|
616 (error "No documentation for the specified language"))
|
|
617 (if (symbolp language-name)
|
|
618 (setq language-name (symbol-name language-name)))
|
|
619 (let ((doc (get-language-info language-name 'documentation)))
|
|
620 (with-output-to-temp-buffer "*Help*"
|
165
|
621 (if (stringp doc)
|
207
|
622 (progn
|
|
623 (princ-list doc)
|
|
624 (terpri)))
|
|
625 (let ((str (get-language-info language-name 'sample-text)))
|
|
626 (if (stringp str)
|
|
627 (progn
|
|
628 (princ "Sample text:\n")
|
|
629 (princ-list " " str)
|
|
630 (terpri))))
|
|
631 (princ "Input methods:\n")
|
|
632 (let ((l input-method-alist))
|
|
633 (while l
|
|
634 (if (string= language-name (nth 1 (car l)))
|
|
635 (princ-list " " (car (car l))
|
|
636 (format " (`%s' in mode line)" (nth 3 (car l)))))
|
|
637 (setq l (cdr l))))
|
|
638 (terpri)
|
|
639 (princ "Character sets:\n")
|
|
640 (let ((l (get-language-info language-name 'charset)))
|
|
641 (if (null l)
|
|
642 (princ-list " nothing specific to " language-name)
|
|
643 (while l
|
|
644 (princ-list " " (car l) ": "
|
|
645 (charset-description (car l)))
|
|
646 (setq l (cdr l)))))
|
|
647 (terpri)
|
|
648 (princ "Coding systems:\n")
|
|
649 (let ((l (get-language-info language-name 'coding-system)))
|
|
650 (if (null l)
|
|
651 (princ-list " nothing specific to " language-name)
|
|
652 (while l
|
|
653 (princ ; (format " %s (`%c' in mode line):\n\t%s\n"
|
|
654 ;; In XEmacs, `coding-system-mnemonic' returns string.
|
|
655 (format " %s (`%s' in mode line):\n\t%s\n"
|
|
656 (car l)
|
|
657 (coding-system-mnemonic (car l))
|
|
658 (coding-system-doc-string (car l))))
|
|
659 (setq l (cdr l))))))))
|
155
|
660
|
|
661 ;;; Charset property
|
|
662
|
|
663 ;; (defsubst get-charset-property (charset propname)
|
|
664 ;; "Return the value of CHARSET's PROPNAME property.
|
|
665 ;; This is the last value stored with
|
|
666 ;; `(put-charset-property CHARSET PROPNAME VALUE)'."
|
|
667 ;; (plist-get (charset-plist charset) propname))
|
|
668
|
|
669 ;; (defsubst put-charset-property (charset propname value)
|
|
670 ;; "Store CHARSETS's PROPNAME property with value VALUE.
|
|
671 ;; It can be retrieved with `(get-charset-property CHARSET PROPNAME)'."
|
|
672 ;; (set-charset-plist charset
|
|
673 ;; (plist-put (charset-plist charset) propname value)))
|
|
674
|
207
|
675 (defvar char-code-property-table
|
|
676 (make-char-table 'generic)
|
|
677 "Char-table containing a property list of each character code.
|
155
|
678 ;;
|
207
|
679 See also the documentation of `get-char-code-property' and
|
|
680 `put-char-code-property'")
|
|
681 ;; (let ((plist (aref char-code-property-table char)))
|
|
682 (defun get-char-code-property (char propname)
|
|
683 "Return the value of CHAR's PROPNAME property in `char-code-property-table'."
|
|
684 (let ((plist (get-char-table char char-code-property-table)))
|
|
685 (if (listp plist)
|
|
686 (car (cdr (memq propname plist))))))
|
155
|
687
|
207
|
688 (defun put-char-code-property (char propname value)
|
|
689 "Store CHAR's PROPNAME property with VALUE in `char-code-property-table'.
|
|
690 It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
|
|
691 (let ((plist (get-char-table char char-code-property-table)))
|
|
692 (if plist
|
|
693 (let ((slot (memq propname plist)))
|
|
694 (if slot
|
|
695 (setcar (cdr slot) value)
|
|
696 (nconc plist (list propname value))))
|
|
697 (put-char-table char (list propname value) char-code-property-table)
|
|
698 )))
|
155
|
699 ;; (setcar (cdr slot) value)
|
|
700 ;; (nconc plist (list propname value))))
|
|
701 ;; (aset char-code-property-table char (list propname value)))))
|
|
702
|
|
703 ;;; mule-cmds.el ends here
|