From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Numeric argument defaulting
Date: Mon, 21 Jun 2004 09:27:38 -0600 [thread overview]
Message-ID: <40D6FE6A.8010403@yahoo.com> (raw)
In-Reply-To: cb41ld$he5$1@reader2.panix.com
Bill Brodie wrote:
> I have several utility functions that take optional numeric arguments and
> that I'd also like to make interactive. There are two ways to do this:
>
> 1. Define the function to accept either a raw or a numeric argument.
>
> (defun f (&optional x)
> (interactive "P")
> (cond
> ((numberp x))
> ((null x) (setq x <default value>))
> (t (setq x (prefix-numeric-value x))))
> ...)
>
> -or-
>
> 2. Define an interactive wrapper around the function.
>
> (defun f (&optional x)
> (if (null x) (setq x <default value>))
> ...)
> (defun f-interactive (x)
> (interactive "P")
> (if x (f (prefix-numeric-value x)) (f)))
>
>
> Neither of these seems especially clean. Is there a standard Emacs Lisp
> idiom for this?
The argument is numeric, so use (interactive "p"). It will default to 1
when the argument isn't specified interactively. If you want to provide
a default when it's called programmatically, you have to do that
explicitly.
(defun f (&optional x)
(interactive "p")
(if (null x) (setq x 1))
...)
--
Kevin Rodgers
prev parent reply other threads:[~2004-06-21 15:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-20 12:58 Numeric argument defaulting Bill Brodie
2004-06-21 15:27 ` Kevin Rodgers [this message]
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=40D6FE6A.8010403@yahoo.com \
--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).