[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."
- [elpa] externals/marginalia 28defd6 014/241: Introduce new name "annotator" for annotation functions, (continued)
- [elpa] externals/marginalia 28defd6 014/241: Introduce new name "annotator" for annotation functions, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia e2af1d3 019/241: Make marginalia-prompt-categories an alist of regexps and categories, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 1c8ef02 020/241: Remove unused marginalia--metadata function, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia c05face 042/241: Improve marginalia-toggle-annotators if invoked from minibuffer, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 59d65af 018/241: Add basic classifiers: orginal category, symbols, by words in prompt, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 0f1e763 025/241: rename some variables for consistency, update readme, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia cd95c65 028/241: buffer annotation: add read-only status, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 675e680 036/241: improve annotator defcustoms, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 8be2daf 046/241: marginalia-annotate-file: remove unnecessary offset which only costs space for no reason, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia c8c3f87 045/241: Rename toggle -> cycle, improve documenation, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 1269445 049/241: marginalia-annotate-command-binding: cache key binding,
Stefan Monnier <=
- [elpa] externals/marginalia 376ccc5 048/241: Revert "fix marginalia--full-candidate for selectrum", Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia ccefc57 052/241: marginalia-annotate-command-binding: add comment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 597186d 065/241: add marginalia-annotate-minor-mode, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 14dce57 062/241: scale field widths such that annotations look better on smaller windows, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 7d3719d 074/241: Fix advice skipping regexp for older Emacsen, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 5373a26 076/241: add marginalia-modified face, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia c0460b6 085/241: classify environment variable, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 9d2f319 080/241: marginalia-annotate-variable: add modification indicator, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 9f1b63b 086/241: add symbol class characters from Emacs 28, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 74603c0 091/241: use mapatoms to fix the harmless unused variable warning, Stefan Monnier, 2021/05/28