branch: externals/marginalia commit 40e2881d156a97e7e60b72ef9e75ad34ecf40314 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
fix marginalia-cycle-annotators such that it works as an embark action * detect action by checking for active-minibuffer and change value locally * readme: add action example * add nil to marginalia-annotators --- README.md | 7 ++++++- marginalia.el | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7f2c797..117a4e8 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,11 @@ commands. ~~~ elisp ;; Enable richer annotations using the Marginalia package (use-package marginalia + ;; When using the Embark package, you can bind `marginalia-cycle-annotators' + ;; as an Embark action! + ;; :bind (:map embark-general-map + ;; ("A" . marginalia-cycle-annotators)) + ;; The :init configuration is always executed (Not lazy!) :init @@ -52,5 +57,5 @@ commands. ;; By default only the keybinding is shown as annotation. ;; Note that there is the command `marginalia-cycle-annotators` to ;; switch between the annotators. - (setq marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light))) + ;; (setq marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil))) ~~~ diff --git a/marginalia.el b/marginalia.el index 055d52a..1d43b70 100644 --- a/marginalia.el +++ b/marginalia.el @@ -58,7 +58,7 @@ This value is adjusted in the `minibuffer-setup-hook' depending on the `window-w :type 'integer) (defcustom marginalia-annotators - '(marginalia-annotators-light marginalia-annotators-heavy) + '(marginalia-annotators-light marginalia-annotators-heavy nil) "Choose an annotator association list for minibuffer completion. The first entry in the list is used for annotations. You can cycle between the annotators using `marginalia-cycle-annotators'. @@ -678,15 +678,16 @@ If called from the minibuffer the annotator cycling is local, that it is, it does not affect subsequent minibuffers. When called from a regular buffer the effect is global." (interactive) - (let ((annotators (append (cdr marginalia-annotators) - (list (car marginalia-annotators))))) - ;; If `marginalia-cycle-annotators' has been invoked from inside the minibuffer, only change - ;; the annotators locally. This is useful if the command is used as an action. If the command is - ;; not triggered from inside the minibuffer, cycle the annotator globally. Hopefully this is - ;; not too confusing. - (if (minibufferp) - (setq-local marginalia-annotators annotators) - (setq marginalia-annotators annotators)))) + ;; If `marginalia-cycle-annotators' has been invoked from inside the minibuffer, only change + ;; the annotators locally. This is useful if the command is used as an action. If the command is + ;; not triggered from inside the minibuffer, cycle the annotator globally. Hopefully this is + ;; not too confusing. + (if-let* ((win (active-minibuffer-window)) + (buf (window-buffer win))) + (let ((a (buffer-local-value 'marginalia-annotators buf))) + (setf (buffer-local-value 'marginalia-annotators buf) (append (cdr a) (list (car a))))) + (let ((a marginalia-annotators)) + (setq marginalia-annotators (append (cdr a) (list (car a))))))) (provide 'marginalia) ;;; marginalia.el ends here