[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/marginalia 86c0461 180/241: consult-multi annotator sho
From: |
Stefan Monnier |
Subject: |
[elpa] externals/marginalia 86c0461 180/241: consult-multi annotator should delegate to original annotation function |
Date: |
Fri, 28 May 2021 20:49:22 -0400 (EDT) |
branch: externals/marginalia
commit 86c0461271d407f5676a8af3776e73832458364f
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
consult-multi annotator should delegate to original annotation function
* The annotator should delegate to the original annotation function
for categories which are not overriden by Marginalia
* Introduce marginalia--metadata variable (replace
marginalia--original-category)
* Store the completion metadata in marginalia--metadata when annotators and
classifiers
are executed
* See https://github.com/minad/consult/issues/210 for the discussion
* Thank you @hmelman for finding the issue!
---
marginalia.el | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/marginalia.el b/marginalia.el
index e962ddf..d492774 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -267,8 +267,8 @@ determine it."
(defvar marginalia--this-command nil
"Last command symbol saved in order to allow annotations.")
-(defvar marginalia--original-category nil
- "Original category reported by completion metadata.")
+(defvar marginalia--metadata nil
+ "Completion metadata from the current completion.")
(defun marginalia--truncate (str width)
"Truncate string STR to WIDTH."
@@ -342,9 +342,15 @@ This hash table is needed to speed up
`marginalia-annotate-binding'.")
;; This annotator is consult-specific, it will annotate commands with
`consult-multi' category
(defun marginalia-annotate-consult-multi (cand)
"Annotate consult-multi CAND with the buffer class."
- (when-let* ((multi (get-text-property 0 'consult-multi cand))
- (annotate (alist-get (car multi) (symbol-value (car
marginalia-annotators)))))
- (funcall annotate (cdr multi))))
+ (if-let* ((multi (get-text-property 0 'consult-multi cand))
+ (annotate (alist-get (car multi) (symbol-value (car
marginalia-annotators)))))
+ ;; Use the Marginalia annotator corresponding to the consult-multi
category.
+ (funcall annotate (cdr multi))
+ ;; Apply the original annotation function on the original candidate, if
there is one.
+ ;; NOTE: Use `alist-get' instead of `completion-metadata-get' to bypass our
+ ;; `marginalia--completion-metadata-get' advice!
+ (when-let (annotate (alist-get 'annotation-function marginalia--metadata))
+ (funcall annotate cand))))
(defconst marginalia--advice-regexp
(rx bos
@@ -640,7 +646,9 @@ using `minibuffer-force-complete' on the candidate CAND."
(defun marginalia-classify-original-category ()
"Return original category reported by completion metadata."
- marginalia--original-category)
+ ;; NOTE: Use `alist-get' instead of `completion-metadata-get' to bypass our
+ ;; `marginalia--completion-metadata-get' advice!
+ (alist-get 'category marginalia--metadata))
(defun marginalia-classify-symbol ()
"Determine if currently completing symbols."
@@ -661,12 +669,14 @@ looking for a regexp that matches the prompt."
when (string-match-p regexp prompt)
return category)))
-(defmacro marginalia--context (&rest body)
- "Setup annotator context around BODY."
+(defmacro marginalia--context (metadata &rest body)
+ "Setup annotator context with completion METADATA around BODY."
+ (declare (indent 1))
(let ((w (make-symbol "w"))
(o (make-symbol "o")))
;; Take the window width of the current window (minibuffer window!)
- `(let ((,w (window-width))
+ `(let ((marginalia--metadata ,metadata)
+ (,w (window-width))
;; Compute marginalia-align-offset. If the right-fringe-width is
;; zero, use an additional offset of 1 by default! See
;; https://github.com/minad/marginalia/issues/42 for the discussion
@@ -694,20 +704,20 @@ PROP is the property which is looked up."
(when-let* ((cat (completion-metadata-get metadata 'category))
(annotate (alist-get cat (symbol-value (car
marginalia-annotators)))))
(lambda (cand)
- (marginalia--context
- (funcall annotate cand)))))
+ (marginalia--context metadata
+ (funcall annotate cand)))))
('affixation-function
;; We do want the advice triggered for `completion-metadata-get'.
;; Return wrapper around `annotation-function'.
(when-let* ((cat (completion-metadata-get metadata 'category))
(annotate (alist-get cat (symbol-value (car
marginalia-annotators)))))
(lambda (cands)
- (marginalia--context
- (mapcar (lambda (x) (list x (funcall annotate x))) cands)))))
+ (marginalia--context metadata
+ (mapcar (lambda (x) (list x (funcall annotate x))) cands)))))
('category
- ;; using alist-get bypasses any advice on completion-metadata-get
- ;; to avoid infinite recursion
- (let ((marginalia--original-category (alist-get 'category metadata)))
+ ;; Find the completion category by trying each of our classifiers.
+ ;; Store the metadata for `marginalia-classify-original-category'.
+ (let ((marginalia--metadata metadata))
(run-hook-with-args-until-success 'marginalia-classifiers)))))
(defun marginalia--minibuffer-setup ()
- [elpa] externals/marginalia 6c8b158 030/241: add license, (continued)
- [elpa] externals/marginalia 6c8b158 030/241: add license, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia f7adb62 044/241: fix #14, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 6567947 050/241: marginalia-annotate-command-binding: use a hash table per buffer, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 1077dba 123/241: update comment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 54a61c7 137/241: update marginalia comment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 35a42dc 142/241: improve buffer directory annotation, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 909b731 160/241: fix #42 - wrapping/alignment problem at the right margin, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia c5e89cf 168/241: describe-symbol: add indicator for obsolete variables/functions, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia d489f4c 171/241: fix #55, use string-width instead of length for alignment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 7a0c2c6 173/241: marginalia-cycle: remove minibuffer local behavior, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 86c0461 180/241: consult-multi annotator should delegate to original annotation function,
Stefan Monnier <=
- [elpa] externals/marginalia 2f977a1 181/241: readme: add illustration, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia e741b24 194/241: Version 0.4, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 06ae3b4 204/241: Some minor improvements on the fix, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia a8e73d9 198/241: Fix overly wide docstring warning, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 5126ba6 223/241: Version 0.5, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 9389f38 217/241: completion-all-completions: Last cdr can also be nil, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 287a369 221/241: Use more strict definition of the affixation function., Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia d1b836d 225/241: Go back to obsolete function project-roots, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 0c24618 233/241: marginalia-bookmark-type-transformers: Use more precise type, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 43c85dc 229/241: README: More documentation, Stefan Monnier, 2021/05/28