I think I found a bug in defmacro
so I'd like to ask for confirmation before I make a fool of myself reporting something silly!
Here is how to reproduce it:
- Define the following macro which simply reports the value of
case-fold-search
in the minibuffer:
(defmacro report-case-fold-search ()
(let ((cfs case-fold-search))
`(message "%s" ,cfs)))
- Execute it several times with randomly alternating values of
case-fold-search
:
(progn (setq case-fold-search nil) (report-case-fold-search))
(progn (setq case-fold-search t) (report-case-fold-search))
The output I get seems to indicate that there is a delay in the sense that each time I go from one to the other, it takes two tries to get the expected output.
- To be more precise, execute the following at least 3 times in a row:
(progn (setq case-fold-search nil) (report-case-fold-search))
- Then execute once:
(progn (setq case-fold-search t) (report-case-fold-search))
- This time a get
nil
for an answer even thoughcase-fold-search
has just been set tot
.
Question. Can anyone reproduce this? If so, is there a sensible explanation for it? Otherwise, should I report it as a bug?
Here is my emacs version:
GNU Emacs 28.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2022-12-08
defun
, it defines a normal function.defmacro
on the other hand might look the same but returns a replacement expression, and it's a lot harder to get right. However, if you really want to use a macro I would recommend themacrostep
package which lets you see what a macro would expand to in the context where it is used.