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