【问题标题】:emacs interactive function with optional numeric prefix带有可选数字前缀的 emacs 交互函数
【发布时间】:2010-02-07 00:10:52
【问题描述】:

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

那么我该如何工作呢? 谢谢

【问题讨论】:

  • FWIW,如果要提示“N”,只需在 N 后面添加提示文本即可; (interactive "NType a number: ").

标签: emacs lisp prefix optional


【解决方案1】:

看看'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: ")))))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 2013-01-17
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    相关资源
    最近更新 更多