gpt4 book ai didi

带有可选数字前缀的 emacs 交互函数

转载 作者:太空宇宙 更新时间:2023-11-03 18:35:00 25 4
gpt4 key购买 nike

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

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

最佳答案

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

关于带有可选数字前缀的 emacs 交互函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2215298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com