emacs-devel
[Top][All Lists]
Advanced

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

Re: Null filename ("") is considered to correspond to an existing, read


From: Luc Teirlinck
Subject: Re: Null filename ("") is considered to correspond to an existing, readable, and writable file?
Date: Tue, 3 Jan 2006 13:40:11 -0600 (CST)

Drew Adams wrote:

    - A program often (not extremely rarely) needs to account for user-input
   filenames. Whereas "" as a name might be rarely constructed in a program,
   and is impossible as the name of a real file, user input can require a
   program to deal with the empty-name case.

You mean what happens if a user exits with an empty minibuffer?  In
that case a program is free to specify any default behavior that makes
sense, as long as it clearly tells that to the user.  This is mainly
relevant for commands.  The examples you gave, file-exists-p and
friends are not commands.

So if you define a command my-file-operation, taking a file name as an
argument, you could show a minibuffer prompt:

Operate on file (default ~/.emacs):

Your _interactive declaration_ could then transform empty user input
("") into the string "~/.emacs".  Then a call to file-exists-p in the
code of your command will apply to "~/.emacs", if the user pressed RET
in an empty minibuffer.  When called from Lisp, (my-file-operation "")
would not change the "" to "~/.emacs" (only the interactive
declaration does) and hence would still operate on default-directory.

But you can do all of this much more easily by reading the file name
with `read-file-name', which allows you to specify a default if the
user exits with an empty minibuffer.  `file-exists-p' will then get
that default as argument, not "".

Sincerely,

Luc.




reply via email to

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