Closed jumper047 closed 1 year ago
Highlighting/transforming candidates is out of scope of Marginalia. But you can easily implement candidate transformations in Vertico as part of your configuration, see https://github.com/minad/vertico/wiki#candidate-display-transformations-custom-candidate-highlighting.
Hmm, thank you for the link, I'll check it! But I thought this is exactly what Marginalia supposed to do - display additional information about candidate. Ivy made it using highlighting, Marginalia can do it with additional symbol before docstring (I suppose, though, Marginalia still can do highlighting with faces), like "[On] Some minor mode ...".
No, Marginalia does not aim to modify the candidate strings itself. We could implement candidate highlighting via the affixation-function
as part of Marginalia, but I prefer if Marginalia is more limited in scope and if candidates are passed through unmodified as created by the backend.
Furthermore I consider highlighting of candidates as not important. I've only found two use cases for it: highlighting directories and highlighting modes. These two use cases are simply not worth adding complexity here, given that you can add candidate transformations to Vertico.
Note that Consult also offers the command consult-minor-mode
.
...Marginalia can do it with additional symbol before docstring (I suppose, though, Marginalia still can do highlighting with faces), like "[On] Some minor mode ...".
This is something we could add. I will give it a try.
Thank you! Personally I'll be fine with the highlighter function in my config, but I still sure this little addition will be useful for other Marginalia users
I implemented this in https://github.com/minad/marginalia/tree/mode-state, but I don't really like the result, since only a minority of the commands are modes. This is also why I don't like the highlighting idea. I could format it a bit differently, such that the On/Off doesn't use its own column, but the result is still not pretty. You can copy this annotator to your user configuration if you like.
Yeah, I also thought the [On]
would look ugly if it didn't get its own column, but that if it did, then it would be a waste of space, since the vast majority of commands are not minor mode toggles. This of course does not apply to the consult-minor-mode-menu
command @minad mentioned since it only shows minor modes and it does annotate candidate with On
or Off
. That's the command I'd recommend to check the status of minor modes, @jumper047.
@oantolin
Yeah, I also thought the [On] would look ugly if it didn't get its own column, but that if it did, then it would be a waste of space, since the vast majority of commands are not minor mode toggle.
Yes, exactly. I also tried to put the On/Off directly behind the key binding, but this is also ugly. Not every command is bound to a key of course, but I consider the key bindings far more important. I often use M-x as a reminder of some rarely used bindings if I remember parts of the command name.
FYI: I realized that marginalia is not the only package which provides metadata for completion:) Just added a method to the all-the-icons-completion:
(cl-defmethod all-the-icons-completion-get-icon (cand (_cat (eql command)))
"Return the icon for the candidate CAND of completion category command."
(let* ((mode-p (string-suffix-p "-mode" cand))
(mode-symbol (intern cand))
(mode-enabled (and (boundp mode-symbol) (symbol-value mode-symbol)))
(icon-name (if mode-p "cogs" "cog"))
(icon-face (when (and mode-p mode-enabled) 'all-the-icons-blue)))
(concat (all-the-icons-faicon icon-name :height 0.95 :v-adjust -0.05 :face icon-face) " ")))
Yes, all-the-icons-completion
was modeled after Marginalia to specifically provide icons which are out of scope of Marginalia. You should find the origins of this package on the Marginalia issue tracker. :)
Minor mode state annotation seems to be a popular request (see #75 ). I just want to share my approach based on @minad solution and some other Marginalia parts:
(defun marginalia--mode-state (mode)
"Return MODE state string."
(if (and (boundp mode) (symbol-value mode))
#(" [On]" 1 5 (face marginalia-on))
#(" [Off]" 1 6 (face marginalia-off))))
(defun marginalia--annotate-minor-mode-command (orig cand)
"Annotate minor-mode command CAND with mode state."
(concat
(when-let* ((sym (intern-soft cand))
(mode (if (and sym (boundp sym))
sym
(lookup-minor-mode-from-indicator cand))))
(marginalia--mode-state mode))
(funcall orig cand)))
(advice-add #'marginalia-annotate-command
:around #'marginalia--annotate-minor-mode-command)
State annotation format is similar to the bindings annotation. Functions ending on "-mode", autoloaded modes and major modes are not annotated. Looks rather pretty for me: Maybe it could be useful for someone, but keep in mind that I am not familiar with Lisp, so this code could have some potential issues, e.g. poor performance.
@minad sorry for tagging but what do you think about solution posted by @panurg? imho it looks awesome, may be this approach is good enough to be included into upstream?
Recently switched to vertico from ivy, and missed one convenient feature - ivy highlighted minor-mode commands when corresponding minor modes were activated. I found myself relying on it often (I use doom mode line which hides many minor mode lighters, and ivy highlighing was convenient way to understand is the command will turn on or off something). Can you add similiar feature to marginalia (or what do you think about PR containing this feature)?