;;; mule-cmds.el --- commands for multilingual environment -*-coding: iso-2022-7bit -*-
;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
-;; 2007, 2008 Free Software Foundation, Inc.
+;; 2007, 2008, 2009 Free Software Foundation, Inc.
;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-;; 2005, 2006, 2007, 2008
+;; 2005, 2006, 2007, 2008, 2009
;; National Institute of Advanced Industrial Science and Technology (AIST)
;; Registration Number H14PRO021
;; Copyright (C) 2003
(if coding coding 'undecided)
(if (numberp eol-type) (aref [unix dos mac] eol-type)))))
+;; Canonicalize the coding system name NAME by removing some prefixes
+;; and delimiter characters. Support function of
+;; coding-system-from-name.
+(defun canonicalize-coding-system-name (name)
+ (if (string-match "^iso[-_ ]?[0-9]" name)
+ ;; "iso-8859-1" -> "8859-1", "iso-2022-jp" ->"2022-jp"
+ (setq name (substring name (1- (match-end 0)))))
+ (let ((idx (string-match "[-_ /]" name)))
+ ;; Delete "-", "_", " ", "/" but do distinguish "16-be" and "16be".
+ (while idx
+ (if (and (>= idx 2)
+ (eq (string-match "16-[lb]e$" name (- idx 2))
+ (- idx 2)))
+ (setq idx (string-match "[-_ /]" name (match-end 0)))
+ (setq name (concat (substring name 0 idx) (substring name (1+ idx)))
+ idx (string-match "[-_ /]" name idx))))
+ name))
+
+(defun coding-system-from-name (name)
+ "Return a coding system whose name matches with NAME (string or symbol)."
+ (let (sym)
+ (if (stringp name) (setq sym (intern name))
+ (setq sym name name (symbol-name name)))
+ (if (coding-system-p sym)
+ sym
+ (let ((eol-type
+ (if (string-match "-\\(unix\\|dos\\|mac\\)$" name)
+ (prog1 (intern (match-string 1 name))
+ (setq name (substring name 0 (match-beginning 0)))))))
+ (setq name (canonicalize-coding-system-name (downcase name)))
+ (catch 'tag
+ (dolist (elt (coding-system-list))
+ (if (string= (canonicalize-coding-system-name (symbol-name elt))
+ name)
+ (throw 'tag (if eol-type (coding-system-change-eol-conversion
+ elt eol-type)
+ elt)))))))))
+
(defun toggle-enable-multibyte-characters (&optional arg)
"Change whether this buffer uses multibyte characters.
-With arg, use multibyte characters if the arg is positive.
+With ARG, use multibyte characters if the ARG is positive.
Note that this command does not convert the byte contents of
the buffer; it only changes the way those bytes are interpreted.
(format "Command to execute with %s:" coding-system)))
(cmd (key-binding keyseq))
prefix)
-
- (when (eq cmd 'universal-argument)
+ ;; read-key-sequence ignores quit, so make an explicit check.
+ ;; Like many places, this assumes quit == C-g, but it need not be.
+ (if (equal last-input-event ?\C-g)
+ (keyboard-quit))
+ (when (memq cmd '(universal-argument digit-argument))
(call-interactively cmd)
;; Process keys bound in `universal-argument-map'.
cmd (key-binding keyseq t))
(not (eq cmd 'universal-argument-other-key)))
(let ((current-prefix-arg prefix-arg)
- ;; Have to bind `last-command-char' here so that
+ ;; Have to bind `last-command-event' here so that
;; `digit-argument', for instance, can compute the
;; prefix arg.
- (last-command-char (aref keyseq 0)))
+ (last-command-event (aref keyseq 0)))
(call-interactively cmd)))
;; This is the final call to `universal-argument-other-key', which
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
- o default value for the command `set-terminal-coding-system' (not on MSDOS)
+ o default value for the command `set-terminal-coding-system'
o default value for the command `set-keyboard-coding-system'
if CODING-SYSTEM is ASCII-compatible"
(check-coding-system coding-system)
(or (not coding-system)
(coding-system-get coding-system 'ascii-compatible-p)))
(setq default-file-name-coding-system coding-system)))
- ;; If coding-system is nil, honor that on MS-DOS as well, so
- ;; that they could reset the terminal coding system.
- (unless (and (eq window-system 'pc) coding-system)
- (setq default-terminal-coding-system coding-system))
+ (setq default-terminal-coding-system coding-system)
(setq default-keyboard-coding-system coding-system)
;; Preserve eol-type from existing default-process-coding-systems.
;; On non-unix-like systems in particular, these may have been set
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 for the command `set-terminal-coding-system' (not on MSDOS)
+ o default value for the command `set-terminal-coding-system'
o default value for the command `set-keyboard-coding-system'
If CODING-SYSTEM specifies a certain type of EOL conversion, the coding
systems set by this function will use that type of EOL conversion.
-This command does not change the default value of terminal coding system
-for MS-DOS terminal, because DOS terminals only support a single coding
-system, and Emacs automatically sets the default to that coding system at
-startup.
-
-A coding system that requires automatic detection of text
-+encoding (e.g. undecided, unix) can't be preferred.."
+A coding system that requires automatic detection of text+encoding
+\(e.g. undecided, unix) can't be preferred."
(interactive "zPrefer coding system: ")
(if (not (and coding-system (coding-system-p coding-system)))
(error "Invalid coding system `%s'" coding-system))
;; Lower utf-16 priority so that we
;; normally prefer utf-8 to it, and put
;; x-ctext below that.
- (cond ((string-match "utf-16"
- (symbol-name mime))
+ (cond ((string-match-p "utf-16"
+ (symbol-name mime))
2)
- ((string-match "^x-" (symbol-name mime))
+ ((string-match-p "^x-" (symbol-name mime))
1)
(t 3))
0))
5)
(lsh (if (memq base lang-preferred) 1 0) 4)
(lsh (if (memq base from-priority) 1 0) 3)
- (lsh (if (string-match "-with-esc\\'"
- (symbol-name base))
+ (lsh (if (string-match-p "-with-esc\\'"
+ (symbol-name base))
0 1) 2)
(if (eq (coding-system-type base) 'iso-2022)
(let ((category (coding-system-category base)))
This only finds coding systems of type `charset', whose
`:charset-list' property includes all of CHARSETS (plus `ascii' for
-ascii-compatible coding systems). It was used in older versions of
+ASCII-compatible coding systems). It was used in older versions of
Emacs, but is unlikely to be what you really want now."
;; Deal with aliases.
(setq charsets (mapcar (lambda (c)
(if (stringp from)
(if (multibyte-string-p from)
(let ((idx 0))
- (while (setq idx (string-match "[^\000-\177]" from idx))
+ (while (setq idx (string-match-p "[^\000-\177]" from idx))
(setq char (aref from idx)
charset (char-charset char))
(unless (memq charset excludes)
between FROM and TO are shown in a popup window. Among them, the most
proper one is suggested as the default.
-The list of `buffer-file-coding-system' of the current buffer,
-the `default-buffer-file-coding-system', and the
-most preferred coding system (if it corresponds to a MIME charset) is
-treated as the default coding system list. Among them, the first one
-that safely encodes the text is normally selected silently and
-returned without any user interaction. See also the command
-`prefer-coding-system'.
+The list of `buffer-file-coding-system' of the current buffer, the
+`default-buffer-file-coding-system', and the most preferred coding
+system (if it corresponds to a MIME charset) is treated as the
+default coding system list. Among them, the first one that safely
+encodes the text is normally selected silently and returned without
+any user interaction. See also the command `prefer-coding-system'.
However, the user is queried if the chosen coding system is
inconsistent with what would be selected by `find-auto-coding' from
That is different from `buffer-file-name' when handling `write-region'
\(for example).
-The variable `select-safe-coding-system-accept-default-p', if
-non-nil, overrides ACCEPT-DEFAULT-P.
+The variable `select-safe-coding-system-accept-default-p', if non-nil,
+overrides ACCEPT-DEFAULT-P.
Kludgy feature: if FROM is a string, the string is the target text,
and TO is ignored."
(if (coding-system-p (car auto-cs))
(setq auto-cs (car auto-cs))
(display-warning
- :warning
+ 'mule
(format "\
Invalid coding system `%s' is specified
for the current buffer/file by the %s.
It is highly recommended to fix it before writing to a file."
(car auto-cs)
(if (eq (cdr auto-cs) :coding) ":coding tag"
- (format "variable `%s'" (cdr auto-cs)))))
+ (format "variable `%s'" (cdr auto-cs))))
+ :warning)
(or (yes-or-no-p "Really proceed with writing? ")
(error "Save aborted"))
(setq auto-cs nil))))))
(append default-coding-system
(list (cons buffer-file-coding-system base)))))))
- ;; If default-buffer-file-coding-system is not nil nor undecided,
- ;; append it to the defaults.
- (if default-buffer-file-coding-system
- (let ((base (coding-system-base default-buffer-file-coding-system)))
- (or (eq base 'undecided)
- (rassq base default-coding-system)
- (setq default-coding-system
- (append default-coding-system
- (list (cons default-buffer-file-coding-system
- base)))))))
-
- ;; If the most preferred coding system has the property mime-charset,
- ;; append it to the defaults.
- (let ((preferred (coding-system-priority-list t))
- base)
- (and (coding-system-p preferred)
- (setq base (coding-system-base preferred))
- (coding-system-get preferred :mime-charset)
- (not (rassq base default-coding-system))
- (setq default-coding-system
- (append default-coding-system
- (list (cons preferred base)))))))
+ (unless (and buffer-file-coding-system-explicit
+ (cdr buffer-file-coding-system-explicit))
+ ;; If default-buffer-file-coding-system is not nil nor undecided,
+ ;; append it to the defaults.
+ (if default-buffer-file-coding-system
+ (let ((base (coding-system-base default-buffer-file-coding-system)))
+ (or (eq base 'undecided)
+ (rassq base default-coding-system)
+ (setq default-coding-system
+ (append default-coding-system
+ (list (cons default-buffer-file-coding-system
+ base)))))))
+
+ ;; If the most preferred coding system has the property mime-charset,
+ ;; append it to the defaults.
+ (let ((preferred (coding-system-priority-list t))
+ base)
+ (and (coding-system-p preferred)
+ (setq base (coding-system-base preferred))
+ (coding-system-get preferred :mime-charset)
+ (not (rassq base default-coding-system))
+ (setq default-coding-system
+ (append default-coding-system
+ (list (cons preferred base))))))))
(if select-safe-coding-system-accept-default-p
(setq accept-default-p select-safe-coding-system-accept-default-p))
(let ((codings (find-coding-systems-region from to))
(coding-system nil)
- (tick (if (not (stringp from)) (buffer-modified-tick)))
+ (tick (if (not (stringp from)) (buffer-chars-modified-tick)))
safe rejected unsafe)
(if (eq (car codings) 'undecided)
;; Any coding system is ok.
%s specified by file contents. Really save (else edit coding cookies \
and try again)? " coding-system auto-cs))
(error "Save aborted"))))
- (when (and tick (/= tick (buffer-modified-tick)))
+ (when (and tick (/= tick (buffer-chars-modified-tick)))
(error "Cancelled because the buffer was modified"))
coding-system)))
language environment.
exit-function value is a function to call to leave this
language environment.
- coding-system value is a list of coding systems that are good
- for saving text written in this language environment.
+ coding-system value is a list of coding systems that are good for
+ saving text written in this language environment.
This list serves as suggestions to the user;
in effect, as a kind of documentation.
coding-priority value is a list of coding systems for this language
features value is a list of features requested in this
language environment.
ctext-non-standard-encodings
- value is a list of non-standard encoding
- names used in extended segments of CTEXT.
- See the variable
- `ctext-non-standard-encodings' for more
- detail.
+ value is a list of non-standard encoding names used
+ in extended segments of CTEXT. See the variable
+ `ctext-non-standard-encodings' for more detail.
The following keys take effect only when multibyte characters are
globally disabled, i.e. the value of `default-enable-multibyte-characters'
is nil.
- unibyte-display value is a coding system to encode characters
- for the terminal. Characters in the range
- of 160 to 255 display not as octal escapes,
- but as non-ASCII characters in this language
- environment.")
+ unibyte-display value is a coding system to encode characters for
+ the terminal. Characters in the range of 160 to
+ 255 display not as octal escapes, but as non-ASCII
+ characters in this language environment.")
(defun get-language-info (lang-env key)
"Return information listed under KEY for language environment LANG-ENV.
(defun update-leim-list-file (&rest dirs)
"Update LEIM list file in directories DIRS."
- (let ((functions update-leim-list-functions))
- (while functions
- (apply (car functions) dirs)
- (setq functions (cdr functions)))))
+ (dolist (function update-leim-list-functions)
+ (apply function dirs)))
(defvar current-input-method nil
"The current input method for multilingual text.
"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.
-The normal action is to enable an input method if none was
-enabled, and disable the current one otherwise. Which input method
-to enable can be determined in various ways--either the one most
-recently used, or the one specified by `default-input-method', or
-as a last resort by reading the name of an input method in the
-minibuffer.
+The normal action is to enable an input method if none was enabled,
+and disable the current one otherwise. Which input method to enable
+can be determined in various ways--either the one most recently used,
+or the one specified by `default-input-method', or as a last resort
+by reading the name of an input method in the minibuffer.
-With a prefix argument, read an input method name with the minibuffer
+With a prefix argument ARG, read an input method name with the minibuffer
and enable that one. The default is the most recent input method specified
\(not including the currently active input method, if any).
-When called interactively, the optional arg INTERACTIVE is non-nil,
+When called interactively, the optional argument INTERACTIVE is non-nil,
which marks the variable `default-input-method' as set for Custom buffers."
(interactive "P\np")
(defun read-multilingual-string (prompt &optional initial-input input-method)
"Read a multilingual string from minibuffer, prompting with string PROMPT.
The input method selected last time is activated in minibuffer.
-If optional second arg INITIAL-INPUT is non-nil, insert it in the minibuffer
-initially.
-Optional 3rd argument INPUT-METHOD specifies the input method
-to be activated instead of the one selected last time. It is a symbol
-or a string."
+If optional second argument INITIAL-INPUT is non-nil, insert it in the
+minibuffer initially.
+Optional 3rd argument INPUT-METHOD specifies the input method to be activated
+instead of the one selected last time. It is a symbol or a string."
(setq input-method
(or input-method
current-input-method
"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, 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.")
+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.")
(defcustom input-method-use-echo-area nil
"This flag controls how an input method shows an intermediate key sequence.
;; The following 2 lines undo the 8-bit display that we set up
;; in standard-display-european-internal, which see. This is in
;; case the user has used standard-display-european earlier in
- ;; this session. (The MS-DOS port doesn't use that setup, so it
- ;; doesn't need to undo it.)
+ ;; this session.
(when standard-display-table
(dotimes (i 128)
(aset standard-display-table (+ i 128) nil))))
- (or (eq window-system 'pc)
- (set-terminal-coding-system (or coding-system coding) display))))
+ (set-terminal-coding-system (or coding-system coding) display)))
(defun set-language-environment (language-name)
"Set up multi-lingual environment for using LANGUAGE-NAME.
(funcall func)))
(setq current-iso639-language
- (get-language-info language-name 'iso639-language))
+ (or (get-language-info language-name 'iso639-language)
+ current-iso639-language))
(run-hooks 'set-language-environment-hook)
(force-mode-line-update t))
This option is intended for use at startup. Removing items doesn't
remove them from the language info until you next restart Emacs.
-Setting this variable directly does not take effect. See
-`set-language-info-alist' for use in programs."
+Setting this variable directly does not take effect.
+See `set-language-info-alist' for use in programs."
:group 'mule
:version "23.1"
:set (lambda (s v)
"Do various coding system setups for language environment LANGUAGE-NAME."
(let* ((priority (get-language-info language-name 'coding-priority))
(default-coding (car priority))
- (eol-type (coding-system-eol-type default-buffer-file-coding-system)))
+ ;; If default-buffer-file-coding-system is nil, don't use
+ ;; coding-system-eol-type, because it treats nil as
+ ;; `no-conversion'. default-buffer-file-coding-system is set
+ ;; to nil by reset-language-environment, and in that case we
+ ;; want to have here the native EOL type for each platform.
+ ;; FIXME: there should be a common code that runs both on
+ ;; startup and here to set the default EOL type correctly.
+ ;; Right now, DOS/Windows platforms set this on dos-w32.el,
+ ;; which works only as long as the order of loading files at
+ ;; dump time and calling functions at startup is not modified
+ ;; significantly, i.e. as long as this function is called
+ ;; _after_ default-buffer-file-coding-system was set by
+ ;; dos-w32.el.
+ (eol-type
+ (if (null default-buffer-file-coding-system)
+ (cond ((memq system-type '(windows-nt ms-dos)) 1)
+ ((eq system-type 'macos) 2)
+ (t 0))
+ (coding-system-eol-type default-buffer-file-coding-system))))
(when priority
(set-default-coding-systems
(if (memq eol-type '(0 1 2 unix dos mac))
;; defined.
(let ((nonascii (get-language-info language-name 'nonascii-translation)))
(if (eq window-system 'pc)
- (setq nonascii (intern "cp%d" dos-codepage)))
+ (setq nonascii (intern (format "cp%d" dos-codepage))))
(or (and (charsetp nonascii)
(get-charset-property nonascii :ascii-compatible-p))
(setq nonascii 'iso-8859-1))
(condition-case nil
(let ((str (eval (get-language-info language-name 'sample-text))))
(if (stringp str)
- (insert "Sample text:\n " str "\n\n")))
+ (insert "Sample text:\n "
+ (replace-regexp-in-string "\n" "\n " str)
+ "\n\n")))
(error nil))
(let ((input-method (get-language-info language-name 'input-method))
(l (copy-sequence input-method-alist))
("big5[-_]?hkscs" . big5-hkscs)
("big5" . big5)
("euc-?tw" . euc-tw)
- ("euc-?cn" .euc-cn)
+ ("euc-?cn" . euc-cn)
("gb2312" . gb2312)
("gbk" . gbk)
("gb18030" . gb18030)
start of KEY, or nil if there is no match."
(let (element)
(while (and alist (not element))
- (if (string-match (concat "\\`\\(?:" (car (car alist)) "\\)") key)
+ (if (string-match-p (concat "\\`\\(?:" (car (car alist)) "\\)") key)
(setq element (car alist)))
(setq alist (cdr alist)))
(cdr element)))
;; want to set them to the same value as LC_CTYPE.
(when locale-name
(setq system-messages-locale locale)
- (setq system-time-locale locale)))
+ (setq system-time-locale locale))
+
+ (if (string-match "^[a-z][a-z]" locale)
+ (setq current-iso639-language (intern (match-string 0 locale)))))
(setq woman-locale
(or system-messages-locale
TABLE may also be nil, in which case no property value is pre-assigned.
-Optional 3rd argment DOCSTRING is a documentation string of the property.
+Optional 3rd argument DOCSTRING is a documentation string of the property.
See also the documentation of `get-char-code-property' and
`put-char-code-property'."
(if slot
(let (table value func)
(if (stringp (cdr slot))
- (load (cdr slot)))
+ (load (cdr slot) nil t))
(setq table (cdr slot)
value (aref table char)
func (char-table-extra-slot table 1))
(if slot
(let (table func)
(if (stringp (cdr slot))
- (load (cdr slot)))
+ (load (cdr slot) nil t))
(setq table (cdr slot)
func (char-table-extra-slot table 2))
(if (functionp func)
(if slot
(let (table func)
(if (stringp (cdr slot))
- (load (cdr slot)))
+ (load (cdr slot) nil t))
(setq table (cdr slot)
func (char-table-extra-slot table 3))
(if (functionp func)
(or ucs-names
(setq ucs-names
(let (name names)
- (dotimes (c #xEFFFF)
+ (dotimes-with-progress-reporter (c #xEFFFF)
+ "Loading Unicode character names..."
(unless (or
(and (>= c #x3400 ) (<= c #x4dbf )) ; CJK Ideograph Extension A
(and (>= c #x4e00 ) (<= c #x9fff )) ; CJK Ideograph
(defvar ucs-completions (lazy-completion-table ucs-completions ucs-names)
"Lazy completion table for completing on Unicode character names.")
+(put 'ucs-completions 'risky-local-variable t)
(defun read-char-by-name (prompt)
"Read a character by its Unicode name or hex number string.
(let* ((completion-ignore-case t)
(input (completing-read prompt ucs-completions)))
(cond
- ((string-match "^[0-9a-fA-F]+$" input)
+ ((string-match-p "^[0-9a-fA-F]+$" input)
(string-to-number input 16))
- ((string-match "^#" input)
+ ((string-match-p "^#" input)
(read input))
(t
(cdr (assoc-string input (ucs-names) t))))))