你能在Emacs Lisp宏中创建交互式功能吗?

8 macros elisp

我正在尝试在emacs lisp中编写一个宏来创建一些"辅助函数".

最终,我的助手功能将比我在这里更有用.我意识到可能有更好/更直观的方法来完成同样的事情(请发帖)但我的基本问题是为什么这不起作用/我做错了什么:

(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?")
Run Code Online (Sandbox Code Playgroud)

如果我获取macroexpand的输出并评估它,我得到了我打算用宏获得的交互式函数,但即使宏运行并且似乎评估,我也无法调用M-x text-nitext-swallow.

Tre*_*son 11

这样做你想要的:

(defmacro deftext (functionname texttoinsert)
  (let ((funsymbol (intern (concat "text-" functionname))))
`(defun ,funsymbol () (interactive) (insert-string ,texttoinsert))))
Run Code Online (Sandbox Code Playgroud)


Mar*_*usQ 1

已经过去很多年了,但我认为您可能缺少fset定义该函数的方法;如果您也想要编译时间,请参阅文档。