From: "Drew Adams" <drew.adams@oracle.com>
To: "'Xah Lee'" <xahlee@gmail.com>, <help-gnu-emacs@gnu.org>
Subject: RE: lisp read-from-minibuffer propels deep questions
Date: Mon, 2 Apr 2012 22:35:49 -0700 [thread overview]
Message-ID: <4AAE721518A14E20A72E8C545C6A6435@us.oracle.com> (raw)
In-Reply-To: <a44f5e91-30cd-4ee8-a588-3747814f4c92@wj4g2000pbc.googlegroups.com>
> (read-from-minibuffer
> (format "Directory (default %s):" default-directory)
> default-directory )
>
> prompt user to enter a dir, with default at current dir.
Try `read-directory-name'. (Its doc too is a bit confusing, IMO.) Here are a
couple ways to read the name of a directory. The first requires the input to be
an existing directory; the second does not.
(expand-file-name
(read-directory-name
(format "Directory (default %s): " default-directory)
default-directory default-directory t))
(let ((insert-default-directory t))
(read-directory-name "Directory: " default-directory))
You can also use `read-file-name'. Both of those functions let the user use
completion: they are file/dir-name aware.
`read-from-minibuffer' on the other hand just reads a string (and optionally
calls the Lisp reader on it).
> however, according to inline doc of read-from-minibuffer, the second
> arg for default input is obsolete.
(FWIW, I disagree with that pronouncement by Emacs Devel, but so be it.)
The doc actually says, at the very end, that you can use the second arg if the
HIST arg is a cons, i.e., is a non-nil history list.
Example:
(read-from-minibuffer "Directory: " default-directory
nil nil file-name-history)
or just (read-from-minibuffer "Directory: " default-directory) if you don't care
about using the file-name history (`M-p').
If you avoid using the "deprecated" INITIAL-CONTENTS arg (like a good boy), then
you must test the string input by the user, and if it is "" then return
DEFAULT-VALUE:
(let ((input (read-from-minibuffer
(format "Directory (default %s): " default-directory)
nil nil nil nil default-directory)))
(when (string= "" input) (setq input default-directory))
input)
But again, `read-from-minibuffer' does not know anything about file or dir names
or how to complete them (unless you jump through hoops, providing it a
file/dir-name completion keymap).
> Instead, you have to use the 6th arg.
Nope, as you discovered, nothing gets inserted in the minibuffer, and empty
input means "" is returned.
> Read the doc again, it turns out that the 4th arg must
> be t in order for the default value to work, else you get empty string
> if the user just press Enter.
Nope, as you discovered. That's something else again.
> woops! no go! because if the 4th arg is t, it means the input as a
> string will be fed to lisp reader, then interpreted as a lisp object.
> Hot damn. This means, if you want a string, you have to feed it
> ?"\"mystring\""?. (the outter string makes it a lisp string to be fed
> to lisp reader, then, the inner string gets you a lisp string object)
No, don't even think of going down that road.
`read-from-minibuffer' is a very general function, which is one reason its doc
is confusing (not that that is an excuse). It is used to implement
`completing-read', `read-file-name', and so on. The 4th arg is only for
situations where you want to get user input as a Lisp sexp and then evaluate it.
> But no! ... WTF?
> This line is supposed to be done in 20 seconds. Now i've spent 40min
> on this. Now, my mind wanders to the deep question of humanity..
Try using `read-file-name' or `read-directory-name'. They should help.
next prev parent reply other threads:[~2012-04-03 5:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 2:01 lisp read-from-minibuffer propels deep questions Xah Lee
2012-04-03 4:57 ` Kevin Rodgers
2012-04-03 5:35 ` Drew Adams [this message]
[not found] ` <mailman.420.1333431363.20052.help-gnu-emacs@gnu.org>
2012-04-03 5:58 ` Xah Lee
2012-04-04 1:06 ` Stefan Monnier
2012-04-04 4:24 ` Xah Lee
2012-04-13 2:03 ` Joe keane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4AAE721518A14E20A72E8C545C6A6435@us.oracle.com \
--to=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=xahlee@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).