* bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
@ 2024-01-30 13:21 Ihor Radchenko
2024-01-30 14:09 ` Eli Zaretskii
0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-30 13:21 UTC (permalink / raw)
To: 68818
[-- Attachment #1: Type: text/plain, Size: 1315 bytes --]
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'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-emacs-lisp-inline.el-Autoload-public-macros.patch --]
[-- Type: text/patch, Size: 1967 bytes --]
From c6f64171998a00c017e9dae5d7c96ad6d277adb5 Mon Sep 17 00:00:00 2001
Message-ID: <c6f64171998a00c017e9dae5d7c96ad6d277adb5.1706620775.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Tue, 30 Jan 2024 14:18:23 +0100
Subject: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
* lisp/emacs-lisp/inline.el (inline-quote):
(inline-const-p):
(inline-const-val):
(inline-error):
(inline-letevals): Autoload macros that may appear inside
`define-inline'. This is necessary to load the indentation rules when
Elisp code that uses `define-inline' is edited.
---
lisp/emacs-lisp/inline.el | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lisp/emacs-lisp/inline.el b/lisp/emacs-lisp/inline.el
index c774296084e..af841c0458d 100644
--- a/lisp/emacs-lisp/inline.el
+++ b/lisp/emacs-lisp/inline.el
@@ -69,21 +69,25 @@
(require 'macroexp)
+;;;###autoload
(defmacro inline-quote (_exp)
"Similar to backquote, but quotes code and only accepts , and not ,@."
(declare (debug (backquote-form)))
(error "inline-quote can only be used within define-inline"))
+;;;###autoload
(defmacro inline-const-p (_exp)
"Return non-nil if the value of EXP is already known."
(declare (debug t))
(error "inline-const-p can only be used within define-inline"))
+;;;###autoload
(defmacro inline-const-val (_exp)
"Return the value of EXP."
(declare (debug t))
(error "inline-const-val can only be used within define-inline"))
+;;;###autoload
(defmacro inline-error (_format &rest _args)
"Signal an error."
(declare (debug t))
@@ -100,6 +104,7 @@ inline--letlisteval
;; inline-letevals, so signal the error in terms of the user's code.
(error "inline-letevals can only be used within define-inline"))
+;;;###autoload
(defmacro inline-letevals (vars &rest body)
"Make sure the expressions in VARS are evaluated.
VARS should be a list of elements of the form (VAR EXP) or just VAR, in case
--
2.43.0
[-- Attachment #3: Type: text/plain, Size: 224 bytes --]
--
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>
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
2024-01-30 13:21 bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros Ihor Radchenko
@ 2024-01-30 14:09 ` Eli Zaretskii
2024-01-30 14:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-01-30 14:09 UTC (permalink / raw)
To: Ihor Radchenko, Stefan Monnier; +Cc: 68818
> From: Ihor Radchenko <yantar92@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?
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
2024-01-30 14:09 ` Eli Zaretskii
@ 2024-01-30 14:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-30 16:24 ` Ihor Radchenko
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-30 14:30 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Ihor Radchenko, 68818
>> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
2024-01-30 14:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-01-30 16:24 ` Ihor Radchenko
2024-01-30 18:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-30 16:24 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Eli Zaretskii, 68818
Stefan Monnier <monnier@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>
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
2024-01-30 16:24 ` Ihor Radchenko
@ 2024-01-30 18:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-30 19:03 ` Ihor Radchenko
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-01-30 18:11 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: Eli Zaretskii, 68818
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros
2024-01-30 18:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-01-30 19:03 ` Ihor Radchenko
0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-30 19:03 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Eli Zaretskii, 68818
Stefan Monnier <monnier@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>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-01-30 19:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-30 13:21 bug#68818: [PATCH] lisp/emacs-lisp/inline.el: Autoload public macros Ihor Radchenko
2024-01-30 14:09 ` Eli Zaretskii
2024-01-30 14:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-30 16:24 ` Ihor Radchenko
2024-01-30 18:11 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-30 19:03 ` Ihor Radchenko
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.