help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rationale behind conversion of a nil prefix arg to numeric 1


From: Kaushal Modi
Subject: Re: Rationale behind conversion of a nil prefix arg to numeric 1
Date: Thu, 08 Sep 2016 13:10:56 +0000

On Wed, Sep 7, 2016 at 10:41 PM Charles Millar <millarc@verizon.net> wrote:

> I have read this thread as well as the other suggested readings.



> If the
> purpose of either p or P is to pass arguments, I do not understand the
> rationale of allowing C-u when using the interactive upper case P.


That's useful if the user wants the function to behave different based on
if the arg is a list or not.


> As
> noted above, It returns an integer as the only element in a list, which
> if evaluated returns an error.


If the arg is a list (C-u), you have to treat it as a list.. e.g. use (car
arg).


> Is there a use for this?


It's up to the user on how they want to treat different arg values.


> Such as you may
> want an error?


Here's a dummy example:

(defun foo (arg)
  (interactive "P")
  (message (concat "Arg is "
                   (cond
                    ((null arg)
                     "nil")
                    ((listp arg)
                     (format "a list with element %d" (car arg)))
                    (t
                     (format "a number %d" arg))))))
(global-set-key (kbd "C-c '") #'foo)''''


After evaluating the above, do

- C-c '
- C-0 C-c ' or M-0 C-c '
- C-1 C-c ' or M-1 C-c '
- ..
- C-u C-c '
- C-4 C-c ' or M-4 C-c '
- C-u C-u C-c '
- C-1 C-6 C-c ' or M-1 M-6 C-c '

If the user wishes, they can make the foo function behave differently for
each of the above bullets.

So it eventually boils down to what the user wants.. do they want the
default arg to be nil or 1, do they want to support C-u and C-4 args in
different manner, etc. Based on that, they can choose to use the "p" or "P"
version of interactive.
-- 

Kaushal Modi


reply via email to

[Prev in Thread] Current Thread [Next in Thread]