[Top][All Lists]

[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: Charles Millar
Subject: Re: Rationale behind conversion of a nil prefix arg to numeric 1
Date: Thu, 08 Sep 2016 10:42:56 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 09/08/2016 09:10 AM, Kaushal Modi wrote:
On Wed, Sep 7, 2016 at 10:41 PM Charles Millar < <>> 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.

    noted above, It returns an integer as the only element in a list,
    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 "
                    ((null arg)
                    ((listp arg)
                     (format "a list with element %d" (car arg)))
                     (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.

Thank you, Kaushal!

I suspect that the following has been said many times on this and other lists - "An example, as is a picture, is worth a 1000 words."

Charlie Millar

reply via email to

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