all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* newbie : elisp - prompt for input
@ 2006-08-28 19:17 Hadron Quark
  2006-08-28 21:07 ` Kevin Rodgers
       [not found] ` <mailman.5849.1156799345.9609.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 6+ messages in thread
From: Hadron Quark @ 2006-08-28 19:17 UTC (permalink / raw)



Is the snippet below the best way to prompt and parse an integer value?


(defun count-words(max)
  "count words in buffer"
  (interactive "nMax words to count to:")
  (while (zerop max)
    (setq max (string-to-number(read-string "> 0 please. re-enter:"))))

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

* Re: newbie : elisp - prompt for input
  2006-08-28 19:17 newbie : elisp - prompt for input Hadron Quark
@ 2006-08-28 21:07 ` Kevin Rodgers
       [not found] ` <mailman.5849.1156799345.9609.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2006-08-28 21:07 UTC (permalink / raw)


Hadron Quark wrote:
> Is the snippet below the best way to prompt and parse an integer value?
> 
> 
> (defun count-words(max)
>   "count words in buffer"
>   (interactive "nMax words to count to:")
>   (while (zerop max)
>     (setq max (string-to-number(read-string "> 0 please. re-enter:"))))

The only thing I see wrong with it is that the check runs outside
of the interactive form, and prompts the user (regardless of whether
the function was called interactively).

-- 
Kevin

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

* Re: newbie : elisp - prompt for input
       [not found] ` <mailman.5849.1156799345.9609.help-gnu-emacs@gnu.org>
@ 2006-08-28 21:15   ` Hadron Quark
  2006-08-29 19:51     ` Kevin Rodgers
  2006-08-28 21:24   ` David Kastrup
  1 sibling, 1 reply; 6+ messages in thread
From: Hadron Quark @ 2006-08-28 21:15 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Hadron Quark wrote:
>> Is the snippet below the best way to prompt and parse an integer value?
>>
>>
>> (defun count-words(max)
>>   "count words in buffer"
>>   (interactive "nMax words to count to:")
>>   (while (zerop max)
>>     (setq max (string-to-number(read-string "> 0 please. re-enter:"))))
>
> The only thing I see wrong with it is that the check runs outside
> of the interactive form, and prompts the user (regardless of whether
> the function was called interactively).

Youve lost me : what do you mean "outside of the interactive form" - the
whole function is an interactive form isnt it?

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

* Re: newbie : elisp - prompt for input
       [not found] ` <mailman.5849.1156799345.9609.help-gnu-emacs@gnu.org>
  2006-08-28 21:15   ` Hadron Quark
@ 2006-08-28 21:24   ` David Kastrup
  2006-08-29 19:53     ` Kevin Rodgers
  1 sibling, 1 reply; 6+ messages in thread
From: David Kastrup @ 2006-08-28 21:24 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Hadron Quark wrote:
>> Is the snippet below the best way to prompt and parse an integer value?
>>
>>
>> (defun count-words(max)
>>   "count words in buffer"
>>   (interactive "nMax words to count to:")
>>   (while (zerop max)
>>     (setq max (string-to-number(read-string "> 0 please. re-enter:"))))
>
> The only thing I see wrong with it is that the check runs outside
> of the interactive form, and prompts the user (regardless of whether
> the function was called interactively).

It will also permit entering negative numbers.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: newbie : elisp - prompt for input
  2006-08-28 21:15   ` Hadron Quark
@ 2006-08-29 19:51     ` Kevin Rodgers
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2006-08-29 19:51 UTC (permalink / raw)


Hadron Quark wrote:
> Kevin Rodgers <ihs_4664@yahoo.com> writes:
> 
>> Hadron Quark wrote:
>>> Is the snippet below the best way to prompt and parse an integer value?
>>>
>>>
>>> (defun count-words(max)
>>>   "count words in buffer"
>>>   (interactive "nMax words to count to:")
>>>   (while (zerop max)
>>>     (setq max (string-to-number(read-string "> 0 please. re-enter:"))))
>> The only thing I see wrong with it is that the check runs outside
>> of the interactive form, and prompts the user (regardless of whether
>> the function was called interactively).
> 
> Youve lost me : what do you mean "outside of the interactive form" - the
> whole function is an interactive form isnt it?

No, the interactive form is exactly that: (interactive "nMax words to 
count to:")

The interactive form is a declaration whose only effect is to bind
the function arguments to values when it's called interactively:
via an input event binding, M-x (execute-extended-command), or the
call-interactively function.

If you type "(count-words 0)" into the *scratch* buffer (without the
quotes) and type `C-x e' or `C-j', you'll be prompted to re-enter MAX
even though you were never prompted in the first place.

-- 
Kevin

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

* Re: newbie : elisp - prompt for input
  2006-08-28 21:24   ` David Kastrup
@ 2006-08-29 19:53     ` Kevin Rodgers
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2006-08-29 19:53 UTC (permalink / raw)


David Kastrup wrote:
> Kevin Rodgers <ihs_4664@yahoo.com> writes:
> 
>> Hadron Quark wrote:
>>> Is the snippet below the best way to prompt and parse an integer value?
>>>
>>>
>>> (defun count-words(max)
>>>   "count words in buffer"
>>>   (interactive "nMax words to count to:")
>>>   (while (zerop max)
>>>     (setq max (string-to-number(read-string "> 0 please. re-enter:"))))
>> The only thing I see wrong with it is that the check runs outside
>> of the interactive form, and prompts the user (regardless of whether
>> the function was called interactively).
> 
> It will also permit entering negative numbers.

If Hadron upgrades to Emacs 22, s/he can use read-number instead of
(string-to-number (read-string ...))

-- 
Kevin

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

end of thread, other threads:[~2006-08-29 19:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-28 19:17 newbie : elisp - prompt for input Hadron Quark
2006-08-28 21:07 ` Kevin Rodgers
     [not found] ` <mailman.5849.1156799345.9609.help-gnu-emacs@gnu.org>
2006-08-28 21:15   ` Hadron Quark
2006-08-29 19:51     ` Kevin Rodgers
2006-08-28 21:24   ` David Kastrup
2006-08-29 19:53     ` Kevin Rodgers

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.