As we all know, you can pass an argument to a function in emacs by pressing C-u and a digit. We also know that just C-u means "4" and C-u C-u means 16. So doing some elisp programming I noticed that C-u 4 passes 4 as you'd expect, but just C-u passes a list .. (4), which surprised me. What is the reasoning for this, and what should I know about this behavior when designing emacs functions?
As we all know, you can pass an argument to a function in emacs by pressing C-u and a digit. We also know that just C-u means "4" and C-u C-u means 16. So doing some elisp programming I noticed that C-u 4 passes 4 as you'd expect, but just C-u passes a list .. (4), which surprised me. What is the reasoning for this, and what should I know about this behavior when designing emacs functions?
Share Improve this question edited Jan 31 at 18:40 Drew 30.8k7 gold badges79 silver badges109 bronze badges asked Jan 31 at 8:26 xpusostomosxpusostomos 1,66716 silver badges18 bronze badges 1 |2 Answers
Reset to default 2You can write an interactive function that behaves differently when called with C-u4 or with just C-u.
(defun my-function (arg) "..."
(interactive "P")
(pcase arg
('(4) ...)
(4 ...)
...
what should I know about this behavior when designing emacs functions?
You should know everything that the Emacs Lisp manual explains at:
C-hig (elisp)Prefix Command Arguments
(4)
and 4 as raw values have the value 4 as the numeric value. The function behavior can choose to behave differently for those different inputs. – Drew Commented Jan 31 at 18:44