unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Daniel Mendler <mail@daniel-mendler.de>
Cc: 48738@debbugs.gnu.org
Subject: bug#48738: [PATCH] Optimized `describe-variable' predicate
Date: Mon, 31 May 2021 06:55:21 +0200	[thread overview]
Message-ID: <87h7ijmrie.fsf@gnus.org> (raw)
In-Reply-To: <55a7f6fc-ccad-a8e3-2f51-1cbc1555a4f8@daniel-mendler.de> (Daniel Mendler's message of "Sun, 30 May 2021 06:27:16 +0200")

Daniel Mendler <mail@daniel-mendler.de> writes:

> Do not switch to the original buffer.  Use `buffer-local-value`
> instead.  The buffer switching is more costly, which slows down
> continuously updating completion UIs like Icomplete or Vertico if
> there are many variables.

Thanks; applied to Emacs 28 with some changes -- I thought the
`ignore-errors' logic was kinda unclear, so I rewrote that bit using an
explicit `condition-case' checking for the error thrown in this case.

Adjusted patch included below; hopefully I didn't introduce any errors
here...

> Ideally there would be a `buffer-local-boundp` predicate we could use
> here.

Yes, that would be nice, I think.

And we probably have a lot of code in Emacs that uses
`with-current-buffer' instead of `buffer-local-value' that could be
similarly optimised (but I guess it mostly only makes sense to do so
when it's called in an intensive loop like here).

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 666583db72..c8f078cb85 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -1024,12 +1024,15 @@ describe-variable
                 (format-prompt "Describe variable" (and (symbolp v) v))
                 #'help--symbol-completion-table
                 (lambda (vv)
-                  ;; In case the variable only exists in the buffer
-                  ;; the command we switch back to that buffer before
-                  ;; we examine the variable.
-                  (with-current-buffer orig-buffer
-                    (or (get vv 'variable-documentation)
-                        (and (boundp vv) (not (keywordp vv))))))
+                  (or (get vv 'variable-documentation)
+                      (and (not (keywordp vv))
+                           ;; Since the variable may only exist in the
+                           ;; original buffer, we have to look for it
+                           ;; there.
+                           (condition-case nil
+                               (buffer-local-value vv orig-buffer)
+                             (:success t)
+                             (void-variable nil)))))
                 t nil nil
                 (if (symbolp v) (symbol-name v))))
      (list (if (equal val "")


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  reply	other threads:[~2021-05-31  4:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30  4:27 bug#48738: [PATCH] Optimized `describe-variable' predicate Daniel Mendler
2021-05-31  4:55 ` Lars Ingebrigtsen [this message]
2021-05-31  5:00   ` Daniel Mendler
2021-05-31  5:06     ` Lars Ingebrigtsen
2021-05-31  5:13       ` Lars Ingebrigtsen
2021-05-31  5:19         ` Daniel Mendler
2021-05-31  5:23           ` Lars Ingebrigtsen
2021-05-31  5:30             ` Daniel Mendler
2021-05-31  5:32               ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h7ijmrie.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=48738@debbugs.gnu.org \
    --cc=mail@daniel-mendler.de \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).