gpt4 book ai didi

elisp - Emacs Lisp : How to use interactive (for conditional arguments)?

转载 作者:行者123 更新时间:2023-12-01 09:56:34 25 4
gpt4 key购买 nike

我想根据第一个问题的答案向用户提出第二个问题。

(defun something (a b)
(interactive
(list
(read-number "First num: ")
(read-number "Second num: ")))
(message "a is %s and b is %s" a b))

所以我需要一种方法来测试条目值:

(defun something-else (a &optional b)
(interactive
(list
(read-number "First num: ")
(if (< a 2)
(read-number "Second num: "))))
(message "a is %s" a))

但是

if: Symbol's value as variable is void: a

问题:我怎样才能以真正互动的方式使用 interactive

最佳答案

(defun xtest (a &optional b)
(interactive
(let (a b)
(setq a (read-number "First: "))
(if (< a 2)
(setq b (read-number "Second: ")))
(list a b)))

(message "a is %s b is %s" a b))

关于elisp - Emacs Lisp : How to use interactive (for conditional arguments)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25447312/

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