Elisp interactive function name

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I'm trying to use the interactive function name feature. On emacs lisp manual it says:

‘a’ A function name (i.e., a symbol satisfying fboundp). Existing, Completion, Prompt.

So I tried it with a small test code:

(defun testfun1 ()   (message "hello, world!"))  (defun test (abcd)   (interactive "aTheme name: ")   (abcd)) 

Emacs gives an error saying,

test: Symbol's function definition is void: abcd

I tried to test abcd with fboundp, it returns t. So I'm quite confused about how to use the 'a' option in interactive. Any body can give some hints?

回答1:

Your function test receives its argument abcd as a function, but you can't just invoke a function by putting a symbol referencing it in the first position of a list to be evaluated. Since Emacs Lisp is a Lisp-2, the reference to the function provided to the interactive query is stored in symbol abcd's value slot, not its function slot. The evaluation rules for a list like

(abcd) 

involve looking in the first object's function slot if that object is a symbol, which it is in your case. If instead you wish to invoke a function referenced in a symbol's value slot, you need the funcall function:

(funcall abcd) 

That says, "Take abcd, grab the value out of its value slot, and, provided it's a function, call it here, just as we would have if that function had been referenced in the list's first position either in a symbol's function slot or by a direct reference to the function object."

Here's an answer to a similar question with references useful to allow you probe further.



回答2:

This should do this trick:

(defun test (abcd)   (interactive "aTheme name: ")   (call-interactively abcd)) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!