1

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?

sudo
  • 647
  • 2
  • 7
  • 19

2 Answers2

5

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.

Community
  • 1
  • 1
seh
  • 14,999
  • 2
  • 48
  • 58
0

This should do this trick:

(defun test (abcd)
  (interactive "aTheme name: ")
  (call-interactively abcd))
Colin Cochrane
  • 2,565
  • 1
  • 19
  • 20