Emacs Lisp:如何使用交互式(用于条件参数)? [英] Emacs Lisp: How to use interactive (for conditional arguments)?

查看:89
本文介绍了Emacs Lisp:如何使用交互式(用于条件参数)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to ask a second question to the user depending on the answer to the first one.

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

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

So I need a way to test the entry values :

(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

Question : How can I use interactive in a really interactive way?

推荐答案

(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))

这篇关于Emacs Lisp:如何使用交互式(用于条件参数)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆