Commit efa2c6d7 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(select-safe-coding-system): New arg FILE; use that for set-auto-coding.

When computing auto-cs, narrow to FROM...TO.
Put save-excursion outside save-restriction.
parent 5b6d51b6
...@@ -543,7 +543,7 @@ function `select-safe-coding-system' (which see). This variable ...@@ -543,7 +543,7 @@ function `select-safe-coding-system' (which see). This variable
overrides that argument.") overrides that argument.")
(defun select-safe-coding-system (from to &optional default-coding-system (defun select-safe-coding-system (from to &optional default-coding-system
accept-default-p) accept-default-p file)
"Ask a user to select a safe coding system from candidates. "Ask a user to select a safe coding system from candidates.
The candidates of coding systems which can safely encode a text The candidates of coding systems which can safely encode a text
between FROM and TO are shown in a popup window. Among them, the most between FROM and TO are shown in a popup window. Among them, the most
...@@ -564,6 +564,10 @@ determine the acceptability of the silently selected coding system. ...@@ -564,6 +564,10 @@ determine the acceptability of the silently selected coding system.
It is called with that coding system, and should return nil if it It is called with that coding system, and should return nil if it
should not be silently selected and thus user interaction is required. should not be silently selected and thus user interaction is required.
Optional 5th arg FILE is the file name to use for this purpose.
That is different from `buffer-file-name' when handling `write-region'
\(for example).
The variable `select-safe-coding-system-accept-default-p', if The variable `select-safe-coding-system-accept-default-p', if
non-nil, overrides ACCEPT-DEFAULT-P. non-nil, overrides ACCEPT-DEFAULT-P.
...@@ -718,11 +722,12 @@ and TO is ignored." ...@@ -718,11 +722,12 @@ and TO is ignored."
;; Check we're not inconsistent with what `coding:' spec &c would ;; Check we're not inconsistent with what `coding:' spec &c would
;; give when file is re-read. ;; give when file is re-read.
(unless (stringp from) (unless (stringp from)
(let ((auto-cs (save-restriction (let ((auto-cs (save-excursion
(save-restriction
(widen) (widen)
(save-excursion (narrow-to-region from to)
(goto-char (point-min)) (goto-char (point-min))
(set-auto-coding (or buffer-file-name "") (set-auto-coding (or file buffer-file-name "")
(buffer-size)))))) (buffer-size))))))
(if (and auto-cs (if (and auto-cs
(not (coding-system-equal (coding-system-base coding-system) (not (coding-system-equal (coding-system-base coding-system)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment