unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Reading from minibuffer with default value when return pressed
@ 2007-04-22 18:01 Nordlöw
  2007-04-22 18:07 ` Nordlöw
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nordlöw @ 2007-04-22 18:01 UTC (permalink / raw)
  To: help-gnu-emacs

Hey there, Emacs-Hackers!

I am trying enhance my grep wrapper with the common logic that propose
a default argument like, preferrably using
(thing-at-point 'symbol)

Grep for string (some-default-string):


and that uses this some-default-string I have only press return.

I thought the following should work but it doesn't
(read-from-minibuffer "Grep for string: " nil nil nil nil "default"
nil)

Do I need an alternative to read-from-minibuffer() or have I missed
something=


Many thanks in advance,
Per Nordlöw

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Reading from minibuffer with default value when return pressed
  2007-04-22 18:01 Reading from minibuffer with default value when return pressed Nordlöw
@ 2007-04-22 18:07 ` Nordlöw
  2007-04-22 18:46   ` Drew Adams
  2007-04-23 14:13 ` Johan Bockgård
  2007-04-25  5:13 ` Stefan Monnier
  2 siblings, 1 reply; 6+ messages in thread
From: Nordlöw @ 2007-04-22 18:07 UTC (permalink / raw)
  To: help-gnu-emacs

Hey there, Emacs-Hackers!

Sorry, I accidentally sent this post before it was finished... Here is
the correct version:


I am trying enhance my grep wrapper with the common logic that propose
a default argument like

Grep for string (some-default-string):

preferrably using (thing-at-point 'symbol)

and that it defaults to this "some-default-string" when I press return
only.

I thought the following code should work but it doesn't
(read-from-minibuffer "Grep for string: " nil nil nil nil "default"
nil)

Do I need to use an alternative to read-from-minibuffer() or have I
missed
something?

Many thanks in advance,
Per Nordlöw

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Reading from minibuffer with default value when return pressed
  2007-04-22 18:07 ` Nordlöw
@ 2007-04-22 18:46   ` Drew Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2007-04-22 18:46 UTC (permalink / raw)
  To: Nordlöw, help-gnu-emacs

> Grep for string (some-default-string):
> preferrably using (thing-at-point 'symbol) and that it defaults to
> this "some-default-string" when I press return only.

I think this does what you are asking for:
http://www.emacswiki.org/cgi-bin/wiki/GrepPlus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Reading from minibuffer with default value when return pressed
  2007-04-22 18:01 Reading from minibuffer with default value when return pressed Nordlöw
  2007-04-22 18:07 ` Nordlöw
@ 2007-04-23 14:13 ` Johan Bockgård
  2007-04-23 17:05   ` Chris McMahan
  2007-04-25  5:13 ` Stefan Monnier
  2 siblings, 1 reply; 6+ messages in thread
From: Johan Bockgård @ 2007-04-23 14:13 UTC (permalink / raw)
  To: help-gnu-emacs

Nordlöw <per.nordlow@gmail.com> writes:

> I thought the following should work but it doesn't
> (read-from-minibuffer "Grep for string: " nil nil nil nil "default"
> nil)

C-h f read-from-minibuffer

    [...]
    Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is
    available for history commands; but, unless READ is non-nil,
    `read-from-minibuffer' does NOT return DEFAULT-VALUE if the user
    enters empty input! It returns the empty string.

> Do I need an alternative to read-from-minibuffer() or have I missed
> something=

You can just test for "", or use read-string:

    Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is
    used for history commands, and as the value to return if the user
    enters the empty string.

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Reading from minibuffer with default value when return pressed
  2007-04-23 14:13 ` Johan Bockgård
@ 2007-04-23 17:05   ` Chris McMahan
  0 siblings, 0 replies; 6+ messages in thread
From: Chris McMahan @ 2007-04-23 17:05 UTC (permalink / raw)
  To: help-gnu-emacs

Take a look at the function
 completing-read

... If initial-input is non-nil, insert it in the minibuffer initially,
  with point positioned at the end.

I'm using it to set the default value when creating a shell buffer.

- Chris

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

> Nordlöw <per.nordlow@gmail.com> writes:
>
>> I thought the following should work but it doesn't
>> (read-from-minibuffer "Grep for string: " nil nil nil nil "default"
>> nil)
>
> C-h f read-from-minibuffer
>
>     [...]
>     Sixth arg DEFAULT-VALUE is the default value. If non-nil, it is
>     available for history commands; but, unless READ is non-nil,
>     `read-from-minibuffer' does NOT return DEFAULT-VALUE if the user
>     enters empty input! It returns the empty string.
>
>> Do I need an alternative to read-from-minibuffer() or have I missed
>> something=
>
> You can just test for "", or use read-string:
>
>     Fourth arg DEFAULT-VALUE is the default value. If non-nil, it is
>     used for history commands, and as the value to return if the user
>     enters the empty string.
>
> -- 
> Johan Bockgård

-- 
     (.   .)
  =ooO=(_)=Ooo=====================================
  Chris McMahan | first_initiallastname@one.dot.net
  =================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Reading from minibuffer with default value when return pressed
  2007-04-22 18:01 Reading from minibuffer with default value when return pressed Nordlöw
  2007-04-22 18:07 ` Nordlöw
  2007-04-23 14:13 ` Johan Bockgård
@ 2007-04-25  5:13 ` Stefan Monnier
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2007-04-25  5:13 UTC (permalink / raw)
  To: help-gnu-emacs

> I am trying enhance my grep wrapper with the common logic that propose
> a default argument like, preferrably using
> (thing-at-point 'symbol)

It's also part of the standard M-x grep:
Try to use C-u before the M-x grep.


        Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-04-25  5:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-22 18:01 Reading from minibuffer with default value when return pressed Nordlöw
2007-04-22 18:07 ` Nordlöw
2007-04-22 18:46   ` Drew Adams
2007-04-23 14:13 ` Johan Bockgård
2007-04-23 17:05   ` Chris McMahan
2007-04-25  5:13 ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).