help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to handle default value in read-string?


From: Marcin Borkowski
Subject: Re: How to handle default value in read-string?
Date: Tue, 04 Aug 2015 20:44:21 +0200

On 2015-08-04, at 01:51, Drew Adams <address@hidden> wrote:

>> I'd like read-string to somehow indicate the default value.  A natural
>> idea is to include it in the prompt, for example having a prompt like
>> 
>> (format "Foo (%s): " default)
>> 
>> However, Icicles' version of read-string already does exactly that, so
>> for Icicles users this would be superfluous.
>> 
>> So here's the question: is there a better way than just have a prompt of
>> 
>> (if icicle-mode (don't-include-default) (do-include-default))?
>
> That's OK.  Or wrap the `read-string' call in:
>
>  (let ((icicle-default-value  nil)) ...)
>
> A nil value of `icicle-default-value' tells Icicles not to put the
> default value in the prompt.  Then you can add it to the prompt
> explicitly, so it will be there with and without Icicle mode:
>
> (defun foo (strg)
>  (interactive
>    (let ((icicle-default-value nil))
>      (list (read-string "String (default my-default): "
>                         nil nil "my-default")))))

Thanks, Drew, that's much better!

Fun fact: I thought that putting the default into the prompt was the
default Emacs behavior, until I ran my code with Icicles off (I
occasionally turn Icicles off to restore some keybindings used by
Org-mode.  Yes, yes, I should check how to customize Icicles.  I'll do
it some day;-).).  Then I spent a few minutes looking for a bug in my
code ("Did I change anything recently that could influence the
read-string prompt?").  Then it dawned upon me that Icicles (again?)
does what (maybe) Emacs should do by default...

Drew, thanks again for Icicles.  It is so cool.  (The only problem
I have with it is speed.  But I'll move to a faster computer within
a few weeks, and I hope this won't be an issue then.)

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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