unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#48738: [PATCH] Optimized `describe-variable' predicate
@ 2021-05-30  4:27 Daniel Mendler
  2021-05-31  4:55 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Mendler @ 2021-05-30  4:27 UTC (permalink / raw)
  To: 48738; +Cc: Lars Ingebrigtsen

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

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.

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

In GNU Emacs 28.0.50 (build 12, x86_64-pc-linux-gnu, GTK+ Version
3.24.5, cairo version 1.16.0)
 of 2021-05-23 built on projects
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux 10 (buster)

[-- Attachment #2: 0001-describe-variable-Do-not-switch-to-the-original-buff.patch --]
[-- Type: text/x-diff, Size: 1877 bytes --]

From 9100bce6f057787df9f255a9bb98f37bbef44940 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <mail@daniel-mendler.de>
Date: Sun, 30 May 2021 06:16:17 +0200
Subject: [PATCH] (describe-variable): Do not switch to the original buffer in
 the predicate

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.

* lisp/help-fns.el (describe-variable): Use optimized predicate.
---
 lisp/help-fns.el | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 0b0ae4364c..46ace6bd24 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -1022,12 +1022,14 @@ 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 exists in
+                           ;; the original buffer, we have to look for
+                           ;; it there.
+                           (ignore-errors
+                             (or (buffer-local-value vv orig-buffer)
+                                 t)))))
                 t nil nil
                 (if (symbolp v) (symbol-name v))))
      (list (if (equal val "")
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-31  5:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-30  4:27 bug#48738: [PATCH] Optimized `describe-variable' predicate Daniel Mendler
2021-05-31  4:55 ` Lars Ingebrigtsen
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

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).