最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论