From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 54802@debbugs.gnu.org
Subject: bug#54802: OClosure: Make `interactive-form` a generic function
Date: Wed, 13 Apr 2022 15:53:58 +0800 [thread overview]
Message-ID: <87r161to4p.fsf@yahoo.com> (raw)
In-Reply-To: <jwvy20fz55c.fsf@iro.umontreal.ca> (Stefan Monnier's message of "Fri, 08 Apr 2022 16:33:51 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> `nadvice.el` needs to build commands whose interactive spec is computed.
> This currently can't be done with `lambda` (see also bug#51695 for
> a related problem) but `nadvice.el` is unaffected because it assembles
> its byte-code functions all by hand. In order for `nadvice.el` to be
> able to use OClosures, we need to address this limitation.
>
> The patch below does it by making `interactive-form` a generic function,
> so OClosures can compute their interactive specs from their slots.
>
> Maybe it should be `call-interactively` that's turned into a generic
> function (which would also open up the possibility to do more than just
> compute the args to pass to the function, such as also printing the
> return value or things like that), but that would be a more significant
> change.
>
> While the performance of `call-interactively` and `interactive-form` are
> not critical, `commandp` is a function that is occasionally used in
> tight loops (typically when filtering completions from `obarray`) so
> I refrained from making it into a generic function, and instead I make
> it defer to `interactive-form` when we counter what looks like an OClosure.
>
> That keeps the common code as fast as before, tho it makes `commandp`
> slow(ish) when applied to interactive OClosures.
>
> Making `commandp` into a generic function would apparently slow down
> a loop like
>
> (mapatoms (lambda (s) (if (commandp s) (cl-incf count))))
>
> by a factor around 2x or 3x, which is not the end of the world but
> doesn't seem justified.
>
> The patch below also includes a use of this new generic function by
> moving the interactive spec of kmacros from the kmacro objects
> themselves to the generic function. The gain is that each `kmacro` is
> now 1 word smaller (negligible, in the grand scheme of things, but
> I included it for illustration and testing purposes).
>
> Any commment? Objection?
Calling `interactive-form' in a loop is also fairly common. For
example, I wrote some code a while back to list commands which operate
on the region, which involves running this on each interned atom:
(defun region-command-p (command)
"Test if COMMAND, a symbol, is a command that accepts a region."
(and (commandp command)
(equal (cadr (interactive-form command)) "r")))
I'm sure a 3x slowdown would be noticeable, so why does this have to be
a generic function? Why can't we have `interactive-form' return some
field of a given OClosure object instead?
Thanks.
next prev parent reply other threads:[~2022-04-13 7:53 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 20:33 bug#54802: OClosure: Make `interactive-form` a generic function Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-09 5:58 ` Eli Zaretskii
2022-04-09 13:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-10 12:45 ` Lars Ingebrigtsen
2022-04-13 7:53 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-04-14 18:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-15 0:46 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-15 1:18 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-15 1:37 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-15 3:24 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-15 4:27 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-15 16:08 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-15 16:14 ` Eli Zaretskii
2022-04-18 22:59 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-19 5:40 ` Eli Zaretskii
2022-04-19 12:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-19 12:43 ` Lars Ingebrigtsen
2022-04-19 13:00 ` Eli Zaretskii
2022-04-19 13:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-19 13:53 ` Eli Zaretskii
2022-04-19 14:53 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-19 16:35 ` Eli Zaretskii
2022-04-19 17:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-26 14:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-27 16:05 ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-11 21:24 ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-12 5:34 ` Eli Zaretskii
2022-06-12 20:56 ` Basil L. Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=87r161to4p.fsf@yahoo.com \
--to=bug-gnu-emacs@gnu.org \
--cc=54802@debbugs.gnu.org \
--cc=luangruo@yahoo.com \
--cc=monnier@iro.umontreal.ca \
/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.