unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: newbie : elisp - prompt for input
Date: Tue, 29 Aug 2006 13:51:45 -0600	[thread overview]
Message-ID: <ed25u4$fhp$1@sea.gmane.org> (raw)
In-Reply-To: <87y7t836ka.fsf@mail.com>

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	other threads:[~2006-08-29 19:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2006-08-28 21:24   ` David Kastrup
2006-08-29 19:53     ` Kevin Rodgers

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='ed25u4$fhp$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /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.
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).