all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: How to handle default value in read-string?
Date: Wed, 19 Aug 2015 23:15:46 +0200	[thread overview]
Message-ID: <87bne36ku5.fsf@mbork.pl> (raw)
In-Reply-To: <93600d92-2698-483a-8c1b-f1333363f541@default>


On 2015-08-04, at 01:51, Drew Adams <drew.adams@oracle.com> 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 inherit-input-method)
  "A replacement for `read-string', displaying the default.
Also, not displaying it twice should the user use Icicles."
  (let ((icicle-default-value nil)
	(prompt-with-default
	 (progn
	   (string-match "\\(: \\)?$" prompt)
	   (replace-match (format " (%s)\\1" default-value) t nil prompt))))
    (read-string prompt-with-default initial-input history default-value inherit-input-method)))
--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
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



  parent reply	other threads:[~2015-08-19 21:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 21:00 How to handle default value in read-string? Marcin Borkowski
2015-08-03 21:17 ` John Mastro
2015-08-03 23:40   ` Marcin Borkowski
2015-08-03 23:51 ` Drew Adams
2015-08-04 18:44   ` Marcin Borkowski
2015-08-19 21:15   ` Marcin Borkowski [this message]
2015-08-21  7:46     ` Drew Adams
2015-08-05 20:02 ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bne36ku5.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.