emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

find-file-literally (was: find-file-read-args)


From: Juri Linkov
Subject: find-file-literally (was: find-file-read-args)
Date: Mon, 23 Nov 2009 23:17:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

> So, I like it.  But I have some more questions:
>
>> ***************
>> *** 2020,2026 ****
>>   In a Lisp program, if you want to be sure of accessing a file's
>>   contents literally, you should create a temporary buffer and then read
>>   the file contents into it using `insert-file-contents-literally'."
>> !   (interactive "FFind file literally: ")
>>     (switch-to-buffer (find-file-noselect filename nil t)))
>>   
>>   (defvar after-find-file-from-revert-buffer nil)
>> --- 2012,2021 ----
>>   In a Lisp program, if you want to be sure of accessing a file's
>>   contents literally, you should create a temporary buffer and then read
>>   the file contents into it using `insert-file-contents-literally'."
>> !   (interactive
>> !    (list (read-file-name
>> !      "Find file literally: " nil default-directory
>> !      (confirm-nonexistent-file-or-buffer))))
>>     (switch-to-buffer (find-file-noselect filename nil t)))
>>   
>>   (defvar after-find-file-from-revert-buffer nil)
>
> Good change, thank you.

Please note that this change would be unnecessary if following lines
were removed from `read-file-name':

  (unless default-filename
    (setq default-filename (if initial (expand-file-name initial dir)
                             buffer-file-name)))

That's because (interactive "FFind file literally: ") calls
`read-file-name' with `default-filename' = nil:

        case 'F':               /* Possibly nonexistent file name. */
          args[i] = Fread_file_name (callint_message,
                                     Qnil, Qnil, Qnil, Qnil, Qnil);

and `read-file-name' sets `default-filename' to `buffer-file-name'.

IMHO, it's dangerous when the user types RET on the directory name
(in the initial input) not expecting that buffer-file-name will be
really used as the default.

Fortunately, there are not many places where that call `read-file-name'
with `default-filename' = nil.  Most commands call `read-file-name'
with `default-filename' = default directory.

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]