;; If the most preferred coding system has the property mime-charset,
;; append it to the defaults.
- (let ((tail coding-category-list)
- preferred base)
- (while (and tail (not (setq preferred (symbol-value (car tail)))))
- (setq tail (cdr tail)))
+ (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)
+ (coding-system-get preferred :mime-charset)
(not (rassq base default-coding-system))
(push (cons preferred base)
- default-coding-system)))))
-
- (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)
- safe rejected unsafe)
- ;; Classify the defaults into safe, rejected, and unsafe.
- (dolist (elt default-coding-system)
- (if (or (eq (car codings) 'undecided)
- (memq (cdr elt) codings))
- (if (and (functionp accept-default-p)
- (not (funcall accept-default-p (cdr elt))))
- (push (car elt) rejected)
- (push (car elt) safe))
- (push (car elt) unsafe)))
- (if safe
- (setq coding-system (car safe)))
-
- ;; If all the defaults failed, ask a user.
- (unless coding-system
- (setq coding-system (select-safe-coding-system-interactively
- from to codings unsafe rejected (car codings))))
-
- (if (and coding-system (vectorp (coding-system-eol-type coding-system)))
- (let ((eol (coding-system-eol-type buffer-file-coding-system)))
- (if (numberp eol)
- (setq coding-system
- (coding-system-change-eol-conversion coding-system eol)))))
-
- ;; Check we're not inconsistent with what `coding:' spec &c would
- ;; give when file is re-read.
- ;; But don't do this if we explicitly ignored the cookie
- ;; by using `find-file-literally'.
- (unless (or (stringp from)
- find-file-literally
- (and coding-system
- (memq (coding-system-type coding-system) '(0 5))))
- (let ((auto-cs (save-excursion
- (save-restriction
- (widen)
- (narrow-to-region from to)
- (goto-char (point-min))
- (set-auto-coding (or file buffer-file-name "")
- (buffer-size))))))
+ default-coding-system))))
+
+ (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)
+ safe rejected unsafe)
- (if (eq (car codings) 'undecided)
- ;; Any coding system is ok.
- (setq coding-system t)
- ;; Classify the defaults into safe, rejected, and unsafe.
- (dolist (elt default-coding-system)
- (if (memq (cdr elt) codings)
- (if (and (functionp accept-default-p)
- (not (funcall accept-default-p (cdr elt))))
- (push (car elt) rejected)
- (push (car elt) safe))
- (push (car elt) unsafe)))
- (if safe
- (setq coding-system (car safe))))
++ ;; Classify the defaults into safe, rejected, and unsafe.
++ (dolist (elt default-coding-system)
++ (if (or (eq (car codings) 'undecided)
++ (memq (cdr elt) codings))
++ (if (and (functionp accept-default-p)
++ (not (funcall accept-default-p (cdr elt))))
++ (push (car elt) rejected)
++ (push (car elt) safe))
++ (push (car elt) unsafe)))
++ (if safe
++ (setq coding-system (car safe)))
+
+ ;; If all the defaults failed, ask a user.
- (when (not coding-system)
++ (unless coding-system
+ (setq coding-system (select-safe-coding-system-interactively
+ from to codings unsafe rejected (car codings))))
+
- (if (vectorp (coding-system-eol-type coding-system))
++ (if (and coding-system (vectorp (coding-system-eol-type coding-system)))
+ (let ((eol (coding-system-eol-type buffer-file-coding-system)))
+ (if (numberp eol)
+ (setq coding-system
+ (coding-system-change-eol-conversion coding-system eol)))))
+
- (if (eq coding-system t)
- (setq coding-system buffer-file-coding-system))
+ ;; Check we're not inconsistent with what `coding:' spec &c would
+ ;; give when file is re-read.
+ ;; But don't do this if we explicitly ignored the cookie
+ ;; by using `find-file-literally'.
+ (when (and auto-cs
+ (not (and
+ coding-system
+ (memq (coding-system-type coding-system) '(0 5)))))
;; Merge coding-system and auto-cs as far as possible.
(if (not coding-system)
(setq coding-system auto-cs)