如何指定具有可选数字前缀的函数,如果没有,它会提示输入数字?基本上goto-line表现如何?
(defun my-function(&optional n)
; I have tried
(interactive "N") ; reads string, no prompt
(interactive "p") ; defaults to one
(interactive (if (not n) (read-number "N: "))) ; runtime error
那我怎么做工作? 感谢
答案 0 :(得分:9)
了解'goto-line
的定义方式M-x find-function goto-line RET
。
(defun my-function (n)
"Example function taking a prefix arg, or reading a number if no prefix arg"
(interactive
(if (and current-prefix-arg (not (consp current-prefix-arg)))
(list (prefix-numeric-value current-prefix-arg))
(list (read-number "N: ")))))