带有可选数字前缀的emacs交互式功能

时间:2010-02-07 00:10:52

标签: emacs lisp prefix optional

如何指定具有可选数字前缀的函数,如果没有,它会提示输入数字?基本上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

那我怎么做工作? 感谢

1 个答案:

答案 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: ")))))
相关问题