|
From: | Bill Brodie |
Subject: | Numeric argument defaulting |
Date: | Sun, 20 Jun 2004 12:58:21 +0000 (UTC) |
User-agent: | tin/1.6.1-20030810 ("Mingulay") (UNIX) (NetBSD/1.5.4_ALPHA (i386)) |
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?
[Prev in Thread] | Current Thread | [Next in Thread] |