GNU bug report logs - #68818
[PATCH] lisp/emacs-lisp/inline.el: Autoload public macros

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Tue, 30 Jan 2024 13:20:01 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 68818 AT debbugs.gnu.org.

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#68818; Package emacs. (Tue, 30 Jan 2024 13:20:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ihor Radchenko <yantar92 <at> posteo.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 30 Jan 2024 13:20:01 GMT) Full text and rfc822 format available.

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

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
Date: Tue, 30 Jan 2024 13:21:51 +0000
[Message part 1 (text/plain, inline)]
Tags: patch

Hello,

This patch solves annoying problem with `define-inline' forms not being
indented correctly unless inline.el is explicitly loaded.

For illustration, try to open the following foo.el file:

(define-inline org-element-type-p (node types)
  "Return non-nil when NODE type is one of TYPES.
TYPES can be a type symbol or a list of symbols."
  (if (inline-const-p types)
      (if (listp (inline-const-val types))
          (inline-quote (memq (org-element-type ,node t) ,types))
        (inline-quote (eq (org-element-type ,node t) ,types)))
    (inline-letevals (node types)
      (inline-quote
       (if (listp ,types)
           (memq (org-element-type ,node t) ,types)
         (eq (org-element-type ,node t) ,types))))))

with emacs -Q, indenting the file will yield different results with and
without executing (require 'inline).

With the patch, indentation becomes consistent.

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.39, cairo version 1.18.0) of 2024-01-28 built on localhost
Repository revision: 5e9ef5d65aea4c278bb58cfc84ea22e7983385da
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101010
System Description: Gentoo Linux

Configured using:
 'configure JAVAC=/etc/java-config-2/current-system-vm/bin/javac'

[0001-lisp-emacs-lisp-inline.el-Autoload-public-macros.patch (text/patch, attachment)]
[Message part 3 (text/plain, inline)]
-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68818; Package emacs. (Tue, 30 Jan 2024 14:11:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 68818 <at> debbugs.gnu.org
Subject: Re: bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public
 macros
Date: Tue, 30 Jan 2024 16:09:52 +0200
> From: Ihor Radchenko <yantar92 <at> posteo.net>
> Date: Tue, 30 Jan 2024 13:21:51 +0000
> 
> This patch solves annoying problem with `define-inline' forms not being
> indented correctly unless inline.el is explicitly loaded.
> 
> For illustration, try to open the following foo.el file:
> 
> (define-inline org-element-type-p (node types)
>   "Return non-nil when NODE type is one of TYPES.
> TYPES can be a type symbol or a list of symbols."
>   (if (inline-const-p types)
>       (if (listp (inline-const-val types))
>           (inline-quote (memq (org-element-type ,node t) ,types))
>         (inline-quote (eq (org-element-type ,node t) ,types)))
>     (inline-letevals (node types)
>       (inline-quote
>        (if (listp ,types)
>            (memq (org-element-type ,node t) ,types)
>          (eq (org-element-type ,node t) ,types))))))
> 
> with emacs -Q, indenting the file will yield different results with and
> without executing (require 'inline).
> 
> With the patch, indentation becomes consistent.

Hmm, I wonder whether there's a less heavy-handed approach to this.

Stefan, any suggestions?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68818; Package emacs. (Tue, 30 Jan 2024 14:31:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Ihor Radchenko <yantar92 <at> posteo.net>, 68818 <at> debbugs.gnu.org
Subject: Re: bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public
 macros
Date: Tue, 30 Jan 2024 09:30:36 -0500
>> This patch solves annoying problem with `define-inline' forms not being
>> indented correctly unless inline.el is explicitly loaded.
>> 
>> For illustration, try to open the following foo.el file:
>> 
>> (define-inline org-element-type-p (node types)
>>   "Return non-nil when NODE type is one of TYPES.
>> TYPES can be a type symbol or a list of symbols."
>>   (if (inline-const-p types)
>>       (if (listp (inline-const-val types))
>>           (inline-quote (memq (org-element-type ,node t) ,types))
>>         (inline-quote (eq (org-element-type ,node t) ,types)))
>>     (inline-letevals (node types)
>>       (inline-quote
>>        (if (listp ,types)
>>            (memq (org-element-type ,node t) ,types)
>>          (eq (org-element-type ,node t) ,types))))))

[ Side note: IIRC the above can be simplified as:

    (define-inline org-element-type-p (node types)
      "Return non-nil when NODE type is one of TYPES.
    TYPES can be a type symbol or a list of symbols."
      (inline-letevals (node types)
        (if (listp (inline-const-val types))
            (inline-quote (memq (org-element-type ,node t) ,types))
          (inline-quote (eq (org-element-type ,node t) ,types)))))

]

>> with emacs -Q, indenting the file will yield different results with and
>> without executing (require 'inline).
>> With the patch, indentation becomes consistent.
> Hmm, I wonder whether there's a less heavy-handed approach to this.

Agreed.  Also, I think this problem is not specific to `define-inline`.
Maybe the indentation code should try and (auto)load the macros
it encounters.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68818; Package emacs. (Tue, 30 Jan 2024 16:22:02 GMT) Full text and rfc822 format available.

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

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 68818 <at> debbugs.gnu.org
Subject: Re: bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public
 macros
Date: Tue, 30 Jan 2024 16:24:25 +0000
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

> [ Side note: IIRC the above can be simplified as:
>
>     (define-inline org-element-type-p (node types)
>       "Return non-nil when NODE type is one of TYPES.
>     TYPES can be a type symbol or a list of symbols."
>       (inline-letevals (node types)
>         (if (listp (inline-const-val types))
>             (inline-quote (memq (org-element-type ,node t) ,types))
>           (inline-quote (eq (org-element-type ,node t) ,types)))))

Thanks!
`inline-const-val' docstring does not make it clear what happens when
the value is not known at compile time.

>>> with emacs -Q, indenting the file will yield different results with and
>>> without executing (require 'inline).
>>> With the patch, indentation becomes consistent.
>> Hmm, I wonder whether there's a less heavy-handed approach to this.
>
> Agreed.  Also, I think this problem is not specific to `define-inline`.
> Maybe the indentation code should try and (auto)load the macros
> it encounters.

But how does it know that a given (expr ...) is a macro call or a
function call without loading the containing library? AFAIK, only
autoloading can provide such information.

Maybe, autoloading can automatically collect information about all the
symbols defined in each library - whether they are a
function/variable/macro and their declare statement?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68818; Package emacs. (Tue, 30 Jan 2024 18:12:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 68818 <at> debbugs.gnu.org
Subject: Re: bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public
 macros
Date: Tue, 30 Jan 2024 13:11:06 -0500
> Thanks!
> `inline-const-val' docstring does not make it clear what happens when
> the value is not known at compile time.

Indeed, the docstring is lacking. 🙁
It "fails" which means that we revert to the "fallback" of not inlining.

>>>> with emacs -Q, indenting the file will yield different results with and
>>>> without executing (require 'inline).
>>>> With the patch, indentation becomes consistent.
>>> Hmm, I wonder whether there's a less heavy-handed approach to this.
>>
>> Agreed.  Also, I think this problem is not specific to `define-inline`.
>> Maybe the indentation code should try and (auto)load the macros
>> it encounters.
>
> But how does it know that a given (expr ...) is a macro call or a
> function call without loading the containing library? AFAIK, only
> autoloading can provide such information.

The autoload of `define-inline` says that it's a macro, so I was
thinking that maybe when the indentation code see `define-inline` it
could `autoload-do-load`.

> Maybe, autoloading can automatically collect information about all the
> symbols defined in each library - whether they are a
> function/variable/macro and their declare statement?

The point of an autoload object is that it's *much* cheaper than the
real thing.  So we can't add very much info to them.


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#68818; Package emacs. (Tue, 30 Jan 2024 19:01:01 GMT) Full text and rfc822 format available.

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

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 68818 <at> debbugs.gnu.org
Subject: Re: bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public
 macros
Date: Tue, 30 Jan 2024 19:03:36 +0000
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:

>> But how does it know that a given (expr ...) is a macro call or a
>> function call without loading the containing library? AFAIK, only
>> autoloading can provide such information.
>
> The autoload of `define-inline` says that it's a macro, so I was
> thinking that maybe when the indentation code see `define-inline` it
> could `autoload-do-load`.

That would make sense, yes.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




This bug report was last modified 297 days ago.

Previous Next


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