I've noticed a trend in my code of repeating the same (with-current-buffer ....
over and over again so I decided to define a macro based off that macro definition of with-current-buffer
- this is what I have so far:
(defmacro with-assembla-buffer(asm-buffer-name heading-str &rest body)
"Create buffer with name of ASM-BUFFER-NAME, or uses it if exists,
preps it with readonly/erase/heading - executes `body' - then puts
readonly back on, goes to beginning of buffer, and switches to it."
(with-current-buffer (get-buffer-create asm-buffer-name)
(assembla-mode)
(toggle-read-only -1)
(erase-buffer)
(insert (format "-- %s --------------------" heading-str))
(newline)
`(progn ,@body)
(toggle-read-only 1)
(goto-char (point-min))
(switch-to-buffer (current-buffer))))
The body of this is never being executed, however when it's switched to defun
instead of defmacro
is does work perfectly. So aside from why is body never executed, my other question is - does this make more sense as a macro than a defun?
Remember, a macro generates code. Your macro looks like it does not. Check out a macro expansion of an example call. The first step of debugging a macro is to check the macro expansion of some code.
....
(with-current-buffer (get-buffer-create asm-buffer-name)
Above: why is this as code in the macro and not as source code? This code will be executed when the macro is expanded, it won't appear in the generated code. You probably want to backquote it.
(assembla-mode)
(toggle-read-only -1)
(erase-buffer)
(insert (format "-- %s --------------------" heading-str))
(newline)
`(progn ,@body)
Above: this won't do what you want. You need to backquote ALL the code you want to generate - not just this form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With