[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I debug a macro?
From: |
Phillip Lord |
Subject: |
Re: How can I debug a macro? |
Date: |
Wed, 16 Dec 2015 09:43:30 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> Hello,
>
> I'm trying to track down a bug in `org-babel-comint-with-output' which
> is a macro in org's ob-comint.el. I know how to use edebug, but it does
> not seem to work with macros. I tried to read the info manual to figure
> out how to use it (for instance info:elisp#Instrumenting Macro Calls),
> but I don't understand what I actually need to do to be able to step
> through this code.
>
> Could someone please give me a hand in debugging this macro?
It depends what you want to do. If you use edebug on the macro itself,
you will get step-through debugging on the macro expansion. This can be
useful, although in most cases, I find "M-x pp-macroexpand-last-sexp"
works better (the macrostep package is worth looking as well, cause it's
very cool).
If you want to debug a *usage* of the macro, then the macro itself needs
to declare to edebug how it should be evaled. In most cases this is
quite easy. For `org-babel-comint-with-output' it's slightly tricker
because AFAICT the `meta' argument is not evaluated.
Consider these:
(defmacro temp-m (one &rest body)
(declare (debug (form body)))
(let ((a one))
`(progn ,@body)))
(defun h ()
(temp-m
'(1 2 3)
(message "hello")))
with the "declare" form in temp-m, calling "h" will step through the
code in "h" as you expect. The debug sexp means "first argument is a
form, the rest are body elements which need stepping through".
So, I think evalling:
(def-edebug-spec org-babel-comint-with-output
(form body))
should do the trick, although probably you want to send a patch in for
org-comint.el (using the declare version) so that it works for everyone.
Phil