emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/marginalia 1269445 049/241: marginalia-annotate-command


From: Stefan Monnier
Subject: [elpa] externals/marginalia 1269445 049/241: marginalia-annotate-command-binding: cache key binding
Date: Fri, 28 May 2021 20:48:54 -0400 (EDT)

branch: externals/marginalia
commit 126944545a148f3391318eb3c9f90946c885b2aa
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    marginalia-annotate-command-binding: cache key binding
    
    * See #16.
    * This eliminates the annotation overhead entirely.
    * Unfortunately we are back to showing minibuffer bindings again (Emacs 28 
behavior).
    * It is not entirely clear to me why it is fast to loop once over
      all symbols doing the where-is-internal lookup.
      For some reason it is better to do the work in bulk.
      This is not uncommon for work depending on gc throughput.
    * Should we add a different function marginalia-annotate-binding-exact
      and rename the caching function to marginalia-annotate-binding-fast?
      Then the user can select between the two functions via fset.
---
 marginalia.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/marginalia.el b/marginalia.el
index 5215762..5122740 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -217,14 +217,18 @@ determine it."
   "Truncate string STR to WIDTH."
   (truncate-string-to-width (car (split-string str "\n")) width 0 32 "…"))
 
+(defvar marginalia-annotate-command-binding--init nil)
 (defun marginalia-annotate-command-binding (cand)
   "Annotate command CAND with keybinding."
-  ;; Taken from Emacs 28, read-extended-command--annotation
-  (when-let* ((binding
-               (with-current-buffer (window-buffer 
(minibuffer-selected-window))
-                 (where-is-internal (intern cand) overriding-local-map t)))
-              (desc (and (not (stringp binding)) (key-description binding))))
-    (propertize (format " (%s)" desc) 'face 'marginalia-key)))
+  (unless marginalia-annotate-command-binding--init
+    (setq marginalia-annotate-command-binding--init t)
+    (cl-do-all-symbols (sym)
+      (when (commandp sym)
+        (when-let (key (where-is-internal sym nil t))
+          (put sym 'marginalia--cached-binding
+               (propertize (format " (%s)" (key-description key))
+                           'face 'marginalia-key))))))
+  (get (intern cand) 'marginalia--cached-binding))
 
 (defun marginalia-annotate-command-full (cand)
   "Annotate command CAND with the keybinding and its documentation string."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]