unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* lisp read-from-minibuffer propels deep questions
@ 2012-04-03  2:01 Xah Lee
  2012-04-03  4:57 ` Kevin Rodgers
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Xah Lee @ 2012-04-03  2:01 UTC (permalink / raw)
  To: help-gnu-emacs

slightly frustrated with emacs lisp read-from-minibuffer.

Spent now about a hour on this.

what i want i simple, like this:

(read-from-minibuffer
 (format "Directory (default %s):" default-directory) default-
directory )

prompt user to enter a dir, with default at current dir.

however, according to inline doc of read-from-minibuffer, the second
arg for default input is obsolete. Instead, you have to use the 6th
arg. Quote:

(read-from-minibuffer PROMPT &optional INITIAL-CONTENTS KEYMAP READ
HIST DEFAULT-VALUE INHERIT-INPUT-METHOD)

the doc is long so i won't paste here. See it by calling “describe-
function”.

Now, so i do:

(read-from-minibuffer
 (format "Directory (default %s):" default-directory) nil nil nil nil
default-directory)

doesn't work. 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.

So i do

(read-from-minibuffer
 (format "Directory (default %s):" default-directory) nil nil t nil
default-directory)

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)

So, now i have to do this:

(read-from-minibuffer
 (format "Directory (default %s):" default-directory) nil nil t nil
(format "\"%s\"" default-directory) )

But no! Because, now if user actually enter a value, e.g. type 「mary」,
lisp reader freaks out. Again, it doesn't undertand what the letter
sequence 「mary」 is. It wants a string 「"\"mary\""」. So, user will have
to actually type 「"mary"」 for this to work.

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….

 Xah


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-04-13  2:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
     [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

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).