[Top][All Lists]

[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 01:40:16 +0200

On 2015-08-03, at 23:17, John Mastro <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))?
> There's no getting around that you'll need a condition somewhere.

Well, that was more or less obvious...  However, your suggestion of
bound-and-true-p (below) is (obviously) a significant improvement for
anyone without Icicles loaded:-).  Thanks!

> However, you can of course wrap it up in a helper function, so you're
> not repeating the condition every time you use `read-string'.
>     (defun my-read-string (prompt &optional ...)
>       (unless (bound-and-true-p icicle-mode)
>         (setq prompt (concat prompt " (%s)" default)))
>       (read-string prompt ...))
> You could use advice to do the same thing but I don't think it would be
> an improvement in this case.

Thanks a lot!

Marcin Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

reply via email to

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