GNU bug report logs - #18821
25.0.50; Let pp-macroexpand-expression expand only once

Previous Next

Package: emacs;

Reported by: michael_heerdegen <at> web.de

Date: Fri, 24 Oct 2014 23:15:02 UTC

Severity: wishlist

Found in version 25.0.50

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 18821 in the body.
You can then email your comments to 18821 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#18821; Package emacs. (Fri, 24 Oct 2014 23:15:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to michael_heerdegen <at> web.de:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 24 Oct 2014 23:15:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; Let pp-macroexpand-expression expand only once
Date: Sat, 25 Oct 2014 01:13:36 +0200
Hello,

this is a feature request.

The problem is the following:

When writing a complex macro, one often wants to check some examples to
see if it expands code as intended.

There are different ways of doing that: M-x pp-macroexpand-expression or
M-x emacs-lisp-macroexpand for example.

But there is a problem: if the macro expansion is a toplevel call to
some other macro, this one will also be expanded, because the above
commands use `macroexpand' which successively expands until the result
is not a macro call.  This is not useful for checking macro expansions.

I want to suggest to alter `pp-macroexpand-expression', or to provide a
new command, based on a function that expands only one time like

    (defun macroexpand1 (expr)
      (apply (cdr (symbol-function (car expr))) (cdr expr)))

(This can no doubt be improved, e.g. to DTRT for autoloaded macros.)


Or did I miss something?  Opinions?


Thanks,

Michael.





In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.14.1)
 of 2014-10-17 on drachen
Windowing system distributor `The X.Org Foundation', version 11.0.11601000
System Description:	Debian GNU/Linux testing (jessie)





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18821; Package emacs. (Tue, 28 Oct 2014 17:01:01 GMT) Full text and rfc822 format available.

Message #8 received at 18821 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 18821 <at> debbugs.gnu.org
Subject: Re: bug#18821: 25.0.50; Let pp-macroexpand-expression expand only once
Date: Tue, 28 Oct 2014 13:00:09 -0400
>     (defun macroexpand1 (expr)
>       (apply (cdr (symbol-function (car expr))) (cdr expr)))

Daniel Colascione already submitted a patch that provides
a macroexpand1.  And if that's not sufficient I also wrote my own.
The only reason I haven't installed it is because it would make a lot of
sense to reimplement `macroexpand' (in Elisp) on top of `macroexpand1',
but when I tried that, byte-compilation slowed down by about 5%, which
seemed excessive (especially since it reflects an even larger slowdown
of macroexpansion itself, tho I haven't measured that in more detail).


        Stefan


(defun macroexp-expand-1 (form environment)
  "Perform (at most) one step of macroexpansion."
  (cond
   ((consp form)
    (let* ((head (car form))
           (env-expander (assq head environment)))
      (if env-expander
          (if (cdr env-expander)
              (apply (cdr env-expander) (cdr form))
            form)
        (if (not (and (symbolp head) (fboundp head)))
            form
          (let ((def (autoload-do-load (symbol-function head) head 'macro)))
            (cond
             ;; Follow alias, but only for macros, otherwise we may end up
             ;; skipping an important compiler-macro (e.g. cl--block-wrapper).
             ((and (symbolp def) (macrop def)) (cons def (cdr form)))
             ((not (consp def)) form)
             (t
              (if (eq 'macro (car def))
                  (apply (cdr def) (cdr form))
                form))))))))
   (t form)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18821; Package emacs. (Wed, 29 Oct 2014 03:55:02 GMT) Full text and rfc822 format available.

Message #11 received at 18821 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18821 <at> debbugs.gnu.org
Subject: Re: bug#18821: 25.0.50; Let pp-macroexpand-expression expand only once
Date: Wed, 29 Oct 2014 04:53:56 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> Daniel Colascione already submitted a patch that provides a
> macroexpand1.  And if that's not sufficient I also wrote my own.  The
> only reason I haven't installed it is because it [...]

Ok, thanks for the info.  I think that this macroexpand1 should also be
made available via some command.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18821; Package emacs. (Fri, 31 Oct 2014 21:38:01 GMT) Full text and rfc822 format available.

Message #14 received at 18821 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 18821 <at> debbugs.gnu.org
Subject: Re: bug#18821: 25.0.50; Let pp-macroexpand-expression expand only once
Date: Fri, 31 Oct 2014 17:36:59 -0400
>> Daniel Colascione already submitted a patch that provides a
>> macroexpand1.  And if that's not sufficient I also wrote my own.  The
>> only reason I haven't installed it is because it [...]
> Ok, thanks for the info.  I think that this macroexpand1 should also be
> made available via some command.

I installed my macroexpand-1 into trunk.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18821; Package emacs. (Sun, 02 Nov 2014 04:08:02 GMT) Full text and rfc822 format available.

Message #17 received at 18821 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 18821 <at> debbugs.gnu.org
Subject: Re: bug#18821: 25.0.50; Let pp-macroexpand-expression expand only once
Date: Sun, 02 Nov 2014 05:07:29 +0100
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> I installed my macroexpand-1 into trunk.

Thanks!

Do you think that `pp-macroexpand-expression' and
`pp-macroexpand-last-sexp' should use it?  I don't use these, but they
seem to be intended mainly for testing, where `macroexpand-1'
would makes more sense then `macroexpand'.

If you think the question is not important cause nobody uses the
pp-macroexpand stuff (dunno), feel free to close.


Thanks,

Michael.




Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Sun, 02 Nov 2014 05:47:02 GMT) Full text and rfc822 format available.

Notification sent to michael_heerdegen <at> web.de:
bug acknowledged by developer. (Sun, 02 Nov 2014 05:47:02 GMT) Full text and rfc822 format available.

Message #22 received at 18821-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: 18821-done <at> debbugs.gnu.org
Subject: Re: bug#18821: 25.0.50; Let pp-macroexpand-expression expand only once
Date: Sun, 02 Nov 2014 01:46:23 -0400
>> I installed my macroexpand-1 into trunk.
> Thanks!
> Do you think that `pp-macroexpand-expression' and
> `pp-macroexpand-last-sexp' should use it?

Oh, yes, of course.  Same for emacs-lisp-macroexpand.
Sorry for forgetting about the actual bug report.  It's done now,


        Stefan




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 30 Nov 2014 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 202 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.