help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a way to instrument for edebug a form (say, a progn) given


From: Marcin Borkowski
Subject: Re: Is there a way to instrument for edebug a form (say, a progn) given to `eval'?
Date: Tue, 05 Jan 2016 10:16:50 +0100
User-agent: mu4e 0.9.13; emacs 25.1.50.1


On 2016-01-05, at 00:26, Michael Heerdegen <michael_heerdegen@web.de> wrote:

> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> (eval
>>  '(progn
>>     (message "foo")
>>     (message "bar")))
>>
>> and see how Edebug doesn't step into the progn.
>
> That's expected, the argument to eval can be anything, in particular,
> something that is not written down in some buffer.  In the above case,
> you call eval on a constant, and edebug can't know where this constant
> comes from.
>
> Paste the progn form somewhere and hit C-u C-M-x if you want to use
> edebug.

I guess you misunderstood me.  It's not that I have this in actual code,
or that I really want to edebug _this_ progn.  I have (more or less)
this in actual code:

(defun conditional-save-excursion-1-function (arg form)
  "If ARG is non-nil, eval FORM inside a `save-excursion'."
  (if arg
      (save-excursion
        (eval form))
    (eval form)))

I was curious whether it is possible to step with edebug through
`form'.

Also, this is not "actual code" in a sense that I want to actually use
it anywhere.  Disclosure: it comes from the draft of my Emacs book,
chapter on macros, where I try to explain why a macro is better than
a function in such a case.  One of the reasons is that you can't use
edebug if you use a function and not a macro like this:

(defmacro conditional-save-excursion-1 (arg form)
  "If ARG is non-nil, wrap FORM in `save-excursion'."
  (declare (indent 1) (debug t))
  (if arg
      `(save-excursion ,form)
    form))

(BTW, this macro is inspired by a real use-case.)

My question was because I do not want to write it in the book if I'm not
100% sure I'm right, and I wasn't sure.  (Though it seems that I was
right after all - Stefan's trick with replacing the backquote with its
edebug-compliant variant doesn't count, I guess;-).)

> Michael.

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

[Prev in Thread] Current Thread [Next in Thread]