[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#48738: [PATCH] Optimized `describe-variable' predicate
From: |
Lars Ingebrigtsen |
Subject: |
bug#48738: [PATCH] Optimized `describe-variable' predicate |
Date: |
Mon, 31 May 2021 06:55:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
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
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Daniel Mendler, 2021/05/30
- bug#48738: [PATCH] Optimized `describe-variable' predicate,
Lars Ingebrigtsen <=
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Daniel Mendler, 2021/05/31
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Lars Ingebrigtsen, 2021/05/31
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Lars Ingebrigtsen, 2021/05/31
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Daniel Mendler, 2021/05/31
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Lars Ingebrigtsen, 2021/05/31
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Daniel Mendler, 2021/05/31
- bug#48738: [PATCH] Optimized `describe-variable' predicate, Lars Ingebrigtsen, 2021/05/31