Questions tagged [elisp-macros]

Emacs Lisp macros enable you to define new control constructs and other language features. A macro is defined much like a function, but instead of telling how to compute a value, it tells how to compute another Lisp expression, which in turn is evaluated to compute the value. We call this expression the "expansion" of the macro call. The macro call is first expanded and then evaluated, returning the value of that evaluation.

Filter by
Sorted by
Tagged with
12
votes
3answers
1k views

When to use macro or not to use [closed]

When should I use macro in my program or not to? This question is inspired by an informative answer by @tarsius. I believe many have great experiences to share others. I hope this question become ...
13
votes
2answers
2k views

“and” vs “when” for conditionals

This is a follow-up on the comments on this answer. The following bits of code seem to be equivalent: (and a b) (when a b) Of course and lets you put more conditions: (and a b c d) means (when (and ...
6
votes
1answer
923 views

Make flycheck's “reference to free variable” work with macros

The use-package is a useful and popular macro for installing packages, but flycheck always complains about it since it hides variable definitions. For example, if I attempt (use-package org), Flycheck ...
4
votes
1answer
223 views

Use a variable to determine let bindings

Is there a way to use a variable to hold the set of let bindings for passing to a later call? For example (setq a '((org-export-with-toc nil) (blah 2))) Then (let-wrapper a ;; Perform ...
2
votes
2answers
172 views

Why does my function-generating macro only work when I evaluate its expansion?

I'm trying to write a macro that will define a function exactly once where I don't really care what the name of the function is. My thought was to generate a symbol, use defun with that, and then put ...
4
votes
1answer
354 views

idefun : a macro to turn defun into an 'interactive' defun?

I have a pattern like this scattered all over my .emacs: (defun my/function () (interactive) (....stuff) ) I would like to write a idefun macro so I could write as following instead: (idefun ...
4
votes
1answer
222 views

Macro with optional paramaters that checks for whether an optional paramater is defined?

Due to my lazy nature, I made something like this: (defmacro iλ (x) `(lambda () (interactive) ,x)) (defmacro iλd (x y) `(lambda () ,x (interactive) ,y)) (global-set-key (kbd "<f8>") (...
3
votes
3answers
402 views

How to avoid use of `lexical-let`

I have a macro that intends to creates a closure: ; -*- lexical-binding: t -*- (defmacro repro () (let ((kmap-sym (gensym "kmap-"))) `(let ((,kmap-sym (make-sparse-keymap))) (define-key ,...
3
votes
0answers
306 views

Byte-compiling a file loads macros with `(eval-and-compile)` but not `(eval-when-compile)`

I created a buffer, test1.el: (eval-when-compile (defmacro dummy-macro (_) nil) (dummy-macro s)) Trying to compile this file, I get the following errors: In toplevel form: test1.el:3:16:Warning:...
0
votes
0answers
73 views

with-accessors for all accessors?

common lisp has a with-accessors macro which is pretty useful but it is still prone to lots of code duplication. Is there a convenient let/binding macro that makes all accessors from a defclass ...