I'm in the process of "modularizing" my config file and ran into a problem involving elisp macros.

Because of the way in which I'm defining my configuration modules, I ended up with a bunch of code blocks as the following:

(with-eval-after-load (expand-file-name
    :infix "o"
    "e" '(ebib :which-key "ebib"))
  (some-function x y z))

Since I was repeting that a lot, I tried to define a macro to have more readable config files. It is my first time writing macros in elisp, so this was what I ended up with:

(defmacro j/con-load (module &rest funcs)
      "TODO doc goes here"
           (expand-file-name (concat ,module ".el" j/config-path))

I'm trying to call it with

(j/con-load "latex"
    :infix "o"
    "e" '(ebib :which-key "ebib"))
  (some-function x y z))

but it just doesn't work.

What am I doing wrong here?


M-x pp-macroexpand-last-sexp is your friend. It shows you the code that your macro is expanding into, which is:

     (concat "latex" ".el" j/config-path))

Which tells Emacs to evaluate the variable funcs (which probably won't exist) should it ever load a library </path/to/current/default-directory>/latex.el</value/of/j/config-path> (which seems rather unlikely to ever occur).

@q.undertow has covered the concat usage.

For the rest, you probably wanted to splice your &rest argument into the expanded macro with ,@funcs ?

See C-hig (elisp)Backquote for more about splicing.


For one thing (and I am not at all sure there isn't another problem), the call to expand-file-name in the macro body is scrambled. It should be

(expand-file-name (concat ,module ".el") j/config-path)

Also you may want to evaluate the concatentation at macro expansion time:

(expand-file-name ,(concat module ".el") j/config-path)

hope this helps

  • Thanks for pointing this out. As you said, there are more errors in my code, with this is one less thing to worry about. – juanerasmoe Aug 30 '20 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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