问题描述
我正在尝试在 emacs lisp 中编写一个宏来创建一些辅助函数".
I'm trying to write a macro in emacs lisp to create some ‘helper functions.’
最终,我的辅助函数将比我这里的更有用.我意识到可能有更好/更直观的方法来完成同样的事情(请发布),但我的基本问题是为什么这不起作用/我做错了什么:
Ultimately, my helper functions will be more useful than what I have here. I realize that there may be better/more intuitive ways to accomplish the same thing (please post) but my basic question is why won't this work/what am I doing wrong:
(defmacro deftext (functionname texttoinsert)
`(defun ,(make-symbol (concatenate 'string "text-" functionname)) ()
(interactive)
(insert-string ,texttoinsert)))
(deftext "swallow" "What is the flight speed velocity of a laden swallow?")
(deftext "ni" "What is the flight speed velocity of a laden swallow?")
如果我获取宏扩展的输出并对其进行评估,我将获得我打算通过宏获得的交互式函数,但即使宏运行并似乎在评估,我也无法调用 Mx text-ni
或 text-swallow
.
If I take the output of the macroexpand and evaluate that, I get the interactive functions I was intending to get with the macro, but even though the macro runs and appears to evaluate, I can't call M-x text-ni
or text-swallow
.
推荐答案
这就是你想要的:
(defmacro deftext (functionname texttoinsert)
(let ((funsymbol (intern (concat "text-" functionname))))
`(defun ,funsymbol () (interactive) (insert-string ,texttoinsert))))
这篇关于你能在 Emacs Lisp 宏中创建交互式函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!