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

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

[elpa] externals/marginalia f9ca52c 032/241: Fallback for when full cand


From: Stefan Monnier
Subject: [elpa] externals/marginalia f9ca52c 032/241: Fallback for when full candidate is requested outside of minibuffer
Date: Fri, 28 May 2021 20:48:51 -0400 (EDT)

branch: externals/marginalia
commit f9ca52c4e5c2d2a0b1f175309102d68378464ed2
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>

    Fallback for when full candidate is requested outside of minibuffer
    
    If marginalia--full-candidate is called when the minibuffer is no
    longer active, return cand unchanged.
    
    I made this change to support Embark which can call annotators from
    Embark Occur buffers when the minibuffer is not longer active.
---
 marginalia.el | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/marginalia.el b/marginalia.el
index 862867a..9081339 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -271,16 +271,20 @@ component of a full file path.
 
 This function returns what would be the minibuffer contents after
 using `minibuffer-force-complete' on the candidate CAND."
-  (let* ((contents (minibuffer-contents))
-         (pt (- (point) (minibuffer-prompt-end)))
-         (bounds (completion-boundaries
-                  (substring contents 0 pt)
-                  minibuffer-completion-table
-                  minibuffer-completion-predicate
-                  (substring contents pt))))
-    (concat (substring contents 0 (car bounds))
-            cand
-            (substring contents (+ pt (cdr bounds))))))
+  (if (minibufferp)
+      (let* ((contents (minibuffer-contents))
+             (pt (- (point) (minibuffer-prompt-end)))
+             (bounds (completion-boundaries
+                      (substring contents 0 pt)
+                      minibuffer-completion-table
+                      minibuffer-completion-predicate
+                      (substring contents pt))))
+        (concat (substring contents 0 (car bounds))
+                cand
+                (substring contents (+ pt (cdr bounds)))))
+    ;; not in a minibuffer, trust that cand already conveys all
+    ;; necessary information (there's not much else we can do)
+    cand))
 
 (defun marginalia-annotate-file (cand)
   "Annotate file CAND with its size and modification time."



reply via email to

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