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

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

[elpa] externals/marginalia 80fa320 016/241: Introduce list of classifie


From: Stefan Monnier
Subject: [elpa] externals/marginalia 80fa320 016/241: Introduce list of classifiers
Date: Fri, 28 May 2021 20:48:48 -0400 (EDT)

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

    Introduce list of classifiers
    
    The new variable marginalia-classifiers will contain functions that
    are run one after another to attempt to determine the category
    metadatum. The existing logic for determining the category has been
    moved into marginalia-classify-by-command-name.
---
 marginalia.el | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/marginalia.el b/marginalia.el
index 7559307..0b6dd71 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -73,6 +73,15 @@ Annotations are only shown if `marginalia-mode' is enabled."
   :type '(alist :key-type symbol :value-type function)
   :group 'marginalia)
 
+(defcustom marginalia-classifiers
+  '(marginalia-classify-by-command-name)
+  "List of functions to determine current completion category.
+Each function should take no arguments and return a symbol
+indicating the category, or nil to indicate it could not
+determine it."
+  :type 'hook
+  :group 'marginalia)
+
 (defcustom marginalia-command-category-alist
   '((execute-extended-command . command)
     (customize-face . face)
@@ -207,6 +216,11 @@ Annotations are only shown if `marginalia-mode' is 
enabled."
       (mapcar (lambda (cand) (concat cand (funcall annotate cand))) candidates)
     candidates))
 
+(defun marginalia-classify-by-command-name ()
+  "Lookup category for current command."
+  (and marginalia--this-command
+       (alist-get marginalia--this-command marginalia-command-category-alist)))
+
 (defun marginalia--completion-metadata-get (_metadata prop)
   "Advice for `completion-metadata-get'.
 Replaces the category and annotation function.
@@ -219,8 +233,7 @@ PROP is the property which is looked up."
      (when-let (cat (marginalia--category-type))
        (alist-get cat marginalia-annotator-alist)))
     ('category
-     (and marginalia--this-command
-          (alist-get marginalia--this-command 
marginalia-command-category-alist)))))
+     (run-hook-with-args-until-success 'marginalia-classifiers))))
 
 (defun marginalia--minibuffer-setup ()
   "Setup minibuffer for `marginalia-mode'.



reply via email to

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