[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: Wed, 19 Aug 2015 23:15:46 +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")))))

OK, so I sat to this today, and didn't manage to get it to work.  Here's
my function:

--8<---------------cut here---------------start------------->8---
(defun my-read-string (prompt &optional initial-input history default-value 
  "A replacement for `read-string', displaying the default.
Also, not displaying it twice should the user use Icicles."
  (let ((icicle-default-value nil)
           (string-match "\\(: \\)?$" prompt)
           (replace-match (format " (%s)\\1" default-value) t nil prompt))))
    (read-string prompt-with-default initial-input history default-value 
--8<---------------cut here---------------end--------------->8---

If I do M-: (my-read-string "foo: " nil nil "bar") with Icicles off,
everything is fine.  If Icicles are on, however, this is what I get:

foo (bar) (bar): -!-

Setting icicle-default-value to nil globally doesn't help, either.

My Icicles version is

--8<---------------cut here---------------start------------->8---
;; Version: 2015.04.03
;; Package-Requires: ()
;; Last-Updated: Fri Apr  3 09:12:40 2015 (-0700)
;;           By: dradams
;;     Update #: 23650
--8<---------------cut here---------------end--------------->8---

What am I doing wrong?

Marcin Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

reply via email to

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