* Another lisp question
@ 2010-04-15 16:13 Klaus Jantzen
2010-04-15 16:51 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: Klaus Jantzen @ 2010-04-15 16:13 UTC (permalink / raw)
To: emacs-list
Hi,
in an interactive function I have
(interactive "sEnter number: ")
When hitting <Enter> without entering anything, emacs comes back to the
input request.
How can I find out, that nothing has been entered so that I can use e.g.
a default value?
Thanks for a pointer.
--
K.D.J.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Another lisp question
2010-04-15 16:13 Another lisp question Klaus Jantzen
@ 2010-04-15 16:51 ` Drew Adams
2010-04-16 9:40 ` Klaus Jantzen
0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2010-04-15 16:51 UTC (permalink / raw)
To: 'Klaus Jantzen', 'emacs-list'
> (interactive "sEnter number: ")
Consider using `read-number':
(interactive (list (read-number "Number: " 42)))
> When hitting <Enter> without entering anything, emacs comes
> back to the input request. How can I find out, that nothing
> has been entered so that I can use e.g. a default value?
I don't understand how that happens to you.
It should just return the empty string, "".
M-: (defun foo (arg) (interactive "sNum: ") (message "%S" arg))
M-x foo RET RET
That returns "" for me.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Another lisp question
2010-04-15 16:51 ` Drew Adams
@ 2010-04-16 9:40 ` Klaus Jantzen
2010-04-16 13:54 ` Drew Adams
0 siblings, 1 reply; 6+ messages in thread
From: Klaus Jantzen @ 2010-04-16 9:40 UTC (permalink / raw)
To: Drew Adams; +Cc: 'emacs-list'
[-- Attachment #1: Type: text/html, Size: 1710 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Another lisp question
2010-04-16 9:40 ` Klaus Jantzen
@ 2010-04-16 13:54 ` Drew Adams
2010-04-16 16:31 ` Klaus Jantzen
0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2010-04-16 13:54 UTC (permalink / raw)
To: 'Klaus Jantzen'; +Cc: 'emacs-list'
(defun mytest (n)
" Test"
; (interactive "nEnter number: ")
(interactive (list (read-number "Enter number: ")))
(message "%d was entered" n))
With both versions of the interactive statement I have the
same effect: the prompt comes back as long as I do not enter anything.
I am running emacs22 on Debian lenny.
Do I need a special setting to achive what I want?
You said you wanted to use the default value if the user hit Return with typing
anything first. For that, use (read-number "Number: " MY-DEFAULT), as I
suggested before.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Another lisp question
2010-04-16 13:54 ` Drew Adams
@ 2010-04-16 16:31 ` Klaus Jantzen
2010-04-16 17:58 ` Suvayu Ali
0 siblings, 1 reply; 6+ messages in thread
From: Klaus Jantzen @ 2010-04-16 16:31 UTC (permalink / raw)
To: Drew Adams; +Cc: 'emacs-list'
Drew Adams wrote:
> (defun mytest (n)
> " Test"
> ; (interactive "nEnter number: ")
> (interactive (list (read-number "Enter number: ")))
> (message "%d was entered" n))
>
> With both versions of the interactive statement I have the
> same effect: the prompt comes back as long as I do not enter anything.
>
> I am running emacs22 on Debian lenny.
> Do I need a special setting to achive what I want?
>
> You said you wanted to use the default value if the user hit Return with typing
> anything first. For that, use (read-number "Number: " MY-DEFAULT), as I
> suggested before.
>
>
>
OK; I did not really understand why you had that 42 in your code.
It works.
Thank you.
--
K.D.J.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Another lisp question
2010-04-16 16:31 ` Klaus Jantzen
@ 2010-04-16 17:58 ` Suvayu Ali
0 siblings, 0 replies; 6+ messages in thread
From: Suvayu Ali @ 2010-04-16 17:58 UTC (permalink / raw)
To: help-gnu-emacs
On Friday 16 April 2010 09:31 AM, Klaus Jantzen wrote:
> Drew Adams wrote:
>> (defun mytest (n)
>> " Test"
>> ; (interactive "nEnter number: ")
>> (interactive (list (read-number "Enter number: ")))
>> (message "%d was entered" n))
>>
>> With both versions of the interactive statement I have the
>> same effect: the prompt comes back as long as I do not enter anything.
>>
>> I am running emacs22 on Debian lenny.
>> Do I need a special setting to achive what I want?
>>
>> You said you wanted to use the default value if the user hit Return
>> with typing
>> anything first. For that, use (read-number "Number: " MY-DEFAULT), as I
>> suggested before.
>>
>>
> OK; I did not really understand why you had that 42 in your code.
> It works.
> Thank you.
I believe its the answer to the ultimate question? ;)
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-04-16 17:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-15 16:13 Another lisp question Klaus Jantzen
2010-04-15 16:51 ` Drew Adams
2010-04-16 9:40 ` Klaus Jantzen
2010-04-16 13:54 ` Drew Adams
2010-04-16 16:31 ` Klaus Jantzen
2010-04-16 17:58 ` Suvayu Ali
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.