-;;; mule-cmds.el --- commands for mulitilingual environment -*-coding: iso-2022-7bit -*-
+;;; mule-cmds.el --- commands for multilingual environment -*-coding: iso-2022-7bit -*-
;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-;; 2006 Free Software Foundation, Inc.
+;; 2006, 2007 Free Software Foundation, Inc.
;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006
+;; 2005, 2006, 2007
;; National Institute of Advanced Industrial Science and Technology (AIST)
;; Registration Number H14PRO021
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
t)
(define-key-after set-coding-system-map [set-terminal-coding-system]
'(menu-item "For Terminal" set-terminal-coding-system
- :enable (null (memq window-system '(x w32 mac)))
+ :enable (null (memq initial-window-system '(x w32 mac)))
:help "How to encode terminal output")
t)
(define-key-after set-coding-system-map [separator-3]
"`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'")))
(defun coding-system-change-eol-conversion (coding-system eol-type)
- "Return a coding system which differs from CODING-SYSTEM in eol conversion.
+ "Return a coding system which differs from CODING-SYSTEM in EOL conversion.
The returned coding system converts end-of-line by EOL-TYPE
but text as the same way as CODING-SYSTEM.
EOL-TYPE should be `unix', `dos', `mac', or nil.
In general, therefore, this command *changes* the sequence of
characters that the current buffer contains.
-We suggest you avoid using use this command unless you know what you
-are doing. If you use it by mistake, and the buffer is now displayed
+We suggest you avoid using this command unless you know what you are
+doing. If you use it by mistake, and the buffer is now displayed
wrong, use this command again to toggle back to the right mode."
(interactive "P")
(let ((new-flag
o default coding system for subprocess I/O
This also sets the following values:
o default value used as `file-name-coding-system' for converting file names
- if CODING-SYSTEM is ASCII-compatible.
+ if CODING-SYSTEM is ASCII-compatible
o default value for the command `set-terminal-coding-system' (not on MSDOS)
o default value for the command `set-keyboard-coding-system'
- if CODING-SYSTEM is ASCII-compatible.."
+ if CODING-SYSTEM is ASCII-compatible"
(check-coding-system coding-system)
(setq-default buffer-file-coding-system coding-system)
(if (fboundp 'ucs-set-table-for-input)
o coding system of a newly created buffer
o default coding system for subprocess I/O
This also sets the following values:
- o default value used as `file-name-coding-system' for converting file names.
+ o default value used as `file-name-coding-system' for converting file names
o default value for the command `set-terminal-coding-system' (not on MSDOS)
o default value for the command `set-keyboard-coding-system'
(defun sort-coding-systems (codings)
"Sort coding system list CODINGS by a priority of each coding system.
-Returns the sorted list. CODINGS is modified by side effects.
+Return the sorted list. CODINGS is modified by side effects.
If a coding system is most preferred, it has the highest priority.
-Otherwise, a coding system corresponds to some MIME charset has higher
-priorities. Among them, a coding system included in `coding-system'
-key of the current language environment has higher priorities. See
-also the documentation of `language-info-alist'.
+Otherwise, coding systems that correspond to MIME charsets have
+higher priorities. Among them, a coding system included in the
+`coding-system' key of the current language environment has higher
+priority. See also the documentation of `language-info-alist'.
If the variable `sort-coding-systems-predicate' (which see) is
-non-nil, it is used to sort CODINGS in the different way than above."
+non-nil, it is used to sort CODINGS instead."
(if sort-coding-systems-predicate
(sort codings sort-coding-systems-predicate)
(let* ((from-categories (mapcar #'(lambda (x) (symbol-value x))
(let ((base (coding-system-base x)))
;; We calculate the priority number 0..255 by
;; using the 8 bits PMMLCEII as this:
- ;; P: 1 iff most preferred.
- ;; MM: greater than 0 iff mime-charset.
- ;; L: 1 iff one of the current lang. env.'s codings.
- ;; C: 1 iff one of codings listed in the category list.
- ;; E: 1 iff not XXX-with-esc
+ ;; P: 1 if most preferred.
+ ;; MM: greater than 0 if mime-charset.
+ ;; L: 1 if one of the current lang. env.'s codings.
+ ;; C: 1 if one of codings listed in the category list.
+ ;; E: 1 if not XXX-with-esc
;; II: if iso-2022 based, 0..3, else 1.
(logior
(lsh (if (eq base most-preferred) 1 0) 7)
COUNT is a number of characters,
CHARs are the characters found from the character set.
Optional 3rd arg MAXCOUNT limits how many CHARs are put in the above list.
-Optional 4th arg EXCLUDE is a list of character sets to be ignored.
+Optional 4th arg EXCLUDES is a list of character sets to be ignored.
For invalid characters, CHARs are actually strings."
(let ((chars nil)
If such a character is found, set point after that character.
Otherwise, don't move point.
-When called from a program, the value is a position of the found character,
-or nil if all characters are encodable."
+When called from a program, the value is the position of the unencodable
+character found, or nil if all characters are encodable."
(interactive
(list (let ((default (or buffer-file-coding-system 'us-ascii)))
(read-coding-system
(defvar leim-list-entry-regexp "^(register-input-method"
"Regexp matching head of each entry in LEIM list file.
-See also the variable `leim-list-header'")
+See also the variable `leim-list-header'.")
(defvar update-leim-list-functions
'(quail-update-leim-list-file)
which marks the variable `default-input-method' as set for Custom buffers.
To deactivate the input method interactively, use \\[toggle-input-method].
-To deactivate it programmatically, use \\[inactivate-input-method]."
+To deactivate it programmatically, use `inactivate-input-method'."
(interactive
(let* ((default (or (car input-method-history) default-input-method)))
(list (read-input-method-name
(customize-mark-as-set 'default-input-method))
default-input-method)
+(defvar toggle-input-method-active nil
+ "Non-nil inside `toggle-input-method'.")
+
(defun toggle-input-method (&optional arg interactive)
"Enable or disable multilingual text input method for the current buffer.
Only one input method can be enabled at any time in a given buffer.
which marks the variable `default-input-method' as set for Custom buffers."
(interactive "P\np")
+ (if toggle-input-method-active
+ (error "Recursive use of `toggle-input-method'"))
(if (and current-input-method (not arg))
(inactivate-input-method)
- (let ((default (or (car input-method-history) default-input-method)))
+ (let ((toggle-input-method-active t)
+ (default (or (car input-method-history) default-input-method)))
(if (and arg default (equal current-input-method default)
(> (length input-method-history) 1))
(setq default (nth 1 input-method-history)))
"This flag controls when an input method returns.
Usually, the input method does not return while there's a possibility
that it may find a different translation if a user types another key.
-But, it this flag is non-nil, the input method returns as soon as
+But, if this flag is non-nil, the input method returns as soon as
the current key sequence gets long enough to have some valid translation.")
(defvar input-method-use-echo-area nil
is still bound to the language environment being exited.
This hook is mainly used for canceling the effect of
-`set-language-environment-hook' (which-see).")
+`set-language-environment-hook' (which see).")
(put 'setup-specified-language-environment 'apropos-inhibit t)
(reset-language-environment)
-(defun set-display-table-and-terminal-coding-system (language-name &optional coding-system)
+(defun set-display-table-and-terminal-coding-system (language-name &optional coding-system display)
"Set up the display table and terminal coding system for LANGUAGE-NAME."
(let ((coding (get-language-info language-name 'unibyte-display)))
(if (and coding
(dotimes (i 128)
(aset standard-display-table (+ i 128) nil))))
(or (eq window-system 'pc)
- (set-terminal-coding-system (or coding-system coding)))))
+ (set-terminal-coding-system (or coding-system coding) display))))
(defun set-language-environment (language-name)
"Set up multi-lingual environment for using LANGUAGE-NAME.
(set-display-table-and-terminal-coding-system language-name))
(defsubst princ-list (&rest args)
- "Print all arguments with `princ', then print \"\n\"."
+ "Print all arguments with `princ', then print \"\\n\"."
(while args (princ (car args)) (setq args (cdr args)))
(princ "\n"))
;; en_IN -- fx.
("en_IN" "English" utf-8) ; glibc uses utf-8 for English in India
("en" "English" iso-8859-1) ; English
- ("eo" . "Latin-3") ; Esperanto
+ ("eo" . "Esperanto") ; Esperanto
("es" "Spanish" iso-8859-1)
("et" . "Latin-1") ; Estonian
("eu" . "Latin-1") ; Basque
("wen" . "Latin-2") ; MS Windows Upper Sorbian
))
"Alist of locale regexps vs the corresponding languages and coding systems.
-Each element has these form:
+Each element has this form:
\(LOCALE-REGEXP LANG-ENV CODING-SYSTEM)
The first element whose LOCALE-REGEXP matches the start of a
-downcased locale specifies the LANG-ENV \(language environtment)
+downcased locale specifies the LANG-ENV \(language environment)
and CODING-SYSTEM corresponding to that locale. If there is no
appropriate language environment, the element may have this form:
\(LOCALE-REGEXP . LANG-ENV)
The first element whose locale regexp matches the start of a downcased locale
specifies the language name whose charset corresponds to that locale.
This language name is used if the locale is not listed in
-`locale-language-names'")
+`locale-language-names'.")
(defconst locale-preferred-coding-systems
(purecopy
;; too, for setting things such as calendar holidays, ps-print paper
;; size, spelling dictionary.
-(defun set-locale-environment (&optional locale-name)
+(defun set-locale-environment (&optional locale-name frame)
"Set up multi-lingual environment for using LOCALE-NAME.
This sets the language environment, the coding system priority,
the default input method and sometimes other things.
will be translated according to the table specified by
`locale-translation-file-name'.
+If FRAME is non-nil, only set the keyboard coding system and the
+terminal coding system for the terminal of that frame, and don't
+touch session-global parameters like the language environment.
+
See also `locale-charset-language-names', `locale-language-names',
`locale-preferred-coding-systems' and `locale-coding-system'."
(interactive "sSet environment for locale: ")
(let ((vars '("LC_ALL" "LC_CTYPE" "LANG")))
(while (and vars
(= 0 (length locale))) ; nil or empty string
- (setq locale (getenv (pop vars))))))
+ (setq locale (getenv (pop vars) frame)))))
(unless locale
;; The two tests are kept separate so the byte-compiler sees
;; Set up for this character set. This is now the right way
;; to do it for both unibyte and multibyte modes.
- (set-language-environment language-name)
+ (unless frame
+ (set-language-environment language-name))
;; If default-enable-multibyte-characters is nil,
;; we are using single-byte characters,
;; so the display table and terminal coding system are irrelevant.
(when default-enable-multibyte-characters
(set-display-table-and-terminal-coding-system
- language-name coding-system))
+ language-name coding-system frame))
;; Set the `keyboard-coding-system' if appropriate (tty
;; only). At least X and MS Windows can generate
;; multilingual input.
- (unless window-system
- (let ((kcs (or coding-system
- (car (get-language-info language-name
- 'coding-system)))))
- (if kcs (set-keyboard-coding-system kcs))))
-
- (setq locale-coding-system
- (car (get-language-info language-name 'coding-priority))))
-
- (when (and coding-system
+ ;; XXX This was disabled unless `window-system', but that
+ ;; leads to buggy behaviour when a tty frame is opened
+ ;; later. Setting the keyboard coding system has no adverse
+ ;; effect on X, so let's do it anyway. -- Lorentey
+ (let ((kcs (or coding-system
+ (car (get-language-info language-name
+ 'coding-system)))))
+ (if kcs (set-keyboard-coding-system kcs frame)))
+
+ (unless frame
+ (setq locale-coding-system
+ (car (get-language-info language-name 'coding-priority)))))
+
+ (when (and (not frame)
+ coding-system
(not (coding-system-equal coding-system
locale-coding-system)))
(prefer-coding-system coding-system)
(setq locale-coding-system coding-system))))
;; On Windows, override locale-coding-system,
- ;; keyboard-coding-system with system codepage. Note:
- ;; selection-coding-system is already set in w32select.c.
+ ;; default-file-name-coding-system, keyboard-coding-system,
+ ;; terminal-coding-system with system codepage.
(when (boundp 'w32-ansi-code-page)
(let ((code-page-coding (intern (format "cp%d" w32-ansi-code-page))))
(when (coding-system-p code-page-coding)
- (setq locale-coding-system code-page-coding)
- (set-keyboard-coding-system code-page-coding)
- (set-terminal-coding-system code-page-coding))))
+ (unless frame (setq locale-coding-system code-page-coding))
+ (set-keyboard-coding-system code-page-coding frame)
+ (set-terminal-coding-system code-page-coding frame)
+ ;; Set default-file-name-coding-system last, so that Emacs
+ ;; doesn't try to use cpNNNN when it defines keyboard and
+ ;; terminal encoding. That's because the above two lines
+ ;; will want to load code-pages.el, where cpNNNN are
+ ;; defined; if default-file-name-coding-system were set to
+ ;; cpNNNN while these two lines run, Emacs will want to use
+ ;; it for encoding the file name it wants to load. And that
+ ;; will fail, since cpNNNN is not yet usable until
+ ;; code-pages.el finishes loading.
+ (setq default-file-name-coding-system code-page-coding))))
(when (eq system-type 'darwin)
;; On Darwin, file names are always encoded in utf-8, no matter
;; Mac OS X's Terminal.app by default uses utf-8 regardless of
;; the locale.
(when (and (null window-system)
- (equal (getenv "TERM_PROGRAM") "Apple_Terminal"))
+ (equal (getenv "TERM_PROGRAM" frame) "Apple_Terminal"))
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)))
;; Default to A4 paper if we're not in a C, POSIX or US locale.
;; (See comments in Flocale_info.)
- (let ((locale locale)
- (paper (locale-info 'paper)))
- (if paper
- ;; This will always be null at the time of writing.
- (cond
- ((equal paper '(216 279))
- (setq ps-paper-type 'letter))
- ((equal paper '(210 297))
- (setq ps-paper-type 'a4)))
- (let ((vars '("LC_ALL" "LC_PAPER" "LANG")))
- (while (and vars (= 0 (length locale)))
- (setq locale (getenv (pop vars)))))
- (when locale
- ;; As of glibc 2.2.5, these are the only US Letter locales,
- ;; and the rest are A4.
- (setq ps-paper-type
- (or (locale-name-match locale '(("c$" . letter)
- ("posix$" . letter)
- (".._us" . letter)
- (".._pr" . letter)
- (".._ca" . letter)
- ("enu$" . letter) ; Windows
- ("esu$" . letter)
- ("enc$" . letter)
- ("frc$" . letter)))
- 'a4))))))
+ (unless frame
+ (let ((locale locale)
+ (paper (locale-info 'paper)))
+ (if paper
+ ;; This will always be null at the time of writing.
+ (cond
+ ((equal paper '(216 279))
+ (setq ps-paper-type 'letter))
+ ((equal paper '(210 297))
+ (setq ps-paper-type 'a4)))
+ (let ((vars '("LC_ALL" "LC_PAPER" "LANG")))
+ (while (and vars (= 0 (length locale)))
+ (setq locale (getenv (pop vars) frame))))
+ (when locale
+ ;; As of glibc 2.2.5, these are the only US Letter locales,
+ ;; and the rest are A4.
+ (setq ps-paper-type
+ (or (locale-name-match locale '(("c$" . letter)
+ ("posix$" . letter)
+ (".._us" . letter)
+ (".._pr" . letter)
+ (".._ca" . letter)
+ ("enu$" . letter) ; Windows
+ ("esu$" . letter)
+ ("enc$" . letter)
+ ("frc$" . letter)))
+ 'a4)))))))
nil)
\f
;;; Charset property