From: phillip.lord@russet.org.uk (Phillip Lord)
To: Alan Schmitt <alan.schmitt@polytechnique.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How can I debug a macro?
Date: Wed, 16 Dec 2015 21:21:28 +0000 [thread overview]
Message-ID: <87y4cuxf6v.fsf@russet.org.uk> (raw)
In-Reply-To: <m2fuz2h6l5.fsf@polytechnique.org> (Alan Schmitt's message of "Wed, 16 Dec 2015 14:21:42 +0100")
Alan Schmitt <alan.schmitt@polytechnique.org> writes:
> On 2015-12-16 10:43, phillip.lord@russet.org.uk (Phillip Lord) writes:
>
>> 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.
>
> I want to debug the usage of the macro. It returns the wrong value and
> I want to understand why.
>
>>
>> (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.
>
> I'm trying this, but I'm confused at to what I need to do after I add
> the declare form.
Sorry, I should have given a complete example. But I didn't know how to
call org-babel-comint-with-output, so I was guessing.
>
> This is what I tried:
> - add the declare form to org-babel-comint-with-output
So, on closer insepction I realise that there is an edebug spec
immediately after the macro.
(def-edebug-spec org-babel-comint-with-output (sexp body))
> - C-u C-M-x on org-babel-comint-with-output
Yeah, don't do that. Otherwise, you will be debugging the macro
expansion.
> - evaluate a block in org-mode
>
> I then see a message:
> edebug: Symbol's value as variable is void: edebug-def-mark
Yep, sorry by debug form was a bit wrong.
> I then tried to debug the function calling the macro:
> - C-u C-M-x on org-babel-execute:ocaml
> - strangely, a debugging start even though I have not called the
> function yet (I have not evaluated the source block)
That's correct. You've instrumented org-babel-comint-with-output, so it
gets evaluated at the time you eval org-babel-execute:ocaml. The macro
returns some form, of course, and this will be evaluated when the
calling function is evaled.
> I feel like I'm missing something here. Am I using this correctly?
Try the debug statement given here. You should now get step through
debugging of the arguments to org-babel-comint-with-output (or the
second one anyway -- the first one is not evaluated).
If this still doesn't help, and you need to debug the *macro* not the
usage, then put point after this after do M-x pp-macroexpand-last-sexp
(org-babel-comint-with-output
(session org-babel-ocaml-eoe-output t full-body)
(insert
(concat
(org-babel-chomp
full-body)";;\n"org-babel-ocaml-eoe-indicator))
which will give you this.
(org-babel-comint-in-buffer session
(let
((string-buffer "")
dangling-text raw)
(setq comint-output-filter-functions
(cons
(lambda
(text)
(setq string-buffer
(concat string-buffer text)))
comint-output-filter-functions))
(unwind-protect
(progn
(goto-char
(process-mark
(get-buffer-process
(current-buffer))))
(let
((start
(point))
(end
(point-max)))
(setq dangling-text
(buffer-substring start end))
(delete-region start end))
(insert
(concat
(org-babel-chomp full-body)
";;\n" org-babel-ocaml-eoe-indicator))
(tuareg-interactive-send-input)
(while
(progn
(goto-char comint-last-input-end)
(not
(save-excursion
(and
(re-search-forward
(regexp-quote org-babel-ocaml-eoe-output)
nil t)
(re-search-forward comint-prompt-regexp nil t)))))
(accept-process-output
(get-buffer-process
(current-buffer))))
(goto-char
(process-mark
(get-buffer-process
(current-buffer))))
(insert dangling-text))
(setq comint-output-filter-functions
(cdr comint-output-filter-functions)))
(if
(and t full-body
(string-match
(replace-regexp-in-string "\n" "[\n]+"
(regexp-quote
(or full-body "")))
string-buffer))
(setq raw
(substring string-buffer
(match-end 0))))
(split-string string-buffer comint-prompt-regexp)))
Unfortunately, it's got another macro inside. If you *really* need to
debug this, then, the best you can do is put org-babel-execute:ocaml
into a file, and replace the org-babel-comint-with-output form with this
expansion. Then you can run edebug directly on that.
I'd rather not have a macro with such a large expansion myself, because
it is hard to debug, but sometimes it's necessary.
Phil
next prev parent reply other threads:[~2015-12-16 21:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-16 8:21 How can I debug a macro? Alan Schmitt
2015-12-16 9:43 ` Phillip Lord
2015-12-16 13:21 ` Alan Schmitt
2015-12-16 21:21 ` Phillip Lord [this message]
2015-12-17 7:27 ` Alan Schmitt
2015-12-17 11:39 ` William Xu
2015-12-17 12:03 ` Alan Schmitt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y4cuxf6v.fsf@russet.org.uk \
--to=phillip.lord@russet.org.uk \
--cc=alan.schmitt@polytechnique.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.