[Top][All Lists]

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

lisp read-from-minibuffer propels deep questions

From: Xah Lee
Subject: lisp read-from-minibuffer propels deep questions
Date: Mon, 2 Apr 2012 19:01:18 -0700 (PDT)
User-agent: G2/1.0

slightly frustrated with emacs lisp read-from-minibuffer.

Spent now about a hour on this.

what i want i simple, like this:

 (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

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

Now, so i do:

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

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

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

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:

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


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


reply via email to

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