[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION
From: |
gnuist006 |
Subject: |
Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION |
Date: |
17 Oct 2002 07:22:41 -0700 |
"Bingham, Jay" <Jay.Bingham@hp.com> wrote in message
news:<mailman.1034620095.15632.help-gnu-emacs@gnu.org>...
>
> Here is your function using a string arg-descriptor, that does some very
> crude numeric validation and inserts a 5 when nothing is entered at the
> prompt.
>
> (defun demo (&optional number)
> "Demo of an optional argument of the function."
> (interactive "sEnter a numeric value:")
> (setq defaultval "5")
> (if (string= "" number) (setq number defaultval))
> (if (not (string-match "[:alpha:]" number))
> (insert (format "%s" number))
> (message "non-numeric value entered, please re-enter"))
> )
It works on my GNU Emacs 20.3.1 when modified to:
(if (string-match "[0-9]+" number)
(insert (format "%s" number))
(message "non-numeric value entered, please re-enter"))
)
But as you said below fails to ask number again when "x" is given
as the value. I am still lookin for a good solution that does validation
and probably displays the default value when it asks the number
first time without ruining single instantiation of the default value.
> If you want a function that prompts for a number until one is entered
> you will have to use an elisp expression type arg-descriptor and do your
> own number validation.
- Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION, (continued)
Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION, Friedrich Dominicus, 2002/10/18
RE: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION, Bingham, Jay, 2002/10/14
Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION,
gnuist006 <=