tags:

views:

238

answers:

2

I'm trying to write a macro in emacs lisp to create some 'helper functions'

Ultimately, my helper functions will be more useful that 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?")

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

Suggestions? Thanks!

A: 

It's been years, but I think you're probably missing an fset to define the function; see the docs if you are wanting it a compile time too.

MarkusQ
+3  A: 

This does what you want:

(defmacro deftext (functionname texttoinsert)
  (let ((funsymbol (intern (concat "text-" functionname))))
`(defun ,funsymbol () (interactive) (insert-string ,texttoinsert))))
Trey Jackson
intern did the trick. I didn't even need the let(defmacro deftext (functionname texttoinsert) `(defun ,(intern (concatenate 'string "text-" functionname)) () (interactive) (insert-string ,texttoinsert)))I had tried intern before, but I think I had called it wrong.Thanks!