unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Bill Brodie <wbrodie@panix.com>
Subject: Numeric argument defaulting
Date: Sun, 20 Jun 2004 12:58:21 +0000 (UTC)	[thread overview]
Message-ID: <cb41ld$he5$1@reader2.panix.com> (raw)

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?

             reply	other threads:[~2004-06-20 12:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-20 12:58 Bill Brodie [this message]
2004-06-21 15:27 ` Numeric argument defaulting 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='cb41ld$he5$1@reader2.panix.com' \
    --to=wbrodie@panix.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).