emacs - Why does C-u pass a list to elisp? - Stack Overflow

As we all know, you can pass an argument to a function in emacs by pressing C-u and a digit. We also kn

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
  • The function can behave differently depending on the raw value of the prefix argument and its numeric value. But (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
Add a comment  | 

2 Answers 2

Reset to default 2

You 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745275230a4619998.html

相关推荐

  • emacs - Why does C-u pass a list to elisp? - Stack Overflow

    As we all know, you can pass an argument to a function in emacs by pressing C-u and a digit. We also kn

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信