Mercurial > hg > xemacs-beta
comparison lisp/mule/mule-cmds.el @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 4f79e16b1112 |
children | a86b2b5e0111 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
1 ;;; mule-cmds.el --- Commands for multilingual environment | 1 ;;; mule-cmds.el --- Commands for multilingual environment |
2 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | 3 ;; Copyright (C) 1995,1999 Electrotechnical Laboratory, JAPAN. |
4 ;; Licensed to the Free Software Foundation. | 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 |
25 | 25 |
26 ;;; Code: | 26 ;;; Code: |
27 | 27 |
28 ;;; MULE related key bindings and menus. | 28 ;;; MULE related key bindings and menus. |
29 | 29 |
30 (defvar mule-keymap (make-sparse-keymap "MULE") | 30 (defvar mule-keymap (make-sparse-keymap "Mule") |
31 "Keymap for MULE (Multilingual environment) specific commands.") | 31 "Keymap for Mule (Multilingual environment) specific commands.") |
32 | 32 |
33 ;; Keep "C-x C-m ..." for mule specific commands. | 33 ;; Keep "C-x C-m ..." for mule specific commands. |
34 (define-key ctl-x-map "\C-m" mule-keymap) | 34 (define-key ctl-x-map "\C-m" mule-keymap) |
35 | 35 |
36 (define-key mule-keymap "f" 'set-buffer-file-coding-system) | 36 (define-key mule-keymap "f" 'set-buffer-file-coding-system) |
37 (define-key mule-keymap "F" 'set-default-buffer-file-coding-system) ; XEmacs | 37 (define-key mule-keymap "F" 'set-default-buffer-file-coding-system) ; XEmacs |
38 (define-key mule-keymap "t" 'set-terminal-coding-system) | 38 (define-key mule-keymap "t" 'set-terminal-coding-system) |
39 (define-key mule-keymap "k" 'set-keyboard-coding-system) | 39 (define-key mule-keymap "k" 'set-keyboard-coding-system) |
40 (define-key mule-keymap "p" 'set-buffer-process-coding-system) | 40 (define-key mule-keymap "p" 'set-buffer-process-coding-system) |
41 (define-key mule-keymap "\C-\\" 'select-input-method) | 41 (define-key mule-keymap "x" 'set-selection-coding-system) |
42 (define-key mule-keymap "X" 'set-next-selection-coding-system) | |
43 (define-key mule-keymap "\C-\\" 'set-input-method) | |
42 (define-key mule-keymap "c" 'universal-coding-system-argument) | 44 (define-key mule-keymap "c" 'universal-coding-system-argument) |
43 ;;(define-key mule-keymap "c" 'list-coding-system-briefly) ; XEmacs | 45 ;;(define-key mule-keymap "c" 'list-coding-system-briefly) ; XEmacs |
44 (define-key mule-keymap "C" 'list-coding-system) ; XEmacs | 46 (define-key mule-keymap "C" 'describe-coding-system) ; XEmacs |
45 (define-key mule-keymap "r" 'toggle-display-direction) ; XEmacs | 47 (define-key mule-keymap "r" 'toggle-display-direction) ; XEmacs |
46 (define-key mule-keymap "l" 'set-language-environment) | 48 (define-key mule-keymap "l" 'set-language-environment) |
47 | 49 |
48 (define-key help-map "\C-L" 'describe-language-support) | 50 (define-key help-map "\C-L" 'describe-language-support) |
49 (define-key help-map "L" 'describe-language-environment) | 51 (define-key help-map "L" 'describe-language-environment) |
61 ;; convenient because it requires shifting on most keyboards. An | 63 ;; convenient because it requires shifting on most keyboards. An |
62 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit' | 64 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit' |
63 ;; but it won't be used that frequently. | 65 ;; but it won't be used that frequently. |
64 (define-key global-map "\C-\\" 'toggle-input-method) | 66 (define-key global-map "\C-\\" 'toggle-input-method) |
65 | 67 |
68 ;;; This is no good because people often type Shift-SPC | |
69 ;;; meaning to type SPC. -- rms. | |
70 ;;; ;; Here's an alternative key binding for X users (Shift-SPACE). | |
71 ;;; (define-key global-map [?\S- ] 'toggle-input-method) | |
72 | |
73 (defun coding-system-change-eol-conversion (coding-system eol-type) | |
74 "Return a coding system which differs from CODING-SYSTEM in eol conversion. | |
75 The returned coding system converts end-of-line by EOL-TYPE | |
76 but text as the same way as CODING-SYSTEM. | |
77 EOL-TYPE should be `lf', `crlf', `cr' or nil. | |
78 If EOL-TYPE is nil, the returned coding system detects | |
79 how end-of-line is formatted automatically while decoding. | |
80 | |
81 EOL-TYPE can be specified by an symbol `unix', `dos' or `mac'. | |
82 They means `lf', `crlf', and `cr' respectively." | |
83 (if (symbolp eol-type) | |
84 (setq eol-type (cond ((or (eq eol-type 'unix) | |
85 (eq eol-type 'lf)) | |
86 'eol-lf) | |
87 ((or (eq eol-type 'dos) | |
88 (eq eol-type 'crlf)) | |
89 'eol-crlf) | |
90 ((or (eq eol-type 'mac) | |
91 (eq eol-type 'cr)) | |
92 'eol-cr) | |
93 (t eol-type)))) | |
94 (let ((orig-eol-type (coding-system-eol-type coding-system))) | |
95 (if (null orig-eol-type) | |
96 (if (not eol-type) | |
97 coding-system | |
98 (coding-system-property coding-system eol-type)) | |
99 (let ((base (coding-system-base coding-system))) | |
100 (if (not eol-type) | |
101 base | |
102 (if (= eol-type orig-eol-type) | |
103 coding-system | |
104 (setq orig-eol-type (coding-system-eol-type base)) | |
105 (if (null orig-eol-type) | |
106 (coding-system-property base eol-type)))))))) | |
107 | |
108 ;; (defun coding-system-change-text-conversion (coding-system coding) | |
109 ;; "Return a coding system which differs from CODING-SYSTEM in text conversion. | |
110 ;; The returned coding system converts text by CODING | |
111 ;; but end-of-line as the same way as CODING-SYSTEM. | |
112 ;; If CODING is nil, the returned coding system detects | |
113 ;; how text is formatted automatically while decoding." | |
114 ;; (if (not coding) | |
115 ;; (coding-system-base coding-system) | |
116 ;; (let ((eol-type (coding-system-eol-type coding-system))) | |
117 ;; (coding-system-change-eol-conversion | |
118 ;; coding | |
119 ;; (if (numberp eol-type) (aref [unix dos mac] eol-type)))))) | |
120 | |
66 (defun view-hello-file () | 121 (defun view-hello-file () |
67 "Display the HELLO file which list up many languages and characters." | 122 "Display the HELLO file which list up many languages and characters." |
68 (interactive) | 123 (interactive) |
69 ;; We have to decode the file in any environment. | 124 ;; We have to decode the file in any environment. |
70 (let ((coding-system-for-read 'iso-2022-7)) | 125 (let ((coding-system-for-read 'iso-2022-7bit)) |
71 (find-file-read-only (expand-file-name "HELLO" data-directory)))) | 126 (find-file-read-only (expand-file-name "HELLO" data-directory)))) |
72 | 127 |
73 (defun universal-coding-system-argument () | 128 (defun universal-coding-system-argument () |
74 "Execute an I/O command using the specified coding system." | 129 "Execute an I/O command using the specified coding system." |
75 (interactive) | 130 (interactive) |
76 (let* ((coding-system | 131 (let* ((default (and buffer-file-coding-system |
77 (read-coding-system "Coding system for following command: ")) | 132 (not (eq (coding-system-type buffer-file-coding-system) |
133 t)) | |
134 (coding-system-name buffer-file-coding-system))) | |
135 (coding-system | |
136 (read-coding-system | |
137 (if default | |
138 (format "Coding system for following command (default, %s): " | |
139 default) | |
140 "Coding system for following command: ") | |
141 default)) | |
78 (keyseq (read-key-sequence | 142 (keyseq (read-key-sequence |
79 (format "Command to execute with %s:" coding-system))) | 143 (format "Command to execute with %s:" coding-system))) |
80 (cmd (key-binding keyseq))) | 144 (cmd (key-binding keyseq))) |
81 (let ((coding-system-for-read coding-system) | 145 (let ((coding-system-for-read coding-system) |
82 (coding-system-for-write coding-system)) | 146 (coding-system-for-write coding-system)) |
83 (message "") | 147 (message "") |
84 (call-interactively cmd)))) | 148 (call-interactively cmd)))) |
85 | 149 |
86 (defun set-default-coding-systems (coding-system) | 150 (defun set-default-coding-systems (coding-system) |
87 "Set default value of various coding systems to CODING-SYSTEM. | 151 "Set default value of various coding systems to CODING-SYSTEM. |
88 The follwing coding systems are set: | 152 This sets the following coding systems: |
89 o coding system of a newly created buffer | 153 o coding system of a newly created buffer |
90 o default coding system for terminal output | 154 o default coding system for terminal output |
91 o default coding system for keyboard input | 155 o default coding system for keyboard input |
92 o default coding system for subprocess I/O" | 156 o default coding system for subprocess I/O |
157 o default coding system for converting file names." | |
93 (check-coding-system coding-system) | 158 (check-coding-system coding-system) |
94 ;;(setq-default buffer-file-coding-system coding-system) | 159 ;;(setq-default buffer-file-coding-system coding-system) |
95 (set-default-buffer-file-coding-system coding-system) | 160 (set-default-buffer-file-coding-system coding-system) |
96 ;;(setq default-terminal-coding-system coding-system) | 161 ;; (if default-enable-multibyte-characters |
162 ;; (setq default-file-name-coding-system coding-system)) | |
163 ;; If coding-system is nil, honor that on MS-DOS as well, so | |
164 ;; that they could reset the terminal coding system. | |
165 ;; (unless (and (eq window-system 'pc) coding-system) | |
166 ;; (setq default-terminal-coding-system coding-system)) | |
97 (setq terminal-coding-system coding-system) | 167 (setq terminal-coding-system coding-system) |
98 ;;(setq default-keyboard-coding-system coding-system) | 168 ;;(setq default-keyboard-coding-system coding-system) |
99 (setq keyboard-coding-system coding-system) | 169 (setq keyboard-coding-system coding-system) |
100 ;;(setq default-process-coding-system (cons coding-system coding-system)) | 170 ;;(setq default-process-coding-system (cons coding-system coding-system)) |
171 ;; Refer to coding-system-for-read and coding-system-for-write | |
172 ;; so that C-x RET c works. | |
101 (add-hook 'comint-exec-hook | 173 (add-hook 'comint-exec-hook |
102 `(lambda () | 174 `(lambda () |
103 (let ((proc (get-buffer-process (current-buffer)))) | 175 (let ((proc (get-buffer-process (current-buffer)))) |
104 (set-process-input-coding-system proc ',coding-system) | 176 (set-process-input-coding-system |
105 (set-process-output-coding-system proc ',coding-system))) | 177 proc (or coding-system-for-read ',coding-system)) |
178 (set-process-output-coding-system | |
179 proc (or coding-system-for-write ',coding-system)))) | |
106 'append) | 180 'append) |
107 (setq file-name-coding-system coding-system)) | 181 (setq file-name-coding-system coding-system)) |
108 | 182 |
109 (defun prefer-coding-system (coding-system) | 183 (defun prefer-coding-system (coding-system) |
110 "Add CODING-SYSTEM at the front of the priority list for automatic detection. | 184 "Add CODING-SYSTEM at the front of the priority list for automatic detection. |
111 This also sets the following coding systems to CODING-SYSTEM: | 185 This also sets the following coding systems: |
112 o coding system of a newly created buffer | 186 o coding system of a newly created buffer |
113 o default coding system for terminal output | 187 o default coding system for terminal output |
114 o default coding system for keyboard input | 188 o default coding system for keyboard input |
115 o default coding system for subprocess I/O" | 189 o default coding system for converting file names. |
190 | |
191 If CODING-SYSTEM specifies a certain type of EOL conversion, the coding | |
192 systems set by this function will use that type of EOL conversion. | |
193 | |
194 This command does not change the default value of terminal coding system | |
195 for MS-DOS terminal, because DOS terminals only support a single coding | |
196 system, and Emacs automatically sets the default to that coding system at | |
197 startup." | |
116 (interactive "zPrefer coding system: ") | 198 (interactive "zPrefer coding system: ") |
117 (if (not (and coding-system (coding-system-p coding-system))) | 199 (if (not (and coding-system (find-coding-system coding-system))) |
118 (error "Invalid coding system `%s'" coding-system)) | 200 (error "Invalid coding system `%s'" coding-system)) |
119 (let ((coding-category (coding-system-category coding-system)) | 201 (let ((coding-category (coding-system-category coding-system)) |
120 (parent (coding-system-parent coding-system))) | 202 (base (coding-system-base coding-system)) |
203 (eol-type (coding-system-eol-type coding-system))) | |
121 (if (not coding-category) | 204 (if (not coding-category) |
122 ;; CODING-SYSTEM is no-conversion or undecided. | 205 ;; CODING-SYSTEM is no-conversion or undecided. |
123 (error "Can't prefer the coding system `%s'" coding-system)) | 206 (error "Can't prefer the coding system `%s'" coding-system)) |
124 (set coding-category (or parent coding-system)) | 207 (set-coding-category-system coding-category (or base coding-system)) |
125 (if (not (eq coding-category (car coding-category-list))) | 208 ;; (update-coding-systems-internal) |
209 (or (eq coding-category (car (coding-category-list))) | |
126 ;; We must change the order. | 210 ;; We must change the order. |
127 (setq coding-category-list | 211 (set-coding-priority-list (list coding-category))) |
128 (cons coding-category | 212 (if (and base (interactive-p)) |
129 (delq coding-category coding-category-list)))) | 213 (message "Highest priority is set to %s (base of %s)" |
130 (if (and parent (interactive-p)) | 214 base coding-system)) |
131 (message "Highest priority is set to %s (parent of %s)" | 215 ;; If they asked for specific EOL conversion, honor that. |
132 parent coding-system)) | 216 (if (memq eol-type '(lf crlf mac)) |
133 (set-default-coding-systems (or parent coding-system)))) | 217 (setq coding-system |
134 | 218 (coding-system-change-eol-conversion base eol-type)) |
219 (setq coding-system base)) | |
220 (set-default-coding-systems coding-system))) | |
221 | |
222 ;; (defun find-coding-systems-region-subset-p (list1 list2) | |
223 ;; "Return non-nil if all elements in LIST1 are included in LIST2. | |
224 ;; Comparison done with EQ." | |
225 ;; (catch 'tag | |
226 ;; (while list1 | |
227 ;; (or (memq (car list1) list2) | |
228 ;; (throw 'tag nil)) | |
229 ;; (setq list1 (cdr list1))) | |
230 ;; t)) | |
231 | |
232 ;; (defun find-coding-systems-region (from to) | |
233 ;; "Return a list of proper coding systems to encode a text between FROM and TO. | |
234 ;; All coding systems in the list can safely encode any multibyte characters | |
235 ;; in the text. | |
236 ;; | |
237 ;; If the text contains no multibyte characters, return a list of a single | |
238 ;; element `undecided'." | |
239 ;; (find-coding-systems-for-charsets (find-charset-region from to))) | |
240 | |
241 ;; (defun find-coding-systems-string (string) | |
242 ;; "Return a list of proper coding systems to encode STRING. | |
243 ;; All coding systems in the list can safely encode any multibyte characters | |
244 ;; in STRING. | |
245 ;; | |
246 ;; If STRING contains no multibyte characters, return a list of a single | |
247 ;; element `undecided'." | |
248 ;; (find-coding-systems-for-charsets (find-charset-string string))) | |
249 | |
250 ;; (defun find-coding-systems-for-charsets (charsets) | |
251 ;; "Return a list of proper coding systems to encode characters of CHARSETS. | |
252 ;; CHARSETS is a list of character sets." | |
253 ;; (if (or (null charsets) | |
254 ;; (and (= (length charsets) 1) | |
255 ;; (eq 'ascii (car charsets)))) | |
256 ;; '(undecided) | |
257 ;; (setq charsets (delq 'composition charsets)) | |
258 ;; (let ((l (coding-system-list 'base-only)) | |
259 ;; (charset-preferred-codings | |
260 ;; (mapcar (function | |
261 ;; (lambda (x) | |
262 ;; (if (eq x 'unknown) | |
263 ;; 'raw-text | |
264 ;; (get-charset-property x 'preferred-coding-system)))) | |
265 ;; charsets)) | |
266 ;; (priorities (mapcar (function (lambda (x) (symbol-value x))) | |
267 ;; coding-category-list)) | |
268 ;; codings coding safe) | |
269 ;; (if (memq 'unknown charsets) | |
270 ;; ;; The region contains invalid multibyte characters. | |
271 ;; (setq l '(raw-text))) | |
272 ;; (while l | |
273 ;; (setq coding (car l) l (cdr l)) | |
274 ;; (if (and (setq safe (coding-system-get coding 'safe-charsets)) | |
275 ;; (or (eq safe t) | |
276 ;; (find-coding-systems-region-subset-p charsets safe))) | |
277 ;; ;; We put the higher priority to coding systems included | |
278 ;; ;; in CHARSET-PREFERRED-CODINGS, and within them, put the | |
279 ;; ;; higher priority to coding systems which support smaller | |
280 ;; ;; number of charsets. | |
281 ;; (let ((priority | |
282 ;; (+ (if (coding-system-get coding 'mime-charset) 4096 0) | |
283 ;; (lsh (length (memq coding priorities)) 7) | |
284 ;; (if (memq coding charset-preferred-codings) 64 0) | |
285 ;; (if (> (coding-system-type coding) 0) 32 0) | |
286 ;; (if (consp safe) (- 32 (length safe)) 0)))) | |
287 ;; (setq codings (cons (cons priority coding) codings))))) | |
288 ;; (mapcar 'cdr | |
289 ;; (sort codings (function (lambda (x y) (> (car x) (car y)))))) | |
290 ;; ))) | |
291 | |
292 ;; (defun find-multibyte-characters (from to &optional maxcount excludes) | |
293 ;; "Find multibyte characters in the region specified by FROM and TO. | |
294 ;; If FROM is a string, find multibyte characters in the string. | |
295 ;; The return value is an alist of the following format: | |
296 ;; ((CHARSET COUNT CHAR ...) ...) | |
297 ;; where | |
298 ;; CHARSET is a character set, | |
299 ;; COUNT is a number of characters, | |
300 ;; CHARs are found characters of the character set. | |
301 ;; Optional 3rd arg MAXCOUNT limits how many CHARs are put in the above list. | |
302 ;; Optional 4th arg EXCLUDE is a list of character sets to be ignored. | |
303 ;; | |
304 ;; For invalid characters, CHARs are actually strings." | |
305 ;; (let ((chars nil) | |
306 ;; charset char) | |
307 ;; (if (stringp from) | |
308 ;; (let ((idx 0)) | |
309 ;; (while (setq idx (string-match "[^\000-\177]" from idx)) | |
310 ;; (setq char (aref from idx) | |
311 ;; charset (char-charset char)) | |
312 ;; (if (eq charset 'unknown) | |
313 ;; (setq char (match-string 0))) | |
314 ;; (if (or (eq charset 'unknown) | |
315 ;; (not (or (eq excludes t) (memq charset excludes)))) | |
316 ;; (let ((slot (assq charset chars))) | |
317 ;; (if slot | |
318 ;; (if (not (memq char (nthcdr 2 slot))) | |
319 ;; (let ((count (nth 1 slot))) | |
320 ;; (setcar (cdr slot) (1+ count)) | |
321 ;; (if (or (not maxcount) (< count maxcount)) | |
322 ;; (nconc slot (list char))))) | |
323 ;; (setq chars (cons (list charset 1 char) chars))))) | |
324 ;; (setq idx (1+ idx)))) | |
325 ;; (save-excursion | |
326 ;; (goto-char from) | |
327 ;; (while (re-search-forward "[^\000-\177]" to t) | |
328 ;; (setq char (preceding-char) | |
329 ;; charset (char-charset char)) | |
330 ;; (if (eq charset 'unknown) | |
331 ;; (setq char (match-string 0))) | |
332 ;; (if (or (eq charset 'unknown) | |
333 ;; (not (or (eq excludes t) (memq charset excludes)))) | |
334 ;; (let ((slot (assq charset chars))) | |
335 ;; (if slot | |
336 ;; (if (not (member char (nthcdr 2 slot))) | |
337 ;; (let ((count (nth 1 slot))) | |
338 ;; (setcar (cdr slot) (1+ count)) | |
339 ;; (if (or (not maxcount) (< count maxcount)) | |
340 ;; (nconc slot (list char))))) | |
341 ;; (setq chars (cons (list charset 1 char) chars)))))))) | |
342 ;; (nreverse chars))) | |
343 | |
344 ;; (defvar last-coding-system-specified nil | |
345 ;; "Most recent coding system explicitly specified by the user when asked. | |
346 ;; This variable is set whenever Emacs asks the user which coding system | |
347 ;; to use in order to write a file. If you set it to nil explicitly, | |
348 ;; then call `write-region', then afterward this variable will be non-nil | |
349 ;; only if the user was explicitly asked and specified a coding system.") | |
350 | |
351 ;; (defun select-safe-coding-system (from to &optional default-coding-system) | |
352 ;; "Ask a user to select a safe coding system from candidates. | |
353 ;; The candidates of coding systems which can safely encode a text | |
354 ;; between FROM and TO are shown in a popup window. | |
355 ;; | |
356 ;; Optional arg DEFAULT-CODING-SYSTEM specifies a coding system to be | |
357 ;; checked at first. If omitted, buffer-file-coding-system of the | |
358 ;; current buffer is used. | |
359 ;; | |
360 ;; If the text can be encoded safely by DEFAULT-CODING-SYSTEM, it is | |
361 ;; returned without any user interaction. | |
362 ;; | |
363 ;; Kludgy feature: if FROM is a string, the string is the target text, | |
364 ;; and TO is ignored." | |
365 ;; (or default-coding-system | |
366 ;; (setq default-coding-system buffer-file-coding-system)) | |
367 ;; (let* ((charsets (if (stringp from) (find-charset-string from) | |
368 ;; (find-charset-region from to))) | |
369 ;; (safe-coding-systems (find-coding-systems-for-charsets charsets))) | |
370 ;; (if (or (not enable-multibyte-characters) | |
371 ;; (eq (car safe-coding-systems) 'undecided) | |
372 ;; (eq default-coding-system 'no-conversion) | |
373 ;; (and default-coding-system | |
374 ;; (memq (coding-system-base default-coding-system) | |
375 ;; safe-coding-systems))) | |
376 ;; default-coding-system | |
377 ;; | |
378 ;; ;; At first, change each coding system to the corresponding | |
379 ;; ;; mime-charset name if it is also a coding system. | |
380 ;; (let ((l safe-coding-systems) | |
381 ;; mime-charset) | |
382 ;; (while l | |
383 ;; (setq mime-charset (coding-system-get (car l) 'mime-charset)) | |
384 ;; (if (and mime-charset (coding-system-p mime-charset)) | |
385 ;; (setcar l mime-charset)) | |
386 ;; (setq l (cdr l)))) | |
387 ;; | |
388 ;; (let ((non-safe-chars (find-multibyte-characters | |
389 ;; from to 3 | |
390 ;; (and default-coding-system | |
391 ;; (coding-system-get default-coding-system | |
392 ;; 'safe-charsets)))) | |
393 ;; show-position overlays) | |
394 ;; (save-excursion | |
395 ;; ;; Highlight characters that default-coding-system can't encode. | |
396 ;; (when (integerp from) | |
397 ;; (goto-char from) | |
398 ;; (let ((found nil)) | |
399 ;; (while (and (not found) | |
400 ;; (re-search-forward "[^\000-\177]" to t)) | |
401 ;; (setq found (assq (char-charset (preceding-char)) | |
402 ;; non-safe-chars)))) | |
403 ;; (forward-line -1) | |
404 ;; (setq show-position (point)) | |
405 ;; (save-excursion | |
406 ;; (while (and (< (length overlays) 256) | |
407 ;; (re-search-forward "[^\000-\177]" to t)) | |
408 ;; (let* ((char (preceding-char)) | |
409 ;; (charset (char-charset char))) | |
410 ;; (when (assq charset non-safe-chars) | |
411 ;; (setq overlays (cons (make-overlay (1- (point)) (point)) | |
412 ;; overlays)) | |
413 ;; (overlay-put (car overlays) 'face 'highlight)))))) | |
414 ;; | |
415 ;; ;; At last, ask a user to select a proper coding system. | |
416 ;; (unwind-protect | |
417 ;; (save-window-excursion | |
418 ;; (when show-position | |
419 ;; ;; At first, be sure to show the current buffer. | |
420 ;; (set-window-buffer (selected-window) (current-buffer)) | |
421 ;; (set-window-start (selected-window) show-position)) | |
422 ;; ;; Then, show a helpful message. | |
423 ;; (with-output-to-temp-buffer "*Warning*" | |
424 ;; (save-excursion | |
425 ;; (set-buffer standard-output) | |
426 ;; (insert "The target text contains the following non ASCII character(s):\n") | |
427 ;; (let ((len (length non-safe-chars)) | |
428 ;; (shown 0)) | |
429 ;; (while (and non-safe-chars (< shown 3)) | |
430 ;; (when (> (length (car non-safe-chars)) 2) | |
431 ;; (setq shown (1+ shown)) | |
432 ;; (insert (format "%25s: " (car (car non-safe-chars)))) | |
433 ;; (let ((l (nthcdr 2 (car non-safe-chars)))) | |
434 ;; (while l | |
435 ;; (if (or (stringp (car l)) (char-valid-p (car l))) | |
436 ;; (insert (car l))) | |
437 ;; (setq l (cdr l)))) | |
438 ;; (if (> (nth 1 (car non-safe-chars)) 3) | |
439 ;; (insert "...")) | |
440 ;; (insert "\n")) | |
441 ;; (setq non-safe-chars (cdr non-safe-chars))) | |
442 ;; (if (< shown len) | |
443 ;; (insert (format "%27s\n" "...")))) | |
444 ;; (insert (format "\ | |
445 ;; These can't be encoded safely by the coding system %s. | |
446 ;; | |
447 ;; Please select one from the following safe coding systems:\n" | |
448 ;; default-coding-system)) | |
449 ;; (let ((pos (point)) | |
450 ;; (fill-prefix " ")) | |
451 ;; (mapcar (function (lambda (x) (princ " ") (princ x))) | |
452 ;; safe-coding-systems) | |
453 ;; (fill-region-as-paragraph pos (point))))) | |
454 ;; | |
455 ;; ;; Read a coding system. | |
456 ;; (let* ((safe-names (mapcar (lambda (x) (list (symbol-name x))) | |
457 ;; safe-coding-systems)) | |
458 ;; (name (completing-read | |
459 ;; (format "Select coding system (default %s): " | |
460 ;; (car safe-coding-systems)) | |
461 ;; safe-names nil t nil nil | |
462 ;; (car (car safe-names))))) | |
463 ;; (setq last-coding-system-specified (intern name)) | |
464 ;; (if (integerp (coding-system-eol-type default-coding-system)) | |
465 ;; (setq last-coding-system-specified | |
466 ;; (coding-system-change-eol-conversion | |
467 ;; last-coding-system-specified | |
468 ;; (coding-system-eol-type default-coding-system)))) | |
469 ;; last-coding-system-specified)) | |
470 ;; (kill-buffer "*Warning*") | |
471 ;; (while overlays | |
472 ;; (delete-overlay (car overlays)) | |
473 ;; (setq overlays (cdr overlays))))))))) | |
474 | |
475 ;; (setq select-safe-coding-system-function 'select-safe-coding-system) | |
476 | |
477 ;; (defun select-message-coding-system () | |
478 ;; "Return a coding system to encode the outgoing message of the current buffer. | |
479 ;; It at first tries the first coding system found in these variables | |
480 ;; in this order: | |
481 ;; (1) local value of `buffer-file-coding-system' | |
482 ;; (2) value of `sendmail-coding-system' | |
483 ;; (3) value of `default-buffer-file-coding-system' | |
484 ;; (4) value of `default-sendmail-coding-system' | |
485 ;; If the found coding system can't encode the current buffer, | |
486 ;; or none of them are bound to a coding system, | |
487 ;; it asks the user to select a proper coding system." | |
488 ;; (let ((coding (or (and (local-variable-p 'buffer-file-coding-system) | |
489 ;; buffer-file-coding-system) | |
490 ;; sendmail-coding-system | |
491 ;; default-buffer-file-coding-system | |
492 ;; default-sendmail-coding-system))) | |
493 ;; (if (eq coding 'no-conversion) | |
494 ;; ;; We should never use no-conversion for outgoing mails. | |
495 ;; (setq coding nil)) | |
496 ;; (if (fboundp select-safe-coding-system-function) | |
497 ;; (funcall select-safe-coding-system-function | |
498 ;; (point-min) (point-max) coding) | |
499 ;; coding))) | |
135 | 500 |
136 ;;; Language support staffs. | 501 ;;; Language support stuff. |
137 | 502 |
138 (defvar language-info-alist nil | 503 (defvar language-info-alist nil |
139 "Alist of language names vs the corresponding information of various kind. | 504 "Alist of language environment definitions. |
140 Each element looks like: | 505 Each element looks like: |
141 (LANGUAGE-NAME . ((KEY . INFO) ...)) | 506 (LANGUAGE-NAME . ((KEY . INFO) ...)) |
142 where LANGUAGE-NAME is a string, | 507 where LANGUAGE-NAME is a string, the name of the language environment, |
143 KEY is a symbol denoting the kind of information, | 508 KEY is a symbol denoting the kind of information, and |
144 INFO is any Lisp object which contains the actual information related | 509 INFO is the data associated with KEY. |
145 to KEY.") | 510 Meaningful values for KEY include |
146 | 511 |
147 (defun get-language-info (language-name key) | 512 documentation value is documentation of what this language environment |
148 "Return the information for LANGUAGE-NAME of the kind KEY. | 513 is meant for, and how to use it. |
149 KEY is a symbol denoting the kind of required information." | 514 charset value is a list of the character sets used by this |
150 (if (symbolp language-name) | 515 language environment. |
151 (setq language-name (symbol-name language-name))) | 516 sample-text value is one line of text, |
152 (let ((lang-slot (assoc-ignore-case language-name language-info-alist))) | 517 written using those character sets, |
518 appropriate for this language environment. | |
519 setup-function value is a function to call to switch to this | |
520 language environment. | |
521 exit-function value is a function to call to leave this | |
522 language environment. | |
523 coding-system value is a list of coding systems that are good | |
524 for saving text written in this language environment. | |
525 This list serves as suggestions to the user; | |
526 in effect, as a kind of documentation. | |
527 coding-priority value is a list of coding systems for this language | |
528 environment, in order of decreasing priority. | |
529 This is used to set up the coding system priority | |
530 list when you switch to this language environment. | |
531 input-method value is a default input method for this language | |
532 environment. | |
533 features value is a list of features requested in this | |
534 language environment. | |
535 tutorial value is a tutorial file name written in the language.") | |
536 | |
537 (defun get-language-info (lang-env key) | |
538 "Return information listed under KEY for language environment LANG-ENV. | |
539 KEY is a symbol denoting the kind of information. | |
540 For a list of useful values for KEY and their meanings, | |
541 see `language-info-alist'." | |
542 (if (symbolp lang-env) | |
543 (setq lang-env (symbol-name lang-env))) | |
544 (let ((lang-slot (assoc-ignore-case lang-env language-info-alist))) | |
153 (if lang-slot | 545 (if lang-slot |
154 (cdr (assq key (cdr lang-slot)))))) | 546 (cdr (assq key (cdr lang-slot)))))) |
155 | 547 |
156 (defun set-language-info (language-name key info) | 548 (defun set-language-info (lang-env key info) |
157 "Set for LANGUAGE-NAME the information INFO under KEY. | 549 "Modify part of the definition of language environment LANG-ENV. |
550 Specifically, this stores the information INFO under KEY | |
551 in the definition of this language environment. | |
158 KEY is a symbol denoting the kind of information. | 552 KEY is a symbol denoting the kind of information. |
159 INFO is any Lisp object which contains the actual information. | 553 INFO is the value for that information. |
160 | 554 |
161 Currently, the following KEYs are used by Emacs: | 555 For a list of useful values for KEY and their meanings, |
162 | 556 see `language-info-alist'." |
163 charset: list of symbols whose values are charsets specific to the language. | 557 (if (symbolp lang-env) |
164 | 558 (setq lang-env (symbol-name lang-env))) |
165 coding-system: list of coding systems specific to the language. | |
166 | |
167 tutorial: a tutorial file name written in the language. | |
168 | |
169 sample-text: one line short text containing characters of the language. | |
170 | |
171 documentation: t or a string describing how Emacs supports the language. | |
172 If a string is specified, it is shown before any other information | |
173 of the language by the command `describe-language-environment'. | |
174 | |
175 setup-function: a function to call for setting up environment | |
176 convenient for a user of the language. | |
177 | |
178 If KEY is documentation or setup-function, you can also specify | |
179 a cons cell as INFO, in which case, the car part should be | |
180 a normal value as INFO for KEY (as described above), | |
181 and the cdr part should be a symbol whose value is a menu keymap | |
182 in which an entry for the language is defined. But, only the car part | |
183 is actually set as the information. | |
184 | |
185 We will define more KEYs in the future. To avoid conflict, | |
186 if you want to use your own KEY values, make them start with `user-'." | |
187 (if (symbolp language-name) | |
188 (setq language-name (symbol-name language-name))) | |
189 (let (lang-slot key-slot) | 559 (let (lang-slot key-slot) |
190 (setq lang-slot (assoc language-name language-info-alist)) | 560 (setq lang-slot (assoc lang-env language-info-alist)) |
191 (if (null lang-slot) ; If no slot for the language, add it. | 561 (if (null lang-slot) ; If no slot for the language, add it. |
192 (setq lang-slot (list language-name) | 562 (setq lang-slot (list lang-env) |
193 language-info-alist (cons lang-slot language-info-alist))) | 563 language-info-alist (cons lang-slot language-info-alist))) |
194 (setq key-slot (assq key lang-slot)) | 564 (setq key-slot (assq key lang-slot)) |
195 (if (null key-slot) ; If no slot for the key, add it. | 565 (if (null key-slot) ; If no slot for the key, add it. |
196 (progn | 566 (progn |
197 (setq key-slot (list key)) | 567 (setq key-slot (list key)) |
198 (setcdr lang-slot (cons key-slot (cdr lang-slot))))) | 568 (setcdr lang-slot (cons key-slot (cdr lang-slot))))) |
199 ;; Setup menu. | 569 (setcdr key-slot info))) |
200 (cond ((eq key 'documentation) | 570 |
201 ;; (define-key-after | 571 (defun set-language-info-alist (lang-env alist &optional parents) |
202 ;; (if (consp info) | 572 "Store ALIST as the definition of language environment LANG-ENV. |
203 ;; (prog1 (symbol-value (cdr info)) | 573 ALIST is an alist of KEY and INFO values. See the documentation of |
204 ;; (setq info (car info))) | 574 `set-language-info' for the meanings of KEY and INFO." |
205 ;; describe-language-environment-map) | 575 (if (symbolp lang-env) |
206 ;; (vector (intern language-name)) | 576 (setq lang-env (symbol-name lang-env))) |
207 ;; (cons language-name 'describe-specified-language-support) | 577 (let (; (describe-map describe-language-environment-map) |
208 ;; t) | 578 ; (setup-map setup-language-environment-map) |
209 (if (consp info) | 579 ) |
210 (setq info (car info))) | 580 ;; (if parents |
211 (when (featurep 'menubar) | 581 ;; (let ((l parents) |
212 (eval-after-load | 582 ;; map parent-symbol parent) |
583 ;; (while l | |
584 ;; (if (symbolp (setq parent-symbol (car l))) | |
585 ;; (setq parent (symbol-name parent)) | |
586 ;; (setq parent parent-symbol parent-symbol (intern parent))) | |
587 ;; (setq map (lookup-key describe-map (vector parent-symbol))) | |
588 ;; (if (not map) | |
589 ;; (progn | |
590 ;; (setq map (intern (format "describe-%s-environment-map" | |
591 ;; (downcase parent)))) | |
592 ;; (define-prefix-command map) | |
593 ;; (define-key-after describe-map (vector parent-symbol) | |
594 ;; (cons parent map) t))) | |
595 ;; (setq describe-map (symbol-value map)) | |
596 ;; (setq map (lookup-key setup-map (vector parent-symbol))) | |
597 ;; (if (not map) | |
598 ;; (progn | |
599 ;; (setq map (intern (format "setup-%s-environment-map" | |
600 ;; (downcase parent)))) | |
601 ;; (define-prefix-command map) | |
602 ;; (define-key-after setup-map (vector parent-symbol) | |
603 ;; (cons parent map) t))) | |
604 ;; (setq setup-map (symbol-value map)) | |
605 ;; (setq l (cdr l))))) | |
606 | |
607 ;; Set up menu items for this language env. | |
608 (let ((doc (assq 'documentation alist))) | |
609 (when doc | |
610 ;; (define-key-after describe-map (vector (intern lang-env)) | |
611 ;; (cons lang-env 'describe-specified-language-support) t) | |
612 (when (featurep 'menubar) | |
613 (eval-after-load | |
213 "menubar-items.elc" | 614 "menubar-items.elc" |
214 `(add-menu-button | 615 `(add-menu-button |
215 '("Mule" "Describe Language Support") | 616 '("Mule" "Describe Language Support") |
216 (vector ,language-name | 617 (vector ,lang-env |
217 '(describe-language-environment ,language-name) | 618 '(describe-language-environment ,lang-env) |
218 t)))) | 619 t)))) |
219 ) | 620 )) |
220 ((eq key 'setup-function) | 621 ;; (define-key-after setup-map (vector (intern lang-env)) |
221 ;; (define-key-after | 622 ;; (cons lang-env 'setup-specified-language-environment) t) |
222 ;; (if (consp info) | 623 (when (featurep 'menubar) |
223 ;; (prog1 (symbol-value (cdr info)) | 624 (eval-after-load |
224 ;; (setq info (car info))) | 625 "menubar-items.elc" |
225 ;; setup-language-environment-map) | 626 `(add-menu-button |
226 ;; (vector (intern language-name)) | 627 '("Mule" "Set Language Environment") |
227 ;; (cons language-name 'setup-specified-language-environment) | 628 (vector ,lang-env |
228 ;; t) | 629 '(set-language-environment ,lang-env) |
229 (if (consp info) | 630 t)))) |
230 (setq info (car info))) | 631 |
231 (when (featurep 'menubar) | 632 (while alist |
232 (eval-after-load | 633 (set-language-info lang-env (car (car alist)) (cdr (car alist))) |
233 "menubar-items.elc" | 634 (setq alist (cdr alist))))) |
234 `(add-menu-button | |
235 '("Mule" "Set Language Environment") | |
236 (vector ,language-name | |
237 '(set-language-environment ,language-name) | |
238 t)))) | |
239 )) | |
240 | |
241 (setcdr key-slot info) | |
242 )) | |
243 | |
244 (defun set-language-info-alist (language-name alist) | |
245 "Set for LANGUAGE-NAME the information in ALIST. | |
246 ALIST is an alist of KEY and INFO. See the documentation of | |
247 `set-language-info' for the meanings of KEY and INFO." | |
248 (if (symbolp language-name) | |
249 (setq language-name (symbol-name language-name))) | |
250 (while alist | |
251 (set-language-info language-name (car (car alist)) (cdr (car alist))) | |
252 (setq alist (cdr alist)))) | |
253 | 635 |
254 (defun read-language-name (key prompt &optional default) | 636 (defun read-language-name (key prompt &optional default) |
255 "Read language name which has information for KEY, prompting with PROMPT. | 637 "Read a language environment name which has information for KEY. |
256 DEFAULT is the default choice of language. | 638 If KEY is nil, read any language environment. |
257 This returns a language name as a string." | 639 Prompt with PROMPT. DEFAULT is the default choice of language environment. |
640 This returns a language environment name as a string." | |
258 (let* ((completion-ignore-case t) | 641 (let* ((completion-ignore-case t) |
259 (name (completing-read prompt | 642 (name (completing-read prompt |
260 language-info-alist | 643 language-info-alist |
261 (function (lambda (elm) (assq key elm))) | 644 (and key |
262 t nil default))) | 645 (function (lambda (elm) (assq key elm)))) |
646 t nil nil default))) | |
263 (if (and (> (length name) 0) | 647 (if (and (> (length name) 0) |
264 (get-language-info name key)) | 648 (or (not key) |
649 (get-language-info name key))) | |
265 name))) | 650 name))) |
266 | 651 |
267 ;;; Multilingual input methods. | 652 ;;; Multilingual input methods. |
268 | 653 |
269 (defconst leim-list-file-name "leim-list.el" | 654 (defconst leim-list-file-name "leim-list.el" |
274 | 659 |
275 (defvar leim-list-header (format | 660 (defvar leim-list-header (format |
276 ";;; %s -- list of LEIM (Library of Emacs Input Method) | 661 ";;; %s -- list of LEIM (Library of Emacs Input Method) |
277 ;; | 662 ;; |
278 ;; This file contains a list of LEIM (Library of Emacs Input Method) | 663 ;; This file contains a list of LEIM (Library of Emacs Input Method) |
279 ;; in the same directory as this file. Loading this file registeres | 664 ;; in the same directory as this file. Loading this file registers |
280 ;; the whole input methods in Emacs. | 665 ;; the whole input methods in Emacs. |
281 ;; | 666 ;; |
282 ;; Each entry has the form: | 667 ;; Each entry has the form: |
283 ;; (register-input-method | 668 ;; (register-input-method |
284 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC | 669 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC |
319 "Title string of the current input method shown in mode line.") | 704 "Title string of the current input method shown in mode line.") |
320 (make-variable-buffer-local 'current-input-method-title) | 705 (make-variable-buffer-local 'current-input-method-title) |
321 (put 'current-input-method-title 'permanent-local t) | 706 (put 'current-input-method-title 'permanent-local t) |
322 | 707 |
323 (defcustom default-input-method nil | 708 (defcustom default-input-method nil |
324 "*Default input method for multilingual text. | 709 "*Default input method for multilingual text (a string). |
325 This is the input method activated automatically by the command | 710 This is the input method activated automatically by the command |
326 `toggle-input-method' (\\[toggle-input-method])." | 711 `toggle-input-method' (\\[toggle-input-method])." |
327 :group 'mule) | 712 :group 'mule |
713 :type '(choice (const nil) string)) | |
714 | |
715 (put 'input-method-function 'permanent-local t) | |
328 | 716 |
329 (defvar input-method-history nil | 717 (defvar input-method-history nil |
330 "History list for some commands that read input methods.") | 718 "History list for some commands that read input methods.") |
331 (make-variable-buffer-local 'input-method-history) | 719 (make-variable-buffer-local 'input-method-history) |
332 (put 'input-method-history 'permanent-local t) | 720 (put 'input-method-history 'permanent-local t) |
346 This function is called with no argument.") | 734 This function is called with no argument.") |
347 (make-variable-buffer-local 'describe-current-input-method-function) | 735 (make-variable-buffer-local 'describe-current-input-method-function) |
348 (put 'describe-current-input-method-function 'permanent-local t) | 736 (put 'describe-current-input-method-function 'permanent-local t) |
349 | 737 |
350 (defvar input-method-alist nil | 738 (defvar input-method-alist nil |
351 "Alist of input method names vs the corresponding information to use it. | 739 "Alist of input method names vs how to use them. |
352 Each element has the form: | 740 Each element has the form: |
353 (INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC TITLE DESCRIPTION ...) | 741 (INPUT-METHOD LANGUAGE-ENV ACTIVATE-FUNC TITLE DESCRIPTION ARGS...) |
354 See the function `register-input-method' for the meanings of each elements.") | 742 See the function `register-input-method' for the meanings of the elements.") |
355 | 743 |
356 (defun register-input-method (input-method language-name &rest args) | 744 (defun register-input-method (input-method lang-env &rest args) |
357 "Register INPUT-METHOD as an input method for LANGUAGE-NAME. | 745 "Register INPUT-METHOD as an input method for language environment ENV. |
358 INPUT-METHOD and LANGUAGE-NAME are symbols or strings. | 746 INPUT-METHOD and LANG-ENV are symbols or strings. |
747 | |
359 The remaining arguments are: | 748 The remaining arguments are: |
360 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARG ... | 749 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARGS... |
361 where, | 750 ACTIVATE-FUNC is a function to call to activate this method. |
362 ACTIVATE-FUNC is a function to call for activating this method. | 751 TITLE is a string to show in the mode line when this method is active. |
363 TITLE is a string shown in mode-line while this method is active, | 752 DESCRIPTION is a string describing this method and what it is good for. |
364 DESCRIPTION is a string describing about this method, | 753 The ARGS, if any, are passed as arguments to ACTIVATE-FUNC. |
365 Arguments to ACTIVATE-FUNC are INPUT-METHOD and ARGs." | 754 All told, the arguments to ACTIVATE-FUNC are INPUT-METHOD and the ARGS. |
366 (if (symbolp language-name) | 755 |
367 (setq language-name (symbol-name language-name))) | 756 This function is mainly used in the file \"leim-list.el\" which is |
757 created at building time of emacs, registering all quail input methods | |
758 contained in the emacs distribution. | |
759 | |
760 In case you want to register a new quail input method by yourself, be | |
761 careful to use the same input method title as given in the third | |
762 parameter of `quail-define-package' (if the values are different, the | |
763 string specified in this function takes precedence). | |
764 | |
765 The commands `describe-input-method' and `list-input-methods' need | |
766 this duplicated values to show some information about input methods | |
767 without loading the affected quail packages." | |
768 (if (symbolp lang-env) | |
769 (setq lang-env (symbol-name lang-env))) | |
368 (if (symbolp input-method) | 770 (if (symbolp input-method) |
369 (setq input-method (symbol-name input-method))) | 771 (setq input-method (symbol-name input-method))) |
370 (let ((info (cons language-name args)) | 772 (let ((info (cons lang-env args)) |
371 (slot (assoc input-method input-method-alist))) | 773 (slot (assoc input-method input-method-alist))) |
372 (if slot | 774 (if slot |
373 (setcdr slot info) | 775 (setcdr slot info) |
374 (setq slot (cons input-method info)) | 776 (setq slot (cons input-method info)) |
375 (setq input-method-alist (cons slot input-method-alist))))) | 777 (setq input-method-alist (cons slot input-method-alist))))) |
385 (setq prompt (format prompt default))) | 787 (setq prompt (format prompt default))) |
386 (let* ((completion-ignore-case t) | 788 (let* ((completion-ignore-case t) |
387 ;; This binding is necessary because input-method-history is | 789 ;; This binding is necessary because input-method-history is |
388 ;; buffer local. | 790 ;; buffer local. |
389 (input-method (completing-read prompt input-method-alist | 791 (input-method (completing-read prompt input-method-alist |
390 nil t nil 'input-method-history) | 792 nil t nil 'input-method-history |
391 ;;default) | 793 default))) |
392 )) | 794 (if (and input-method (symbolp input-method)) |
795 (setq input-method (symbol-name input-method))) | |
393 (if (> (length input-method) 0) | 796 (if (> (length input-method) 0) |
394 input-method | 797 input-method |
395 (if inhibit-null | 798 (if inhibit-null |
396 (error "No valid input method is specified"))))) | 799 (error "No valid input method is specified"))))) |
397 | 800 |
398 (defun activate-input-method (input-method) | 801 (defun activate-input-method (input-method) |
399 "Turn INPUT-METHOD on. | 802 "Switch to input method INPUT-METHOD for the current buffer. |
400 If some input method is already on, turn it off at first." | 803 If some other input method is already active, turn it off first. |
401 (if (symbolp input-method) | 804 If INPUT-METHOD is nil, deactivate any current input method." |
805 (if (and input-method (symbolp input-method)) | |
402 (setq input-method (symbol-name input-method))) | 806 (setq input-method (symbol-name input-method))) |
403 (if (and current-input-method | 807 (if (and current-input-method |
404 (not (string= current-input-method input-method))) | 808 (not (string= current-input-method input-method))) |
405 (inactivate-input-method)) | 809 (inactivate-input-method)) |
406 (unless current-input-method | 810 (unless (or current-input-method (null input-method)) |
407 (let ((slot (assoc input-method input-method-alist))) | 811 (let ((slot (assoc input-method input-method-alist))) |
408 (if (null slot) | 812 (if (null slot) |
409 (error "Can't activate input method `%s'" input-method)) | 813 (error "Can't activate input method `%s'" input-method)) |
410 (apply (nth 2 slot) input-method (nthcdr 5 slot)) | 814 (let ((func (nth 2 slot))) |
815 (if (functionp func) | |
816 (apply (nth 2 slot) input-method (nthcdr 5 slot)) | |
817 (if (and (consp func) (symbolp (car func)) (symbolp (cdr func))) | |
818 (progn | |
819 (require (cdr func)) | |
820 (apply (car func) input-method (nthcdr 5 slot))) | |
821 (error "Can't activate input method `%s'" input-method)))) | |
411 (setq current-input-method input-method) | 822 (setq current-input-method input-method) |
412 (setq current-input-method-title (nth 3 slot)) | 823 (setq current-input-method-title (nth 3 slot)) |
413 (run-hooks 'input-method-activate-hook)))) | 824 (unwind-protect |
825 (run-hooks 'input-method-activate-hook) | |
826 (force-mode-line-update))))) | |
414 | 827 |
415 (defun inactivate-input-method () | 828 (defun inactivate-input-method () |
416 "Turn off the current input method." | 829 "Turn off the current input method." |
417 (when current-input-method | 830 (when current-input-method |
418 (if input-method-history | 831 (if input-method-history |
424 (unwind-protect | 837 (unwind-protect |
425 (funcall inactivate-current-input-method-function) | 838 (funcall inactivate-current-input-method-function) |
426 (unwind-protect | 839 (unwind-protect |
427 (run-hooks 'input-method-inactivate-hook) | 840 (run-hooks 'input-method-inactivate-hook) |
428 (setq current-input-method nil | 841 (setq current-input-method nil |
429 current-input-method-title nil))))) | 842 current-input-method-title nil) |
430 | 843 (force-mode-line-update))))) |
431 (defun select-input-method (input-method) | 844 |
432 "Select and turn on INPUT-METHOD. | 845 (defun set-input-method (input-method) |
433 This sets the default input method to what you specify, | 846 "Select and activate input method INPUT-METHOD for the current buffer. |
434 and turn it on for the current buffer." | 847 This also sets the default input method to the one you specify." |
435 (interactive | 848 (interactive |
436 (let* ((default (or (car input-method-history) default-input-method))) | 849 (let* ((default (or (car input-method-history) default-input-method))) |
437 (list (read-input-method-name | 850 (list (read-input-method-name |
438 (if default "Select input method (default %s): " "Select input method: ") | 851 (if default "Select input method (default %s): " "Select input method: ") |
439 default t)))) | 852 default t)))) |
441 (setq default-input-method input-method)) | 854 (setq default-input-method input-method)) |
442 | 855 |
443 (defun toggle-input-method (&optional arg) | 856 (defun toggle-input-method (&optional arg) |
444 "Turn on or off a multilingual text input method for the current buffer. | 857 "Turn on or off a multilingual text input method for the current buffer. |
445 | 858 |
446 With arg, read an input method from minibuffer and turn it on. | 859 With no prefix argument, if an input method is currently activated, |
447 | 860 turn it off. Otherwise, activate an input method -- the one most |
448 Without arg, if some input method is currently activated, turn it off, | 861 recently used, or the one specified in `default-input-method', or |
449 else turn on an input method selected last time | 862 the one read from the minibuffer. |
450 or the default input method (see `default-input-method'). | 863 |
451 | 864 With a prefix argument, read an input method from the minibuffer and |
452 When there's no input method to turn on, turn on what read from minibuffer." | 865 turn it on. |
866 | |
867 The default is to use the most recent input method specified | |
868 \(not including the currently active input method, if any)." | |
453 (interactive "P") | 869 (interactive "P") |
454 (let* ((default (or (car input-method-history) default-input-method))) | 870 (if (and current-input-method (not arg)) |
455 (if (and current-input-method (not arg)) | 871 (inactivate-input-method) |
456 (inactivate-input-method) | 872 (let ((default (or (car input-method-history) default-input-method))) |
873 (if (and arg default (equal current-input-method default) | |
874 (> (length input-method-history) 1)) | |
875 (setq default (nth 1 input-method-history))) | |
457 (activate-input-method | 876 (activate-input-method |
458 (if (or arg (not default)) | 877 (if (or arg (not default)) |
459 (read-input-method-name | 878 (progn |
460 (if default "Input method (default %s): " "Input method: " ) | 879 (read-input-method-name |
461 default t) | 880 (if default "Input method (default %s): " "Input method: " ) |
881 default t)) | |
462 default)) | 882 default)) |
463 (or default-input-method | 883 (or default-input-method |
464 (setq default-input-method current-input-method))))) | 884 (setq default-input-method current-input-method))))) |
465 | 885 |
466 (defun describe-input-method (input-method) | 886 (defun describe-input-method (input-method) |
467 "Describe input method INPUT-METHOD." | 887 "Describe input method INPUT-METHOD." |
468 (interactive | 888 (interactive |
469 (list (read-input-method-name | 889 (list (read-input-method-name |
470 "Describe input method (default, current choice): "))) | 890 "Describe input method (default, current choice): "))) |
471 (if (and input-method (symbolp input-method)) | 891 (if (and input-method (symbolp input-method)) |
472 (setq input-method (symbol-name input-method))) | 892 (setq input-method (symbol-name input-method))) |
482 (if current-input-method | 902 (if current-input-method |
483 (if (and (symbolp describe-current-input-method-function) | 903 (if (and (symbolp describe-current-input-method-function) |
484 (fboundp describe-current-input-method-function)) | 904 (fboundp describe-current-input-method-function)) |
485 (funcall describe-current-input-method-function) | 905 (funcall describe-current-input-method-function) |
486 (message "No way to describe the current input method `%s'" | 906 (message "No way to describe the current input method `%s'" |
487 (cdr current-input-method)) | 907 current-input-method) |
488 (ding)) | 908 (ding)) |
489 (error "No input method is activated now"))) | 909 (error "No input method is activated now"))) |
490 | 910 |
491 (defun read-multilingual-string (prompt &optional initial-input | 911 (defun read-multilingual-string (prompt &optional initial-input input-method) |
492 input-method) | |
493 "Read a multilingual string from minibuffer, prompting with string PROMPT. | 912 "Read a multilingual string from minibuffer, prompting with string PROMPT. |
494 The input method selected last time is activated in minibuffer. | 913 The input method selected last time is activated in minibuffer. |
495 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer | 914 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer |
496 initially. | 915 initially. |
497 Optional 3rd argument INPUT-METHOD specifies the input method | 916 Optional 3rd argument INPUT-METHOD specifies the input method |
498 to be activated instead of the one selected last time. It is a symbol | 917 to be activated instead of the one selected last time. It is a symbol |
499 or a string." | 918 or a string." |
500 (setq input-method | 919 (setq input-method |
501 (or input-method | 920 (or input-method |
921 current-input-method | |
502 default-input-method | 922 default-input-method |
503 (read-input-method-name "Input method: " nil t))) | 923 (read-input-method-name "Input method: " nil t))) |
504 (if (and input-method (symbolp input-method)) | 924 (if (and input-method (symbolp input-method)) |
505 (setq input-method (symbol-name input-method))) | 925 (setq input-method (symbol-name input-method))) |
506 (let ((current-input-method input-method)) | 926 (let ((prev-input-method current-input-method)) |
507 ;; FSFmacs | 927 (unwind-protect |
508 ;; (read-string prompt initial-input nil nil t))) | 928 (progn |
509 (read-string prompt initial-input nil))) | 929 (activate-input-method input-method) |
930 ;; FSF Emacs | |
931 ;; (read-string prompt initial-input nil nil t) | |
932 (read-string prompt initial-input nil)) | |
933 (activate-input-method prev-input-method)))) | |
510 | 934 |
511 ;; Variables to control behavior of input methods. All input methods | 935 ;; Variables to control behavior of input methods. All input methods |
512 ;; should react to these variables. | 936 ;; should react to these variables. |
513 | 937 |
514 (defcustom input-method-verbose-flag t | 938 (defcustom input-method-verbose-flag 'default |
515 "*If this flag is non-nil, input methods give extra guidance. | 939 "*A flag to control extra guidance given by input methods. |
940 The value should be nil, t, `complex-only', or `default'. | |
516 | 941 |
517 The extra guidance is done by showing list of available keys in echo | 942 The extra guidance is done by showing list of available keys in echo |
518 area. | 943 area. When you use the input method in the minibuffer, the guidance |
519 | 944 is shown at the bottom short window (split from the existing window). |
520 For complex input methods such as `chinese-py' and `japanese', | 945 |
521 when you use the input method in the minibuffer, the guidance is | 946 If the value is t, extra guidance is always given, if the value is |
522 shown at the bottom short window (split from the existing window). | 947 nil, extra guidance is always suppressed. |
523 For simple input methods, guidance is not shown | 948 |
524 when you are in the minibuffer." | 949 If the value is `complex-only', only complex input methods such as |
525 :type 'boolean | 950 `chinese-py' and `japanese' give extra guidance. |
951 | |
952 If the value is `default', complex input methods always give extra | |
953 guidance, but simple input methods give it only when you are not in | |
954 the minibuffer. | |
955 | |
956 See also the variable `input-method-highlight-flag'." | |
957 :type '(choice (const t) (const nil) (const complex-only) (const default)) | |
526 :group 'mule) | 958 :group 'mule) |
527 | 959 |
528 (defcustom input-method-highlight-flag t | 960 (defcustom input-method-highlight-flag t |
529 "*If this flag is non-nil, input methods highlight partially-entered text. | 961 "*If this flag is non-nil, input methods highlight partially-entered text. |
530 For instance, while you are in the middle of a Quail input method sequence, | 962 For instance, while you are in the middle of a Quail input method sequence, |
531 the text inserted so far is temporarily underlined. | 963 the text inserted so far is temporarily underlined. |
532 The underlining goes away when you finish or abort the input method sequence." | 964 The underlining goes away when you finish or abort the input method sequence. |
965 See also the variable `input-method-verbose-flag'." | |
533 :type 'boolean | 966 :type 'boolean |
534 :group 'mule) | 967 :group 'mule) |
535 | 968 |
536 (defvar input-method-activate-hook nil | 969 (defvar input-method-activate-hook nil |
537 "Normal hook run just after an input method is activated. | 970 "Normal hook run just after an input method is activated. |
541 | 974 |
542 (defvar input-method-inactivate-hook nil | 975 (defvar input-method-inactivate-hook nil |
543 "Normal hook run just after an input method is inactivated. | 976 "Normal hook run just after an input method is inactivated. |
544 | 977 |
545 The variable `current-input-method' still keeps the input method name | 978 The variable `current-input-method' still keeps the input method name |
546 just inacitvated.") | 979 just inactivated.") |
547 | 980 |
548 (defvar input-method-after-insert-chunk-hook nil | 981 (defvar input-method-after-insert-chunk-hook nil |
549 "Normal hook run just after an input method insert some chunk of text.") | 982 "Normal hook run just after an input method insert some chunk of text.") |
983 | |
984 (defvar input-method-exit-on-first-char nil | |
985 "This flag controls a timing when an input method returns. | |
986 Usually, the input method does not return while there's a possibility | |
987 that it may find a different translation if a user types another key. | |
988 But, it this flag is non-nil, the input method returns as soon as | |
989 the current key sequence gets long enough to have some valid translation.") | |
990 | |
991 (defvar input-method-use-echo-area nil | |
992 "This flag controls how an input method shows an intermediate key sequence. | |
993 Usually, the input method inserts the intermediate key sequence, | |
994 or candidate translations corresponding to the sequence, | |
995 at point in the current buffer. | |
996 But, if this flag is non-nil, it displays them in echo area instead.") | |
550 | 997 |
551 (defvar input-method-exit-on-invalid-key nil | 998 (defvar input-method-exit-on-invalid-key nil |
552 "This flag controls the behaviour of an input method on invalid key input. | 999 "This flag controls the behaviour of an input method on invalid key input. |
553 Usually, when a user types a key which doesn't start any character | 1000 Usually, when a user types a key which doesn't start any character |
554 handled by the input method, the key is handled by turning off the | 1001 handled by the input method, the key is handled by turning off the |
555 input method temporalily. After the key is handled, the input method is | 1002 input method temporarily. After that key, the input method is re-enabled. |
556 back on. | |
557 But, if this flag is non-nil, the input method is never back on.") | 1003 But, if this flag is non-nil, the input method is never back on.") |
558 | 1004 |
559 | 1005 |
1006 (defvar set-language-environment-hook nil | |
1007 "Normal hook run after some language environment is set. | |
1008 | |
1009 When you set some hook function here, that effect usually should not | |
1010 be inherited to another language environment. So, you had better set | |
1011 another function in `exit-language-environment-hook' (which see) to | |
1012 cancel the effect.") | |
1013 | |
1014 (defvar exit-language-environment-hook nil | |
1015 "Normal hook run after exiting from some language environment. | |
1016 When this hook is run, the variable `current-language-environment' | |
1017 is still bound to the language environment being exited. | |
1018 | |
1019 This hook is mainly used for canceling the effect of | |
1020 `set-language-environment-hook' (which-see).") | |
1021 | |
1022 (put 'setup-specified-language-environment 'apropos-inhibit t) | |
1023 | |
560 (defun setup-specified-language-environment () | 1024 (defun setup-specified-language-environment () |
561 "Set up multi-lingual environment convenient for the specified language." | 1025 "Switch to a specified language environment." |
562 (interactive) | 1026 (interactive) |
563 (let (language-name) | 1027 (let (language-name) |
564 (if (and (symbolp last-command-event) | 1028 (if (and (symbolp last-command-event) |
565 (or (not (eq last-command-event 'Default)) | 1029 (or (not (eq last-command-event 'Default)) |
566 (setq last-command-event 'English)) | 1030 (setq last-command-event 'English)) |
567 (setq language-name (symbol-name last-command-event))) | 1031 (setq language-name (symbol-name last-command-event))) |
568 (set-language-environment language-name) | 1032 (set-language-environment language-name) |
569 (error "Bogus calling sequence")))) | 1033 (error "Bogus calling sequence")))) |
570 | 1034 |
571 (defvar current-language-environment "English" | 1035 (defcustom current-language-environment "English" |
572 "The last language environment specified with `set-language-environment'.") | 1036 "The last language environment specified with `set-language-environment'. |
1037 This variable should be set only with \\[customize], which is equivalent | |
1038 to using the function `set-language-environment'." | |
1039 :link '(custom-manual "(emacs)Language Environments") | |
1040 :set (lambda (symbol value) (set-language-environment value)) | |
1041 :get (lambda (x) | |
1042 (or (car-safe (assoc-ignore-case | |
1043 (if (symbolp current-language-environment) | |
1044 (symbol-name current-language-environment) | |
1045 current-language-environment) | |
1046 language-info-alist)) | |
1047 "English")) | |
1048 :type (cons 'choice (mapcar (lambda (lang) | |
1049 (list 'const (car lang))) | |
1050 language-info-alist)) | |
1051 :initialize 'custom-initialize-default | |
1052 :group 'mule | |
1053 :type 'string) | |
1054 | |
1055 (defun reset-language-environment () | |
1056 "Reset multilingual environment of Emacs to the default status. | |
1057 | |
1058 The default status is as follows: | |
1059 | |
1060 The default value of buffer-file-coding-system is nil. | |
1061 The default coding system for process I/O is nil. | |
1062 The default value for the command `set-terminal-coding-system' is nil. | |
1063 The default value for the command `set-keyboard-coding-system' is nil. | |
1064 | |
1065 The order of priorities of coding categories and the coding system | |
1066 bound to each category are as follows | |
1067 coding category coding system | |
1068 -------------------------------------------------- | |
1069 iso-8-2 iso-8859-1 | |
1070 iso-8-1 iso-8859-1 | |
1071 iso-7 iso-2022-7bit | |
1072 iso-lock-shift iso-2022-lock | |
1073 iso-8-designate iso-2022-8bit-ss2 | |
1074 no-conversion raw-text | |
1075 shift-jis shift_jis | |
1076 big5 big5 | |
1077 ucs-4 ---- | |
1078 utf-8 ---- | |
1079 " | |
1080 (interactive) | |
1081 ;; This function formerly set default-enable-multibyte-characters to t, | |
1082 ;; but that is incorrect. It should not alter the unibyte/multibyte choice. | |
1083 | |
1084 (set-coding-category-system 'iso-7 'iso-2022-7bit) | |
1085 (set-coding-category-system 'iso-8-1 'iso-8859-1) | |
1086 (set-coding-category-system 'iso-8-2 'iso-8859-1) | |
1087 (set-coding-category-system 'iso-lock-shift 'iso-2022-lock) | |
1088 (set-coding-category-system 'iso-8-designate 'iso-2022-8bit-ss2) | |
1089 (set-coding-category-system 'no-conversion 'raw-text) | |
1090 (set-coding-category-system 'shift-jis 'shift_jis) | |
1091 (set-coding-category-system 'big5 'big5) | |
1092 (cond ((eq (coding-system-type (coding-category-system 'utf-8)) 'utf-8) | |
1093 (set-coding-category-system 'ucs-4 'iso-10646-ucs-4) | |
1094 (set-coding-category-system 'utf-8 'utf-8) | |
1095 (set-coding-priority-list | |
1096 '(iso-8-1 | |
1097 iso-8-2 | |
1098 iso-7 | |
1099 iso-lock-shift | |
1100 iso-8-designate | |
1101 utf-8 | |
1102 ucs-4 | |
1103 no-conversion | |
1104 shift-jis | |
1105 big5)) | |
1106 ) | |
1107 (t | |
1108 (set-coding-priority-list | |
1109 '(iso-8-1 | |
1110 iso-8-2 | |
1111 iso-7 | |
1112 iso-lock-shift | |
1113 iso-8-designate | |
1114 no-conversion | |
1115 shift-jis | |
1116 big5)) | |
1117 )) | |
1118 | |
1119 ;; (update-coding-systems-internal) | |
1120 | |
1121 (set-default-coding-systems nil) | |
1122 ;; Don't alter the terminal and keyboard coding systems here. | |
1123 ;; The terminal still supports the same coding system | |
1124 ;; that it supported a minute ago. | |
1125 ;;; (set-terminal-coding-system-internal nil) | |
1126 ;;; (set-keyboard-coding-system-internal nil) | |
1127 | |
1128 ;; (setq nonascii-translation-table nil | |
1129 ;; nonascii-insert-offset 0) | |
1130 ) | |
573 | 1131 |
574 (defun set-language-environment (language-name) | 1132 (defun set-language-environment (language-name) |
575 "Set up multi-lingual environment for using LANGUAGE-NAME. | 1133 "Set up multi-lingual environment for using LANGUAGE-NAME. |
576 This sets the coding system priority and the default input method | 1134 This sets the coding system priority and the default input method |
577 and sometimes other things." | 1135 and sometimes other things. LANGUAGE-NAME should be a string |
578 (interactive (list (read-language-name 'setup-function | 1136 which is the name of a language environment. For example, \"Latin-1\" |
579 "Set language environment: "))) | 1137 specifies the character set for the major languages of Western Europe." |
1138 (interactive (list (read-language-name | |
1139 nil | |
1140 "Set language environment (default, English): "))) | |
580 (if language-name | 1141 (if language-name |
581 (if (symbolp language-name) | 1142 (if (symbolp language-name) |
582 (setq language-name (symbol-name language-name))) | 1143 (setq language-name (symbol-name language-name))) |
583 (setq language-name "English")) | 1144 (setq language-name "English")) |
584 (if (null (get-language-info language-name 'setup-function)) | 1145 (or (assoc-ignore-case language-name language-info-alist) |
585 (error "Language environment not defined: %S" language-name)) | 1146 (error "Language environment not defined: %S" language-name)) |
586 (funcall (get-language-info language-name 'setup-function)) | 1147 (if current-language-environment |
587 (setq current-language-environment language-name) | 1148 (let ((func (get-language-info current-language-environment |
1149 'exit-function))) | |
1150 (run-hooks 'exit-language-environment-hook) | |
1151 (if (fboundp func) (funcall func)))) | |
1152 (let ((default-eol-type (coding-system-eol-type | |
1153 default-buffer-file-coding-system))) | |
1154 (reset-language-environment) | |
1155 | |
1156 (setq current-language-environment language-name) | |
1157 (set-language-environment-coding-systems language-name default-eol-type)) | |
1158 (let ((input-method (get-language-info language-name 'input-method))) | |
1159 (when input-method | |
1160 (setq default-input-method input-method) | |
1161 (if input-method-history | |
1162 (setq input-method-history | |
1163 (cons input-method | |
1164 (delete input-method input-method-history)))))) | |
1165 ;; (let ((nonascii (get-language-info language-name 'nonascii-translation)) | |
1166 ;; (dos-table | |
1167 ;; (if (eq window-system 'pc) | |
1168 ;; (intern | |
1169 ;; (concat "cp" dos-codepage "-nonascii-translation-table"))))) | |
1170 ;; (cond | |
1171 ;; ((char-table-p nonascii) | |
1172 ;; (setq nonascii-translation-table nonascii)) | |
1173 ;; ((and (eq window-system 'pc) (boundp dos-table)) | |
1174 ;; ;; DOS terminals' default is to use a special non-ASCII translation | |
1175 ;; ;; table as appropriate for the installed codepage. | |
1176 ;; (setq nonascii-translation-table (symbol-value dos-table))) | |
1177 ;; ((charsetp nonascii) | |
1178 ;; (setq nonascii-insert-offset (- (make-char nonascii) 128))))) | |
1179 | |
1180 ;; (setq charset-origin-alist | |
1181 ;; (get-language-info language-name 'charset-origin-alist)) | |
1182 | |
1183 ;; Unibyte setups if necessary. | |
1184 ;; (unless default-enable-multibyte-characters | |
1185 ;; ;; Syntax and case table. | |
1186 ;; (let ((syntax (get-language-info language-name 'unibyte-syntax))) | |
1187 ;; (if syntax | |
1188 ;; (let ((set-case-syntax-set-multibyte nil)) | |
1189 ;; (load syntax nil t)) | |
1190 ;; ;; No information for syntax and case. Reset to the defaults. | |
1191 ;; (let ((syntax-table (standard-syntax-table)) | |
1192 ;; (case-table (standard-case-table)) | |
1193 ;; (ch (if (eq window-system 'pc) 128 160))) | |
1194 ;; (while (< ch 256) | |
1195 ;; (modify-syntax-entry ch " " syntax-table) | |
1196 ;; (aset case-table ch ch) | |
1197 ;; (setq ch (1+ ch))) | |
1198 ;; (set-char-table-extra-slot case-table 0 nil) | |
1199 ;; (set-char-table-extra-slot case-table 1 nil) | |
1200 ;; (set-char-table-extra-slot case-table 2 nil)) | |
1201 ;; (set-standard-case-table (standard-case-table)) | |
1202 ;; (let ((list (buffer-list))) | |
1203 ;; (while list | |
1204 ;; (with-current-buffer (car list) | |
1205 ;; (set-case-table (standard-case-table))) | |
1206 ;; (setq list (cdr list)))))) | |
1207 ;; ;; Display table and coding system for terminal. | |
1208 ;; (let ((coding (get-language-info language-name 'unibyte-display))) | |
1209 ;; (if coding | |
1210 ;; (standard-display-european-internal) | |
1211 ;; (standard-display-default (if (eq window-system 'pc) 128 160) 255) | |
1212 ;; (aset standard-display-table 146 nil)) | |
1213 ;; (or (eq window-system 'pc) | |
1214 ;; (set-terminal-coding-system coding)))) | |
1215 | |
1216 (let ((required-features (get-language-info language-name 'features))) | |
1217 (while required-features | |
1218 (require (car required-features)) | |
1219 (setq required-features (cdr required-features)))) | |
1220 (let ((func (get-language-info language-name 'setup-function))) | |
1221 (if (fboundp func) | |
1222 (funcall func))) | |
1223 (run-hooks 'set-language-environment-hook) | |
588 (force-mode-line-update t)) | 1224 (force-mode-line-update t)) |
1225 | |
1226 ;; (defun standard-display-european-internal () | |
1227 ;; ;; Actually set up direct output of non-ASCII characters. | |
1228 ;; (standard-display-8bit (if (eq window-system 'pc) 128 160) 255) | |
1229 ;; ;; Unibyte Emacs on MS-DOS wants to display all 8-bit characters with | |
1230 ;; ;; the native font, and codes 160 and 146 stand for something very | |
1231 ;; ;; different there. | |
1232 ;; (or (and (eq window-system 'pc) (not default-enable-multibyte-characters)) | |
1233 ;; (progn | |
1234 ;; ;; Make non-line-break space display as a plain space. | |
1235 ;; ;; Most X fonts do the wrong thing for code 160. | |
1236 ;; (aset standard-display-table 160 [32]) | |
1237 ;; ;; Most Windows programs send out apostrophe's as \222. Most X fonts | |
1238 ;; ;; don't contain a character at that position. Map it to the ASCII | |
1239 ;; ;; apostrophe. | |
1240 ;; (aset standard-display-table 146 [39])))) | |
1241 | |
1242 (defun set-language-environment-coding-systems (language-name | |
1243 &optional eol-type) | |
1244 "Do various coding system setups for language environment LANGUAGE-NAME. | |
1245 | |
1246 The optional arg EOL-TYPE specifies the eol-type of the default value | |
1247 of buffer-file-coding-system set by this function." | |
1248 (let* ((priority (get-language-info language-name 'coding-priority)) | |
1249 (default-coding (car priority))) | |
1250 (if priority | |
1251 (let ((categories (mapcar 'coding-system-category priority)) | |
1252 category checked-categories) | |
1253 (set-default-coding-systems | |
1254 (if (memq eol-type '(lf crlf cr unix dos mac)) | |
1255 (coding-system-change-eol-conversion default-coding eol-type) | |
1256 default-coding)) | |
1257 ;; (setq default-sendmail-coding-system default-coding) | |
1258 (while priority | |
1259 (unless (memq (setq category (car categories)) checked-categories) | |
1260 (set-coding-category-system category (car priority)) | |
1261 (setq checked-categories (cons category checked-categories))) | |
1262 (setq priority (cdr priority) | |
1263 categories (cdr categories))) | |
1264 (set-coding-priority-list (nreverse checked-categories)) | |
1265 ;; (update-coding-systems-internal) | |
1266 )))) | |
589 | 1267 |
590 ;; Print all arguments with `princ', then print "\n". | 1268 ;; Print all arguments with `princ', then print "\n". |
591 (defsubst princ-list (&rest args) | 1269 (defsubst princ-list (&rest args) |
592 (while args (princ (car args)) (setq args (cdr args))) | 1270 (while args (princ (car args)) (setq args (cdr args))) |
593 (princ "\n")) | 1271 (princ "\n")) |
1272 | |
1273 (put 'describe-specified-language-support 'apropos-inhibit t) | |
594 | 1274 |
595 ;; Print a language specific information such as input methods, | 1275 ;; Print a language specific information such as input methods, |
596 ;; charsets, and coding systems. This function is intended to be | 1276 ;; charsets, and coding systems. This function is intended to be |
597 ;; called from the menu: | 1277 ;; called from the menu: |
598 ;; [menu-bar mule describe-language-environment LANGUAGE] | 1278 ;; [menu-bar mule describe-language-environment LANGUAGE] |
609 (defun describe-language-environment (language-name) | 1289 (defun describe-language-environment (language-name) |
610 "Describe how Emacs supports language environment LANGUAGE-NAME." | 1290 "Describe how Emacs supports language environment LANGUAGE-NAME." |
611 (interactive | 1291 (interactive |
612 (list (read-language-name | 1292 (list (read-language-name |
613 'documentation | 1293 'documentation |
614 "Describe language environment (default, current choise): "))) | 1294 "Describe language environment (default, current choice): "))) |
615 (if (null language-name) | 1295 (if (null language-name) |
616 (setq language-name current-language-environment)) | 1296 (setq language-name current-language-environment)) |
617 (if (or (null language-name) | 1297 (if (or (null language-name) |
618 (null (get-language-info language-name 'documentation))) | 1298 (null (get-language-info language-name 'documentation))) |
619 (error "No documentation for the specified language")) | 1299 (error "No documentation for the specified language")) |
620 (if (symbolp language-name) | 1300 (if (symbolp language-name) |
621 (setq language-name (symbol-name language-name))) | 1301 (setq language-name (symbol-name language-name))) |
622 (let ((doc (get-language-info language-name 'documentation))) | 1302 (let ((doc (get-language-info language-name 'documentation))) |
623 (with-output-to-temp-buffer "*Help*" | 1303 (with-output-to-temp-buffer "*Help*" |
1304 (princ-list language-name " language environment" "\n") | |
624 (if (stringp doc) | 1305 (if (stringp doc) |
625 (progn | 1306 (progn |
626 (princ-list doc) | 1307 (princ-list doc) |
627 (terpri))) | 1308 (terpri))) |
628 (let ((str (get-language-info language-name 'sample-text))) | 1309 (let ((str (get-language-info language-name 'sample-text))) |
629 (if (stringp str) | 1310 (if (stringp str) |
630 (progn | 1311 (progn |
631 (princ "Sample text:\n") | 1312 (princ "Sample text:\n") |
632 (princ-list " " str) | 1313 (princ-list " " str) |
633 (terpri)))) | 1314 (terpri)))) |
634 (princ "Input methods:\n") | 1315 (let ((input-method (get-language-info language-name 'input-method)) |
635 (let ((l input-method-alist)) | 1316 (l (copy-sequence input-method-alist))) |
636 (while l | 1317 (princ "Input methods") |
1318 (when input-method | |
1319 (princ (format " (default, %s)" input-method)) | |
1320 (setq input-method (assoc input-method input-method-alist)) | |
1321 (setq l (cons input-method (delete input-method l)))) | |
1322 (princ ":\n") | |
1323 (while l | |
637 (if (string= language-name (nth 1 (car l))) | 1324 (if (string= language-name (nth 1 (car l))) |
638 (princ-list " " (car (car l)) | 1325 (princ-list " " (car (car l)) |
639 (format " (`%s' in mode line)" (nth 3 (car l))))) | 1326 (format " (`%s' in mode line)" (nth 3 (car l))))) |
640 (setq l (cdr l)))) | 1327 (setq l (cdr l)))) |
641 (terpri) | 1328 (terpri) |
654 (princ-list " nothing specific to " language-name) | 1341 (princ-list " nothing specific to " language-name) |
655 (while l | 1342 (while l |
656 (princ ; (format " %s (`%c' in mode line):\n\t%s\n" | 1343 (princ ; (format " %s (`%c' in mode line):\n\t%s\n" |
657 ;; In XEmacs, `coding-system-mnemonic' returns string. | 1344 ;; In XEmacs, `coding-system-mnemonic' returns string. |
658 (format " %s (`%s' in mode line):\n\t%s\n" | 1345 (format " %s (`%s' in mode line):\n\t%s\n" |
659 (car l) | 1346 (car l) |
660 (coding-system-mnemonic (car l)) | 1347 (coding-system-mnemonic (car l)) |
661 (coding-system-doc-string (car l)))) | 1348 (coding-system-doc-string (car l)))) |
1349 ;; (let ((aliases (coding-system-get (car l) 'alias-coding-systems))) | |
1350 ;; (when aliases | |
1351 ;; (princ "\t") | |
1352 ;; (princ (cons 'alias: (cdr aliases))) | |
1353 ;; (terpri))) | |
662 (setq l (cdr l)))))))) | 1354 (setq l (cdr l)))))))) |
663 | 1355 |
664 ;;; Charset property | 1356 ;;; Charset property |
665 | 1357 |
666 ;; (defsubst get-charset-property (charset propname) | 1358 ;; (defsubst get-charset-property (charset propname) |
676 ;; (plist-put (charset-plist charset) propname value))) | 1368 ;; (plist-put (charset-plist charset) propname value))) |
677 | 1369 |
678 (defvar char-code-property-table | 1370 (defvar char-code-property-table |
679 (make-char-table 'generic) | 1371 (make-char-table 'generic) |
680 "Char-table containing a property list of each character code. | 1372 "Char-table containing a property list of each character code. |
681 ;; | 1373 |
682 See also the documentation of `get-char-code-property' and | 1374 See also the documentation of `get-char-code-property' and |
683 `put-char-code-property'") | 1375 `put-char-code-property'") |
684 ;; (let ((plist (aref char-code-property-table char))) | 1376 ;; (let ((plist (aref char-code-property-table char))) |
685 (defun get-char-code-property (char propname) | 1377 (defun get-char-code-property (char propname) |
686 "Return the value of CHAR's PROPNAME property in `char-code-property-table'." | 1378 "Return the value of CHAR's PROPNAME property in `char-code-property-table'." |
697 (if slot | 1389 (if slot |
698 (setcar (cdr slot) value) | 1390 (setcar (cdr slot) value) |
699 (nconc plist (list propname value)))) | 1391 (nconc plist (list propname value)))) |
700 (put-char-table char (list propname value) char-code-property-table) | 1392 (put-char-table char (list propname value) char-code-property-table) |
701 ))) | 1393 ))) |
702 ;; (setcar (cdr slot) value) | 1394 |
703 ;; (nconc plist (list propname value)))) | 1395 |
704 ;; (aset char-code-property-table char (list propname value))))) | 1396 ;; Pretty description of encoded string |
1397 | |
1398 ;; Alist of ISO 2022 control code vs the corresponding mnemonic string. | |
1399 ;; (defvar iso-2022-control-alist | |
1400 ;; '((?\x1b . "ESC") | |
1401 ;; (?\x0e . "SO") | |
1402 ;; (?\x0f . "SI") | |
1403 ;; (?\x8e . "SS2") | |
1404 ;; (?\x8f . "SS3") | |
1405 ;; (?\x9b . "CSI"))) | |
1406 | |
1407 ;; (defun encoded-string-description (str coding-system) | |
1408 ;; "Return a pretty description of STR that is encoded by CODING-SYSTEM." | |
1409 ;; (setq str (string-as-unibyte str)) | |
1410 ;; (let ((char (aref str 0)) | |
1411 ;; desc) | |
1412 ;; (when (< char 128) | |
1413 ;; (setq desc (or (cdr (assq char iso-2022-control-alist)) | |
1414 ;; (char-to-string char))) | |
1415 ;; (let ((i 1) | |
1416 ;; (len (length str))) | |
1417 ;; (while (< i len) | |
1418 ;; (setq char (aref str i)) | |
1419 ;; (if (>= char 128) | |
1420 ;; (setq desc nil i len) | |
1421 ;; (setq desc (concat desc " " | |
1422 ;; (or (cdr (assq char iso-2022-control-alist)) | |
1423 ;; (char-to-string char))) | |
1424 ;; i (1+ i)))))) | |
1425 ;; (or desc | |
1426 ;; (mapconcat (function (lambda (x) (format "0x%02x" x))) str " ")))) | |
1427 | |
1428 ;; (defun encode-coding-char (char coding-system) | |
1429 ;; "Encode CHAR by CODING-SYSTEM and return the resulting string. | |
1430 ;; If CODING-SYSTEM can't safely encode CHAR, return nil." | |
1431 ;; (if (cmpcharp char) | |
1432 ;; (setq char (car (decompose-composite-char char 'list)))) | |
1433 ;; (let ((str1 (char-to-string char)) | |
1434 ;; (str2 (make-string 2 char)) | |
1435 ;; (safe-charsets (and coding-system | |
1436 ;; (coding-system-get coding-system 'safe-charsets))) | |
1437 ;; enc1 enc2 i1 i2) | |
1438 ;; (when (or (eq safe-charsets t) | |
1439 ;; (memq (char-charset char) safe-charsets)) | |
1440 ;; ;; We must find the encoded string of CHAR. But, just encoding | |
1441 ;; ;; CHAR will put extra control sequences (usually to designate | |
1442 ;; ;; ASCII charset) at the tail if type of CODING is ISO 2022. | |
1443 ;; ;; To exclude such tailing bytes, we at first encode one-char | |
1444 ;; ;; string and two-char string, then check how many bytes at the | |
1445 ;; ;; tail of both encoded strings are the same. | |
1446 ;; | |
1447 ;; (setq enc1 (string-as-unibyte (encode-coding-string str1 coding-system)) | |
1448 ;; i1 (length enc1) | |
1449 ;; enc2 (string-as-unibyte (encode-coding-string str2 coding-system)) | |
1450 ;; i2 (length enc2)) | |
1451 ;; (while (and (> i1 0) (= (aref enc1 (1- i1)) (aref enc2 (1- i2)))) | |
1452 ;; (setq i1 (1- i1) i2 (1- i2))) | |
1453 ;; | |
1454 ;; ;; Now (substring enc1 i1) and (substring enc2 i2) are the same, | |
1455 ;; ;; and they are the extra control sequences at the tail to | |
1456 ;; ;; exclude. | |
1457 ;; (substring enc2 0 i2)))) | |
1458 | |
705 | 1459 |
706 ;;; mule-cmds.el ends here | 1460 ;;; mule-cmds.el ends here |