1 ;;; mule-cmds.el --- commands for mulitilingual environment -*-coding: iso-2022-7bit -*-
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 2003 Electrotechnical Laboratory, JAPAN.
5 ;; Licensed to the Free Software Foundation.
7 ;; National Institute of Advanced Industrial Science and Technology (AIST)
8 ;; Registration Number H13PRO009
10 ;; Keywords: mule, i18n
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
37 ;;; MULE related key bindings and menus.
39 (defvar mule-keymap (make-sparse-keymap)
40 "Keymap for Mule (Multilingual environment) specific commands.")
42 ;; Keep "C-x C-m ..." for mule specific commands.
43 (define-key ctl-x-map "\C-m" mule-keymap)
45 (define-key mule-keymap "f" 'set-buffer-file-coding-system)
46 (define-key mule-keymap "r" 'revert-buffer-with-coding-system)
47 (define-key mule-keymap "F" 'set-file-name-coding-system)
48 (define-key mule-keymap "t" 'set-terminal-coding-system)
49 (define-key mule-keymap "k" 'set-keyboard-coding-system)
50 (define-key mule-keymap "p" 'set-buffer-process-coding-system)
51 (define-key mule-keymap "x" 'set-selection-coding-system)
52 (define-key mule-keymap "X" 'set-next-selection-coding-system)
53 (define-key mule-keymap "\C-\\" 'set-input-method)
54 (define-key mule-keymap "c" 'universal-coding-system-argument)
55 (define-key mule-keymap "l" 'set-language-environment)
57 (defvar mule-menu-keymap
58 (make-sparse-keymap "Mule (Multilingual Environment)")
59 "Keymap for Mule (Multilingual environment) menu specific commands.")
61 (defvar describe-language-environment-map
62 (make-sparse-keymap "Describe Language Environment"))
64 (defvar setup-language-environment-map
65 (make-sparse-keymap "Set Language Environment"))
67 (defvar set-coding-system-map
68 (make-sparse-keymap "Set Coding System"))
70 (define-key-after mule-menu-keymap [set-language-environment]
71 (list 'menu-item "Set Language Environment" setup-language-environment-map
72 :help "Multilingual environment suitable for a specific language"))
73 (define-key-after mule-menu-keymap [separator-mule]
76 (define-key-after mule-menu-keymap [toggle-input-method]
77 '(menu-item "Toggle Input Method" toggle-input-method)
79 (define-key-after mule-menu-keymap [set-input-method]
80 '(menu-item "Select Input Method..." set-input-method)
82 (define-key-after mule-menu-keymap [describe-input-method]
83 '(menu-item "Describe Input Method" describe-input-method))
84 (define-key-after mule-menu-keymap [separator-input-method]
87 (define-key-after mule-menu-keymap [set-various-coding-system]
88 (list 'menu-item "Set Coding Systems" set-coding-system-map
89 :enable 'default-enable-multibyte-characters))
90 (define-key-after mule-menu-keymap [view-hello-file]
91 '(menu-item "Show Multi-lingual Text" view-hello-file
92 :enable (file-readable-p
93 (expand-file-name "HELLO" data-directory))
94 :help "Display file which says HELLO in many languages")
96 (define-key-after mule-menu-keymap [separator-coding-system]
99 (define-key-after mule-menu-keymap [describe-language-environment]
100 (list 'menu-item "Describe Language Environment"
101 describe-language-environment-map
102 :help "Show multilingual settings for a specific language")
104 (define-key-after mule-menu-keymap [describe-input-method]
105 '(menu-item "Describe Input Method..." describe-input-method
106 :help "Keyboard layout for a specific input method")
108 (define-key-after mule-menu-keymap [describe-coding-system]
109 '(menu-item "Describe Coding System..." describe-coding-system)
111 (define-key-after mule-menu-keymap [list-character-sets]
112 '(menu-item "List Character Sets" list-character-sets
113 :help "Show table of available character sets"))
114 (define-key-after mule-menu-keymap [mule-diag]
115 '(menu-item "Show All of Mule Status" mule-diag
116 :help "Display multilingual environment settings")
119 (define-key-after set-coding-system-map [universal-coding-system-argument]
120 '(menu-item "For Next Command" universal-coding-system-argument
121 :help "Coding system to be used by next command")
123 (define-key-after set-coding-system-map [separator-1]
126 (define-key-after set-coding-system-map [set-buffer-file-coding-system]
127 '(menu-item "For Saving This Buffer" set-buffer-file-coding-system
128 :help "How to encode this buffer when saved")
130 (define-key-after set-coding-system-map [revert-buffer-with-coding-system]
131 '(menu-item "For Reverting This File Now" revert-buffer-with-coding-system
132 :enable buffer-file-name
133 :help "Revisit this file immediately using specified coding system")
135 (define-key-after set-coding-system-map [set-file-name-coding-system]
136 '(menu-item "For File Name" set-file-name-coding-system
137 :help "How to decode/encode file names")
139 (define-key-after set-coding-system-map [separator-2]
143 (define-key-after set-coding-system-map [set-keyboard-coding-system]
144 '(menu-item "For Keyboard" set-keyboard-coding-system
145 :help "How to decode keyboard input")
147 (define-key-after set-coding-system-map [set-terminal-coding-system]
148 '(menu-item "For Terminal" set-terminal-coding-system
149 :enable (null (memq window-system '(x w32 mac)))
150 :help "How to encode terminal output")
152 (define-key-after set-coding-system-map [separator-3]
155 (define-key-after set-coding-system-map [set-selection-coding-system]
156 '(menu-item "For X Selections/Clipboard" set-selection-coding-system
157 :visible (display-selections-p)
158 :help "How to en/decode data to/from selection/clipboard")
160 (define-key-after set-coding-system-map [set-next-selection-coding-system]
161 '(menu-item "For Next X Selection" set-next-selection-coding-system
162 :visible (display-selections-p)
163 :help "How to en/decode next selection/clipboard operation")
165 (define-key-after set-coding-system-map [set-buffer-process-coding-system]
166 '(menu-item "For I/O with Subprocess" set-buffer-process-coding-system
167 :visible (fboundp 'start-process)
168 :enable (get-buffer-process (current-buffer))
169 :help "How to en/decode I/O from/to subprocess connected to this buffer")
173 (define-key setup-language-environment-map
174 [Default] '(menu-item "Default" setup-specified-language-environment))
176 (define-key describe-language-environment-map
177 [Default] '(menu-item "Default" describe-specified-language-support))
179 ;; This should be a single character key binding because users use it
180 ;; very frequently while editing multilingual text. Now we can use
181 ;; only two such keys: "\C-\\" and "\C-^", but the latter is not
182 ;; convenient because it requires shifting on most keyboards. An
183 ;; alternative is "\C-\]" which is now bound to `abort-recursive-edit'
184 ;; but it won't be used that frequently.
185 (define-key global-map "\C-\\" 'toggle-input-method)
187 ;; This is no good because people often type Shift-SPC
188 ;; meaning to type SPC. -- rms.
189 ;; ;; Here's an alternative key binding for X users (Shift-SPACE).
190 ;; (define-key global-map [?\S- ] 'toggle-input-method)
192 ;;; Mule related hyperlinks.
193 (defconst help-xref-mule-regexp-template
194 (purecopy (concat "\\(\\<\\("
195 "\\(coding system\\)\\|"
196 "\\(input method\\)\\|"
197 "\\(character set\\)\\|"
200 ;; Note starting with word-syntax character:
201 "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'")))
203 (defun coding-system-change-eol-conversion (coding-system eol-type)
204 "Return a coding system which differs from CODING-SYSTEM in eol conversion.
205 The returned coding system converts end-of-line by EOL-TYPE
206 but text as the same way as CODING-SYSTEM.
207 EOL-TYPE should be `unix', `dos', `mac', or nil.
208 If EOL-TYPE is nil, the returned coding system detects
209 how end-of-line is formatted automatically while decoding.
211 EOL-TYPE can be specified by an integer 0, 1, or 2.
212 They means `unix', `dos', and `mac' respectively."
213 (if (symbolp eol-type)
214 (setq eol-type (cond ((eq eol-type 'unix) 0)
215 ((eq eol-type 'dos) 1)
216 ((eq eol-type 'mac) 2)
218 (let ((orig-eol-type (coding-system-eol-type coding-system)))
219 (if (vectorp orig-eol-type)
222 (aref orig-eol-type eol-type))
223 (let ((base (coding-system-base coding-system)))
226 (if (= eol-type orig-eol-type)
228 (setq orig-eol-type (coding-system-eol-type base))
229 (if (vectorp orig-eol-type)
230 (aref orig-eol-type eol-type))))))))
232 (defun coding-system-change-text-conversion (coding-system coding)
233 "Return a coding system which differs from CODING-SYSTEM in text conversion.
234 The returned coding system converts text by CODING
235 but end-of-line as the same way as CODING-SYSTEM.
236 If CODING is nil, the returned coding system detects
237 how text is formatted automatically while decoding."
238 (let ((eol-type (coding-system-eol-type coding-system)))
239 (coding-system-change-eol-conversion
240 (if coding coding 'undecided)
241 (if (numberp eol-type) (aref [unix dos mac] eol-type)))))
243 (defun toggle-enable-multibyte-characters (&optional arg)
244 "Change whether this buffer uses multibyte characters.
245 With arg, use multibyte characters if the arg is positive.
247 Note that this command does not convert the byte contents of
248 the buffer; it only changes the way those bytes are interpreted.
249 In general, therefore, this command *changes* the sequence of
250 characters that the current buffer contains.
252 We suggest you avoid using use this command unless you know what you
253 are doing. If you use it by mistake, and the buffer is now displayed
254 wrong, use this command again to toggle back to the right mode."
257 (if (null arg) (null enable-multibyte-characters)
258 (> (prefix-numeric-value arg) 0))))
259 (set-buffer-multibyte new-flag))
260 (force-mode-line-update))
262 (defun view-hello-file ()
263 "Display the HELLO file which list up many languages and characters."
265 ;; We have to decode the file in any environment.
266 (let ((default-enable-multibyte-characters t)
267 (coding-system-for-read 'iso-2022-7bit))
268 (view-file (expand-file-name "HELLO" data-directory))))
270 (defun universal-coding-system-argument (coding-system)
271 "Execute an I/O command using the specified coding system."
273 (let ((default (and buffer-file-coding-system
274 (not (eq (coding-system-type buffer-file-coding-system)
276 buffer-file-coding-system)))
277 (list (read-coding-system
279 (format "Coding system for following command (default, %s): " default)
280 "Coding system for following command: ")
282 (let* ((keyseq (read-key-sequence
283 (format "Command to execute with %s:" coding-system)))
284 (cmd (key-binding keyseq))
287 (when (eq cmd 'universal-argument)
288 (call-interactively cmd)
290 ;; Process keys bound in `universal-argument-map'.
292 (setq keyseq (read-key-sequence nil t)
293 cmd (key-binding keyseq t))
294 (not (eq cmd 'universal-argument-other-key)))
295 (let ((current-prefix-arg prefix-arg)
296 ;; Have to bind `last-command-char' here so that
297 ;; `digit-argument', for instance, can compute the
299 (last-command-char (aref keyseq 0)))
300 (call-interactively cmd)))
302 ;; This is the final call to `universal-argument-other-key', which
303 ;; set's the final `prefix-arg.
304 (let ((current-prefix-arg prefix-arg))
305 (call-interactively cmd))
307 ;; Read the command to execute with the given prefix arg.
308 (setq prefix prefix-arg
309 keyseq (read-key-sequence nil t)
310 cmd (key-binding keyseq)))
312 (let ((coding-system-for-read coding-system)
313 (coding-system-for-write coding-system)
314 (coding-system-require-warning t)
315 (current-prefix-arg prefix))
317 (call-interactively cmd))))
319 (defun set-default-coding-systems (coding-system)
320 "Set default value of various coding systems to CODING-SYSTEM.
321 This sets the following coding systems:
322 o coding system of a newly created buffer
323 o default coding system for subprocess I/O
324 This also sets the following values:
325 o default value used as `file-name-coding-system' for converting file names.
326 o default value for the command `set-terminal-coding-system' (not on MSDOS)
327 o default value for the command `set-keyboard-coding-system'."
328 (check-coding-system coding-system)
329 (setq-default buffer-file-coding-system coding-system)
330 (if (fboundp 'ucs-set-table-for-input)
331 (dolist (buffer (buffer-list))
332 (or (local-variable-p 'buffer-file-coding-system buffer)
333 (ucs-set-table-for-input buffer))))
335 (if (and default-enable-multibyte-characters (not (eq system-type 'darwin)))
336 ;; The file-name coding system on Darwin systems is always utf-8.
337 (setq default-file-name-coding-system coding-system))
338 ;; If coding-system is nil, honor that on MS-DOS as well, so
339 ;; that they could reset the terminal coding system.
340 (unless (and (eq window-system 'pc) coding-system)
341 (setq default-terminal-coding-system coding-system))
342 (setq default-keyboard-coding-system coding-system)
343 ;; Preserve eol-type from existing default-process-coding-systems.
344 ;; On non-unix-like systems in particular, these may have been set
345 ;; carefully by the user, or by the startup code, to deal with the
346 ;; users shell appropriately, so should not be altered by changing
347 ;; language environment.
349 (coding-system-change-text-conversion
350 (car default-process-coding-system) coding-system))
352 (coding-system-change-text-conversion
353 (cdr default-process-coding-system) coding-system)))
354 (setq default-process-coding-system
355 (cons output-coding input-coding))))
357 (defalias 'update-iso-coding-systems 'update-coding-systems-internal)
358 (make-obsolete 'update-iso-coding-systems 'update-coding-systems-internal "20.3")
360 (defun prefer-coding-system (coding-system)
361 "Add CODING-SYSTEM at the front of the priority list for automatic detection.
362 This also sets the following coding systems:
363 o coding system of a newly created buffer
364 o default coding system for subprocess I/O
365 This also sets the following values:
366 o default value used as `file-name-coding-system' for converting file names.
367 o default value for the command `set-terminal-coding-system' (not on MSDOS)
368 o default value for the command `set-keyboard-coding-system'
370 If CODING-SYSTEM specifies a certain type of EOL conversion, the coding
371 systems set by this function will use that type of EOL conversion.
373 This command does not change the default value of terminal coding system
374 for MS-DOS terminal, because DOS terminals only support a single coding
375 system, and Emacs automatically sets the default to that coding system at
378 A coding system that requires automatic detection of text
379 +encoding (e.g. undecided, unix) can't be preferred.."
380 (interactive "zPrefer coding system: ")
381 (if (not (and coding-system (coding-system-p coding-system)))
382 (error "Invalid coding system `%s'" coding-system))
383 (if (memq (coding-system-type coding-system) '(raw-text undecided))
384 (error "Can't prefer the coding system `%s'" coding-system))
385 (let ((base (coding-system-base coding-system))
386 (eol-type (coding-system-eol-type coding-system)))
387 (set-coding-system-priority base)
389 (or (eq base coding-system)
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))
395 (coding-system-change-eol-conversion base eol-type)))
396 (set-default-coding-systems base)))
398 (defvar sort-coding-systems-predicate nil
399 "If non-nil, a predicate function to sort coding systems.
401 It is called with two coding systems, and should return t if the first
402 one is \"less\" than the second.
404 The function `sort-coding-systems' use it.")
406 (defun sort-coding-systems (codings)
407 "Sort coding system list CODINGS by a priority of each coding system.
409 If a coding system is most preferred, it has the highest priority.
410 Otherwise, a coding system corresponds to some MIME charset has higher
411 priorities. Among them, a coding system included in `coding-system'
412 key of the current language environment has higher priorities. See
413 also the documentation of `language-info-alist'.
415 If the variable `sort-coding-systems-predicate' (which see) is
416 non-nil, it is used to sort CODINGS in the different way than above."
417 (if sort-coding-systems-predicate
418 (sort codings sort-coding-systems-predicate)
419 (let* ((from-priority (coding-system-priority-list))
420 (most-preferred (car from-priority))
421 (lang-preferred (get-language-info current-language-environment
425 (let ((base (coding-system-base x)))
426 ;; We calculate the priority number 0..255 by
427 ;; using the 8 bits PMMLCEII as this:
428 ;; P: 1 iff most preferred.
429 ;; MM: greater than 0 iff mime-charset.
430 ;; L: 1 iff one of the current lang. env.'s codings.
431 ;; C: 1 iff one of codings listed in the category list.
432 ;; E: 1 iff not XXX-with-esc
433 ;; II: if iso-2022 based, 0..3, else 1.
435 (lsh (if (eq base most-preferred) 1 0) 7)
437 (let ((mime (coding-system-get base :mime-charset)))
438 ;; Prefer coding systems corresponding to a
441 ;; Lower utf-16 priority so that we
442 ;; normally prefer utf-8 to it, and put
443 ;; x-ctext below that.
444 (cond ((string-match "utf-16"
447 ((string-match "^x-" (symbol-name mime))
452 (lsh (if (memq base lang-preferred) 1 0) 4)
453 (lsh (if (memq base from-priority) 1 0) 3)
454 (lsh (if (string-match "-with-esc\\'"
457 (if (eq (coding-system-type base) 'iso-2022)
458 (let ((category (coding-system-category base)))
459 ;; For ISO based coding systems, prefer
460 ;; one that doesn't use designation nor
461 ;; locking/single shifting.
463 ((or (eq category 'coding-category-iso-8-1)
464 (eq category 'coding-category-iso-8-2))
466 ((or (eq category 'coding-category-iso-7-tight)
467 (eq category 'coding-category-iso-7))
473 (sort codings (function (lambda (x y)
474 (> (funcall func x) (funcall func y))))))))
476 (defun find-coding-systems-region (from to)
477 "Return a list of proper coding systems to encode a text between FROM and TO.
479 If FROM is a string, find coding systems in that instead of the buffer.
480 All coding systems in the list can safely encode any multibyte characters
483 If the text contains no multibyte characters, return a list of a single
484 element `undecided'."
485 (let ((codings (find-coding-systems-region-internal from to)))
487 ;; The text contains only ASCII characters. Any coding
490 ;; We need copy-sequence because sorting will alter the argument.
491 (sort-coding-systems (copy-sequence codings)))))
493 (defun find-coding-systems-string (string)
494 "Return a list of proper coding systems to encode STRING.
495 All coding systems in the list can safely encode any multibyte characters
498 If STRING contains no multibyte characters, return a list of a single
499 element `undecided'."
500 (find-coding-systems-region string nil))
502 (defun find-coding-systems-for-charsets (charsets)
503 "Return a list of proper coding systems to encode characters of CHARSETS.
504 CHARSETS is a list of character sets.
506 This only finds coding systems of type `charset', whose
507 `:charset-list' property includes all of CHARSETS (plus `ascii' for
508 ascii-compatible coding systems). It was used in older versions of
509 Emacs, but is unlikely to be what you really want now."
510 ;; Deal with aliases.
511 (setq charsets (mapcar (lambda (c)
512 (get-charset-property c :name))
514 (cond ((or (null charsets)
515 (and (= (length charsets) 1)
516 (eq 'ascii (car charsets))))
518 ((or (memq 'eight-bit-control charsets)
519 (memq 'eight-bit-graphic charsets))
520 '(raw-text utf-8-emacs))
523 (dolist (cs (coding-system-list t))
524 (let ((cs-charsets (and (eq (coding-system-type cs) 'charset)
525 (coding-system-charset-list cs)))
527 (if (coding-system-get cs :ascii-compatible-p)
528 (add-to-list 'cs-charsets 'ascii))
532 (unless (memq (pop charsets) cs-charsets)
536 (nreverse codings)))))
538 (defun find-multibyte-characters (from to &optional maxcount excludes)
539 "Find multibyte characters in the region specified by FROM and TO.
540 If FROM is a string, find multibyte characters in the string.
541 The return value is an alist of the following format:
542 ((CHARSET COUNT CHAR ...) ...)
544 CHARSET is a character set,
545 COUNT is a number of characters,
546 CHARs are the characters found from the character set.
547 Optional 3rd arg MAXCOUNT limits how many CHARs are put in the above list.
548 Optional 4th arg EXCLUDE is a list of character sets to be ignored."
552 (if (multibyte-string-p from)
554 (while (setq idx (string-match "[^\000-\177]" from idx))
555 (setq char (aref from idx)
556 charset (char-charset char))
557 (unless (memq charset excludes)
558 (let ((slot (assq charset chars)))
560 (if (not (memq char (nthcdr 2 slot)))
561 (let ((count (nth 1 slot)))
562 (setcar (cdr slot) (1+ count))
563 (if (or (not maxcount) (< count maxcount))
564 (nconc slot (list char)))))
565 (setq chars (cons (list charset 1 char) chars)))))
566 (setq idx (1+ idx)))))
567 (if enable-multibyte-characters
570 (while (re-search-forward "[^\000-\177]" to t)
571 (setq char (preceding-char)
572 charset (char-charset char))
573 (unless (memq charset excludes)
574 (let ((slot (assq charset chars)))
576 (if (not (member char (nthcdr 2 slot)))
577 (let ((count (nth 1 slot)))
578 (setcar (cdr slot) (1+ count))
579 (if (or (not maxcount) (< count maxcount))
580 (nconc slot (list char)))))
581 (setq chars (cons (list charset 1 char) chars)))))))))
584 (defun search-unencodable-char (coding-system)
585 "Search forward from point for a character that is not encodable.
586 It asks which coding system to check.
587 If such a character is found, set point after that character.
588 Otherwise, don't move point.
590 When called from a program, the value is a position of the found character,
591 or nil if all characters are encodable."
593 (list (let ((default (or buffer-file-coding-system 'us-ascii)))
595 (format "Coding-system (default, %s): " default)
597 (let ((pos (unencodable-char-position (point) (point-max) coding-system)))
600 (message "All following characters are encodable by %s" coding-system))
603 (defvar last-coding-system-specified nil
604 "Most recent coding system explicitly specified by the user when asked.
605 This variable is set whenever Emacs asks the user which coding system
606 to use in order to write a file. If you set it to nil explicitly,
607 then call `write-region', then afterward this variable will be non-nil
608 only if the user was explicitly asked and specified a coding system.")
610 (defvar select-safe-coding-system-accept-default-p nil
611 "If non-nil, a function to control the behaviour of coding system selection.
612 The meaning is the same as the argument ACCEPT-DEFAULT-P of the
613 function `select-safe-coding-system' (which see). This variable
614 overrides that argument.")
616 (defun select-safe-coding-system-interactively (from to codings unsafe
617 &optional rejected default)
618 "Select interactively a coding system for the region FROM ... TO.
619 FROM can be a string, as in `write-region'.
620 CODINGS is the list of base coding systems known to be safe for this region,
621 typically obtained with `find-coding-systems-region'.
622 UNSAFE is a list of coding systems known to be unsafe for this region.
623 REJECTED is a list of coding systems which were safe but for some reason
624 were not recommended in the particular context.
625 DEFAULT is the coding system to use by default in the query."
626 ;; At first, if some defaults are unsafe, record at most 11
627 ;; problematic characters and their positions for them by turning
630 ;; ((CODING (POS . CHAR) (POS . CHAR) ...) ...)
633 (mapcar #'(lambda (coding)
636 (mapcar #'(lambda (pos)
637 (cons pos (aref from pos)))
638 (unencodable-char-position
639 0 (length from) coding
641 (mapcar #'(lambda (pos)
642 (cons pos (char-after pos)))
643 (unencodable-char-position
644 from to coding 11)))))
647 ;; Change each safe coding system to the corresponding
648 ;; mime-charset name if it is also a coding system. Such a name
649 ;; is more friendly to users.
653 (setq mime-charset (coding-system-get (car l) :mime-charset))
654 (if (and mime-charset (coding-system-p mime-charset)
655 (coding-system-equal (car l) mime-charset))
656 (setcar l mime-charset))
659 ;; Don't offer variations with locking shift, which you
660 ;; basically never want.
662 (dolist (elt codings (setq codings (nreverse l)))
663 (unless (or (eq 'coding-category-iso-7-else
664 (coding-system-category elt))
665 (eq 'coding-category-iso-8-else
666 (coding-system-category elt)))
669 ;; Remove raw-text, emacs-mule and no-conversion unless nothing
670 ;; else is available.
674 (delq 'no-conversion codings)))
675 '(raw-text emacs-mule no-conversion)))
677 (let ((window-configuration (current-window-configuration))
678 (bufname (buffer-name))
681 ;; If some defaults are unsafe, make sure the offending
682 ;; buffer is displayed.
683 (when (and unsafe (not (stringp from)))
684 (pop-to-buffer bufname)
685 (goto-char (apply 'min (mapcar #'(lambda (x) (car (cadr x)))
687 ;; Then ask users to select one from CODINGS while showing
688 ;; the reason why none of the defaults are not used.
689 (with-output-to-temp-buffer "*Warning*"
690 (with-current-buffer standard-output
691 (if (and (null rejected) (null unsafe))
692 (insert "No default coding systems to try for "
694 (format "string \"%s\"." from)
695 (format "buffer `%s'." bufname)))
697 "These default coding systems were tried to encode"
699 (concat " \"" (if (> (length from) 10)
700 (concat (substring from 0 10) "...\"")
702 (format " text\nin the buffer `%s'" bufname))
706 (dolist (x (append rejected unsafe))
707 (princ " ") (princ (car x)))
709 (fill-region-as-paragraph pos (point)))
711 (insert "These safely encodes the target text,
712 but it is not recommended for encoding text in this context,
713 e.g., for sending an email message.\n ")
715 (princ " ") (princ x))
718 (insert (if rejected "And the others"
719 "However, each of them")
720 " encountered these problematic characters:\n")
721 (dolist (coding unsafe)
722 (insert (format " %s:" (car coding)))
725 #'(lambda (bufname pos)
726 (when (buffer-live-p (get-buffer bufname))
727 (pop-to-buffer bufname)
730 #'(lambda (bufname pos coding)
731 (when (buffer-live-p (get-buffer bufname))
732 (pop-to-buffer bufname)
736 (search-unencodable-char coding)
737 (forward-char -1))))))
738 (dolist (elt (cdr coding))
741 (insert (if (< i 10) (cdr elt) "..."))
747 "mouse-2, RET: jump to this character"
749 'help-args (list bufname (car elt)))
754 "mouse-2, RET: next unencodable character"
756 'help-args (list bufname (car elt)
761 The first problematic character is at point in the displayed buffer,\n"
762 (substitute-command-keys "\
763 and \\[universal-argument] \\[what-cursor-position] will give information about it.\n"))))
765 one of the following safe coding systems, or edit the buffer:\n")
769 (princ " ") (princ x))
771 (fill-region-as-paragraph pos (point)))
772 (insert "Or specify any other coding system
773 at the risk of losing the problematic characters.\n")))
775 ;; Read a coding system.
778 (format "Select coding system (default %s): " default)
780 (setq last-coding-system-specified coding-system))
782 (kill-buffer "*Warning*")
783 (set-window-configuration window-configuration)
786 (defun select-safe-coding-system (from to &optional default-coding-system
787 accept-default-p file)
788 "Ask a user to select a safe coding system from candidates.
789 The candidates of coding systems which can safely encode a text
790 between FROM and TO are shown in a popup window. Among them, the most
791 proper one is suggested as the default.
793 The list of `buffer-file-coding-system' of the current buffer,
794 the `default-buffer-file-coding-system', and the
795 most preferred coding system (if it corresponds to a MIME charset) is
796 treated as the default coding system list. Among them, the first one
797 that safely encodes the text is normally selected silently and
798 returned without any user interaction. See also the command
799 `prefer-coding-system'.
801 However, the user is queried if the chosen coding system is
802 inconsistent with what would be selected by `set-auto-coding' from
803 coding cookies &c. if the contents of the region were read from a
804 file. (That could lead to data corruption in a file subsequently
805 re-visited and edited.)
807 Optional 3rd arg DEFAULT-CODING-SYSTEM specifies a coding system or a
808 list of coding systems to be prepended to the default coding system
809 list. However, if DEFAULT-CODING-SYSTEM is a list and the first
810 element is t, the cdr part is used as the defualt coding system list,
811 i.e. `buffer-file-coding-system', `default-buffer-file-coding-system',
812 and the most preferred coding system are not used.
814 Optional 4th arg ACCEPT-DEFAULT-P, if non-nil, is a function to
815 determine the acceptability of the silently selected coding system.
816 It is called with that coding system, and should return nil if it
817 should not be silently selected and thus user interaction is required.
819 Optional 5th arg FILE is the file name to use for this purpose.
820 That is different from `buffer-file-name' when handling `write-region'
823 The variable `select-safe-coding-system-accept-default-p', if
824 non-nil, overrides ACCEPT-DEFAULT-P.
826 Kludgy feature: if FROM is a string, the string is the target text,
828 (if (and default-coding-system
829 (not (listp default-coding-system)))
830 (setq default-coding-system (list default-coding-system)))
832 (let ((no-other-defaults nil))
833 (if (eq (car default-coding-system) t)
834 (setq no-other-defaults t
835 default-coding-system (cdr default-coding-system)))
837 ;; Change elements of the list to (coding . base-coding).
838 (setq default-coding-system
839 (mapcar (function (lambda (x) (cons x (coding-system-base x))))
840 default-coding-system))
842 ;; From now on, the list of defaults is reversed.
843 (setq default-coding-system (nreverse default-coding-system))
845 (unless no-other-defaults
846 ;; If buffer-file-coding-system is not nil nor undecided, append it
848 (if buffer-file-coding-system
849 (let ((base (coding-system-base buffer-file-coding-system)))
850 (or (eq base 'undecided)
851 (rassq base default-coding-system)
852 (push (cons buffer-file-coding-system base)
853 default-coding-system))))
855 ;; If default-buffer-file-coding-system is not nil nor undecided,
856 ;; append it to the defaults.
857 (if default-buffer-file-coding-system
858 (let ((base (coding-system-base default-buffer-file-coding-system)))
859 (or (eq base 'undecided)
860 (rassq base default-coding-system)
861 (push (cons default-buffer-file-coding-system base)
862 default-coding-system))))
864 ;; If the most preferred coding system has the property mime-charset,
865 ;; append it to the defaults.
866 (let ((preferred (coding-system-priority-list t))
868 (and (coding-system-p preferred)
869 (setq base (coding-system-base preferred))
870 (coding-system-get preferred :mime-charset)
871 (not (rassq base default-coding-system))
872 (push (cons preferred base)
873 default-coding-system)))))
875 (if select-safe-coding-system-accept-default-p
876 (setq accept-default-p select-safe-coding-system-accept-default-p))
878 (let ((codings (find-coding-systems-region from to))
880 safe rejected unsafe)
881 ;; Classify the defaults into safe, rejected, and unsafe.
882 (dolist (elt default-coding-system)
883 (if (or (eq (car codings) 'undecided)
884 (memq (cdr elt) codings))
885 (if (and (functionp accept-default-p)
886 (not (funcall accept-default-p (cdr elt))))
887 (push (car elt) rejected)
888 (push (car elt) safe))
889 (push (car elt) unsafe)))
891 (setq coding-system (car safe)))
893 ;; If all the defaults failed, ask a user.
894 (unless coding-system
895 (setq coding-system (select-safe-coding-system-interactively
896 from to codings unsafe rejected (car codings))))
898 (if (and coding-system (vectorp (coding-system-eol-type coding-system)))
899 (let ((eol (coding-system-eol-type buffer-file-coding-system)))
902 (coding-system-change-eol-conversion coding-system eol)))))
904 ;; Check we're not inconsistent with what `coding:' spec &c would
905 ;; give when file is re-read.
906 ;; But don't do this if we explicitly ignored the cookie
907 ;; by using `find-file-literally'.
908 (unless (or (stringp from) find-file-literally)
909 (let ((auto-cs (save-excursion
912 (narrow-to-region from to)
913 (goto-char (point-min))
914 (set-auto-coding (or file buffer-file-name "")
916 ;; Merge coding-system and auto-cs as far as possible.
917 (if (not coding-system)
918 (setq coding-system auto-cs)
920 (setq auto-cs coding-system)
921 (let ((eol-type-1 (coding-system-eol-type coding-system))
922 (eol-type-2 (coding-system-eol-type auto-cs)))
923 (if (eq (coding-system-base coding-system) 'undecided)
924 (setq coding-system (coding-system-change-text-conversion
925 coding-system auto-cs))
926 (if (eq (coding-system-base auto-cs) 'undecided)
927 (setq auto-cs (coding-system-change-text-conversion
928 auto-cs coding-system))))
929 (if (vectorp eol-type-1)
930 (or (vectorp eol-type-2)
931 (setq coding-system (coding-system-change-eol-conversion
932 coding-system eol-type-2)))
933 (if (vectorp eol-type-2)
934 (setq auto-cs (coding-system-change-eol-conversion
935 auto-cs eol-type-1)))))))
938 ;; Don't barf if writing a compressed file, say.
939 ;; This check perhaps isn't ideal, but is probably
940 ;; the best thing to do.
941 (not (auto-coding-alist-lookup (or file buffer-file-name "")))
942 (not (coding-system-equal coding-system auto-cs)))
944 (format "Selected encoding %s disagrees with \
945 %s specified by file contents. Really save (else edit coding cookies \
946 and try again)? " coding-system auto-cs))
947 (error "Save aborted")))))
950 (setq select-safe-coding-system-function 'select-safe-coding-system)
952 (defun select-message-coding-system ()
953 "Return a coding system to encode the outgoing message of the current buffer.
954 It at first tries the first coding system found in these variables
956 (1) local value of `buffer-file-coding-system'
957 (2) value of `sendmail-coding-system'
958 (3) value of `default-sendmail-coding-system'
959 (4) value of `default-buffer-file-coding-system'
960 If the found coding system can't encode the current buffer,
961 or none of them are bound to a coding system,
962 it asks the user to select a proper coding system."
963 (let ((coding (or (and (local-variable-p 'buffer-file-coding-system)
964 buffer-file-coding-system)
965 sendmail-coding-system
966 default-sendmail-coding-system
967 default-buffer-file-coding-system)))
968 (if (eq coding 'no-conversion)
969 ;; We should never use no-conversion for outgoing mail.
971 (if (fboundp select-safe-coding-system-function)
972 (funcall select-safe-coding-system-function
973 (point-min) (point-max) coding
974 (function (lambda (x) (coding-system-get x :mime-charset))))
977 ;;; Language support stuff.
979 (defvar language-info-alist nil
980 "Alist of language environment definitions.
981 Each element looks like:
982 (LANGUAGE-NAME . ((KEY . INFO) ...))
983 where LANGUAGE-NAME is a string, the name of the language environment,
984 KEY is a symbol denoting the kind of information, and
985 INFO is the data associated with KEY.
986 Meaningful values for KEY include
988 documentation value is documentation of what this language environment
989 is meant for, and how to use it.
990 charset value is a list of the character sets mainly used
991 by this language environment.
992 sample-text value is an expression which is evalled to generate
993 a line of text written using characters appropriate
994 for this language environment.
995 setup-function value is a function to call to switch to this
996 language environment.
997 exit-function value is a function to call to leave this
998 language environment.
999 coding-system value is a list of coding systems that are good
1000 for saving text written in this language environment.
1001 This list serves as suggestions to the user;
1002 in effect, as a kind of documentation.
1003 coding-priority value is a list of coding systems for this language
1004 environment, in order of decreasing priority.
1005 This is used to set up the coding system priority
1006 list when you switch to this language environment.
1007 nonascii-translation
1008 value is a charset of dimension one to use for
1009 converting a unibyte character to multibyte
1011 input-method value is a default input method for this language
1013 features value is a list of features requested in this
1014 language environment.
1015 ctext-non-standard-encodings
1016 value is a list of non-standard encoding
1017 names used in extended segments of CTEXT.
1019 `ctext-non-standard-encodings' for more
1022 The following keys take effect only when multibyte characters are
1023 globally disabled, i.e. the value of `default-enable-multibyte-characters'
1026 unibyte-display value is a coding system to encode characters
1027 for the terminal. Characters in the range
1028 of 160 to 255 display not as octal escapes,
1029 but as non-ASCII characters in this language
1032 (defun get-language-info (lang-env key)
1033 "Return information listed under KEY for language environment LANG-ENV.
1034 KEY is a symbol denoting the kind of information.
1035 For a list of useful values for KEY and their meanings,
1036 see `language-info-alist'."
1037 (if (symbolp lang-env)
1038 (setq lang-env (symbol-name lang-env)))
1039 (let ((lang-slot (assoc-string lang-env language-info-alist t)))
1041 (cdr (assq key (cdr lang-slot))))))
1043 (defun set-language-info (lang-env key info)
1044 "Modify part of the definition of language environment LANG-ENV.
1045 Specifically, this stores the information INFO under KEY
1046 in the definition of this language environment.
1047 KEY is a symbol denoting the kind of information.
1048 INFO is the value for that information.
1050 For a list of useful values for KEY and their meanings,
1051 see `language-info-alist'."
1052 (if (symbolp lang-env)
1053 (setq lang-env (symbol-name lang-env)))
1054 (let (lang-slot key-slot)
1055 (setq lang-slot (assoc lang-env language-info-alist))
1056 (if (null lang-slot) ; If no slot for the language, add it.
1057 (setq lang-slot (list lang-env)
1058 language-info-alist (cons lang-slot language-info-alist)))
1059 (setq key-slot (assq key lang-slot))
1060 (if (null key-slot) ; If no slot for the key, add it.
1062 (setq key-slot (list key))
1063 (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
1064 (setcdr key-slot (purecopy info))
1065 ;; Update the custom-type of `current-language-environment'.
1066 (put 'current-language-environment 'custom-type
1067 (cons 'choice (mapcar
1070 (sort (mapcar 'car language-info-alist) 'string<))))))
1072 (defun set-language-info-alist (lang-env alist &optional parents)
1073 "Store ALIST as the definition of language environment LANG-ENV.
1074 ALIST is an alist of KEY and INFO values. See the documentation of
1075 `language-info-alist' for the meanings of KEY and INFO.
1077 Optional arg PARENTS is a list of parent menu names; it specifies
1078 where to put this language environment in the
1079 Describe Language Environment and Set Language Environment menus.
1080 For example, (\"European\") means to put this language environment
1081 in the European submenu in each of those two menus."
1082 (if (symbolp lang-env)
1083 (setq lang-env (symbol-name lang-env)))
1084 (let ((describe-map describe-language-environment-map)
1085 (setup-map setup-language-environment-map))
1088 map parent-symbol parent prompt)
1090 (if (symbolp (setq parent-symbol (car l)))
1091 (setq parent (symbol-name parent))
1092 (setq parent parent-symbol parent-symbol (intern parent)))
1093 (setq map (lookup-key describe-map (vector parent-symbol)))
1094 ;; This prompt string is for define-prefix-command, so
1095 ;; that the map it creates will be suitable for a menu.
1096 (or map (setq prompt (format "%s Environment" parent)))
1099 (setq map (intern (format "describe-%s-environment-map"
1100 (downcase parent))))
1101 (define-prefix-command map nil prompt)
1102 (define-key-after describe-map (vector parent-symbol)
1103 (cons parent map) t)))
1104 (setq describe-map (symbol-value map))
1105 (setq map (lookup-key setup-map (vector parent-symbol)))
1108 (setq map (intern (format "setup-%s-environment-map"
1109 (downcase parent))))
1110 (define-prefix-command map nil prompt)
1111 (define-key-after setup-map (vector parent-symbol)
1112 (cons parent map) t)))
1113 (setq setup-map (symbol-value map))
1116 ;; Set up menu items for this language env.
1117 (let ((doc (assq 'documentation alist)))
1119 (define-key-after describe-map (vector (intern lang-env))
1120 (cons lang-env 'describe-specified-language-support) t)))
1121 (define-key-after setup-map (vector (intern lang-env))
1122 (cons lang-env 'setup-specified-language-environment) t)
1125 (set-language-info lang-env (car (car alist)) (cdr (car alist)))
1126 (setq alist (cdr alist)))))
1128 (defun read-language-name (key prompt &optional default)
1129 "Read a language environment name which has information for KEY.
1130 If KEY is nil, read any language environment.
1131 Prompt with PROMPT. DEFAULT is the default choice of language environment.
1132 This returns a language environment name as a string."
1133 (let* ((completion-ignore-case t)
1134 (name (completing-read prompt
1137 (function (lambda (elm) (and (listp elm) (assq key elm)))))
1138 t nil nil default)))
1139 (if (and (> (length name) 0)
1141 (get-language-info name key)))
1144 ;;; Multilingual input methods.
1146 "LEIM: Libraries of Emacs Input Methods."
1149 (defconst leim-list-file-name "leim-list.el"
1150 "Name of LEIM list file.
1151 This file contains a list of libraries of Emacs input methods (LEIM)
1152 in the format of Lisp expression for registering each input method.
1153 Emacs loads this file at startup time.")
1155 (defvar leim-list-header (format
1156 ";;; %s -- list of LEIM (Library of Emacs Input Method) -*-coding: iso-2022-7bit;-*-
1158 ;; This file contains a list of LEIM (Library of Emacs Input Method)
1159 ;; methods in the same directory as this file. Loading this file
1160 ;; registers all the input methods in Emacs.
1162 ;; Each entry has the form:
1163 ;; (register-input-method
1164 ;; INPUT-METHOD LANGUAGE-NAME ACTIVATE-FUNC
1165 ;; TITLE DESCRIPTION
1167 ;; See the function `register-input-method' for the meanings of the arguments.
1169 ;; If this directory is included in load-path, Emacs automatically
1170 ;; loads this file at startup time.
1173 leim-list-file-name)
1174 "Header to be inserted in LEIM list file.")
1176 (defvar leim-list-entry-regexp "^(register-input-method"
1177 "Regexp matching head of each entry in LEIM list file.
1178 See also the variable `leim-list-header'")
1180 (defvar update-leim-list-functions
1181 '(quail-update-leim-list-file)
1182 "List of functions to call to update LEIM list file.
1183 Each function is called with one arg, LEIM directory name.")
1185 (defun update-leim-list-file (&rest dirs)
1186 "Update LEIM list file in directories DIRS."
1187 (let ((functions update-leim-list-functions))
1189 (apply (car functions) dirs)
1190 (setq functions (cdr functions)))))
1192 (defvar current-input-method nil
1193 "The current input method for multilingual text.
1194 If nil, that means no input method is activated now.")
1195 (make-variable-buffer-local 'current-input-method)
1196 (put 'current-input-method 'permanent-local t)
1198 (defvar current-input-method-title nil
1199 "Title string of the current input method shown in mode line.")
1200 (make-variable-buffer-local 'current-input-method-title)
1201 (put 'current-input-method-title 'permanent-local t)
1203 (defcustom default-input-method nil
1204 "*Default input method for multilingual text (a string).
1205 This is the input method activated automatically by the command
1206 `toggle-input-method' (\\[toggle-input-method])."
1207 :link '(custom-manual "(emacs)Input Methods")
1209 :type '(choice (const nil) (string
1210 :completion-ignore-case t
1211 :complete-function widget-string-complete
1212 :completion-alist input-method-alist
1213 :prompt-history input-method-history))
1214 :set-after '(current-language-environment))
1216 (put 'input-method-function 'permanent-local t)
1218 (defvar input-method-history nil
1219 "History list for some commands that read input methods.")
1220 (make-variable-buffer-local 'input-method-history)
1221 (put 'input-method-history 'permanent-local t)
1223 (defvar inactivate-current-input-method-function nil
1224 "Function to call for inactivating the current input method.
1225 Every input method should set this to an appropriate value when activated.
1226 This function is called with no argument.
1228 This function should never change the value of `current-input-method'.
1229 It is set to nil by the function `inactivate-input-method'.")
1230 (make-variable-buffer-local 'inactivate-current-input-method-function)
1231 (put 'inactivate-current-input-method-function 'permanent-local t)
1233 (defvar describe-current-input-method-function nil
1234 "Function to call for describing the current input method.
1235 This function is called with no argument.")
1236 (make-variable-buffer-local 'describe-current-input-method-function)
1237 (put 'describe-current-input-method-function 'permanent-local t)
1239 (defvar input-method-alist nil
1240 "Alist of input method names vs how to use them.
1241 Each element has the form:
1242 (INPUT-METHOD LANGUAGE-ENV ACTIVATE-FUNC TITLE DESCRIPTION ARGS...)
1243 See the function `register-input-method' for the meanings of the elements.")
1245 (defun register-input-method (input-method lang-env &rest args)
1246 "Register INPUT-METHOD as an input method for language environment LANG-ENV.
1247 INPUT-METHOD and LANG-ENV are symbols or strings.
1249 The remaining arguments are:
1250 ACTIVATE-FUNC, TITLE, DESCRIPTION, and ARGS...
1251 ACTIVATE-FUNC is a function to call to activate this method.
1252 TITLE is a string to show in the mode line when this method is active.
1253 DESCRIPTION is a string describing this method and what it is good for.
1254 The ARGS, if any, are passed as arguments to ACTIVATE-FUNC.
1255 All told, the arguments to ACTIVATE-FUNC are INPUT-METHOD and the ARGS.
1257 This function is mainly used in the file \"leim-list.el\" which is
1258 created at Emacs build time, registering all Quail input methods
1259 contained in the Emacs distribution.
1261 In case you want to register a new Quail input method by yourself, be
1262 careful to use the same input method title as given in the third
1263 parameter of `quail-define-package'. (If the values are different, the
1264 string specified in this function takes precedence.)
1266 The commands `describe-input-method' and `list-input-methods' need
1267 these duplicated values to show some information about input methods
1268 without loading the relevant Quail packages."
1269 (if (symbolp lang-env)
1270 (setq lang-env (symbol-name lang-env)))
1271 (if (symbolp input-method)
1272 (setq input-method (symbol-name input-method)))
1273 (let ((info (cons lang-env args))
1274 (slot (assoc input-method input-method-alist)))
1277 (setq slot (cons input-method info))
1278 (setq input-method-alist (cons slot input-method-alist)))))
1280 (defun read-input-method-name (prompt &optional default inhibit-null)
1281 "Read a name of input method from a minibuffer prompting with PROMPT.
1282 If DEFAULT is non-nil, use that as the default,
1283 and substitute it into PROMPT at the first `%s'.
1284 If INHIBIT-NULL is non-nil, null input signals an error.
1286 The return value is a string."
1288 (setq prompt (format prompt default)))
1289 (let* ((completion-ignore-case t)
1290 ;; As it is quite normal to change input method in the
1291 ;; minibuffer, we must enable it even if
1292 ;; enable-recursive-minibuffers is currently nil.
1293 (enable-recursive-minibuffers t)
1294 ;; This binding is necessary because input-method-history is
1296 (input-method (completing-read prompt input-method-alist
1297 nil t nil 'input-method-history
1299 (if (and input-method (symbolp input-method))
1300 (setq input-method (symbol-name input-method)))
1301 (if (> (length input-method) 0)
1304 (error "No valid input method is specified")))))
1306 (defun activate-input-method (input-method)
1307 "Switch to input method INPUT-METHOD for the current buffer.
1308 If some other input method is already active, turn it off first.
1309 If INPUT-METHOD is nil, deactivate any current input method."
1310 (if (and input-method (symbolp input-method))
1311 (setq input-method (symbol-name input-method)))
1312 (if (and current-input-method
1313 (not (string= current-input-method input-method)))
1314 (inactivate-input-method))
1315 (unless (or current-input-method (null input-method))
1316 (let ((slot (assoc input-method input-method-alist)))
1318 (error "Can't activate input method `%s'" input-method))
1319 (setq current-input-method-title nil)
1320 (let ((func (nth 2 slot)))
1321 (if (functionp func)
1322 (apply (nth 2 slot) input-method (nthcdr 5 slot))
1323 (if (and (consp func) (symbolp (car func)) (symbolp (cdr func)))
1325 (require (cdr func))
1326 (apply (car func) input-method (nthcdr 5 slot)))
1327 (error "Can't activate input method `%s'" input-method))))
1328 (setq current-input-method input-method)
1329 (or (stringp current-input-method-title)
1330 (setq current-input-method-title (nth 3 slot)))
1332 (run-hooks 'input-method-activate-hook)
1333 (force-mode-line-update)))))
1335 (defun inactivate-input-method ()
1336 "Turn off the current input method."
1337 (when current-input-method
1338 (if input-method-history
1339 (unless (string= current-input-method (car input-method-history))
1340 (setq input-method-history
1341 (cons current-input-method
1342 (delete current-input-method input-method-history))))
1343 (setq input-method-history (list current-input-method)))
1345 (funcall inactivate-current-input-method-function)
1347 (run-hooks 'input-method-inactivate-hook)
1348 (setq current-input-method nil
1349 input-method-function nil
1350 current-input-method-title nil)
1351 (force-mode-line-update)))))
1353 (defun set-input-method (input-method &optional interactive)
1354 "Select and activate input method INPUT-METHOD for the current buffer.
1355 This also sets the default input method to the one you specify.
1356 If INPUT-METHOD is nil, this function turns off the input method, and
1357 also causes you to be prompted for a name of an input method the next
1358 time you invoke \\[toggle-input-method].
1359 When called interactively, the optional arg INTERACTIVE is non-nil,
1360 which marks the variable `default-input-method' as set for Custom buffers.
1362 To deactivate the input method interactively, use \\[toggle-input-method].
1363 To deactivate it programmatically, use \\[inactivate-input-method]."
1365 (let* ((default (or (car input-method-history) default-input-method)))
1366 (list (read-input-method-name
1367 (if default "Select input method (default %s): " "Select input method: ")
1370 (activate-input-method input-method)
1371 (setq default-input-method input-method)
1373 (customize-mark-as-set 'default-input-method))
1374 default-input-method)
1376 (defun toggle-input-method (&optional arg interactive)
1377 "Enable or disable multilingual text input method for the current buffer.
1378 Only one input method can be enabled at any time in a given buffer.
1380 The normal action is to enable an input method if none was
1381 enabled, and disable the current one otherwise. Which input method
1382 to enable can be determined in various ways--either the one most
1383 recently used, or the one specified by `default-input-method', or
1384 as a last resort by reading the name of an input method in the
1387 With a prefix argument, read an input method name with the minibuffer
1388 and enable that one. The default is the most recent input method specified
1389 \(not including the currently active input method, if any).
1391 When called interactively, the optional arg INTERACTIVE is non-nil,
1392 which marks the variable `default-input-method' as set for Custom buffers."
1394 (interactive "P\np")
1395 (if (and current-input-method (not arg))
1396 (inactivate-input-method)
1397 (let ((default (or (car input-method-history) default-input-method)))
1398 (if (and arg default (equal current-input-method default)
1399 (> (length input-method-history) 1))
1400 (setq default (nth 1 input-method-history)))
1401 (activate-input-method
1402 (if (or arg (not default))
1404 (read-input-method-name
1405 (if default "Input method (default %s): " "Input method: " )
1408 (unless default-input-method
1410 (setq default-input-method current-input-method)
1412 (customize-mark-as-set 'default-input-method)))))))
1414 (eval-when-compile (autoload 'help-buffer "help-mode"))
1416 (defun describe-input-method (input-method)
1417 "Describe input method INPUT-METHOD."
1419 (list (read-input-method-name
1420 "Describe input method (default, current choice): ")))
1421 (if (and input-method (symbolp input-method))
1422 (setq input-method (symbol-name input-method)))
1423 (help-setup-xref (list #'describe-input-method
1424 (or input-method current-input-method))
1427 (if (null input-method)
1428 (describe-current-input-method)
1429 (let ((current current-input-method))
1433 (activate-input-method input-method)
1434 (describe-current-input-method))
1435 (activate-input-method current))
1437 (activate-input-method current)
1438 (help-setup-xref (list #'describe-input-method input-method)
1440 (with-output-to-temp-buffer (help-buffer)
1441 (let ((elt (assoc input-method input-method-alist)))
1443 "Input method: %s (`%s' in mode line) for %s\n %s\n"
1444 input-method (nth 3 elt) (nth 1 elt) (nth 4 elt))))))))))
1446 (defun describe-current-input-method ()
1447 "Describe the input method currently in use.
1448 This is a subroutine for `describe-input-method'."
1449 (if current-input-method
1450 (if (and (symbolp describe-current-input-method-function)
1451 (fboundp describe-current-input-method-function))
1452 (funcall describe-current-input-method-function)
1453 (message "No way to describe the current input method `%s'"
1454 current-input-method)
1456 (error "No input method is activated now")))
1458 (defun read-multilingual-string (prompt &optional initial-input input-method)
1459 "Read a multilingual string from minibuffer, prompting with string PROMPT.
1460 The input method selected last time is activated in minibuffer.
1461 If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
1463 Optional 3rd argument INPUT-METHOD specifies the input method
1464 to be activated instead of the one selected last time. It is a symbol
1468 current-input-method
1469 default-input-method
1470 (read-input-method-name "Input method: " nil t)))
1471 (if (and input-method (symbolp input-method))
1472 (setq input-method (symbol-name input-method)))
1473 (let ((prev-input-method current-input-method))
1476 (activate-input-method input-method)
1477 (read-string prompt initial-input nil nil t))
1478 (activate-input-method prev-input-method))))
1480 ;; Variables to control behavior of input methods. All input methods
1481 ;; should react to these variables.
1483 (defcustom input-method-verbose-flag 'default
1484 "*A flag to control extra guidance given by input methods.
1485 The value should be nil, t, `complex-only', or `default'.
1487 The extra guidance is done by showing list of available keys in echo
1488 area. When you use the input method in the minibuffer, the guidance
1489 is shown at the bottom short window (split from the existing window).
1491 If the value is t, extra guidance is always given, if the value is
1492 nil, extra guidance is always suppressed.
1494 If the value is `complex-only', only complex input methods such as
1495 `chinese-py' and `japanese' give extra guidance.
1497 If the value is `default', complex input methods always give extra
1498 guidance, but simple input methods give it only when you are not in
1501 See also the variable `input-method-highlight-flag'."
1502 :type '(choice (const :tag "Always" t) (const :tag "Never" nil)
1503 (const complex-only) (const default))
1506 (defcustom input-method-highlight-flag t
1507 "*If this flag is non-nil, input methods highlight partially-entered text.
1508 For instance, while you are in the middle of a Quail input method sequence,
1509 the text inserted so far is temporarily underlined.
1510 The underlining goes away when you finish or abort the input method sequence.
1511 See also the variable `input-method-verbose-flag'."
1515 (defcustom input-method-activate-hook nil
1516 "Normal hook run just after an input method is activated.
1518 The variable `current-input-method' keeps the input method name
1523 (defcustom input-method-inactivate-hook nil
1524 "Normal hook run just after an input method is inactivated.
1526 The variable `current-input-method' still keeps the input method name
1531 (defcustom input-method-after-insert-chunk-hook nil
1532 "Normal hook run just after an input method insert some chunk of text."
1536 (defvar input-method-exit-on-first-char nil
1537 "This flag controls when an input method returns.
1538 Usually, the input method does not return while there's a possibility
1539 that it may find a different translation if a user types another key.
1540 But, it this flag is non-nil, the input method returns as soon as
1541 the current key sequence gets long enough to have some valid translation.")
1543 (defcustom input-method-use-echo-area nil
1544 "This flag controls how an input method shows an intermediate key sequence.
1545 Usually, the input method inserts the intermediate key sequence,
1546 or candidate translations corresponding to the sequence,
1547 at point in the current buffer.
1548 But, if this flag is non-nil, it displays them in echo area instead."
1552 (defvar input-method-exit-on-invalid-key nil
1553 "This flag controls the behaviour of an input method on invalid key input.
1554 Usually, when a user types a key which doesn't start any character
1555 handled by the input method, the key is handled by turning off the
1556 input method temporarily. After that key, the input method is re-enabled.
1557 But, if this flag is non-nil, the input method is never back on.")
1560 (defcustom set-language-environment-hook nil
1561 "Normal hook run after some language environment is set.
1563 When you set some hook function here, that effect usually should not
1564 be inherited to another language environment. So, you had better set
1565 another function in `exit-language-environment-hook' (which see) to
1570 (defcustom exit-language-environment-hook nil
1571 "Normal hook run after exiting from some language environment.
1572 When this hook is run, the variable `current-language-environment'
1573 is still bound to the language environment being exited.
1575 This hook is mainly used for canceling the effect of
1576 `set-language-environment-hook' (which-see)."
1580 (put 'setup-specified-language-environment 'apropos-inhibit t)
1582 (defun setup-specified-language-environment ()
1583 "Switch to a specified language environment."
1585 (let (language-name)
1586 (if (and (symbolp last-command-event)
1587 (or (not (eq last-command-event 'Default))
1588 (setq last-command-event 'English))
1589 (setq language-name (symbol-name last-command-event)))
1591 (set-language-environment language-name)
1592 (customize-mark-as-set 'current-language-environment))
1593 (error "Bogus calling sequence"))))
1595 (defcustom current-language-environment "English"
1596 "The last language environment specified with `set-language-environment'.
1597 This variable should be set only with \\[customize], which is equivalent
1598 to using the function `set-language-environment'."
1599 :link '(custom-manual "(emacs)Language Environments")
1600 :set (lambda (symbol value) (set-language-environment value))
1602 (or (car-safe (assoc-string
1603 (if (symbolp current-language-environment)
1604 (symbol-name current-language-environment)
1605 current-language-environment)
1606 language-info-alist t))
1608 ;; custom type will be updated with `set-language-info'.
1609 :type (if language-info-alist
1610 (cons 'choice (mapcar
1613 (sort (mapcar 'car language-info-alist) 'string<)))
1615 :initialize 'custom-initialize-default
1618 (defun reset-language-environment ()
1619 "Reset multilingual environment of Emacs to the default status.
1621 The default status is as follows:
1623 The default value of `buffer-file-coding-system' is nil.
1624 The default coding system for process I/O is nil.
1625 The default value for the command `set-terminal-coding-system' is nil.
1626 The default value for the command `set-keyboard-coding-system' is nil.
1628 The order of priorities of coding systems are as follows:
1637 ;; This function formerly set default-enable-multibyte-characters to t,
1638 ;; but that is incorrect. It should not alter the unibyte/multibyte choice.
1640 (set-coding-system-priority
1649 (set-default-coding-systems nil)
1650 (setq default-sendmail-coding-system 'iso-latin-1)
1651 ;; On Darwin systems, this should be utf-8, but when this file is loaded
1652 ;; utf-8 is not yet defined, so we set it in set-locale-environment instead.
1653 (setq default-file-name-coding-system 'iso-latin-1)
1654 ;; Preserve eol-type from existing default-process-coding-systems.
1655 ;; On non-unix-like systems in particular, these may have been set
1656 ;; carefully by the user, or by the startup code, to deal with the
1657 ;; users shell appropriately, so should not be altered by changing
1658 ;; language environment.
1659 (let ((output-coding
1660 ;; When bootstrapping, coding-systems are not defined yet, so
1661 ;; we need to catch the error from check-coding-system.
1663 (coding-system-change-text-conversion
1664 (car default-process-coding-system) 'undecided)
1665 (coding-system-error 'undecided)))
1668 (coding-system-change-text-conversion
1669 (cdr default-process-coding-system) 'iso-latin-1)
1670 (coding-system-error 'iso-latin-1))))
1671 (setq default-process-coding-system
1672 (cons output-coding input-coding)))
1674 ;; Don't alter the terminal and keyboard coding systems here.
1675 ;; The terminal still supports the same coding system
1676 ;; that it supported a minute ago.
1677 ;; (set-terminal-coding-system-internal nil)
1678 ;; (set-keyboard-coding-system-internal nil)
1680 (set-unibyte-charset 'iso-8859-1))
1682 (reset-language-environment)
1684 (defun set-display-table-and-terminal-coding-system (language-name)
1685 "Set up the display table and terminal coding system for LANGUAGE-NAME."
1686 (let ((coding (get-language-info language-name 'unibyte-display)))
1688 (standard-display-european-internal)
1689 ;; The following 2 lines undo the 8-bit display that we set up
1690 ;; in standard-display-european-internal, which see. This is in
1691 ;; case the user has used standard-display-european earlier in
1692 ;; this session. (The MS-DOS port doesn't use that setup, so it
1693 ;; doesn't need to undo it.)
1694 (when standard-display-table
1696 (aset standard-display-table (+ i 128) nil))))
1697 (or (eq window-system 'pc)
1698 (set-terminal-coding-system coding))))
1700 (defun set-language-environment (language-name)
1701 "Set up multi-lingual environment for using LANGUAGE-NAME.
1702 This sets the coding system priority and the default input method
1703 and sometimes other things. LANGUAGE-NAME should be a string
1704 which is the name of a language environment. For example, \"Latin-1\"
1705 specifies the character set for the major languages of Western Europe."
1706 (interactive (list (read-language-name
1708 "Set language environment (default, English): ")))
1710 (if (symbolp language-name)
1711 (setq language-name (symbol-name language-name)))
1712 (setq language-name "English"))
1713 (let ((slot (assoc-string language-name language-info-alist t)))
1715 (error "Language environment not defined: %S" language-name))
1716 (setq language-name (car slot)))
1717 (if current-language-environment
1718 (let ((func (get-language-info current-language-environment
1720 (run-hooks 'exit-language-environment-hook)
1721 (if (functionp func) (funcall func))))
1722 (let ((default-eol-type (coding-system-eol-type
1723 default-buffer-file-coding-system)))
1724 (reset-language-environment)
1726 ;; The features might set up coding systems.
1727 (let ((required-features (get-language-info language-name 'features)))
1728 (while required-features
1729 (require (car required-features))
1730 (setq required-features (cdr required-features))))
1732 (setq current-language-environment language-name)
1733 (set-language-environment-coding-systems language-name default-eol-type))
1734 (let ((input-method (get-language-info language-name 'input-method)))
1736 (setq default-input-method input-method)
1737 (if input-method-history
1738 (setq input-method-history
1740 (delete input-method input-method-history))))))
1742 ;; Put higher priorities to such charsets that are supported by the
1743 ;; coding systems of higher priorities in this environment.
1744 (let ((charsets (get-language-info language-name 'charset)))
1745 (dolist (coding (get-language-info language-name 'coding-priority))
1746 (setq charsets (append charsets (coding-system-charset-list coding))))
1748 (apply 'set-charset-priority charsets)))
1750 ;; Note: For DOS, we assumed that the charset cpXXX is already
1752 (let ((nonascii (get-language-info language-name 'nonascii-translation)))
1753 (if (eq window-system 'pc)
1754 (setq nonascii (intern "cp%d" dos-codepage)))
1755 (or (and (charsetp nonascii)
1756 (get-charset-property nonascii :ascii-compatible-p))
1757 (setq nonascii 'iso-8859-1))
1758 (set-unibyte-charset nonascii))
1760 ;; Unibyte setups if necessary.
1761 (or default-enable-multibyte-characters
1762 (set-display-table-and-terminal-coding-system language-name))
1764 (let ((required-features (get-language-info language-name 'features)))
1765 (while required-features
1766 (require (car required-features))
1767 (setq required-features (cdr required-features))))
1769 (let ((func (get-language-info language-name 'setup-function)))
1770 (if (functionp func)
1772 (run-hooks 'set-language-environment-hook)
1773 (force-mode-line-update t))
1775 (define-widget 'charset 'symbol
1778 :complete-function (lambda ()
1780 (lisp-complete-symbol 'charsetp))
1781 :completion-ignore-case t
1783 :validate (lambda (widget)
1784 (unless (charsetp (widget-value widget))
1785 (widget-put widget :error (format "Invalid charset: %S"
1786 (widget-value widget)))
1788 :prompt-history 'charset-history)
1790 (defcustom language-info-custom-alist nil
1791 "Customizations of language environment parameters.
1792 Value is an alist with elements like those of `language-info-alist'.
1793 These are used to set values in `language-info-alist' which replace
1794 the defaults. A typical use is replacing the default input method for
1795 the environment. Use \\[describe-language-environment] to find the environment's settings.
1797 This option is intended for use at startup. Removing items doesn't
1798 remove them from the language info until you next restart Emacs.
1800 Setting this variable directly does not take effect. See
1801 `set-language-info-alist' for use in programs."
1805 (custom-set-default s v)
1806 ;; Can't do this before language environments are set up.
1808 ;; modify language-info-alist
1810 (set-language-info-alist (car elt) (cdr elt)))
1811 ;; re-set the environment in case its parameters changed
1812 (set-language-environment current-language-environment)))
1814 :key-type (string :tag "Language environment"
1815 :completion-ignore-case t
1816 :complete-function widget-string-complete
1817 :completion-alist language-info-alist)
1819 (alist :key-type symbol
1820 :options ((documentation string)
1821 (charset (repeat charset))
1822 (sample-text string)
1823 (setup-function function)
1824 (exit-function function)
1825 (coding-system (repeat coding-system))
1826 (coding-priority (repeat coding-system))
1827 (nonascii-translation charset)
1830 :completion-ignore-case t
1831 :complete-function widget-string-complete
1832 :completion-alist input-method-alist
1833 :prompt-history input-method-history))
1834 (features (repeat symbol))
1835 (unibyte-display coding-system)))))
1837 (defun standard-display-european-internal ()
1838 ;; Actually set up direct output of non-ASCII characters.
1839 (standard-display-8bit (if (eq window-system 'pc) 128 160) 255)
1840 ;; Unibyte Emacs on MS-DOS wants to display all 8-bit characters with
1841 ;; the native font, and codes 160 and 146 stand for something very
1843 (or (and (eq window-system 'pc) (not default-enable-multibyte-characters))
1845 ;; Most X fonts used to do the wrong thing for latin-1 code 160.
1846 (unless (and (eq window-system 'x)
1847 ;; XFree86 4 has fixed the fonts.
1848 (string= "The XFree86 Project, Inc" (x-server-vendor))
1849 (> (aref (number-to-string (nth 2 (x-server-version))) 0)
1851 ;; Make non-line-break space display as a plain space.
1852 (aset standard-display-table 160 [32]))
1853 ;; Most Windows programs send out apostrophes as \222. Most X fonts
1854 ;; don't contain a character at that position. Map it to the ASCII
1855 ;; apostrophe. [This is actually RIGHT SINGLE QUOTATION MARK,
1856 ;; U+2019, normally from the windows-1252 character set. XFree 4
1857 ;; fonts probably have the appropriate glyph at this position,
1858 ;; so they could use standard-display-8bit. It's better to use a
1859 ;; proper windows-1252 coding system. --fx]
1860 (aset standard-display-table 146 [39]))))
1862 (defun set-language-environment-coding-systems (language-name
1864 "Do various coding system setups for language environment LANGUAGE-NAME.
1866 The optional arg EOL-TYPE specifies the eol-type of the default value
1867 of `buffer-file-coding-system' set by this function."
1868 (let* ((priority (get-language-info language-name 'coding-priority))
1869 (default-coding (car priority)))
1871 (set-default-coding-systems
1872 (if (memq eol-type '(0 1 2 unix dos mac))
1873 (coding-system-change-eol-conversion default-coding eol-type)
1875 (setq default-sendmail-coding-system default-coding)
1876 (apply 'set-coding-system-priority priority))))
1878 (defsubst princ-list (&rest args)
1879 "Print all arguments with `princ', then print \"\n\"."
1880 (while args (princ (car args)) (setq args (cdr args)))
1883 (put 'describe-specified-language-support 'apropos-inhibit t)
1885 ;; Print language-specific information such as input methods,
1886 ;; charsets, and coding systems. This function is intended to be
1887 ;; called from the menu:
1888 ;; [menu-bar mule describe-language-environment LANGUAGE]
1889 ;; and should not run it by `M-x describe-current-input-method-function'.
1890 (defun describe-specified-language-support ()
1891 "Describe how Emacs supports the specified language environment."
1893 (let (language-name)
1894 (if (not (and (symbolp last-command-event)
1895 (or (not (eq last-command-event 'Default))
1896 (setq last-command-event 'English))
1897 (setq language-name (symbol-name last-command-event))))
1898 (error "Bogus calling sequence"))
1899 (describe-language-environment language-name)))
1901 (defun describe-language-environment (language-name)
1902 "Describe how Emacs supports language environment LANGUAGE-NAME."
1904 (list (read-language-name
1906 "Describe language environment (default, current choice): ")))
1907 (if (null language-name)
1908 (setq language-name current-language-environment))
1909 (if (or (null language-name)
1910 (null (get-language-info language-name 'documentation)))
1911 (error "No documentation for the specified language"))
1912 (if (symbolp language-name)
1913 (setq language-name (symbol-name language-name)))
1914 (dolist (feature (get-language-info language-name 'features))
1916 (let ((doc (get-language-info language-name 'documentation)))
1917 (help-setup-xref (list #'describe-language-environment language-name)
1919 (with-output-to-temp-buffer (help-buffer)
1921 (set-buffer standard-output)
1922 (insert language-name " language environment\n\n")
1924 (insert doc "\n\n"))
1926 (let ((str (eval (get-language-info language-name 'sample-text))))
1928 (insert "Sample text:\n " str "\n\n")))
1930 (let ((input-method (get-language-info language-name 'input-method))
1931 (l (copy-sequence input-method-alist)))
1932 (insert "Input methods")
1934 (insert " (default, " input-method ")")
1935 (setq input-method (assoc input-method input-method-alist))
1936 (setq l (cons input-method (delete input-method l))))
1939 (when (eq t (compare-strings language-name nil nil
1940 (nth 1 (car l)) nil nil t))
1941 (insert " " (car (car l)))
1942 (search-backward (car (car l)))
1943 (help-xref-button 0 'help-input-method (car (car l)))
1944 (goto-char (point-max))
1946 (if (stringp (nth 3 (car l)))
1948 (car (nth 3 (car l))))
1949 "\" in mode line)\n"))
1952 (insert "Character sets:\n")
1953 (let ((l (get-language-info language-name 'charset)))
1955 (insert " nothing specific to " language-name "\n")
1957 (insert " " (symbol-name (car l)))
1958 (search-backward (symbol-name (car l)))
1959 (help-xref-button 0 'help-character-set (car l))
1960 (goto-char (point-max))
1961 (insert ": " (charset-description (car l)) "\n")
1964 (insert "Coding systems:\n")
1965 (let ((l (get-language-info language-name 'coding-system)))
1967 (insert " nothing specific to " language-name "\n")
1969 (insert " " (symbol-name (car l)))
1970 (search-backward (symbol-name (car l)))
1971 (help-xref-button 0 'help-coding-system (car l))
1972 (goto-char (point-max))
1974 (coding-system-mnemonic (car l))
1975 "' in mode line):\n\t"
1976 (coding-system-doc-string (car l))
1978 (let ((aliases (coding-system-aliases (car l))))
1980 (insert "\t(alias:")
1982 (insert " " (symbol-name (car aliases)))
1983 (setq aliases (cdr aliases)))
1985 (setq l (cdr l)))))))))
1989 (defvar locale-translation-file-name nil
1990 "File name for the system's file of locale-name aliases, or nil if none.")
1992 ;; The following definitions might as well be marked as constants and
1993 ;; purecopied, since they're normally used on startup, and probably
1994 ;; should reflect the facilities of the base Emacs.
1995 (defconst locale-language-names
1998 ;; Locale names of the form LANGUAGE[_TERRITORY][.CODESET][@MODIFIER]
1999 ;; as specified in the Single Unix Spec, Version 2.
2000 ;; LANGUAGE is a language code taken from ISO 639:1988 (E/F)
2001 ;; with additions from ISO 639/RA Newsletter No.1/1989;
2002 ;; see Internet RFC 2165 (1997-06) and
2003 ;; http://www.evertype.com/standards/iso639/iso639-en.html
2004 ;; TERRITORY is a country code taken from ISO 3166
2005 ;; http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1/en_listp1.html.
2006 ;; CODESET and MODIFIER are implementation-dependent.
2008 ;; jasonr comments: MS Windows uses three letter codes for
2009 ;; languages instead of the two letter ISO codes that POSIX
2010 ;; uses. In most cases the first two letters are the same, so
2011 ;; most of the regexps in locale-language-names work. Japanese
2012 ;; and Chinese are exceptions, which are listed in the
2013 ;; non-standard section at the bottom of locale-language-names.
2015 ("aa_DJ" . "Latin-1") ; Afar
2018 ("af" . "Latin-1") ; Afrikaans
2019 ("am" "Ethiopic" utf-8) ; Amharic
2020 ("an" . "Latin-9") ; Aragonese
2021 ; ar Arabic glibc uses 8859-6
2024 ("az" . "UTF-8") ; Azerbaijani
2026 ("be" "Belarusian" cp1251) ; Belarusian [Byelorussian until early 1990s]
2027 ("bg" "Bulgarian" cp1251) ; Bulgarian
2030 ("bn" . "UTF-8") ; Bengali, Bangla
2032 ("br" . "Latin-1") ; Breton
2033 ("bs" . "Latin-2") ; Bosnian
2034 ("byn" . "UTF-8") ; Bilin; Blin
2035 ("ca" . "Latin-1") ; Catalan
2037 ("cs" "Czech" iso-8859-2)
2038 ("cy" "Welsh" iso-8859-14)
2039 ("da" . "Latin-1") ; Danish
2040 ("de" "German" iso-8859-1)
2042 ("el" "Greek" iso-8859-7)
2043 ;; Users who specify "en" explicitly typically want Latin-1, not ASCII.
2044 ;; That's actually what the GNU locales define, modulo things like
2046 ("en_IN" "English" utf-8) ; glibc uses utf-8 for English in India
2047 ("en" . "Latin-1") ; English
2048 ("eo" . "Latin-3") ; Esperanto
2049 ("es" "Spanish" iso-8859-1)
2050 ("et" . "Latin-1") ; Estonian
2051 ("eu" . "Latin-1") ; Basque
2052 ("fa" . "UTF-8") ; Persian
2053 ("fi" . "Latin-1") ; Finnish
2054 ("fj" . "Latin-1") ; Fiji
2055 ("fo" . "Latin-1") ; Faroese
2056 ("fr" "French" iso-8859-1) ; French
2057 ("fy" . "Latin-1") ; Frisian
2058 ("ga" . "Latin-1") ; Irish Gaelic (new orthography)
2059 ("gd" . "Latin-9") ; Scots Gaelic
2060 ("gez" "Ethiopic" utf-8) ; Geez
2061 ("gl" . "Latin-1") ; Gallegan; Galician
2063 ("gu" . "UTF-8") ; Gujarati
2064 ("gv" . "Latin-1") ; Manx Gaelic
2066 ("he" "Hebrew" iso-8859-8)
2067 ("hi" "Devanagari" utf-8) ; Hindi
2068 ("hr" "Croatian" iso-8859-2) ; Croatian
2069 ("hu" . "Latin-2") ; Hungarian
2072 ("id" . "Latin-1") ; Indonesian
2075 ("is" . "Latin-1") ; Icelandic
2076 ("it" "Italian" iso-8859-1) ; Italian
2078 ("iw" "Hebrew" iso-8859-8)
2079 ("ja" "Japanese" euc-jp)
2081 ("ka" "Georgian" georgian-ps) ; Georgian
2083 ("kl" . "Latin-1") ; Greenlandic
2085 ("kn" "Kannada" utf-8)
2086 ("ko" "Korean" euc-kr)
2089 ("kw" . "Latin-1") ; Cornish
2091 ("la" . "Latin-1") ; Latin
2092 ("lb" . "Latin-1") ; Luxemburgish
2093 ("lg" . "Laint-6") ; Ganda
2095 ("lo" "Lao" utf-8) ; Laothian
2096 ("lt" "Lithuanian" iso-8859-13)
2097 ("lv" . "Latvian") ; Latvian, Lettish
2099 ("mi" . "Latin-7") ; Maori
2100 ("mk" "Cyrillic-ISO" iso-8859-5) ; Macedonian
2101 ("ml" "Malayalam" utf-8)
2102 ("mn" . "UTF-8") ; Mongolian
2104 ("mr" "Devanagari" utf-8) ; Marathi
2105 ("ms" . "Latin-1") ; Malay
2106 ("mt" . "Latin-3") ; Maltese
2109 ("nb" . "Latin-1") ; Norwegian
2110 ("ne" "Devanagari" utf-8) ; Nepali
2111 ("nl" "Dutch" iso-8859-1)
2112 ("no" . "Latin-1") ; Norwegian
2113 ("oc" . "Latin-1") ; Occitan
2114 ("om_ET" . "UTF-8") ; (Afan) Oromo
2115 ("om" . "Latin-1") ; (Afan) Oromo
2117 ("pa" . "UTF-8") ; Punjabi
2118 ("pl" . "Latin-2") ; Polish
2120 ("pt" . "Latin-1") ; Portuguese
2122 ("rm" . "Latin-1") ; Rhaeto-Romanic
2124 ("ro" "Romanian" iso-8859-2)
2125 ("ru_RU" "Russian" iso-8859-5)
2126 ("ru_UA" "Russian" koi8-u)
2128 ("sa" . "Devanagari") ; Sanskrit
2130 ("se" . "UTF-8") ; Northern Sami
2132 ("sh" . "Latin-2") ; Serbo-Croatian
2134 ("sid" . "UTF-8") ; Sidamo
2135 ("sk" "Slovak" iso-8859-2)
2136 ("sl" "Slovenian" iso-8859-2)
2139 ("so_ET" "UTF-8") ; Somali
2140 ("so" "Latin-1") ; Somali
2141 ("sq" . "Latin-1") ; Albanian
2142 ("sr" . "Latin-2") ; Serbian (Latin alphabet)
2144 ("st" . "Latin-1") ; Sesotho
2146 ("sv" "Swedish" iso-8859-1) ; Swedish
2147 ("sw" . "Latin-1") ; Swahili
2148 ("ta" "Tamil" utf-8)
2149 ("te" . "UTF-8") ; Telugu
2150 ("tg" "Tajik" koi8-t)
2151 ("th" "Thai" tis-620)
2152 ("ti" "Ethiopic" utf-8) ; Tigrinya
2153 ("tig_ER" . "UTF-8") ; Tigre
2155 ("tl" . "Latin-1") ; Tagalog
2158 ("tr" "Turkish" iso-8859-9)
2160 ("tt" . "UTF-8") ; Tatar
2163 ("uk" "Ukrainian" koi8-u)
2164 ("ur" . "UTF-8") ; Urdu
2165 ("uz_UZ@cyrillic" . "UTF-8"); Uzbek
2166 ("uz" . "Latin-1") ; Uzbek
2167 ("vi" "Vietnamese" utf-8)
2169 ("wa" . "Latin-1") ; Walloon
2171 ("xh" . "Latin-1") ; Xhosa
2172 ("yi" . "Windows-1255") ; Yiddish
2175 ("zh_HK" . "Chinese-Big5")
2176 ("zh_TW" . "Chinese-Big5")
2177 ("zh_CN" . "Chinese-GB")
2178 ("zh" . "Chinese-GB")
2179 ; zh_CN.GB18030/GB18030 \
2181 ; zh_HK/BIG5-HKSCS \
2182 ("zu" . "Latin-1") ; Zulu
2184 ;; ISO standard locales
2186 ("posix$" . "ASCII")
2188 ;; The "IPA" Emacs language environment does not correspond
2189 ;; to any ISO 639 code, so let it stand for itself.
2192 ;; Nonstandard or obsolete language codes
2193 ("cz" . "Czech") ; e.g. Solaris 2.6
2194 ("ee" . "Latin-4") ; Estonian, e.g. X11R6.4
2195 ("iw" . "Hebrew") ; e.g. X11R6.4
2196 ("sp" . "Cyrillic-ISO") ; Serbian (Cyrillic alphabet), e.g. X11R6.4
2197 ("su" . "Latin-1") ; Finnish, e.g. Solaris 2.6
2198 ("jp" . "Japanese") ; e.g. MS Windows
2199 ("chs" . "Chinese-GB") ; MS Windows Chinese Simplified
2200 ("cht" . "Chinese-BIG5") ; MS Windows Chinese Traditional
2202 "Alist of locale regexps vs the corresponding languages and coding systems.
2203 Each element has these form:
2204 \(LOCALE-REGEXP LANG-ENV CODING-SYSTEM)
2205 The first element whose LOCALE-REGEXP matches the start of a
2206 downcased locale specifies the LANG-ENV \(language environtment)
2207 and CODING-SYSTEM corresponding to that locale. If there is no
2208 appropriate language environment, the element may have this form:
2209 \(LOCALE-REGEXP . LANG-ENV)
2210 In this case, LANG-ENV is one of generic language environments for an
2211 specific encoding such as \"Latin-1\" and \"UTF-8\".")
2213 (defconst locale-charset-language-names
2215 '((".*8859[-_]?1\\>" . "Latin-1")
2216 (".*8859[-_]?2\\>" . "Latin-2")
2217 (".*8859[-_]?3\\>" . "Latin-3")
2218 (".*8859[-_]?4\\>" . "Latin-4")
2219 (".*8859[-_]?9\\>" . "Latin-5")
2220 (".*8859[-_]?14\\>" . "Latin-8")
2221 (".*8859[-_]?15\\>" . "Latin-9")
2222 (".*utf\\(?:-?8\\)?\\>" . "UTF-8")
2223 ;; utf-8@euro exists, so put this last. (@euro really specifies
2224 ;; the currency, rather than the charset.)
2225 (".*@euro\\>" . "Latin-9")))
2226 "List of pairs of locale regexps and charset language names.
2227 The first element whose locale regexp matches the start of a downcased locale
2228 specifies the language name whose charset corresponds to that locale.
2229 This language name is used if the locale is not listed in
2230 `locale-language-names'")
2232 (defconst locale-preferred-coding-systems
2234 '((".*8859[-_]?1\\>" . iso-8859-1)
2235 (".*8859[-_]?2\\>" . iso-8859-2)
2236 (".*8859[-_]?3\\>" . iso-8859-3)
2237 (".*8859[-_]?4\\>" . iso-8859-4)
2238 (".*8859[-_]?9\\>" . iso-8859-9)
2239 (".*8859[-_]?14\\>" . iso-8859-14)
2240 (".*8859[-_]?15\\>" . iso-8859-15)
2241 (".*utf\\(?:-?8\\)?" . utf-8)
2242 ;; utf-8@euro exists, so put this after utf-8. (@euro really
2243 ;; specifies the currency, rather than the charset.)
2244 (".*@euro" . iso-8859-15)
2245 ("koi8-?r" . koi8-r)
2246 ("koi8-?u" . koi8-u)
2249 ("euc-?tw" . euc-tw)
2250 ;; We don't support GBK, but as it is upper compatible with
2251 ;; GB-2312, we setup the default coding system to gb2312.
2253 ;; We don't support BIG5-HKSCS, but as it is upper compatible with
2254 ;; BIG5, we setup the default coding system to big5.
2255 ("big5hkscs" . big5)
2256 ("ja.*[._]euc" . japanese-iso-8bit)
2257 ("ja.*[._]jis7" . iso-2022-jp)
2258 ("ja.*[._]pck" . japanese-shift-jis)
2259 ("ja.*[._]sjis" . japanese-shift-jis)
2260 ("jpn" . japanese-shift-jis) ; MS-Windows uses this.
2262 "List of pairs of locale regexps and preferred coding systems.
2263 The first element whose locale regexp matches the start of a downcased locale
2264 specifies the coding system to prefer when using that locale.
2265 This coding system is used if the locale specifies a specific charset.")
2267 (defun locale-name-match (key alist)
2268 "Search for KEY in ALIST, which should be a list of regexp-value pairs.
2269 Return the value corresponding to the first regexp that matches the
2270 start of KEY, or nil if there is no match."
2272 (while (and alist (not element))
2273 (if (string-match (concat "\\`\\(?:" (car (car alist)) "\\)") key)
2274 (setq element (car alist)))
2275 (setq alist (cdr alist)))
2278 (defun locale-charset-match-p (charset1 charset2)
2279 "Whether charset names (strings) CHARSET1 and CHARSET2 are equivalent.
2280 Matching is done ignoring case and any hyphens and underscores in the
2281 names. E.g. `ISO_8859-1' and `iso88591' both match `iso-8859-1'."
2282 (setq charset1 (replace-regexp-in-string "[-_]" "" charset1))
2283 (setq charset2 (replace-regexp-in-string "[-_]" "" charset2))
2284 (eq t (compare-strings charset1 nil nil charset2 nil nil t)))
2286 (defvar locale-charset-alist nil
2287 "Coding system alist keyed on locale-style charset name.
2288 Used by `locale-charset-to-coding-system'.")
2290 (defun locale-charset-to-coding-system (charset)
2291 "Find coding system corresponding to CHARSET.
2292 CHARSET is any sort of non-Emacs charset name, such as might be used
2293 in a locale codeset, or elsewhere. It is matched to a coding system
2294 first by case-insensitive lookup in `locale-charset-alist'. Then
2295 matches are looked for in the coding system list, treating case and
2296 the characters `-' and `_' as insignificant. The coding system base
2297 is returned. Thus, for instance, if charset \"ISO8859-2\",
2298 `iso-latin-2' is returned."
2299 (or (car (assoc-string charset locale-charset-alist t))
2300 (let ((cs coding-system-alist)
2302 (while (and (not c) cs)
2303 (if (locale-charset-match-p charset (caar cs))
2304 (setq c (intern (caar cs)))
2306 (if c (coding-system-base c)))))
2308 ;; Fixme: This ought to deal with the territory part of the locale
2309 ;; too, for setting things such as calendar holidays, ps-print paper
2310 ;; size, spelling dictionary.
2312 (defun set-locale-environment (&optional locale-name)
2313 "Set up multi-lingual environment for using LOCALE-NAME.
2314 This sets the language environment, the coding system priority,
2315 the default input method and sometimes other things.
2317 LOCALE-NAME should be a string which is the name of a locale supported
2318 by the system. Often it is of the form xx_XX.CODE, where xx is a
2319 language, XX is a country, and CODE specifies a character set and
2320 coding system. For example, the locale name \"ja_JP.EUC\" might name
2321 a locale for Japanese in Japan using the `japanese-iso-8bit'
2322 coding-system. The name may also have a modifier suffix, e.g. `@euro'
2325 If LOCALE-NAME is nil, its value is taken from the environment
2326 variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
2328 The locale names supported by your system can typically be found in a
2329 directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
2330 will be translated according to the table specified by
2331 `locale-translation-file-name'.
2333 See also `locale-charset-language-names', `locale-language-names',
2334 `locale-preferred-coding-systems' and `locale-coding-system'."
2335 (interactive "sSet environment for locale: ")
2337 ;; Do this at runtime for the sake of binaries possibly transported
2338 ;; to a system without X.
2339 (setq locale-translation-file-name
2341 '("/usr/lib/X11/locale/locale.alias" ; e.g. X11R6.4
2342 "/usr/X11R6/lib/X11/locale/locale.alias" ; XFree86, e.g. RedHat 4.2
2343 "/usr/openwin/lib/locale/locale.alias" ; e.g. Solaris 2.6
2345 ;; The following name appears after the X-related names above,
2346 ;; since the X-related names are what X actually uses.
2347 "/usr/share/locale/locale.alias" ; GNU/Linux sans X
2349 (while (and files (not (file-exists-p (car files))))
2350 (setq files (cdr files)))
2353 (let ((locale locale-name))
2356 ;; Use the first of these three environment variables
2357 ;; that has a nonempty value.
2358 (let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
2360 (= 0 (length locale))) ; nil or empty string
2361 (setq locale (getenv (pop vars))))))
2365 ;; Translate "swedish" into "sv_SE.ISO8859-1", and so on,
2366 ;; using the translation file that many systems have.
2367 (when locale-translation-file-name
2369 (set-buffer-multibyte nil)
2370 (insert-file-contents locale-translation-file-name)
2371 (when (re-search-forward
2372 (concat "^" (regexp-quote locale) ":?[ \t]+") nil t)
2373 (setq locale (buffer-substring (point) (line-end-position))))))
2375 ;; Leave the system locales alone if the caller did not specify
2376 ;; an explicit locale name, as their defaults are set from
2377 ;; LC_MESSAGES and LC_TIME, not LC_CTYPE, and the user might not
2378 ;; want to set them to the same value as LC_CTYPE.
2380 (setq system-messages-locale locale)
2381 (setq system-time-locale locale))
2383 (setq locale (downcase locale))
2385 (let ((language-name
2386 (locale-name-match locale locale-language-names))
2387 (charset-language-name
2388 (locale-name-match locale locale-charset-language-names))
2390 (or (locale-name-match locale locale-preferred-coding-systems)
2392 (if (string-match "\\.\\([^@]+\\)" locale)
2393 (locale-charset-to-coding-system
2394 (match-string 1 locale)))))))
2396 (if (consp language-name)
2397 ;; locale-language-names specify both lang-env and coding.
2398 ;; But, what specified in locale-preferred-coding-systems
2399 ;; has higher priority.
2400 (setq coding-system (or coding-system
2401 (nth 1 language-name))
2402 language-name (car language-name))
2403 ;; Otherwise, if locale is not listed in locale-language-names,
2404 ;; use what listed in locale-charset-language-names.
2405 (if (not language-name)
2406 (setq language-name charset-language-name)))
2410 ;; Set up for this character set. This is now the right way
2411 ;; to do it for both unibyte and multibyte modes.
2412 (set-language-environment language-name)
2414 ;; If default-enable-multibyte-characters is nil,
2415 ;; we are using single-byte characters,
2416 ;; so the display table and terminal coding system are irrelevant.
2417 (when default-enable-multibyte-characters
2418 (set-display-table-and-terminal-coding-system language-name))
2420 ;; Set the `keyboard-coding-system' if appropriate (tty
2421 ;; only). At least X and MS Windows can generate
2422 ;; multilingual input.
2423 (unless window-system
2424 (let ((kcs (or coding-system
2425 (car (get-language-info language-name
2427 (if kcs (set-keyboard-coding-system kcs))))
2429 (setq locale-coding-system
2430 (car (get-language-info language-name 'coding-priority))))
2432 (when (and coding-system
2433 (not (coding-system-equal coding-system
2434 locale-coding-system)))
2435 (prefer-coding-system coding-system)
2436 (setq locale-coding-system coding-system))
2437 (when (get-language-info current-language-environment 'coding-priority)
2438 (let ((codeset (locale-info 'codeset))
2439 (coding-system (car (coding-system-priority-list))))
2441 (let ((cs (coding-system-aliases coding-system))
2443 (while (and cs (not result))
2445 (locale-charset-match-p (symbol-name (pop cs))
2446 (locale-info 'codeset))))
2448 (message "Warning: Default coding system `%s' disagrees with
2449 system codeset `%s' for this locale." coding-system codeset))))))))
2451 ;; On Windows, override locale-coding-system,
2452 ;; keyboard-coding-system with system codepage. Note:
2453 ;; selection-coding-system is already set in w32select.c.
2454 (when (boundp 'w32-ansi-code-page)
2455 (let ((code-page-coding (intern (format "cp%d" w32-ansi-code-page))))
2456 (when (coding-system-p code-page-coding)
2457 (setq locale-coding-system code-page-coding)
2458 (set-keyboard-coding-system code-page-coding)
2459 (set-terminal-coding-system code-page-coding))))
2461 ;; On Darwin, file names are always encoded in utf-8, no matter the locale.
2462 (when (eq system-type 'darwin)
2463 (setq default-file-name-coding-system 'utf-8))
2465 ;; Default to A4 paper if we're not in a C, POSIX or US locale.
2466 ;; (See comments in Flocale_info.)
2467 (let ((locale locale)
2468 (paper (locale-info 'paper)))
2470 ;; This will always be null at the time of writing.
2472 ((equal paper '(216 279))
2473 (setq ps-paper-type 'letter))
2474 ((equal paper '(210 297))
2475 (setq ps-paper-type 'a4)))
2476 (let ((vars '("LC_ALL" "LC_PAPER" "LANG")))
2477 (while (and vars (= 0 (length locale)))
2478 (setq locale (getenv (pop vars)))))
2480 ;; As of glibc 2.2.5, these are the only US Letter locales,
2481 ;; and the rest are A4.
2483 (or (locale-name-match locale '(("c$" . letter)
2488 ("enu$" . letter) ; Windows
2495 ;;; Character property
2497 ;; Each element has the form (PROP . TABLE).
2498 ;; PROP is a symbol representing a character property.
2499 ;; TABLE is a char-table containing the property value for each character.
2500 ;; TABLE may be a name of file to load to build a char-table.
2501 ;; Don't modify this variable directly but use `define-char-code-property'.
2503 (defvar char-code-property-alist nil
2504 "Alist of character property name vs char-table containing property values.
2505 Internal use only.")
2507 (put 'char-code-property-table 'char-table-extra-slots 5)
2509 (defun define-char-code-property (name table &optional docstring)
2510 "Define NAME as a character code property given by TABLE.
2511 TABLE is a char-table of purpose `char-code-property-table' with
2514 2nd: Function to call to get a property value of a character.
2515 It is called with three arugments CHAR, VAL, and TABLE, where
2516 CHAR is a character, VAL is the value of (aref TABLE CHAR).
2517 3rd: Function to call to put a property value of a character.
2518 It is called with the same arguments as above.
2519 4th: Function to call to get a description string of a property value.
2520 It is called with one argument VALUE, a property value.
2521 5th: Data used by the above functions.
2523 TABLE may be a name of file to load to build a char-table. The
2524 file should contain a call of `define-char-code-property' with a
2525 char-table of the above format as the argument TABLE.
2527 TABLE may also be nil, in which case no property value is pre-assigned.
2529 Optional 3rd argment DOCSTRING is a documentation string of the property.
2531 See also the documentation of `get-char-code-property' and
2532 `put-char-code-property'."
2534 (error "Not a symbol: %s" name))
2535 (if (char-table-p table)
2536 (or (and (eq (char-table-subtype table) 'char-code-property-table)
2537 (eq (char-table-extra-slot table 0) name))
2538 (error "Invalid char-table: %s" table))
2540 (error "Not a char-table nor a file name: %s" table)))
2541 (let ((slot (assq name char-code-property-alist)))
2544 (setq char-code-property-alist
2545 (cons (cons name table) char-code-property-alist))))
2546 (put name 'char-code-property-documentation docstring))
2548 (defvar char-code-property-table
2549 (make-char-table 'char-code-property-table)
2550 "Char-table containing a property list of each character code.
2551 This table is used for properties not listed in `char-code-property-alist'.
2552 See also the documentation of `get-char-code-property' and
2553 `put-char-code-property'.")
2555 (defun get-char-code-property (char propname)
2556 "Return the value of CHAR's PROPNAME property."
2557 (let ((slot (assq propname char-code-property-alist)))
2559 (let (table value func)
2560 (if (stringp (cdr slot))
2562 (setq table (cdr slot)
2563 value (aref table char)
2564 func (char-table-extra-slot table 1))
2565 (if (functionp func)
2566 (setq value (funcall func char value table)))
2568 (plist-get (aref char-code-property-table char) propname))))
2570 (defun put-char-code-property (char propname value)
2571 "Store CHAR's PROPNAME property with VALUE.
2572 It can be retrieved with `(get-char-code-property CHAR PROPNAME)'."
2573 (let ((slot (assq propname char-code-property-alist)))
2576 (if (stringp (cdr slot))
2578 (setq table (cdr slot)
2579 func (char-table-extra-slot table 2))
2580 (if (functionp func)
2581 (funcall func char value table)
2582 (aset table char value)))
2583 (let* ((plist (aref char-code-property-table char))
2584 (x (plist-put plist propname value)))
2586 (aset char-code-property-table char x))))
2589 (defun char-code-property-description (prop value)
2590 "Return a description string of character property PROP's value VALUE.
2591 If there's no description string for VALUE, return nil."
2592 (let ((slot (assq prop char-code-property-alist)))
2595 (if (stringp (cdr slot))
2597 (setq table (cdr slot)
2598 func (char-table-extra-slot table 3))
2599 (if (functionp func)
2600 (funcall func value))))))
2603 ;; Pretty description of encoded string
2605 ;; Alist of ISO 2022 control code vs the corresponding mnemonic string.
2606 (defvar iso-2022-control-alist
2614 (defun encoded-string-description (str coding-system)
2615 "Return a pretty description of STR that is encoded by CODING-SYSTEM."
2616 (setq str (string-as-unibyte str))
2618 (if (and coding-system (eq (coding-system-type coding-system) 'iso-2022))
2619 ;; Try to get a pretty description for ISO 2022 escape sequences.
2620 (function (lambda (x) (or (cdr (assq x iso-2022-control-alist))
2621 (format "0x%02X" x))))
2622 (function (lambda (x) (format "0x%02X" x))))
2625 (defun encode-coding-char (char coding-system)
2626 "Encode CHAR by CODING-SYSTEM and return the resulting string.
2627 If CODING-SYSTEM can't safely encode CHAR, return nil."
2628 (let ((str1 (string-as-multibyte (string char)))
2629 (str2 (string-as-multibyte (string char char)))
2631 (when (memq (coding-system-base coding-system)
2632 (find-coding-systems-string str1))
2633 ;; We must find the encoded string of CHAR. But, just encoding
2634 ;; CHAR will put extra control sequences (usually to designate
2635 ;; ASCII charset) at the tail if type of CODING is ISO 2022.
2636 ;; To exclude such tailing bytes, we at first encode one-char
2637 ;; string and two-char string, then check how many bytes at the
2638 ;; tail of both encoded strings are the same.
2640 (setq enc1 (encode-coding-string str1 coding-system)
2642 enc2 (encode-coding-string str2 coding-system)
2644 (while (and (> i1 0) (= (aref enc1 (1- i1)) (aref enc2 (1- i2))))
2645 (setq i1 (1- i1) i2 (1- i2)))
2647 ;; Now (substring enc1 i1) and (substring enc2 i2) are the same,
2648 ;; and they are the extra control sequences at the tail to
2650 (substring enc2 0 i2))))
2652 ;; Backwards compatibility. These might be better with :init-value t,
2653 ;; but that breaks loadup.
2654 (define-minor-mode unify-8859-on-encoding-mode
2658 (define-minor-mode unify-8859-on-decoding-mode
2663 (defvar nonascii-insert-offset 0 "This variable is obsolete.")
2664 (defvar nonascii-translation-table nil "This variable is obsolete.")
2667 ;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc
2668 ;;; mule-cmds.el ends here