diff options
| -rw-r--r-- | lisp/international/mule-cmds.el | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 2965b95e3b3..9694a4e52c8 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el | |||
| @@ -915,32 +915,50 @@ It is highly recommended to fix it before writing to a file." | |||
| 915 | (if select-safe-coding-system-accept-default-p | 915 | (if select-safe-coding-system-accept-default-p |
| 916 | (setq accept-default-p select-safe-coding-system-accept-default-p)) | 916 | (setq accept-default-p select-safe-coding-system-accept-default-p)) |
| 917 | 917 | ||
| 918 | ;; Decide the eol-type from the top of the default codings, | ||
| 919 | ;; buffer-file-coding-system, or | ||
| 920 | ;; default-buffer-file-coding-system. | ||
| 921 | (if default-coding-system | ||
| 922 | (let ((default-eol-type (coding-system-eol-type | ||
| 923 | (caar default-coding-system)))) | ||
| 924 | (if (and (vectorp default-eol-type) buffer-file-coding-system) | ||
| 925 | (setq default-eol-type (coding-system-eol-type | ||
| 926 | buffer-file-coding-system))) | ||
| 927 | (if (and (vectorp default-eol-type) default-buffer-file-coding-system) | ||
| 928 | (setq default-eol-type (coding-system-eol-type | ||
| 929 | default-buffer-file-coding-system))) | ||
| 930 | (if (and default-eol-type (not (vectorp default-eol-type))) | ||
| 931 | (dolist (elt default-coding-system) | ||
| 932 | (setcar elt (coding-system-change-eol-conversion | ||
| 933 | (car elt) default-eol-type)))))) | ||
| 934 | |||
| 918 | (let ((codings (find-coding-systems-region from to)) | 935 | (let ((codings (find-coding-systems-region from to)) |
| 919 | (coding-system nil) | 936 | (coding-system nil) |
| 920 | safe rejected unsafe) | 937 | safe rejected unsafe) |
| 921 | ;; Classify the defaults into safe, rejected, and unsafe. | 938 | (if (eq (car codings) 'undecided) |
| 922 | (dolist (elt default-coding-system) | 939 | ;; Any coding system is ok. |
| 923 | (if (or (eq (car codings) 'undecided) | 940 | (setq coding-system (caar default-coding-system)) |
| 924 | (memq (cdr elt) codings)) | 941 | ;; Reverse the list so that elements are accumulated in safe, |
| 925 | (if (and (functionp accept-default-p) | 942 | ;; rejected, and unsafe in the correct order. |
| 926 | (not (funcall accept-default-p (cdr elt)))) | 943 | (setq default-coding-system (nreverse default-coding-system)) |
| 927 | (push (car elt) rejected) | 944 | |
| 928 | (push (car elt) safe)) | 945 | ;; Classify the defaults into safe, rejected, and unsafe. |
| 929 | (push (car elt) unsafe))) | 946 | (dolist (elt default-coding-system) |
| 930 | (if safe | 947 | (if (or (eq (car codings) 'undecided) |
| 931 | (setq coding-system (car safe))) | 948 | (memq (cdr elt) codings)) |
| 949 | (if (and (functionp accept-default-p) | ||
| 950 | (not (funcall accept-default-p (cdr elt)))) | ||
| 951 | (push (car elt) rejected) | ||
| 952 | (push (car elt) safe)) | ||
| 953 | (push (car elt) unsafe))) | ||
| 954 | (if safe | ||
| 955 | (setq coding-system (car safe)))) | ||
| 932 | 956 | ||
| 933 | ;; If all the defaults failed, ask a user. | 957 | ;; If all the defaults failed, ask a user. |
| 934 | (unless coding-system | 958 | (when (not coding-system) |
| 935 | (setq coding-system (select-safe-coding-system-interactively | 959 | (setq coding-system (select-safe-coding-system-interactively |
| 936 | from to codings unsafe rejected (car codings)))) | 960 | from to codings unsafe rejected (car codings)))) |
| 937 | 961 | ||
| 938 | (if (and coding-system (vectorp (coding-system-eol-type coding-system))) | ||
| 939 | (let ((eol (coding-system-eol-type buffer-file-coding-system))) | ||
| 940 | (if (numberp eol) | ||
| 941 | (setq coding-system | ||
| 942 | (coding-system-change-eol-conversion coding-system eol))))) | ||
| 943 | |||
| 944 | ;; Check we're not inconsistent with what `coding:' spec &c would | 962 | ;; Check we're not inconsistent with what `coding:' spec &c would |
| 945 | ;; give when file is re-read. | 963 | ;; give when file is re-read. |
| 946 | ;; But don't do this if we explicitly ignored the cookie | 964 | ;; But don't do this if we explicitly ignored the cookie |