]> code.delx.au - gnu-emacs/blob - lisp/international/mule-cmds.el
(customize-changed-options): Doc addition. Load the
[gnu-emacs] / lisp / international / mule-cmds.el
1 ;;; mule-cmds.el --- commands for mulitilingual environment
2
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
6
7 ;; Keywords: mule, multilingual
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile (defvar dos-codepage))
31
32 ;;; MULE related key bindings and menus.
33
34 (defvar mule-keymap (make-sparse-keymap)
35 "Keymap for Mule (Multilingual environment) specific commands.")
36
37 ;; Keep "C-x C-m ..." for mule specific commands.
38 (define-key ctl-x-map "\C-m" mule-keymap)
39
40 (define-key mule-keymap "f" 'set-buffer-file-coding-system)
41 (define-key mule-keymap "r" 'revert-buffer-with-coding-system)
42 (define-key mule-keymap "F" 'set-file-name-coding-system)
43 (define-key mule-keymap "t" 'set-terminal-coding-system)
44 (define-key mule-keymap "k" 'set-keyboard-coding-system)
45 (define-key mule-keymap "p" 'set-buffer-process-coding-system)
46 (define-key mule-keymap "x" 'set-selection-coding-system)
47 (define-key mule-keymap "X" 'set-next-selection-coding-system)
48 (define-key mule-keymap "\C-\\" 'set-input-method)
49 (define-key mule-keymap "c" 'universal-coding-system-argument)
50 (define-key mule-keymap "l" 'set-language-environment)
51
52 (defvar mule-menu-keymap
53 (make-sparse-keymap "Mule (Multilingual Environment)")
54 "Keymap for Mule (Multilingual environment) menu specific commands.")
55
56 (defvar describe-language-environment-map
57 (make-sparse-keymap "Describe Language Environment"))
58
59 (defvar setup-language-environment-map
60 (make-sparse-keymap "Set Language Environment"))
61
62 (defvar set-coding-system-map
63 (make-sparse-keymap "Set Coding System"))
64
65 (define-key-after mule-menu-keymap [set-language-environment]
66 (list 'menu-item "Set Language Environment" setup-language-environment-map
67 :help "Multilingual environment suitable for a specific language"))
68 (define-key-after mule-menu-keymap [mouse-set-font]
69 '(menu-item "Set Font/Fontset" mouse-set-font
70 :visible (fboundp 'generate-fontset-menu)
71 :help "Select a font from list of known fonts/fontsets"))
72 (define-key-after mule-menu-keymap [separator-mule]
73 '("--")
74 t)
75 (define-key-after mule-menu-keymap [toggle-input-method]
76 '(menu-item "Toggle Input Method" toggle-input-method)
77 t)
78 (define-key-after mule-menu-keymap [set-input-method]
79 '(menu-item "Select Input Method..." set-input-method)
80 t)
81 (define-key-after mule-menu-keymap [describe-input-method]
82 '(menu-item "Describe Input Method" describe-input-method))
83 (define-key-after mule-menu-keymap [separator-input-method]
84 '("--")
85 t)
86 (define-key-after mule-menu-keymap [set-various-coding-system]
87 (list 'menu-item "Set Coding Systems" set-coding-system-map
88 :enable 'enable-multibyte-characters))
89 (define-key-after mule-menu-keymap [view-hello-file]
90 '(menu-item "Show Multi-lingual Text" view-hello-file
91 :enable (file-readable-p
92 (expand-file-name "HELLO" data-directory))
93 :help "Display file which says HELLO in many languages")
94 t)
95 (define-key-after mule-menu-keymap [separator-coding-system]
96 '("--")
97 t)
98 (define-key-after mule-menu-keymap [describe-language-environment]
99 (list 'menu-item "Describe Language Environment"
100 describe-language-environment-map
101 :help "Show multilingual settings for a specific language")
102 t)
103 (define-key-after mule-menu-keymap [describe-input-method]
104 '(menu-item "Describe Input Method..." describe-input-method
105 :help "Keyboard layout for a specific input method")
106 t)
107 (define-key-after mule-menu-keymap [describe-coding-system]
108 '(menu-item "Describe Coding System..." describe-coding-system)
109 t)
110 (define-key-after mule-menu-keymap [list-character-sets]
111 '(menu-item "List Character Sets" list-character-sets
112 :help "Show table of available character sets"))
113 (define-key-after mule-menu-keymap [mule-diag]
114 '(menu-item "Show All of Mule Status" mule-diag
115 :help "Display multilingual environment settings")
116 t)
117
118 (define-key-after set-coding-system-map [universal-coding-system-argument]
119 '(menu-item "For Next Command" universal-coding-system-argument
120 :help "Coding system to be used by next command")
121 t)
122 (define-key-after set-coding-system-map [separator-1]
123 '("--")
124 t)
125 (define-key-after set-coding-system-map [set-buffer-file-coding-system]
126 '(menu-item "For Saving This Buffer" set-buffer-file-coding-system
127 :help "How to encode this buffer when saved")
128 t)
129 (define-key-after set-coding-system-map [revert-buffer-with-coding-system]
130 '(menu-item "For Reverting This File Now" revert-buffer-with-coding-system
131 :enable buffer-file-name
132 :help "Revisit this file immediately using specified coding system")
133 t)
134 (define-key-after set-coding-system-map [set-file-name-coding-system]
135 '(menu-item "For File Name" set-file-name-coding-system
136 :help "How to decode/encode file names")
137 t)
138 (define-key-after set-coding-system-map [separator-2]
139 '("--")
140 t)
141
142 (define-key-after set-coding-system-map [set-keyboard-coding-system]
143 '(menu-item "For Keyboard" set-keyboard-coding-system
144 :help "How to decode keyboard input")
145 t)
146 (define-key-after set-coding-system-map [set-terminal-coding-system]
147 '(menu-item "For Terminal" set-terminal-coding-system
148 :enable (null (memq window-system '(x w32 mac)))
149 :help "How to encode terminal output")
150 t)
151 (define-key-after set-coding-system-map [separator-3]
152 '("--")
153 t)
154 (define-key-after set-coding-system-map [set-selection-coding-system]
155 '(menu-item "For X Selections/Clipboard" set-selection-coding-system
156 :visible (display-selections-p)
157 :help "How to en/decode data to/from selection/clipboard")
158 t)
159 (define-key-after set-coding-system-map [set-next-selection-coding-system]
160 '(menu-item "For Next X Selection" set-next-selection-coding-system
161 :visible (display-selections-p)
162 :help "How to en/decode next selection/clipboard operation")
163 t)
164 (define-key-after set-coding-system-map [set-buffer-process-coding-system]
165 '(menu-item "For I/O with Subprocess" set-buffer-process-coding-system
166 :visible (fboundp 'start-process)
167 :enable (get-buffer-process (current-buffer))
168 :help "How to en/decode I/O from/to subprocess connected to this buffer")
169 t)
170
171
172 (define-key setup-language-environment-map
173 [Default] '(menu-item "Default" setup-specified-language-environment))
174
175 (define-key describe-language-environment-map
176 [Default] '(menu-item "Default" describe-specified-language-support))
177
178 ;; This should be a single character key binding because users use it
179 ;; very frequently while editing multilingual text. Now we can use
180 ;; only two such keys: "\C-\\" and "\C-^", but the latter is not
181 ;; convenient because it requires shifting on most keyboards. An
182 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit'
183 ;; but it won't be used that frequently.
184 (define-key global-map "\C-\\" 'toggle-input-method)
185
186 ;; This is no good because people often type Shift-SPC
187 ;; meaning to type SPC. -- rms.
188 ;; ;; Here's an alternative key binding for X users (Shift-SPACE).
189 ;; (define-key global-map [?\S- ] 'toggle-input-method)
190
191 ;;; Mule related hyperlinks.
192 (defconst help-xref-mule-regexp-template
193 (purecopy (concat "\\(\\<\\("
194 "\\(coding system\\)\\|"
195 "\\(input method\\)\\|"
196 "\\(character set\\)\\|"
197 "\\(charset\\)"
198 "\\)\\s-+\\)?"
199 ;; Note starting with word-syntax character:
200 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'")))
201
202 (defun coding-system-change-eol-conversion (coding-system eol-type)
203 "Return a coding system which differs from CODING-SYSTEM in eol conversion.
204 The returned coding system converts end-of-line by EOL-TYPE
205 but text as the same way as CODING-SYSTEM.
206 EOL-TYPE should be `unix', `dos', `mac', or nil.
207 If EOL-TYPE is nil, the returned coding system detects
208 how end-of-line is formatted automatically while decoding.
209
210 EOL-TYPE can be specified by an integer 0, 1, or 2.
211 They means `unix', `dos', and `mac' respectively."
212 (if (symbolp eol-type)
213 (setq eol-type (cond ((eq eol-type 'unix) 0)
214 ((eq eol-type 'dos) 1)
215 ((eq eol-type 'mac) 2)
216 (t eol-type))))
217 (let ((orig-eol-type (coding-system-eol-type coding-system)))
218 (if (vectorp orig-eol-type)
219 (if (not eol-type)
220 coding-system
221 (aref orig-eol-type eol-type))
222 (let ((base (coding-system-base coding-system)))
223 (if (not eol-type)
224 base
225 (if (= eol-type orig-eol-type)
226 coding-system
227 (setq orig-eol-type (coding-system-eol-type base))
228 (if (vectorp orig-eol-type)
229 (aref orig-eol-type eol-type))))))))
230
231 (defun coding-system-change-text-conversion (coding-system coding)
232 "Return a coding system which differs from CODING-SYSTEM in text conversion.
233 The returned coding system converts text by CODING
234 but end-of-line as the same way as CODING-SYSTEM.
235 If CODING is nil, the returned coding system detects
236 how text is formatted automatically while decoding."
237 (let ((eol-type (coding-system-eol-type coding-system)))
238 (coding-system-change-eol-conversion
239 (if coding coding 'undecided)
240 (if (numberp eol-type) (aref [unix dos mac] eol-type)))))
241
242 (defun toggle-enable-multibyte-characters (&optional arg)
243 "Change whether this buffer uses multibyte characters.
244 With arg, use multibyte characters if the arg is positive.
245
246 Note that this command does not convert the byte contents of
247 the buffer; it only changes the way those bytes are interpreted.
248 In general, therefore, this command *changes* the sequence of
249 characters that the current buffer contains.
250
251 We suggest you avoid using use this command unless you know what you
252 are doing. If you use it by mistake, and the buffer is now displayed
253 wrong, use this command again to toggle back to the right mode."
254 (interactive "P")
255 (let ((new-flag
256 (if (null arg) (null enable-multibyte-characters)
257 (> (prefix-numeric-value arg) 0))))
258 (set-buffer-multibyte new-flag))
259 (force-mode-line-update))
260
261 (defun view-hello-file ()
262 "Display the HELLO file which list up many languages and characters."
263 (interactive)
264 ;; We have to decode the file in any environment.
265 (let ((default-enable-multibyte-characters t)
266 (coding-system-for-read 'iso-2022-7bit))
267 (find-file-read-only (expand-file-name "HELLO" data-directory))))
268
269 (defun universal-coding-system-argument (coding-system)
270 "Execute an I/O command using the specified coding system."
271 (interactive
272 (let ((default (and buffer-file-coding-system
273 (not (eq (coding-system-type buffer-file-coding-system)
274 t))
275 buffer-file-coding-system)))
276 (list (read-coding-system
277 (if default
278 (format "Coding system for following command (default, %s): " default)
279 "Coding system for following command: ")
280 default))))
281 (let* ((keyseq (read-key-sequence
282 (format "Command to execute with %s:" coding-system)))
283 (cmd (key-binding keyseq))
284 prefix)
285
286 (when (eq cmd 'universal-argument)
287 (call-interactively cmd)
288
289 ;; Process keys bound in `universal-argument-map'.
290 (while (progn
291 (setq keyseq (read-key-sequence nil t)
292 cmd (key-binding keyseq t))
293 (not (eq cmd 'universal-argument-other-key)))
294 (let ((current-prefix-arg prefix-arg)
295 ;; Have to bind `last-command-char' here so that
296 ;; `digit-argument', for isntance, can compute the
297 ;; prefix arg.
298 (last-command-char (aref keyseq 0)))
299 (call-interactively cmd)))
300
301 ;; This is the final call to `univeral-argument-other-key', which
302 ;; set's the final `prefix-arg.
303 (let ((current-prefix-arg prefix-arg))
304 (call-interactively cmd))
305
306 ;; Read the command to execute with the given prefix arg.
307 (setq prefix prefix-arg
308 keyseq (read-key-sequence nil t)
309 cmd (key-binding keyseq)))
310
311 (let ((coding-system-for-read coding-system)
312 (coding-system-for-write coding-system)
313 (coding-system-require-warning t)
314 (current-prefix-arg prefix))
315 (message "")
316 (call-interactively cmd))))
317
318 (defun set-default-coding-systems (coding-system)
319 "Set default value of various coding systems to CODING-SYSTEM.
320 This sets the following coding systems:
321 o coding system of a newly created buffer
322 o default coding system for subprocess I/O
323 This also sets the following values:
324 o default value used as `file-name-coding-system' for converting file names.
325 o default value for the command `set-terminal-coding-system' (not on MSDOS)
326 o default value for the command `set-keyboard-coding-system'."
327 (check-coding-system coding-system)
328 (setq-default buffer-file-coding-system coding-system)
329 (if default-enable-multibyte-characters
330 (setq default-file-name-coding-system coding-system))
331 ;; If coding-system is nil, honor that on MS-DOS as well, so
332 ;; that they could reset the terminal coding system.
333 (unless (and (eq window-system 'pc) coding-system)
334 (setq default-terminal-coding-system coding-system))
335 (setq default-keyboard-coding-system coding-system)
336 ;; Preserve eol-type from existing default-process-coding-systems.
337 ;; On non-unix-like systems in particular, these may have been set
338 ;; carefully by the user, or by the startup code, to deal with the
339 ;; users shell appropriately, so should not be altered by changing
340 ;; language environment.
341 (let ((output-coding
342 (coding-system-change-text-conversion
343 (car default-process-coding-system) coding-system))
344 (input-coding
345 (coding-system-change-text-conversion
346 (cdr default-process-coding-system) coding-system)))
347 (setq default-process-coding-system
348 (cons output-coding input-coding))))
349
350 (defalias 'update-iso-coding-systems 'update-coding-systems-internal)
351 (make-obsolete 'update-iso-coding-systems 'update-coding-systems-internal "20.3")
352
353 (defun prefer-coding-system (coding-system)
354 "Add CODING-SYSTEM at the front of the priority list for automatic detection.
355 This also sets the following coding systems:
356 o coding system of a newly created buffer
357 o default coding system for subprocess I/O
358 This also sets the following values:
359 o default value used as `file-name-coding-system' for converting file names.
360 o default value for the command `set-terminal-coding-system' (not on MSDOS)
361 o default value for the command `set-keyboard-coding-system'
362
363 If CODING-SYSTEM specifies a certain type of EOL conversion, the coding
364 systems set by this function will use that type of EOL conversion.
365
366 This command does not change the default value of terminal coding system
367 for MS-DOS terminal, because DOS terminals only support a single coding
368 system, and Emacs automatically sets the default to that coding system at
369 startup.
370
371 A coding system that requires automatic detection of text
372 encoding (e.g. undecided, unix) can't be preferred.
373
374 See also `coding-category-list' and `coding-system-category'."
375 (interactive "zPrefer coding system: ")
376 (if (not (and coding-system (coding-system-p coding-system)))
377 (error "Invalid coding system `%s'" coding-system))
378 (let ((coding-category (coding-system-category coding-system))
379 (base (coding-system-base coding-system))
380 (eol-type (coding-system-eol-type coding-system)))
381 (if (not coding-category)
382 ;; CODING-SYSTEM is no-conversion or undecided.
383 (error "Can't prefer the coding system `%s'" coding-system))
384 (set coding-category (or base coding-system))
385 (update-coding-systems-internal)
386 (or (eq coding-category (car coding-category-list))
387 ;; We must change the order.
388 (set-coding-priority (list coding-category)))
389 (if (and base (interactive-p))
390 (message "Highest priority is set to %s (base of %s)"
391 base coding-system))
392 ;; If they asked for specific EOL conversion, honor that.
393 (if (memq eol-type '(0 1 2))
394 (setq coding-system
395 (coding-system-change-eol-conversion base eol-type))
396 (setq coding-system base))
397 (set-default-coding-systems coding-system)))
398
399 (defvar sort-coding-systems-predicate nil
400 "If non-nil, a predicate function to sort coding systems.
401
402 It is called with two coding systems, and should return t if the first
403 one is \"less\" than the second.
404
405 The function `sort-coding-systems' use it.")
406
407 (defun sort-coding-systems (codings)
408 "Sort coding system list CODINGS by a priority of each coding system.
409
410 If a coding system is most preferred, it has the highest priority.
411 Otherwise, a coding system corresponds to some MIME charset has higher
412 priorities. Among them, a coding system included in `coding-system'
413 key of the current language environment has higher priorities. See
414 also the documentation of `language-info-alist'.
415
416 If the variable `sort-coding-systems-predicate' (which see) is
417 non-nil, it is used to sort CODINGS in the different way than above."
418 (if sort-coding-systems-predicate
419 (sort codings sort-coding-systems-predicate)
420 (let* ((most-preferred (symbol-value (car coding-category-list)))
421 (lang-preferred (get-language-info current-language-environment
422 'coding-system))
423 (func (function
424 (lambda (x)
425 (let ((base (coding-system-base x)))
426 (+ (if (eq base most-preferred) 64 0)
427 (let ((mime (coding-system-get base 'mime-charset)))
428 ;; Prefer coding systems corresponding to a
429 ;; MIME charset.
430 (if mime
431 ;; Lower utf-16 priority so that we
432 ;; normally prefer utf-8 to it, and put
433 ;; x-ctext below that.
434 (cond ((or (eq base 'mule-utf-16-le)
435 (eq base 'mule-utf-16-be))
436 16)
437 ((string-match "^x-" (symbol-name mime))
438 8)
439 (t 32))
440 0))
441 (if (memq base lang-preferred) 8 0)
442 (if (string-match "-with-esc$" (symbol-name base))
443 0 4)
444 (if (eq (coding-system-type base) 2)
445 ;; For ISO based coding systems, prefer
446 ;; one that doesn't use escape sequences.
447 (let ((flags (coding-system-flags base)))
448 (if (or (consp (aref flags 0))
449 (consp (aref flags 1))
450 (consp (aref flags 2))
451 (consp (aref flags 3)))
452 (if (or (aref flags 8) (aref flags 9))
453 0
454 1)
455 2))
456 1)))))))
457 (sort codings (function (lambda (x y)
458 (> (funcall func x) (funcall func y))))))))
459
460 (defun find-coding-systems-region (from to)
461 "Return a list of proper coding systems to encode a text between FROM and TO.
462 If FROM is a string, find coding systems in that instead of the buffer.
463 All coding systems in the list can safely encode any multibyte characters
464 in the text.
465
466 If the text contains no multibyte characters, return a list of a single
467 element `undecided'."
468 (let ((codings (find-coding-systems-region-internal from to)))
469 (if (eq codings t)
470 ;; The text contains only ASCII characters. Any coding
471 ;; systems are safe.
472 '(undecided)
473 ;; We need copy-sequence because sorting will alter the argument.
474 (sort-coding-systems (copy-sequence codings)))))
475
476 (defun find-coding-systems-string (string)
477 "Return a list of proper coding systems to encode STRING.
478 All coding systems in the list can safely encode any multibyte characters
479 in STRING.
480
481 If STRING contains no multibyte characters, return a list of a single
482 element `undecided'."
483 (find-coding-systems-region string nil))
484
485 (defun find-coding-systems-for-charsets (charsets)
486 "Return a list of proper coding systems to encode characters of CHARSETS.
487 CHARSETS is a list of character sets."
488 (cond ((or (null charsets)
489 (and (= (length charsets) 1)
490 (eq 'ascii (car charsets))))
491 '(undecided))
492 ((or (memq 'eight-bit-control charsets)
493 (memq 'eight-bit-graphic charsets))
494 '(raw-text emacs-mule))
495 (t
496 (let ((codings t)
497 charset l ll)
498 (while (and codings charsets)
499 (setq charset (car charsets) charsets (cdr charsets))
500 (unless (eq charset 'ascii)
501 (setq l (aref char-coding-system-table (make-char charset)))
502 (if (eq codings t)
503 (setq codings l)
504 (let ((ll nil))
505 (while codings
506 (if (memq (car codings) l)
507 (setq ll (cons (car codings) ll)))
508 (setq codings (cdr codings)))
509 (setq codings ll)))))
510 (append codings
511 (char-table-extra-slot char-coding-system-table 0))))))
512
513 (defun find-multibyte-characters (from to &optional maxcount excludes)
514 "Find multibyte characters in the region specified by FROM and TO.
515 If FROM is a string, find multibyte characters in the string.
516 The return value is an alist of the following format:
517 ((CHARSET COUNT CHAR ...) ...)
518 where
519 CHARSET is a character set,
520 COUNT is a number of characters,
521 CHARs are found characters of the character set.
522 Optional 3rd arg MAXCOUNT limits how many CHARs are put in the above list.
523 Optional 4th arg EXCLUDE is a list of character sets to be ignored.
524
525 For invalid characters, CHARs are actually strings."
526 (let ((chars nil)
527 charset char)
528 (if (stringp from)
529 (let ((idx 0))
530 (while (setq idx (string-match "[^\000-\177]" from idx))
531 (setq char (aref from idx)
532 charset (char-charset char))
533 (if (eq charset 'unknown)
534 (setq char (match-string 0)))
535 (if (or (memq charset '(unknown
536 eight-bit-control eight-bit-graphic))
537 (not (or (eq excludes t) (memq charset excludes))))
538 (let ((slot (assq charset chars)))
539 (if slot
540 (if (not (memq char (nthcdr 2 slot)))
541 (let ((count (nth 1 slot)))
542 (setcar (cdr slot) (1+ count))
543 (if (or (not maxcount) (< count maxcount))
544 (nconc slot (list char)))))
545 (setq chars (cons (list charset 1 char) chars)))))
546 (setq idx (1+ idx))))
547 (save-excursion
548 (goto-char from)
549 (while (re-search-forward "[^\000-\177]" to t)
550 (setq char (preceding-char)
551 charset (char-charset char))
552 (if (eq charset 'unknown)
553 (setq char (match-string 0)))
554 (if (or (memq charset '(unknown eight-bit-control eight-bit-graphic))
555 (not (or (eq excludes t) (memq charset excludes))))
556 (let ((slot (assq charset chars)))
557 (if slot
558 (if (not (member char (nthcdr 2 slot)))
559 (let ((count (nth 1 slot)))
560 (setcar (cdr slot) (1+ count))
561 (if (or (not maxcount) (< count maxcount))
562 (nconc slot (list char)))))
563 (setq chars (cons (list charset 1 char) chars))))))))
564 (nreverse chars)))
565
566
567 (defun search-unencodable-char (coding-system)
568 "Search forward from point for a character that is not encodable.
569 It asks which coding system to check.
570 If such a character is found, set point after that character.
571 Otherwise, don't move point.
572
573 When called from a program, the value is a position of the found character,
574 or nil if all characters are encodable."
575 (interactive
576 (list (let ((default (or buffer-file-coding-system 'us-ascii)))
577 (read-coding-system
578 (format "Coding-system (default, %s): " default)
579 default))))
580 (let ((pos (unencodable-char-position (point) (point-max) coding-system)))
581 (if pos
582 (goto-char (1+ pos))
583 (message "All following characters are encodable by %s" coding-system))
584 pos))
585
586
587 (defvar last-coding-system-specified nil
588 "Most recent coding system explicitly specified by the user when asked.
589 This variable is set whenever Emacs asks the user which coding system
590 to use in order to write a file. If you set it to nil explicitly,
591 then call `write-region', then afterward this variable will be non-nil
592 only if the user was explicitly asked and specified a coding system.")
593
594 (defvar select-safe-coding-system-accept-default-p nil
595 "If non-nil, a function to control the behaviour of coding system selection.
596 The meaning is the same as the argument ACCEPT-DEFAULT-P of the
597 function `select-safe-coding-system' (which see). This variable
598 overrides that argument.")
599
600 (defun select-safe-coding-system (from to &optional default-coding-system
601 accept-default-p file)
602 "Ask a user to select a safe coding system from candidates.
603 The candidates of coding systems which can safely encode a text
604 between FROM and TO are shown in a popup window. Among them, the most
605 proper one is suggested as the default.
606
607 The list of `buffer-file-coding-system' of the current buffer and the
608 most preferred coding system (if it corresponds to a MIME charset) is
609 treated as the default coding system list. Among them, the first one
610 that safely encodes the text is normally selected silently and
611 returned without any user interaction. See also the command
612 `prefer-coding-system'.
613
614 However, the user is queried if the chosen coding system is
615 inconsistent with what would be selected by `set-auto-coding' from
616 coding cookies &c. if the contents of the region were read from a
617 file. (That could lead to data corruption in a file subsequently
618 re-visited and edited.)
619
620 Optional 3rd arg DEFAULT-CODING-SYSTEM specifies a coding system or a
621 list of coding systems to be prepended to the default coding system
622 list. However, if DEFAULT-CODING-SYSTEM is a list and the first
623 element is t, the cdr part is used as the defualt coding system list,
624 i.e. `buffer-file-coding-system' and the most prepended coding system
625 is not used.
626
627 Optional 4th arg ACCEPT-DEFAULT-P, if non-nil, is a function to
628 determine the acceptability of the silently selected coding system.
629 It is called with that coding system, and should return nil if it
630 should not be silently selected and thus user interaction is required.
631
632 Optional 5th arg FILE is the file name to use for this purpose.
633 That is different from `buffer-file-name' when handling `write-region'
634 \(for example).
635
636 The variable `select-safe-coding-system-accept-default-p', if
637 non-nil, overrides ACCEPT-DEFAULT-P.
638
639 Kludgy feature: if FROM is a string, the string is the target text,
640 and TO is ignored."
641 (if (and default-coding-system
642 (not (listp default-coding-system)))
643 (setq default-coding-system (list default-coding-system)))
644
645 (let ((no-other-defaults nil))
646 (if (eq (car default-coding-system) t)
647 (setq no-other-defaults t
648 default-coding-system (cdr default-coding-system)))
649
650 ;; Change elements of the list to (coding . base-coding).
651 (setq default-coding-system
652 (mapcar (function (lambda (x) (cons x (coding-system-base x))))
653 default-coding-system))
654
655 (unless no-other-defaults
656 ;; If buffer-file-coding-system is not nil nor undecided, append it
657 ;; to the defaults.
658 (if buffer-file-coding-system
659 (let ((base (coding-system-base buffer-file-coding-system)))
660 (or (eq base 'undecided)
661 (assq buffer-file-coding-system default-coding-system)
662 (rassq base default-coding-system)
663 (setq default-coding-system
664 (append default-coding-system
665 (list (cons buffer-file-coding-system base)))))))
666
667 ;; If the most preferred coding system has the property mime-charset,
668 ;; append it to the defaults.
669 (let ((tail coding-category-list)
670 preferred base)
671 (while (and tail
672 (not (setq preferred (symbol-value (car tail)))))
673 (setq tail (cdr tail)))
674 (and (coding-system-p preferred)
675 (setq base (coding-system-base preferred))
676 (coding-system-get preferred 'mime-charset)
677 (not (assq preferred default-coding-system))
678 (not (rassq base default-coding-system))
679 (setq default-coding-system
680 (append default-coding-system
681 (list (cons preferred base))))))))
682
683 (if select-safe-coding-system-accept-default-p
684 (setq accept-default-p select-safe-coding-system-accept-default-p))
685
686 (let ((codings (find-coding-systems-region from to))
687 (coding-system nil)
688 (bufname (buffer-name))
689 safe rejected unsafe)
690 (if (eq (car codings) 'undecided)
691 ;; Any coding system is ok.
692 (setq coding-system t)
693 ;; Classify the defaults into safe, rejected, and unsafe.
694 (dolist (elt default-coding-system)
695 (if (memq (cdr elt) codings)
696 (if (and (functionp accept-default-p)
697 (not (funcall accept-default-p (cdr elt))))
698 (push (car elt) rejected)
699 (push (car elt) safe))
700 (push (car elt) unsafe)))
701 (if safe
702 (setq coding-system (car (last safe)))))
703
704 ;; If all the defaults failed, ask a user.
705 (when (not coding-system)
706 ;; At first, if some defaults are unsafe, record at most 11
707 ;; problematic characters and their positions for them by turning
708 ;; (CODING ...)
709 ;; into
710 ;; ((CODING (POS . CHAR) (POS . CHAR) ...) ...)
711 (if unsafe
712 (if (stringp from)
713 (setq unsafe
714 (mapcar #'(lambda (coding)
715 (cons coding
716 (mapcar #'(lambda (pos)
717 (cons pos (aref from pos)))
718 (unencodable-char-position
719 0 (length from) coding
720 11 from))))
721 unsafe))
722 (setq unsafe
723 (mapcar #'(lambda (coding)
724 (cons coding
725 (mapcar #'(lambda (pos)
726 (cons pos (char-after pos)))
727 (unencodable-char-position
728 from to coding 11))))
729 unsafe))))
730
731 ;; Change each safe coding system to the corresponding
732 ;; mime-charset name if it is also a coding system. Such a name
733 ;; is more friendly to users.
734 (let ((l codings)
735 mime-charset)
736 (while l
737 (setq mime-charset (coding-system-get (car l) 'mime-charset))
738 (if (and mime-charset (coding-system-p mime-charset))
739 (setcar l mime-charset))
740 (setq l (cdr l))))
741
742 ;; Don't offer variations with locking shift, which you
743 ;; basically never want.
744 (let (l)
745 (dolist (elt codings (setq codings (nreverse l)))
746 (unless (or (eq 'coding-category-iso-7-else
747 (coding-system-category elt))
748 (eq 'coding-category-iso-8-else
749 (coding-system-category elt)))
750 (push elt l))))
751
752 (let ((window-configuration (current-window-configuration)))
753 (save-excursion
754 ;; If some defaults are unsafe, make sure the offending
755 ;; buffer is displayed.
756 (when (and unsafe (not (stringp from)))
757 (pop-to-buffer bufname)
758 (goto-char (apply 'min (mapcar #'(lambda (x) (car (cadr x)))
759 unsafe))))
760 ;; Then ask users to select one from CODINGS while showing
761 ;; the reason why none of the defaults are not used.
762 (with-output-to-temp-buffer "*Warning*"
763 (save-excursion
764 (set-buffer standard-output)
765 (if (not default-coding-system)
766 (insert "No default coding systems to try for "
767 (if (stringp from)
768 (format "string \"%s\"." from)
769 (format "buffer `%s'." bufname)))
770 (insert
771 "These default coding systems were tried to encode"
772 (if (stringp from)
773 (concat " \"" (if (> (length from) 10)
774 (concat (substring from 0 10) "...\"")
775 (concat from "\"")))
776 (format " text\nin the buffer `%s'" bufname))
777 ":\n")
778 (let ((pos (point))
779 (fill-prefix " "))
780 (mapc #'(lambda (x) (princ " ") (princ (car x)))
781 default-coding-system)
782 (insert "\n")
783 (fill-region-as-paragraph pos (point)))
784 (when rejected
785 (insert "These safely encodes the target text,
786 but it is not recommended for encoding text in this context,
787 e.g., for sending an email message.\n ")
788 (mapc #'(lambda (x) (princ " ") (princ x)) rejected)
789 (insert "\n"))
790 (when unsafe
791 (insert (if rejected "And the others"
792 "However, each of them")
793 " encountered these problematic characters:\n")
794 (mapc
795 #'(lambda (coding)
796 (insert (format " %s:" (car coding)))
797 (let ((i 0)
798 (func1
799 #'(lambda (bufname pos)
800 (when (buffer-live-p (get-buffer bufname))
801 (pop-to-buffer bufname)
802 (goto-char pos))))
803 (func2
804 #'(lambda (bufname pos coding)
805 (when (buffer-live-p (get-buffer bufname))
806 (pop-to-buffer bufname)
807 (if (< (point) pos)
808 (goto-char pos)
809 (forward-char 1)
810 (search-unencodable-char coding)
811 (forward-char -1))))))
812 (dolist (elt (cdr coding))
813 (insert " ")
814 (if (stringp from)
815 (insert (if (< i 10) (cdr elt) "..."))
816 (if (< i 10)
817 (insert-text-button
818 (cdr elt)
819 :type 'help-xref
820 'help-echo
821 "mouse-2, RET: jump to this character"
822 'help-function func1
823 'help-args (list bufname (car elt)))
824 (insert-text-button
825 "..."
826 :type 'help-xref
827 'help-echo
828 "mouse-2, RET: next unencodable character"
829 'help-function func2
830 'help-args (list bufname (car elt)
831 (car coding)))))
832 (setq i (1+ i))))
833 (insert "\n"))
834 unsafe)
835 (insert "\
836 The first problematic character is at point in the displayed buffer,\n"
837 (substitute-command-keys "\
838 and \\[universal-argument] \\[what-cursor-position] will give information about it.\n"))))
839 (insert (if safe
840 "\nSelect the above, or "
841 "\nSelect ")
842 "\
843 one of the following safe coding systems, or edit the buffer:\n")
844 (let ((pos (point))
845 (fill-prefix " "))
846 (mapcar (function (lambda (x) (princ " ") (princ x)))
847 codings)
848 (insert "\n")
849 (fill-region-as-paragraph pos (point)))
850 (insert "Or specify any other coding system
851 on your risk of losing the problematic characters.\n")))
852
853 ;; Read a coding system.
854 (setq default-coding-system (or (car safe) (car codings)))
855 (setq coding-system
856 (read-coding-system
857 (format "Select coding system (default %s): "
858 default-coding-system)
859 default-coding-system))
860 (setq last-coding-system-specified coding-system))
861
862 (kill-buffer "*Warning*")
863 (set-window-configuration window-configuration)))
864
865 (if (vectorp (coding-system-eol-type coding-system))
866 (let ((eol (coding-system-eol-type buffer-file-coding-system)))
867 (if (numberp eol)
868 (setq coding-system
869 (coding-system-change-eol-conversion coding-system eol)))))
870
871 (if (eq coding-system t)
872 (setq coding-system buffer-file-coding-system))
873 ;; Check we're not inconsistent with what `coding:' spec &c would
874 ;; give when file is re-read.
875 ;; But don't do this if we explicitly ignored the cookie
876 ;; by using `find-file-literally'.
877 (unless (or (stringp from) find-file-literally)
878 (let ((auto-cs (save-excursion
879 (save-restriction
880 (widen)
881 (narrow-to-region from to)
882 (goto-char (point-min))
883 (set-auto-coding (or file buffer-file-name "")
884 (buffer-size))))))
885 (if (and auto-cs coding-system
886 ;; Don't barf if writing a compressed file, say.
887 ;; This check perhaps isn't ideal, but is probably
888 ;; the best thing to do.
889 (not (auto-coding-alist-lookup (or file buffer-file-name "")))
890 (not (coding-system-equal (coding-system-base coding-system)
891 (coding-system-base auto-cs))))
892 (unless (yes-or-no-p
893 (format "Selected encoding %s disagrees with \
894 %s specified by file contents. Really save (else edit coding cookies \
895 and try again)? " coding-system auto-cs))
896 (error "Save aborted")))))
897 coding-system))
898
899 (setq select-safe-coding-system-function 'select-safe-coding-system)
900
901 (defun select-message-coding-system ()
902 "Return a coding system to encode the outgoing message of the current buffer.
903 It at first tries the first coding system found in these variables
904 in this order:
905 (1) local value of `buffer-file-coding-system'
906 (2) value of `sendmail-coding-system'
907 (3) value of `default-sendmail-coding-system'
908 (4) value of `default-buffer-file-coding-system'
909 If the found coding system can't encode the current buffer,
910 or none of them are bound to a coding system,
911 it asks the user to select a proper coding system."
912 (let ((coding (or (and (local-variable-p 'buffer-file-coding-system)
913 buffer-file-coding-system)
914 sendmail-coding-system
915 default-sendmail-coding-system
916 default-buffer-file-coding-system)))
917 (if (eq coding 'no-conversion)
918 ;; We should never use no-conversion for outgoing mail.
919 (setq coding nil))
920 (if (fboundp select-safe-coding-system-function)
921 (funcall select-safe-coding-system-function
922 (point-min) (point-max) coding
923 (function (lambda (x) (coding-system-get x 'mime-charset))))
924 coding)))
925 \f
926 ;;; Language support stuff.
927
928 (defvar language-info-alist nil
929 "Alist of language environment definitions.
930 Each element looks like:
931 (LANGUAGE-NAME . ((KEY . INFO) ...))
932 where LANGUAGE-NAME is a string, the name of the language environment,
933 KEY is a symbol denoting the kind of information, and
934 INFO is the data associated with KEY.
935 Meaningful values for KEY include
936
937 documentation value is documentation of what this language environment
938 is meant for, and how to use it.
939 charset value is a list of the character sets used by this
940 language environment.
941 sample-text value is an expression which is evalled to generate
942 a line of text written using characters appropriate
943 for this language environment.
944 setup-function value is a function to call to switch to this
945 language environment.
946 exit-function value is a function to call to leave this
947 language environment.
948 coding-system value is a list of coding systems that are good
949 for saving text written in this language environment.
950 This list serves as suggestions to the user;
951 in effect, as a kind of documentation.
952 coding-priority value is a list of coding systems for this language
953 environment, in order of decreasing priority.
954 This is used to set up the coding system priority
955 list when you switch to this language environment.
956 nonascii-translation
957 value is a translation table to be set in the
958 variable `nonascii-translation-table' in this
959 language environment, or a character set from
960 which `nonascii-insert-offset' is calculated.
961 input-method value is a default input method for this language
962 environment.
963 features value is a list of features requested in this
964 language environment.
965
966 The following keys take effect only when multibyte characters are
967 globally disabled, i.e. the value of `default-enable-multibyte-characters'
968 is nil.
969
970 unibyte-syntax value is a library name to load to set
971 unibyte 8-bit character syntaxes for this
972 language environment.
973
974 unibyte-display value is a coding system to encode characters
975 for the terminal. Characters in the range
976 of 160 to 255 display not as octal escapes,
977 but as non-ASCII characters in this language
978 environment.")
979
980 (defun get-language-info (lang-env key)
981 "Return information listed under KEY for language environment LANG-ENV.
982 KEY is a symbol denoting the kind of information.
983 For a list of useful values for KEY and their meanings,
984 see `language-info-alist'."
985 (if (symbolp lang-env)
986 (setq lang-env (symbol-name lang-env)))
987 (let ((lang-slot (assoc-ignore-case lang-env language-info-alist)))
988 (if lang-slot
989 (cdr (assq key (cdr lang-slot))))))
990
991 (defun set-language-info (lang-env key info)
992 "Modify part of the definition of language environment LANG-ENV.
993 Specifically, this stores the information INFO under KEY
994 in the definition of this language environment.
995 KEY is a symbol denoting the kind of information.
996 INFO is the value for that information.
997
998 For a list of useful values for KEY and their meanings,
999 see `language-info-alist'."
1000 (if (symbolp lang-env)
1001 (setq lang-env (symbol-name lang-env)))
1002 (let (lang-slot key-slot)
1003 (setq lang-slot (assoc lang-env language-info-alist))
1004 (if (null lang-slot) ; If no slot for the language, add it.
1005 (setq lang-slot (list lang-env)
1006 language-info-alist (cons lang-slot language-info-alist)))
1007 (setq key-slot (assq key lang-slot))
1008 (if (null key-slot) ; If no slot for the key, add it.
1009 (progn
1010 (setq key-slot (list key))
1011 (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
1012 (setcdr key-slot (purecopy info))
1013 ;; Update the custom-type of `current-language-environment'.
1014 (put 'current-language-environment 'custom-type
1015 (cons 'choice (mapcar
1016 (lambda (lang)
1017 (list 'const (car lang)))
1018 (sort (copy-sequence language-info-alist)
1019 (lambda (x y) (string< (car x) (car y)))))))))
1020
1021 (defun set-language-info-alist (lang-env alist &optional parents)
1022 "Store ALIST as the definition of language environment LANG-ENV.
1023 ALIST is an alist of KEY and INFO values. See the documentation of
1024 `language-info-alist' for the meanings of KEY and INFO.
1025
1026 Optional arg PARENTS is a list of parent menu names; it specifies
1027 where to put this language environment in the
1028 Describe Language Environment and Set Language Environment menus.
1029 For example, (\"European\") means to put this language environment
1030 in the European submenu in each of those two menus."
1031 (if (symbolp lang-env)
1032 (setq lang-env (symbol-name lang-env)))
1033 (let ((describe-map describe-language-environment-map)
1034 (setup-map setup-language-environment-map))
1035 (if parents
1036 (let ((l parents)
1037 map parent-symbol parent prompt)
1038 (while l
1039 (if (symbolp (setq parent-symbol (car l)))
1040 (setq parent (symbol-name parent))
1041 (setq parent parent-symbol parent-symbol (intern parent)))
1042 (setq map (lookup-key describe-map (vector parent-symbol)))
1043 ;; This prompt string is for define-prefix-command, so
1044 ;; that the map it creates will be suitable for a menu.
1045 (or map (setq prompt (format "%s Environment" parent)))
1046 (if (not map)
1047 (progn
1048 (setq map (intern (format "describe-%s-environment-map"
1049 (downcase parent))))
1050 (define-prefix-command map nil prompt)
1051 (define-key-after describe-map (vector parent-symbol)
1052 (cons parent map) t)))
1053 (setq describe-map (symbol-value map))
1054 (setq map (lookup-key setup-map (vector parent-symbol)))
1055 (if (not map)
1056 (progn
1057 (setq map (intern (format "setup-%s-environment-map"
1058 (downcase parent))))
1059 (define-prefix-command map nil prompt)
1060 (define-key-after setup-map (vector parent-symbol)
1061 (cons parent map) t)))
1062 (setq setup-map (symbol-value map))
1063 (setq l (cdr l)))))
1064
1065 ;; Set up menu items for this language env.
1066 (let ((doc (assq 'documentation alist)))
1067 (when doc
1068 (define-key-after describe-map (vector (intern lang-env))
1069 (cons lang-env 'describe-specified-language-support) t)))
1070 (define-key-after setup-map (vector (intern lang-env))
1071 (cons lang-env 'setup-specified-language-environment) t)
1072
1073 (while alist
1074 (set-language-info lang-env (car (car alist)) (cdr (car alist)))
1075 (setq alist (cdr alist)))))
1076
1077 (defun read-language-name (key prompt &optional default)
1078 "Read a language environment name which has information for KEY.
1079 If KEY is nil, read any language environment.
1080 Prompt with PROMPT. DEFAULT is the default choice of language environment.
1081 This returns a language environment name as a string."
1082 (let* ((completion-ignore-case t)
1083 (name (completing-read prompt
1084 language-info-alist
1085 (and key
1086 (function (lambda (elm) (and (listp elm) (assq key elm)))))
1087 t nil nil default)))
1088 (if (and (> (length name) 0)
1089 (or (not key)
1090 (get-language-info name key)))
1091 name)))
1092 \f
1093 ;;; Multilingual input methods.
1094 (defgroup leim nil
1095 "LEIM: Libraries of Emacs Input Methods."
1096 :group 'mule)
1097
1098 (defconst leim-list-file-name "leim-list.el"
1099 "Name of LEIM list file.
1100 This file contains a list of libraries of Emacs input methods (LEIM)
1101 in the format of Lisp expression for registering each input method.
1102 Emacs loads this file at startup time.")
1103
1104 (defvar leim-list-header (format
1105 ";;; %s -- list of LEIM (Library of Emacs Input Method) -*-coding: iso-2022-7bit;-*-
1106 ;;
1107 ;; This file contains a list of LEIM (Library of Emacs Input Method)
1108 ;; methods in the same directory as this file. Loading this file
1109 ;; registers all the input methods in Emacs.
1110 ;;
1111 ;; Each entry has the form:
1112 ;; (register-input-method
1113 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC
1114 ;; TITLE DESCRIPTION
1115 ;; ARG ...)
1116 ;; See the function `register-input-method' for the meanings of the arguments.
1117 ;;
1118 ;; If this directory is included in load-path, Emacs automatically
1119 ;; loads this file at startup time.
1120
1121 "
1122 leim-list-file-name)
1123 "Header to be inserted in LEIM list file.")
1124
1125 (defvar leim-list-entry-regexp "^(register-input-method"
1126 "Regexp matching head of each entry in LEIM list file.
1127 See also the variable `leim-list-header'")
1128
1129 (defvar update-leim-list-functions
1130 '(quail-update-leim-list-file)
1131 "List of functions to call to update LEIM list file.
1132 Each function is called with one arg, LEIM directory name.")
1133
1134 (defun update-leim-list-file (&rest dirs)
1135 "Update LEIM list file in directories DIRS."
1136 (let ((functions update-leim-list-functions))
1137 (while functions
1138 (apply (car functions) dirs)
1139 (setq functions (cdr functions)))))
1140
1141 (defvar current-input-method nil
1142 "The current input method for multilingual text.
1143 If nil, that means no input method is activated now.")
1144 (make-variable-buffer-local 'current-input-method)
1145 (put 'current-input-method 'permanent-local t)
1146
1147 (defvar current-input-method-title nil
1148 "Title string of the current input method shown in mode line.")
1149 (make-variable-buffer-local 'current-input-method-title)
1150 (put 'current-input-method-title 'permanent-local t)
1151
1152 (defcustom default-input-method nil
1153 "*Default input method for multilingual text (a string).
1154 This is the input method activated automatically by the command
1155 `toggle-input-method' (\\[toggle-input-method])."
1156 :group 'mule
1157 :type '(choice (const nil) string)
1158 :set-after '(current-language-environment))
1159
1160 (put 'input-method-function 'permanent-local t)
1161
1162 (defvar input-method-history nil
1163 "History list for some commands that read input methods.")
1164 (make-variable-buffer-local 'input-method-history)
1165 (put 'input-method-history 'permanent-local t)
1166
1167 (defvar inactivate-current-input-method-function nil
1168 "Function to call for inactivating the current input method.
1169 Every input method should set this to an appropriate value when activated.
1170 This function is called with no argument.
1171
1172 This function should never change the value of `current-input-method'.
1173 It is set to nil by the function `inactivate-input-method'.")
1174 (make-variable-buffer-local 'inactivate-current-input-method-function)
1175 (put 'inactivate-current-input-method-function 'permanent-local t)
1176
1177 (defvar describe-current-input-method-function nil
1178 "Function to call for describing the current input method.
1179 This function is called with no argument.")
1180 (make-variable-buffer-local 'describe-current-input-method-function)
1181 (put 'describe-current-input-method-function 'permanent-local t)
1182
1183 (defvar input-method-alist nil
1184 "Alist of input method names vs how to use them.
1185 Each element has the form:
1186 (INPUT-METHOD LANGUAGE-ENV ACTIVATE-FUNC TITLE DESCRIPTION ARGS...)
1187 See the function `register-input-method' for the meanings of the elements.")
1188
1189 (defun register-input-method (input-method lang-env &rest args)
1190 "Register INPUT-METHOD as an input method for language environment LANG-ENV.
1191 INPUT-METHOD and LANG-ENV are symbols or strings.
1192
1193 The remaining arguments are:
1194 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARGS...
1195 ACTIVATE-FUNC is a function to call to activate this method.
1196 TITLE is a string to show in the mode line when this method is active.
1197 DESCRIPTION is a string describing this method and what it is good for.
1198 The ARGS, if any, are passed as arguments to ACTIVATE-FUNC.
1199 All told, the arguments to ACTIVATE-FUNC are INPUT-METHOD and the ARGS.
1200
1201 This function is mainly used in the file \"leim-list.el\" which is
1202 created at Emacs build time, registering all Quail input methods
1203 contained in the Emacs distribution.
1204
1205 In case you want to register a new Quail input method by yourself, be
1206 careful to use the same input method title as given in the third
1207 parameter of `quail-define-package'. (If the values are different, the
1208 string specified in this function takes precedence.)
1209
1210 The commands `describe-input-method' and `list-input-methods' need
1211 these duplicated values to show some information about input methods
1212 without loading the relevant Quail packages."
1213 (if (symbolp lang-env)
1214 (setq lang-env (symbol-name lang-env)))
1215 (if (symbolp input-method)
1216 (setq input-method (symbol-name input-method)))
1217 (let ((info (cons lang-env args))
1218 (slot (assoc input-method input-method-alist)))
1219 (if slot
1220 (setcdr slot info)
1221 (setq slot (cons input-method info))
1222 (setq input-method-alist (cons slot input-method-alist)))))
1223
1224 (defun read-input-method-name (prompt &optional default inhibit-null)
1225 "Read a name of input method from a minibuffer prompting with PROMPT.
1226 If DEFAULT is non-nil, use that as the default,
1227 and substitute it into PROMPT at the first `%s'.
1228 If INHIBIT-NULL is non-nil, null input signals an error.
1229
1230 The return value is a string."
1231 (if default
1232 (setq prompt (format prompt default)))
1233 (let* ((completion-ignore-case t)
1234 ;; As it is quite normal to change input method in the
1235 ;; minibuffer, we must enable it even if
1236 ;; enable-recursive-minibuffers is currently nil.
1237 (enable-recursive-minibuffers t)
1238 ;; This binding is necessary because input-method-history is
1239 ;; buffer local.
1240 (input-method (completing-read prompt input-method-alist
1241 nil t nil 'input-method-history
1242 default)))
1243 (if (and input-method (symbolp input-method))
1244 (setq input-method (symbol-name input-method)))
1245 (if (> (length input-method) 0)
1246 input-method
1247 (if inhibit-null
1248 (error "No valid input method is specified")))))
1249
1250 (defun activate-input-method (input-method)
1251 "Switch to input method INPUT-METHOD for the current buffer.
1252 If some other input method is already active, turn it off first.
1253 If INPUT-METHOD is nil, deactivate any current input method."
1254 (if (and input-method (symbolp input-method))
1255 (setq input-method (symbol-name input-method)))
1256 (if (and current-input-method
1257 (not (string= current-input-method input-method)))
1258 (inactivate-input-method))
1259 (unless (or current-input-method (null input-method))
1260 (let ((slot (assoc input-method input-method-alist)))
1261 (if (null slot)
1262 (error "Can't activate input method `%s'" input-method))
1263 (setq current-input-method-title nil)
1264 (let ((func (nth 2 slot)))
1265 (if (functionp func)
1266 (apply (nth 2 slot) input-method (nthcdr 5 slot))
1267 (if (and (consp func) (symbolp (car func)) (symbolp (cdr func)))
1268 (progn
1269 (require (cdr func))
1270 (apply (car func) input-method (nthcdr 5 slot)))
1271 (error "Can't activate input method `%s'" input-method))))
1272 (setq current-input-method input-method)
1273 (or (stringp current-input-method-title)
1274 (setq current-input-method-title (nth 3 slot)))
1275 (unwind-protect
1276 (run-hooks 'input-method-activate-hook)
1277 (force-mode-line-update)))))
1278
1279 (defun inactivate-input-method ()
1280 "Turn off the current input method."
1281 (when current-input-method
1282 (if input-method-history
1283 (unless (string= current-input-method (car input-method-history))
1284 (setq input-method-history
1285 (cons current-input-method
1286 (delete current-input-method input-method-history))))
1287 (setq input-method-history (list current-input-method)))
1288 (unwind-protect
1289 (funcall inactivate-current-input-method-function)
1290 (unwind-protect
1291 (run-hooks 'input-method-inactivate-hook)
1292 (setq current-input-method nil
1293 input-method-function nil
1294 current-input-method-title nil)
1295 (force-mode-line-update)))))
1296
1297 (defun set-input-method (input-method)
1298 "Select and activate input method INPUT-METHOD for the current buffer.
1299 This also sets the default input method to the one you specify.
1300 If INPUT-METHOD is nil, this function turns off the input method, and
1301 also causes you to be prompted for a name of an input method the next
1302 time you invoke \\[toggle-input-method].
1303
1304 To deactivate the input method interactively, use \\[toggle-input-method].
1305 To deactivate it programmatically, use \\[inactivate-input-method]."
1306 (interactive
1307 (let* ((default (or (car input-method-history) default-input-method)))
1308 (list (read-input-method-name
1309 (if default "Select input method (default %s): " "Select input method: ")
1310 default t))))
1311 (activate-input-method input-method)
1312 (setq default-input-method input-method)
1313 (when (interactive-p)
1314 (customize-mark-as-set 'default-input-method))
1315 default-input-method)
1316
1317 (defun toggle-input-method (&optional arg)
1318 "Enable or disable multilingual text input method for the current buffer.
1319 Only one input method can be enabled at any time in a given buffer.
1320
1321 The normal action is to enable an input method if none was
1322 enabled, and disable the current one otherwise. Which input method
1323 to enable can be determined in various ways--either the one most
1324 recently used, or the one specified by `default-input-method', or
1325 as a last resort by reading the name of an input method in the
1326 minibuffer.
1327
1328 With a prefix argument, read an input method name with the minibuffer
1329 and enable that one. The default is the most recent input method specified
1330 \(not including the currently active input method, if any)."
1331
1332 (interactive "P")
1333 (if (and current-input-method (not arg))
1334 (inactivate-input-method)
1335 (let ((default (or (car input-method-history) default-input-method)))
1336 (if (and arg default (equal current-input-method default)
1337 (> (length input-method-history) 1))
1338 (setq default (nth 1 input-method-history)))
1339 (activate-input-method
1340 (if (or arg (not default))
1341 (progn
1342 (read-input-method-name
1343 (if default "Input method (default %s): " "Input method: " )
1344 default t))
1345 default))
1346 (unless default-input-method
1347 (prog1
1348 (setq default-input-method current-input-method)
1349 (when (interactive-p)
1350 (customize-mark-as-set 'default-input-method)))))))
1351
1352 (defun describe-input-method (input-method)
1353 "Describe input method INPUT-METHOD."
1354 (interactive
1355 (list (read-input-method-name
1356 "Describe input method (default, current choice): ")))
1357 (if (and input-method (symbolp input-method))
1358 (setq input-method (symbol-name input-method)))
1359 (help-setup-xref (list #'describe-input-method
1360 (or input-method current-input-method))
1361 (interactive-p))
1362
1363 (if (null input-method)
1364 (describe-current-input-method)
1365 (let ((current current-input-method))
1366 (condition-case nil
1367 (progn
1368 (save-excursion
1369 (activate-input-method input-method)
1370 (describe-current-input-method))
1371 (activate-input-method current))
1372 (error
1373 (activate-input-method current)
1374 (help-setup-xref (list #'describe-input-method input-method)
1375 (interactive-p))
1376 (with-output-to-temp-buffer (help-buffer)
1377 (let ((elt (assoc input-method input-method-alist)))
1378 (princ (format
1379 "Input method: %s (`%s' in mode line) for %s\n %s\n"
1380 input-method (nth 3 elt) (nth 1 elt) (nth 4 elt))))))))))
1381
1382 (defun describe-current-input-method ()
1383 "Describe the input method currently in use.
1384 This is a subroutine for `describe-input-method'."
1385 (if current-input-method
1386 (if (and (symbolp describe-current-input-method-function)
1387 (fboundp describe-current-input-method-function))
1388 (funcall describe-current-input-method-function)
1389 (message "No way to describe the current input method `%s'"
1390 current-input-method)
1391 (ding))
1392 (error "No input method is activated now")))
1393
1394 (defun read-multilingual-string (prompt &optional initial-input input-method)
1395 "Read a multilingual string from minibuffer, prompting with string PROMPT.
1396 The input method selected last time is activated in minibuffer.
1397 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
1398 initially.
1399 Optional 3rd argument INPUT-METHOD specifies the input method
1400 to be activated instead of the one selected last time. It is a symbol
1401 or a string."
1402 (setq input-method
1403 (or input-method
1404 current-input-method
1405 default-input-method
1406 (read-input-method-name "Input method: " nil t)))
1407 (if (and input-method (symbolp input-method))
1408 (setq input-method (symbol-name input-method)))
1409 (let ((prev-input-method current-input-method))
1410 (unwind-protect
1411 (progn
1412 (activate-input-method input-method)
1413 (read-string prompt initial-input nil nil t))
1414 (activate-input-method prev-input-method))))
1415
1416 ;; Variables to control behavior of input methods. All input methods
1417 ;; should react to these variables.
1418
1419 (defcustom input-method-verbose-flag 'default
1420 "*A flag to control extra guidance given by input methods.
1421 The value should be nil, t, `complex-only', or `default'.
1422
1423 The extra guidance is done by showing list of available keys in echo
1424 area. When you use the input method in the minibuffer, the guidance
1425 is shown at the bottom short window (split from the existing window).
1426
1427 If the value is t, extra guidance is always given, if the value is
1428 nil, extra guidance is always suppressed.
1429
1430 If the value is `complex-only', only complex input methods such as
1431 `chinese-py' and `japanese' give extra guidance.
1432
1433 If the value is `default', complex input methods always give extra
1434 guidance, but simple input methods give it only when you are not in
1435 the minibuffer.
1436
1437 See also the variable `input-method-highlight-flag'."
1438 :type '(choice (const :tag "Always" t) (const :tag "Never" nil)
1439 (const complex-only) (const default))
1440 :group 'mule)
1441
1442 (defcustom input-method-highlight-flag t
1443 "*If this flag is non-nil, input methods highlight partially-entered text.
1444 For instance, while you are in the middle of a Quail input method sequence,
1445 the text inserted so far is temporarily underlined.
1446 The underlining goes away when you finish or abort the input method sequence.
1447 See also the variable `input-method-verbose-flag'."
1448 :type 'boolean
1449 :group 'mule)
1450
1451 (defvar input-method-activate-hook nil
1452 "Normal hook run just after an input method is activated.
1453
1454 The variable `current-input-method' keeps the input method name
1455 just activated.")
1456
1457 (defvar input-method-inactivate-hook nil
1458 "Normal hook run just after an input method is inactivated.
1459
1460 The variable `current-input-method' still keeps the input method name
1461 just inactivated.")
1462
1463 (defvar input-method-after-insert-chunk-hook nil
1464 "Normal hook run just after an input method insert some chunk of text.")
1465
1466 (defvar input-method-exit-on-first-char nil
1467 "This flag controls when an input method returns.
1468 Usually, the input method does not return while there's a possibility
1469 that it may find a different translation if a user types another key.
1470 But, it this flag is non-nil, the input method returns as soon as
1471 the current key sequence gets long enough to have some valid translation.")
1472
1473 (defvar input-method-use-echo-area nil
1474 "This flag controls how an input method shows an intermediate key sequence.
1475 Usually, the input method inserts the intermediate key sequence,
1476 or candidate translations corresponding to the sequence,
1477 at point in the current buffer.
1478 But, if this flag is non-nil, it displays them in echo area instead.")
1479
1480 (defvar input-method-exit-on-invalid-key nil
1481 "This flag controls the behaviour of an input method on invalid key input.
1482 Usually, when a user types a key which doesn't start any character
1483 handled by the input method, the key is handled by turning off the
1484 input method temporarily. After that key, the input method is re-enabled.
1485 But, if this flag is non-nil, the input method is never back on.")
1486
1487 \f
1488 (defvar set-language-environment-hook nil
1489 "Normal hook run after some language environment is set.
1490
1491 When you set some hook function here, that effect usually should not
1492 be inherited to another language environment. So, you had better set
1493 another function in `exit-language-environment-hook' (which see) to
1494 cancel the effect.")
1495
1496 (defvar exit-language-environment-hook nil
1497 "Normal hook run after exiting from some language environment.
1498 When this hook is run, the variable `current-language-environment'
1499 is still bound to the language environment being exited.
1500
1501 This hook is mainly used for canceling the effect of
1502 `set-language-environment-hook' (which-see).")
1503
1504 (put 'setup-specified-language-environment 'apropos-inhibit t)
1505
1506 (defun setup-specified-language-environment ()
1507 "Switch to a specified language environment."
1508 (interactive)
1509 (let (language-name)
1510 (if (and (symbolp last-command-event)
1511 (or (not (eq last-command-event 'Default))
1512 (setq last-command-event 'English))
1513 (setq language-name (symbol-name last-command-event)))
1514 (prog1
1515 (set-language-environment language-name)
1516 (customize-mark-as-set 'current-language-environment))
1517 (error "Bogus calling sequence"))))
1518
1519 (defcustom current-language-environment "English"
1520 "The last language environment specified with `set-language-environment'.
1521 This variable should be set only with \\[customize], which is equivalent
1522 to using the function `set-language-environment'."
1523 :link '(custom-manual "(emacs)Language Environments")
1524 :set (lambda (symbol value) (set-language-environment value))
1525 :get (lambda (x)
1526 (or (car-safe (assoc-ignore-case
1527 (if (symbolp current-language-environment)
1528 (symbol-name current-language-environment)
1529 current-language-environment)
1530 language-info-alist))
1531 "English"))
1532 ;; custom type will be updated with `set-language-info'.
1533 :type (if language-info-alist
1534 (cons 'choice (mapcar
1535 (lambda (lang)
1536 (list 'const (car lang)))
1537 (sort (copy-sequence language-info-alist)
1538 (lambda (x y) (string< (car x) (car y))))))
1539 'string)
1540 :initialize 'custom-initialize-default
1541 :group 'mule)
1542
1543 (defun reset-language-environment ()
1544 "Reset multilingual environment of Emacs to the default status.
1545
1546 The default status is as follows:
1547
1548 The default value of `buffer-file-coding-system' is nil.
1549 The default coding system for process I/O is nil.
1550 The default value for the command `set-terminal-coding-system' is nil.
1551 The default value for the command `set-keyboard-coding-system' is nil.
1552
1553 The order of priorities of coding categories and the coding system
1554 bound to each category are as follows
1555 coding category coding system
1556 --------------------------------------------------
1557 coding-category-iso-8-2 iso-latin-1
1558 coding-category-iso-8-1 iso-latin-1
1559 coding-category-iso-7-tight iso-2022-jp
1560 coding-category-iso-7 iso-2022-7bit
1561 coding-category-iso-7-else iso-2022-7bit-lock
1562 coding-category-iso-8-else iso-2022-8bit-ss2
1563 coding-category-emacs-mule emacs-mule
1564 coding-category-raw-text raw-text
1565 coding-category-sjis japanese-shift-jis
1566 coding-category-big5 chinese-big5
1567 coding-category-ccl nil
1568 coding-category-binary no-conversion
1569 coding-category-utf-16-be nil
1570 coding-category-utf-16-le nil
1571 coding-category-utf-8 mule-utf-8"
1572 (interactive)
1573 ;; This function formerly set default-enable-multibyte-characters to t,
1574 ;; but that is incorrect. It should not alter the unibyte/multibyte choice.
1575
1576 (setq coding-category-iso-7-tight 'iso-2022-jp
1577 coding-category-iso-7 'iso-2022-7bit
1578 coding-category-iso-8-1 'iso-latin-1
1579 coding-category-iso-8-2 'iso-latin-1
1580 coding-category-iso-7-else 'iso-2022-7bit-lock
1581 coding-category-iso-8-else 'iso-2022-8bit-ss2
1582 coding-category-emacs-mule 'emacs-mule
1583 coding-category-raw-text 'raw-text
1584 coding-category-sjis 'japanese-shift-jis
1585 coding-category-big5 'chinese-big5
1586 coding-category-utf-16-be nil
1587 coding-category-utf-16-le nil
1588 coding-category-utf-8 'mule-utf-8
1589 coding-category-ccl nil
1590 coding-category-binary 'no-conversion)
1591
1592 (set-coding-priority
1593 '(coding-category-iso-8-1
1594 coding-category-iso-8-2
1595 coding-category-iso-7-tight
1596 coding-category-iso-7
1597 coding-category-iso-7-else
1598 coding-category-iso-8-else
1599 coding-category-emacs-mule
1600 coding-category-raw-text
1601 coding-category-sjis
1602 coding-category-big5
1603 coding-category-ccl
1604 coding-category-binary
1605 coding-category-utf-16-be
1606 coding-category-utf-16-le
1607 coding-category-utf-8))
1608
1609 (update-coding-systems-internal)
1610
1611 (set-default-coding-systems nil)
1612 (setq default-sendmail-coding-system 'iso-latin-1)
1613 ;; Preserve eol-type from existing default-process-coding-systems.
1614 ;; On non-unix-like systems in particular, these may have been set
1615 ;; carefully by the user, or by the startup code, to deal with the
1616 ;; users shell appropriately, so should not be altered by changing
1617 ;; language environment.
1618 (let ((output-coding
1619 ;; When bootstrapping, coding-systems are not defined yet, so
1620 ;; we need to catch the error from check-coding-system.
1621 (condition-case nil
1622 (coding-system-change-text-conversion
1623 (car default-process-coding-system) 'undecided)
1624 (coding-system-error 'undecided)))
1625 (input-coding
1626 (condition-case nil
1627 (coding-system-change-text-conversion
1628 (cdr default-process-coding-system) 'iso-latin-1)
1629 (coding-system-error 'iso-latin-1))))
1630 (setq default-process-coding-system
1631 (cons output-coding input-coding)))
1632
1633 ;; Don't alter the terminal and keyboard coding systems here.
1634 ;; The terminal still supports the same coding system
1635 ;; that it supported a minute ago.
1636 ;; (set-terminal-coding-system-internal nil)
1637 ;; (set-keyboard-coding-system-internal nil)
1638
1639 (setq nonascii-translation-table nil
1640 nonascii-insert-offset 0))
1641
1642 (reset-language-environment)
1643
1644 (defun set-display-table-and-terminal-coding-system (language-name)
1645 "Set up the display table and terminal coding system for LANGUAGE-NAME."
1646 (let ((coding (get-language-info language-name 'unibyte-display)))
1647 (if coding
1648 (standard-display-european-internal)
1649 (standard-display-default (if (eq window-system 'pc) 128 160) 255)
1650 (aset standard-display-table 146 nil))
1651 (or (eq window-system 'pc)
1652 (set-terminal-coding-system coding))))
1653
1654 (defun set-language-environment (language-name)
1655 "Set up multi-lingual environment for using LANGUAGE-NAME.
1656 This sets the coding system priority and the default input method
1657 and sometimes other things. LANGUAGE-NAME should be a string
1658 which is the name of a language environment. For example, \"Latin-1\"
1659 specifies the character set for the major languages of Western Europe."
1660 (interactive (list (read-language-name
1661 nil
1662 "Set language environment (default, English): ")))
1663 (if language-name
1664 (if (symbolp language-name)
1665 (setq language-name (symbol-name language-name)))
1666 (setq language-name "English"))
1667 (or (assoc-ignore-case language-name language-info-alist)
1668 (error "Language environment not defined: %S" language-name))
1669 (if current-language-environment
1670 (let ((func (get-language-info current-language-environment
1671 'exit-function)))
1672 (run-hooks 'exit-language-environment-hook)
1673 (if (functionp func) (funcall func))))
1674 (let ((default-eol-type (coding-system-eol-type
1675 default-buffer-file-coding-system)))
1676 (reset-language-environment)
1677
1678 ;; The features might set up coding systems.
1679 (let ((required-features (get-language-info language-name 'features)))
1680 (while required-features
1681 (require (car required-features))
1682 (setq required-features (cdr required-features))))
1683
1684 (setq current-language-environment language-name)
1685 (set-language-environment-coding-systems language-name default-eol-type))
1686 (let ((input-method (get-language-info language-name 'input-method)))
1687 (when input-method
1688 (setq default-input-method input-method)
1689 (if input-method-history
1690 (setq input-method-history
1691 (cons input-method
1692 (delete input-method input-method-history))))))
1693 (let ((nonascii (get-language-info language-name 'nonascii-translation))
1694 (dos-table
1695 (if (eq window-system 'pc)
1696 (intern
1697 (format "cp%d-nonascii-translation-table" dos-codepage)))))
1698 (cond
1699 ((char-table-p nonascii)
1700 (setq nonascii-translation-table nonascii))
1701 ((and (eq window-system 'pc) (boundp dos-table))
1702 ;; DOS terminals' default is to use a special non-ASCII translation
1703 ;; table as appropriate for the installed codepage.
1704 (setq nonascii-translation-table (symbol-value dos-table)))
1705 ((charsetp nonascii)
1706 (setq nonascii-insert-offset (- (make-char nonascii) 128)))))
1707
1708 ;; Unibyte setups if necessary.
1709 (unless default-enable-multibyte-characters
1710 ;; Syntax and case table.
1711 (let ((syntax (get-language-info language-name 'unibyte-syntax)))
1712 (if syntax
1713 (let ((set-case-syntax-set-multibyte nil))
1714 (load syntax nil t))
1715 ;; No information for syntax and case. Reset to the defaults.
1716 (let ((syntax-table (standard-syntax-table))
1717 (case-table (standard-case-table))
1718 (ch (if (eq window-system 'pc) 128 160)))
1719 (while (< ch 256)
1720 (modify-syntax-entry ch " " syntax-table)
1721 (aset case-table ch ch)
1722 (setq ch (1+ ch)))
1723 (set-char-table-extra-slot case-table 0 nil)
1724 (set-char-table-extra-slot case-table 1 nil)
1725 (set-char-table-extra-slot case-table 2 nil))
1726 (set-standard-case-table (standard-case-table))
1727 (let ((list (buffer-list)))
1728 (while list
1729 (with-current-buffer (car list)
1730 (set-case-table (standard-case-table)))
1731 (setq list (cdr list))))))
1732 (set-display-table-and-terminal-coding-system language-name))
1733
1734 (let ((required-features (get-language-info language-name 'features)))
1735 (while required-features
1736 (require (car required-features))
1737 (setq required-features (cdr required-features))))
1738 (let ((func (get-language-info language-name 'setup-function)))
1739 (if (functionp func)
1740 (funcall func)))
1741 (run-hooks 'set-language-environment-hook)
1742 (force-mode-line-update t))
1743
1744 (defun standard-display-european-internal ()
1745 ;; Actually set up direct output of non-ASCII characters.
1746 (standard-display-8bit (if (eq window-system 'pc) 128 160) 255)
1747 ;; Unibyte Emacs on MS-DOS wants to display all 8-bit characters with
1748 ;; the native font, and codes 160 and 146 stand for something very
1749 ;; different there.
1750 (or (and (eq window-system 'pc) (not default-enable-multibyte-characters))
1751 (progn
1752 ;; Make non-line-break space display as a plain space.
1753 ;; Most X fonts do the wrong thing for code 160.
1754 (aset standard-display-table 160 [32])
1755 ;; With luck, non-Latin-1 fonts are more recent and so don't
1756 ;; have this bug.
1757 (aset standard-display-table 2208 [32]) ; Latin-1 NBSP
1758 ;; Most Windows programs send out apostrophes as \222. Most X fonts
1759 ;; don't contain a character at that position. Map it to the ASCII
1760 ;; apostrophe. [This is actually RIGHT SINGLE QUOTATION MARK,
1761 ;; U+2019, normally from the windows-1252 character set. XFree 4
1762 ;; fonts probably have the appropriate glyph at this position,
1763 ;; so they could use standard-display-8bit. It's better to use a
1764 ;; proper windows-1252 coding system. --fx]
1765 (aset standard-display-table 146 [39]))))
1766
1767 (defun set-language-environment-coding-systems (language-name
1768 &optional eol-type)
1769 "Do various coding system setups for language environment LANGUAGE-NAME.
1770
1771 The optional arg EOL-TYPE specifies the eol-type of the default value
1772 of `buffer-file-coding-system' set by this function."
1773 (let* ((priority (get-language-info language-name 'coding-priority))
1774 (default-coding (car priority)))
1775 (if priority
1776 (let ((categories (mapcar 'coding-system-category priority)))
1777 (set-default-coding-systems
1778 (if (memq eol-type '(0 1 2 unix dos mac))
1779 (coding-system-change-eol-conversion default-coding eol-type)
1780 default-coding))
1781 (setq default-sendmail-coding-system default-coding)
1782 (set-coding-priority categories)
1783 (while priority
1784 (set (car categories) (car priority))
1785 (setq priority (cdr priority) categories (cdr categories)))
1786 (update-coding-systems-internal)))))
1787
1788 (defsubst princ-list (&rest args)
1789 "Print all arguments with `princ', then print \"\n\"."
1790 (while args (princ (car args)) (setq args (cdr args)))
1791 (princ "\n"))
1792
1793 (put 'describe-specified-language-support 'apropos-inhibit t)
1794
1795 ;; Print a language specific information such as input methods,
1796 ;; charsets, and coding systems. This function is intended to be
1797 ;; called from the menu:
1798 ;; [menu-bar mule describe-language-environment LANGUAGE]
1799 ;; and should not run it by `M-x describe-current-input-method-function'.
1800 (defun describe-specified-language-support ()
1801 "Describe how Emacs supports the specified language environment."
1802 (interactive)
1803 (let (language-name)
1804 (if (not (and (symbolp last-command-event)
1805 (or (not (eq last-command-event 'Default))
1806 (setq last-command-event 'English))
1807 (setq language-name (symbol-name last-command-event))))
1808 (error "Bogus calling sequence"))
1809 (describe-language-environment language-name)))
1810
1811 (defun describe-language-environment (language-name)
1812 "Describe how Emacs supports language environment LANGUAGE-NAME."
1813 (interactive
1814 (list (read-language-name
1815 'documentation
1816 "Describe language environment (default, current choice): ")))
1817 (if (null language-name)
1818 (setq language-name current-language-environment))
1819 (if (or (null language-name)
1820 (null (get-language-info language-name 'documentation)))
1821 (error "No documentation for the specified language"))
1822 (if (symbolp language-name)
1823 (setq language-name (symbol-name language-name)))
1824 (let ((doc (get-language-info language-name 'documentation))
1825 pos)
1826 (help-setup-xref (list #'describe-language-environment language-name)
1827 (interactive-p))
1828 (with-output-to-temp-buffer (help-buffer)
1829 (save-excursion
1830 (set-buffer standard-output)
1831 (insert language-name " language environment\n\n")
1832 (if (stringp doc)
1833 (insert doc "\n\n"))
1834 (condition-case nil
1835 (let ((str (eval (get-language-info language-name 'sample-text))))
1836 (if (stringp str)
1837 (insert "Sample text:\n " str "\n\n")))
1838 (error nil))
1839 (let ((input-method (get-language-info language-name 'input-method))
1840 (l (copy-sequence input-method-alist)))
1841 (insert "Input methods")
1842 (when input-method
1843 (insert " (default, " input-method ")")
1844 (setq input-method (assoc input-method input-method-alist))
1845 (setq l (cons input-method (delete input-method l))))
1846 (insert ":\n")
1847 (while l
1848 (when (string= language-name (nth 1 (car l)))
1849 (insert " " (car (car l)))
1850 (search-backward (car (car l)))
1851 (help-xref-button 0 'help-input-method (car (car l)))
1852 (goto-char (point-max))
1853 (insert " (\""
1854 (if (stringp (nth 3 (car l)))
1855 (nth 3 (car l))
1856 (car (nth 3 (car l))))
1857 "\" in mode line)\n"))
1858 (setq l (cdr l)))
1859 (insert "\n"))
1860 (insert "Character sets:\n")
1861 (let ((l (get-language-info language-name 'charset)))
1862 (if (null l)
1863 (insert " nothing specific to " language-name "\n")
1864 (while l
1865 (insert " " (symbol-name (car l)))
1866 (search-backward (symbol-name (car l)))
1867 (help-xref-button 0 'help-character-set (car l))
1868 (goto-char (point-max))
1869 (insert ": " (charset-description (car l)) "\n")
1870 (setq l (cdr l)))))
1871 (insert "\n")
1872 (insert "Coding systems:\n")
1873 (let ((l (get-language-info language-name 'coding-system)))
1874 (if (null l)
1875 (insert " nothing specific to " language-name "\n")
1876 (while l
1877 (insert " " (symbol-name (car l)))
1878 (search-backward (symbol-name (car l)))
1879 (help-xref-button 0 'help-coding-system (car l))
1880 (goto-char (point-max))
1881 (insert " (`"
1882 (coding-system-mnemonic (car l))
1883 "' in mode line):\n\t"
1884 (coding-system-doc-string (car l))
1885 "\n")
1886 (let ((aliases (coding-system-get (car l)
1887 'alias-coding-systems)))
1888 (when aliases
1889 (insert "\t(alias:")
1890 (while aliases
1891 (insert " " (symbol-name (car aliases)))
1892 (setq aliases (cdr aliases)))
1893 (insert ")\n")))
1894 (setq l (cdr l)))))))))
1895 \f
1896 ;;; Locales.
1897
1898 (defvar locale-translation-file-name nil
1899 "File name for the system's file of locale-name aliases, or nil if none.")
1900
1901 ;; The following definitions might as well be marked as constants and
1902 ;; purecopied, since they're normally used on startup, and probably
1903 ;; should reflect the facilities of the base Emacs.
1904 (defconst locale-language-names
1905 (purecopy
1906 '(
1907 ;; Locale names of the form LANGUAGE[_TERRITORY][.CODESET][@MODIFIER]
1908 ;; as specified in the Single Unix Spec, Version 2.
1909 ;; LANGUAGE is a language code taken from ISO 639:1988 (E/F)
1910 ;; with additions from ISO 639/RA Newsletter No.1/1989;
1911 ;; see Internet RFC 2165 (1997-06) and
1912 ;; http://www.evertype.com/standards/iso639/iso639-en.html
1913 ;; TERRITORY is a country code taken from ISO 3166
1914 ;; http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html.
1915 ;; CODESET and MODIFIER are implementation-dependent.
1916
1917 ; aa Afar
1918 ; ab Abkhazian
1919 ("af" . "Latin-1") ; Afrikaans
1920 ("am" . "Ethiopic") ; Amharic
1921 ; ar Arabic glibc uses 8859-6
1922 ; as Assamese
1923 ; ay Aymara
1924 ; az Azerbaijani
1925 ; ba Bashkir
1926 ("be" . "Belarusian") ; Belarusian [Byelorussian until early 1990s]
1927 ("bg" . "Bulgarian") ; Bulgarian
1928 ; bh Bihari
1929 ; bi Bislama
1930 ; bn Bengali, Bangla
1931 ("bo" . "Tibetan")
1932 ("br" . "Latin-1") ; Breton
1933 ("bs" . "Latin-2") ; Bosnian
1934 ("ca" . "Latin-1") ; Catalan
1935 ; co Corsican
1936 ("cs" . "Czech")
1937 ("cy" . "Welsh") ; Welsh
1938 ("da" . "Latin-1") ; Danish
1939 ("de" . "German")
1940 ; dz Bhutani
1941 ("el" . "Greek")
1942 ;; Users who specify "en" explicitly typically want Latin-1, not ASCII.
1943 ;; That's actually what the GNU locales define, modulo things like
1944 ;; en_IN -- fx.
1945 ("en" . "Latin-1") ; English
1946 ("eo" . "Latin-3") ; Esperanto
1947 ("es" . "Spanish")
1948 ("et" . "Latin-4") ; Estonian
1949 ("eu" . "Latin-1") ; Basque
1950 ; fa Persian glibc uses utf-8
1951 ("fi" . "Latin-1") ; Finnish
1952 ; fj Fiji
1953 ("fo" . "Latin-1") ; Faroese
1954 ("fr" . "French") ; French
1955 ("fy" . "Latin-1") ; Frisian
1956 ("ga" . "Latin-1") ; Irish Gaelic (new orthography)
1957 ("gd" . "Latin-1") ; Scots Gaelic
1958 ("gl" . "Latin-1") ; Galician
1959 ; gn Guarani
1960 ; gu Gujarati
1961 ("gv" . "Latin-8") ; Manx Gaelic glibc uses 8859-1
1962 ; ha Hausa
1963 ("he" . "Hebrew")
1964 ("hi" . "Devanagari") ; Hindi glibc uses utf-8
1965 ("hr" . "Croatian") ; Croatian
1966 ("hu" . "Latin-2") ; Hungarian
1967 ; hy Armenian
1968 ; ia Interlingua
1969 ("id" . "Latin-1") ; Indonesian
1970 ; ie Interlingue
1971 ; ik Inupiak
1972 ("is" . "Latin-1") ; Icelandic
1973 ("it" . "Latin-1") ; Italian
1974 ; iu Inuktitut
1975 ("ja" . "Japanese")
1976 ; jw Javanese
1977 ("ka" . "Georgian") ; Georgian
1978 ; kk Kazakh
1979 ("kl" . "Latin-1") ; Greenlandic
1980 ; km Cambodian
1981 ; kn Kannada
1982 ("ko" . "Korean")
1983 ; ks Kashmiri
1984 ; ku Kurdish
1985 ("kw" . "Latin-1") ; Cornish
1986 ; ky Kirghiz
1987 ("la" . "Latin-1") ; Latin
1988 ("lb" . "Latin-1") ; Luxemburgish
1989 ; ln Lingala
1990 ("lo" . "Lao") ; Laothian
1991 ("lt" . "Lithuanian")
1992 ("lv" . "Latvian") ; Latvian, Lettish
1993 ; mg Malagasy
1994 ("mi" . "Latin-7") ; Maori
1995 ("mk" . "Cyrillic-ISO") ; Macedonian
1996 ; ml Malayalam
1997 ; mn Mongolian
1998 ; mo Moldavian
1999 ("mr" . "Devanagari") ; Marathi glibc uses utf-8
2000 ("ms" . "Latin-1") ; Malay
2001 ("mt" . "Latin-3") ; Maltese
2002 ; my Burmese
2003 ; na Nauru
2004 ("ne" . "Devanagari") ; Nepali
2005 ("nl" . "Dutch")
2006 ("no" . "Latin-1") ; Norwegian
2007 ("oc" . "Latin-1") ; Occitan
2008 ; om (Afan) Oromo
2009 ; or Oriya
2010 ; pa Punjabi
2011 ("pl" . "Latin-2") ; Polish
2012 ; ps Pashto, Pushto
2013 ("pt" . "Latin-1") ; Portuguese
2014 ; qu Quechua
2015 ("rm" . "Latin-1") ; Rhaeto-Romanic
2016 ; rn Kirundi
2017 ("ro" . "Romanian")
2018 ("ru.*[_.]koi8" . "Cyrillic-KOI8") ; Russian
2019 ("ru" . "Cyrillic-ISO") ; Russian
2020 ; rw Kinyarwanda
2021 ("sa" . "Devanagari") ; Sanskrit
2022 ; sd Sindhi
2023 ; se Northern Sami
2024 ; sg Sangho
2025 ("sh" . "Latin-2") ; Serbo-Croatian
2026 ; si Sinhalese
2027 ("sk" . "Slovak")
2028 ("sl" . "Slovenian")
2029 ; sm Samoan
2030 ; sn Shona
2031 ; so Somali
2032 ("sq" . "Latin-1") ; Albanian
2033 ("sr" . "Latin-2") ; Serbian (Latin alphabet)
2034 ("sr_YU@cyrillic" . "Cyrillic-ISO") ; per glibc
2035 ; ss Siswati
2036 ; st Sesotho
2037 ; su Sundanese
2038 ("sv" . "Swedish") ; Swedish
2039 ("sw" . "Latin-1") ; Swahili
2040 ; ta Tamil glibc uses utf-8
2041 ; te Telugu glibc uses utf-8
2042 ("tg" . "Tajik")
2043 ("th" . "Thai")
2044 ; ti Tigrinya
2045 ; tk Turkmen
2046 ("tl" . "Latin-1") ; Tagalog
2047 ; tn Setswana
2048 ; to Tonga
2049 ("tr" . "Latin-5") ; Turkish
2050 ; ts Tsonga
2051 ; tt Tatar
2052 ; tw Twi
2053 ; ug Uighur
2054 ("uk" . "Ukrainian") ; Ukrainian
2055 ; ur Urdu glibc uses utf-8
2056 ("uz" . "Latin-1") ; Uzbek
2057 ("vi" . "Vietnamese") ; glibc uses utf-8
2058 ; vo Volapuk
2059 ("wa" . "Latin-1") ; Walloon
2060 ; wo Wolof
2061 ; xh Xhosa
2062 ("yi" . "Windows-1255") ; Yiddish
2063 ; yo Yoruba
2064 ; za Zhuang
2065
2066 ; glibc:
2067 ; zh_CN.GB18030/GB18030 \
2068 ; zh_CN.GBK/GBK \
2069 ; zh_HK/BIG5-HKSCS \
2070 ; zh_TW/BIG5 \
2071 ; zh_TW.EUC-TW/EUC-TW \
2072
2073 ("zh.*[._]big5" . "Chinese-BIG5")
2074 ("zh.*[._]gbk" . nil) ; Solaris 2.7; has gbk-0 as well as GB 2312.1980-0
2075 ("zh_tw" . "Chinese-CNS")
2076 ("zh" . "Chinese-GB")
2077 ; zu Zulu
2078
2079 ;; ISO standard locales
2080 ("c$" . "ASCII")
2081 ("posix$" . "ASCII")
2082
2083 ;; The "IPA" Emacs language environment does not correspond
2084 ;; to any ISO 639 code, so let it stand for itself.
2085 ("ipa$" . "IPA")
2086
2087 ;; Nonstandard or obsolete language codes
2088 ("cz" . "Czech") ; e.g. Solaris 2.6
2089 ("ee" . "Latin-4") ; Estonian, e.g. X11R6.4
2090 ("iw" . "Hebrew") ; e.g. X11R6.4
2091 ("sp" . "Cyrillic-ISO") ; Serbian (Cyrillic alphabet), e.g. X11R6.4
2092 ("su" . "Latin-1") ; Finnish, e.g. Solaris 2.6
2093 ("jp" . "Japanese") ; e.g. MS Windows
2094 ("chs" . "Chinese-GB") ; MS Windows Chinese Simplified
2095 ("cht" . "Chinese-BIG5") ; MS Windows Chinese Traditional
2096 ))
2097 "List of pairs of locale regexps and language names.
2098 The first element whose locale regexp matches the start of a downcased locale
2099 specifies the language name corresponding to that locale.
2100 If the language name is nil, there is no corresponding language environment.")
2101
2102 (defconst locale-charset-language-names
2103 (purecopy
2104 '((".*8859[-_]?1\\>" . "Latin-1")
2105 (".*8859[-_]?2\\>" . "Latin-2")
2106 (".*8859[-_]?3\\>" . "Latin-3")
2107 (".*8859[-_]?4\\>" . "Latin-4")
2108 (".*8859[-_]?9\\>" . "Latin-5")
2109 (".*8859[-_]?14\\>" . "Latin-8")
2110 (".*8859[-_]?15\\>" . "Latin-9")
2111 (".*utf\\(-?8\\)\\>" . "UTF-8")
2112 ;; utf-8@euro exists, so put this last. (@euro really specifies
2113 ;; the currency, rather than the charset.)
2114 (".*@euro\\>" . "Latin-9")))
2115 "List of pairs of locale regexps and charset language names.
2116 The first element whose locale regexp matches the start of a downcased locale
2117 specifies the language name whose charsets corresponds to that locale.
2118 This language name is used if its charsets disagree with the charsets of
2119 the language name that would otherwise be used for this locale.")
2120
2121 (defconst locale-preferred-coding-systems
2122 (purecopy
2123 '(("ja.*[._]euc" . japanese-iso-8bit)
2124 ("ja.*[._]jis7" . iso-2022-jp)
2125 ("ja.*[._]pck" . japanese-shift-jis)
2126 ("ja.*[._]sjis" . japanese-shift-jis)
2127 ("jpn" . japanese-shift-jis) ; MS-Windows uses this.
2128 (".*[._]utf" . utf-8)))
2129 "List of pairs of locale regexps and preferred coding systems.
2130 The first element whose locale regexp matches the start of a downcased locale
2131 specifies the coding system to prefer when using that locale.")
2132
2133 (defun locale-name-match (key alist)
2134 "Search for KEY in ALIST, which should be a list of regexp-value pairs.
2135 Return the value corresponding to the first regexp that matches the
2136 start of KEY, or nil if there is no match."
2137 (let (element)
2138 (while (and alist (not element))
2139 (if (string-match (concat "\\`\\(?:" (car (car alist)) "\\)") key)
2140 (setq element (car alist)))
2141 (setq alist (cdr alist)))
2142 (cdr element)))
2143
2144 (defun set-locale-environment (&optional locale-name)
2145 "Set up multi-lingual environment for using LOCALE-NAME.
2146 This sets the language environment, the coding system priority,
2147 the default input method and sometimes other things.
2148
2149 LOCALE-NAME should be a string
2150 which is the name of a locale supported by the system;
2151 often it is of the form xx_XX.CODE, where xx is a language,
2152 XX is a country, and CODE specifies a character set and coding system.
2153 For example, the locale name \"ja_JP.EUC\" might name a locale
2154 for Japanese in Japan using the `japanese-iso-8bit' coding-system.
2155
2156 If LOCALE-NAME is nil, its value is taken from the environment
2157 variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
2158
2159 The locale names supported by your system can typically be found in a
2160 directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
2161 will be translated according to the table specified by
2162 `locale-translation-file-name'.
2163
2164 See also `locale-charset-language-names', `locale-language-names',
2165 `locale-preferred-coding-systems' and `locale-coding-system'."
2166 (interactive "sSet environment for locale: ")
2167
2168 ;; Do this at runtime for the sake of binaries possibly transported
2169 ;; to a system without X.
2170 (setq locale-translation-file-name
2171 (let ((files
2172 '("/usr/lib/X11/locale/locale.alias" ; e.g. X11R6.4
2173 "/usr/X11R6/lib/X11/locale/locale.alias" ; e.g. RedHat 4.2
2174 "/usr/openwin/lib/locale/locale.alias" ; e.g. Solaris 2.6
2175 ;;
2176 ;; The following name appears after the X-related names above,
2177 ;; since the X-related names are what X actually uses.
2178 "/usr/share/locale/locale.alias" ; GNU/Linux sans X
2179 )))
2180 (while (and files (not (file-exists-p (car files))))
2181 (setq files (cdr files)))
2182 (car files)))
2183
2184 (let ((locale locale-name))
2185
2186 (unless locale
2187 ;; Use the first of these three environment variables
2188 ;; that has a nonempty value.
2189 (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
2190 (while (and vars
2191 (= 0 (length locale))) ; nil or empty string
2192 (setq locale (getenv (pop vars))))))
2193
2194 (when locale
2195
2196 ;; Translate "swedish" into "sv_SE.ISO8859-1", and so on,
2197 ;; using the translation file that many systems have.
2198 (when locale-translation-file-name
2199 (with-temp-buffer
2200 (insert-file-contents locale-translation-file-name)
2201 (when (re-search-forward
2202 (concat "^" (regexp-quote locale) ":?[ \t]+") nil t)
2203 (setq locale (buffer-substring (point) (line-end-position))))))
2204
2205 ;; Leave the system locales alone if the caller did not specify
2206 ;; an explicit locale name, as their defaults are set from
2207 ;; LC_MESSAGES and LC_TIME, not LC_CTYPE, and the user might not
2208 ;; want to set them to the same value as LC_CTYPE.
2209 (when locale-name
2210 (setq system-messages-locale locale)
2211 (setq system-time-locale locale))
2212
2213 (setq locale (downcase locale))
2214
2215 (let ((language-name
2216 (locale-name-match locale locale-language-names))
2217 (charset-language-name
2218 (locale-name-match locale locale-charset-language-names))
2219 (coding-system
2220 (locale-name-match locale locale-preferred-coding-systems)))
2221
2222 ;; Give preference to charset-language-name over language-name.
2223 (if (and charset-language-name
2224 (not
2225 (equal (get-language-info language-name 'charset)
2226 (get-language-info charset-language-name 'charset))))
2227 (setq language-name charset-language-name))
2228
2229 (when language-name
2230
2231 ;; Set up for this character set. This is now the right way
2232 ;; to do it for both unibyte and multibyte modes.
2233 (set-language-environment language-name)
2234
2235 ;; If default-enable-multibyte-characters is nil,
2236 ;; we are using single-byte characters,
2237 ;; so the display table and terminal coding system are irrelevant.
2238 (when default-enable-multibyte-characters
2239 (set-display-table-and-terminal-coding-system language-name))
2240
2241 ;; Set the `keyboard-coding-system' if appropriate (tty
2242 ;; only). At least X and MS Windows can generate
2243 ;; multilingual input.
2244 (unless window-system
2245 (let ((kcs (or coding-system
2246 (car (get-language-info language-name
2247 'coding-system)))))
2248 (if kcs (set-keyboard-coding-system kcs))))
2249
2250 (setq locale-coding-system
2251 (car (get-language-info language-name 'coding-priority))))
2252
2253 (when coding-system
2254 (prefer-coding-system coding-system)
2255 (setq locale-coding-system coding-system))))))
2256 \f
2257 ;;; Charset property
2258
2259 (defun get-charset-property (charset propname)
2260 "Return the value of CHARSET's PROPNAME property.
2261 This is the last value stored with
2262 (put-charset-property CHARSET PROPNAME VALUE)."
2263 (and (not (eq charset 'composition))
2264 (plist-get (charset-plist charset) propname)))
2265
2266 (defun put-charset-property (charset propname value)
2267 "Store CHARSETS's PROPNAME property with value VALUE.
2268 It can be retrieved with `(get-charset-property CHARSET PROPNAME)'."
2269 (or (eq charset 'composition)
2270 (set-charset-plist charset
2271 (plist-put (charset-plist charset) propname value))))
2272
2273 ;;; Character code property
2274 (put 'char-code-property-table 'char-table-extra-slots 0)
2275
2276 (defvar char-code-property-table
2277 (make-char-table 'char-code-property-table)
2278 "Char-table containing a property list of each character code.
2279
2280 See also the documentation of `get-char-code-property' and
2281 `put-char-code-property'.")
2282
2283 (defun get-char-code-property (char propname)
2284 "Return the value of CHAR's PROPNAME property in `char-code-property-table'."
2285 (let ((plist (aref char-code-property-table char)))
2286 (if (listp plist)
2287 (car (cdr (memq propname plist))))))
2288
2289 (defun put-char-code-property (char propname value)
2290 "Store CHAR's PROPNAME property with VALUE in `char-code-property-table'.
2291 It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
2292 (let ((plist (aref char-code-property-table char)))
2293 (if plist
2294 (let ((slot (memq propname plist)))
2295 (if slot
2296 (setcar (cdr slot) value)
2297 (nconc plist (list propname value))))
2298 (aset char-code-property-table char (list propname value)))))
2299
2300 \f
2301 ;; Pretty description of encoded string
2302
2303 ;; Alist of ISO 2022 control code vs the corresponding mnemonic string.
2304 (defvar iso-2022-control-alist
2305 '((?\x1b . "ESC")
2306 (?\x0e . "SO")
2307 (?\x0f . "SI")
2308 (?\x8e . "SS2")
2309 (?\x8f . "SS3")
2310 (?\x9b . "CSI")))
2311
2312 (defun encoded-string-description (str coding-system)
2313 "Return a pretty description of STR that is encoded by CODING-SYSTEM."
2314 (setq str (string-as-unibyte str))
2315 (mapconcat
2316 (if (and coding-system (eq (coding-system-type coding-system) 2))
2317 ;; Try to get a pretty description for ISO 2022 escape sequences.
2318 (function (lambda (x) (or (cdr (assq x iso-2022-control-alist))
2319 (format "%02X" x))))
2320 (function (lambda (x) (format "0x%02X" x))))
2321 str " "))
2322
2323 (defun encode-coding-char (char coding-system)
2324 "Encode CHAR by CODING-SYSTEM and return the resulting string.
2325 If CODING-SYSTEM can't safely encode CHAR, return nil."
2326 (let ((str1 (string-as-multibyte (char-to-string char)))
2327 (str2 (string-as-multibyte (make-string 2 char)))
2328 (safe-chars (and coding-system
2329 (coding-system-get coding-system 'safe-chars)))
2330 (charset (char-charset char))
2331 enc1 enc2 i1 i2)
2332 (when (or (eq safe-chars t)
2333 (eq charset 'ascii)
2334 (and safe-chars (aref safe-chars char)))
2335 ;; We must find the encoded string of CHAR. But, just encoding
2336 ;; CHAR will put extra control sequences (usually to designate
2337 ;; ASCII charaset) at the tail if type of CODING is ISO 2022.
2338 ;; To exclude such tailing bytes, we at first encode one-char
2339 ;; string and two-char string, then check how many bytes at the
2340 ;; tail of both encoded strings are the same.
2341
2342 (setq enc1 (encode-coding-string str1 coding-system)
2343 i1 (length enc1)
2344 enc2 (encode-coding-string str2 coding-system)
2345 i2 (length enc2))
2346 (while (and (> i1 0) (= (aref enc1 (1- i1)) (aref enc2 (1- i2))))
2347 (setq i1 (1- i1) i2 (1- i2)))
2348
2349 ;; Now (substring enc1 i1) and (substring enc2 i2) are the same,
2350 ;; and they are the extra control sequences at the tail to
2351 ;; exclude.
2352 (substring enc2 0 i2))))
2353
2354
2355 ;;; mule-cmds.el ends here