[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Coding system of new files on DOS/Windows
From: |
Eli Zaretskii |
Subject: |
Coding system of new files on DOS/Windows |
Date: |
Tue, 24 Oct 2000 10:11:54 +0200 (IST) |
I would like to install the patch below for dos-w32.el. To me, it looks
The Right Thing by any measure. However, since it changes behavior that
I think was there since about v20.2, I'd like to run it through those of
you who use Emacs on DOS/Windows systems.
What this change does is this:
- It causes "C-x RET c foobar RET C-x C-f no-such-file RET" to set the
buffer-file-coding-system to foobar even if no-such-file doesn't exist.
I believe that this is what happens on Unix, but with current dos-w32,
for new files, you get the default coding system instead (either
undecided-dos or what was set by set-language-environment).
Also, the current code doesn't let you use "C-x RET c" and
coding-system-for-read to override the EOL conversion type of a file
on an untranslated filesystem: you always get -unix, even if you say
"C-x RET c latin-1-dos C-x C-f".
- If you set up file-coding-system-alist to visit certain files with a
specific coding system, this change makes Emacs do that for new files
as well as for existing files.
- With the current dos-w32, if you create a file on an untranslated
filesystem, the associations in file-coding-system-alist are
effectively disabled; this change fixes that lossage.
I'm sure there are numerous other misfeatures with the current code,
because what it does is call find-buffer-file-type-coding-system inside a
find-file-not-found-hook. However, find-buffer-file-type-coding-system
is supposed to be called only if no other existing machinery was able to
come up with a coding system; it's a fallback, and as such, it doesn't
consult any other Emacs facilities for setting coding systems. The result
is that the coding system for the new file, which is already set up by
Ffind_operation_coding_system (called from Finsert_file_contents), is
simply overridden by find-buffer-file-type-coding-system.
The change below undoes this damage, and instead limits the hook's effect
to setting up the EOL conversion if the file is on an untranslated
filesystem (unless overridden with coding-system-for-read).
I don't see any possible adverse effects with this change, unless someone
out there has some weird customizations which were designed to work
around the above-mentioned bugs. However, perhaps I miss something.
Please tell me if you see anything wrong with this change.
(The second hunk below fixes what I believe is a confusing prompt in
add-untranslated-filesystem, see the comment in the code.)
Thanks in advance for any feedback.
2000-10-23 Eli Zaretskii <address@hidden>
* dos-w32.el (find-file-not-found-set-buffer-file-coding-system):
Don't call find-buffer-file-type-coding-system. Instead, just
set eol-type to -unix if inhibit-eol-conversion is in effect, or
if the file is on an untranslated filesystem.
(add-untranslated-filesystem): Use "D" instead of "f" inside
interactive.
*** lisp/dos-w32.e~0 Fri Dec 10 15:34:34 1999
--- lisp/dos-w32.el Mon Oct 23 00:17:20 2000
***************
*** 177,186 ****
(defun find-file-not-found-set-buffer-file-coding-system ()
(save-excursion
(set-buffer (current-buffer))
! (let* ((dummy-insert-op (list 'insert-file-contents (buffer-file-name)))
! (coding-system-pair
! (find-buffer-file-type-coding-system dummy-insert-op)))
! (setq buffer-file-coding-system (car coding-system-pair))
(setq buffer-file-type (eq buffer-file-coding-system 'no-conversion)))))
;;; To set the default coding system on new files.
--- 177,192 ----
(defun find-file-not-found-set-buffer-file-coding-system ()
(save-excursion
(set-buffer (current-buffer))
! (let ((coding buffer-file-coding-system))
! ;; buffer-file-coding-system is already set by
! ;; find-operation-coding-system, which was called from
! ;; insert-file-contents. All that's left is to change
! ;; the EOL conversion, if required by the user.
! (when (and (null coding-system-for-read)
! (or inhibit-eol-conversion
! (untranslated-file-p (buffer-file-name))))
! (setq coding (coding-system-change-eol-conversion coding 0))
! (setq buffer-file-coding-system coding))
(setq buffer-file-type (eq buffer-file-coding-system 'no-conversion)))))
;;; To set the default coding system on new files.
***************
*** 233,239 ****
CR/LF translation. FILESYSTEM is a string containing the directory
prefix corresponding to the filesystem. For example, for a Unix
filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
! (interactive "fUntranslated file system: ")
(let ((fs (untranslated-canonical-name filesystem)))
(if (member fs untranslated-filesystem-list)
untranslated-filesystem-list
--- 239,248 ----
CR/LF translation. FILESYSTEM is a string containing the directory
prefix corresponding to the filesystem. For example, for a Unix
filesystem mounted on drive Z:, FILESYSTEM could be \"Z:\"."
! ;; We use "D", not "f", to avoid confusing the user: "f" prompts
! ;; with a directory, but RET returns the current buffer's file, not
! ;; its directory.
! (interactive "DUntranslated file system: ")
(let ((fs (untranslated-canonical-name filesystem)))
(if (member fs untranslated-filesystem-list)
untranslated-filesystem-list
- Coding system of new files on DOS/Windows,
Eli Zaretskii <=