(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.
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 MS-DOS)
+ 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)
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 MS-DOS)
+ 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."
(interactive "zPrefer coding system: ")
(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)))