help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie : elisp - prompt for input


From: Kevin Rodgers
Subject: Re: newbie : elisp - prompt for input
Date: Tue, 29 Aug 2006 13:51:45 -0600
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)

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





reply via email to

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