I have make a macro that creates dynamic functions:

(defmacro tjb-make-register-macro (func-name out-string)
   (list 'defun func-name () '(interactive) (list 'insert out-string)))

;; This call succeeds [note abc1 is not defined]:
(tjb-make-register-macro abc1 "hello1")

;; These fail:
(tjb-make-register-macro (make-symbol "abc2") "hello2")
(tjb-make-register-macro (intern "abc2") "hello2")

;; I'm trying to write a function like this to call this macro dynamically
;; but this doesn't work:
(defun tjb-make-register (func-name out-string)
  (interactive "sFunc-name:\nsfunc-out")
  (tjb-make-register-macro ((intern func-name) out-string)))

How can I make an interactive function that correctly calls my macro.

1 Answer 1


One way to do this is to avoid the defun macro and use defalias for setting up the function:

  (defalias (intern "tjb-make-register")
      (lambda (func-name out-string)
        (interactive "sFunc-name:\nsfunc-out\n")
        (fset (intern func-name) (eval `(lambda () (interactive) (insert ,out-s\
  • 1
    I'd suggest defalias instead of fset
    – npostavs
    Aug 3, 2019 at 22:21
  • Not sure how to make that work here, can you provide an example?
    – tjb
    Aug 5, 2019 at 3:54
  • Just write defalias where you currently have fset.
    – npostavs
    Aug 5, 2019 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.