reddit / emacs
Sample Corfu, Kind-icon, and Corfu-doc configuration
FluentFelicity · 2022-02-28 06:04
Hi, all. Some of you might've seen my last post on [Vertico, Marginalia, All-the-icons-completion, and Orderless](https://kristofferbalintona.me/posts/vertico-marginalia-all-the-icons-completion-and-orderless/) last week.
I present to you my small configuration for [Corfu, Kind-icon, and Corfu-doc](https://kristofferbalintona.me/posts/corfu-kind-icon-and-corfu-doc/), which greatly complement the packages in that previous post by enhancing the built-in `completion-at-point`.
Sometime in the near future, I'll be trying to show my (messy) way of utilizing the `cape` package's `completion-at-point` backends.
Cheers!
zad_iel · 2022-02-28 09:12
awesome can't wait to read!
Available-Bug8339 · 2022-02-28 18:13
Thank you for taking the time - I'll check this out.
Icommentedtoday · 2022-02-28 18:36
Thanks! Great article
JDRiverRun · 2022-02-28 20:23
Thanks. Author of kind-icon here. I was also responsible for the new corfu+orderless behavior you mention (which was inspired by [this discussion](https://www.reddit.com/r/emacs/comments/sh3lio/orderless_corfu_make_the_component_separator/)). IMO, it works really well now.
Here's how it works:
* Normally, the CAPF is asked after every keypress whether it still considers the point a valid completion spot. If not, corfu quits. For most completion backends, this means if you go beyond a normal word boundary, it quits. This is very convenient to avoid "false positives" as you are typing along; corfu will get right out of your way.
* But orderless uses all sorts of characters in its filtering, including SPACE to separate components! How to reconcile?
* By typing M-SPC, you can tell corfu: do not consult the CAPF, instead insert an orderless component separator (SPACE by default) and continue filtering.
* Once your search includes your separator, you can then freely enter anything you want without quitting until you select a candidate or C-g.
So this is sort of a compromise to get you the best of all worlds: few false positives when you are typing along, but ability to use the full orderless syntax in subsequent components. It sounds like you prefer to *always* have full orderless syntax available, and never ask the CAPF if corfu should quit (false positives be damned). Is that right?
Note that orderless is in fact used on all components, it's just that the completion backend says completing after a space is a no-go, so corfu quits. If you want, you can even M-SPC, then backup and change your first component.
FluentFelicity · 2022-02-28 20:36
Thank you for your explanation. Yes, you're right in that I desire full orderless syntax for all components. This is because I use `corfu` manually (e.g. `corfu-auto` set to nil).
My main gripe right now is that I use characters such as "," for orderless dispatchers. From my experience, these characters always quit corfu, so if I'd want my first component with a dispatcher I'd first have to insert `corfu-separator` then go back and add a dispatcher (as you said). Is this the intended behavior or a bug?
JDRiverRun · 2022-02-28 21:01
That's fair. Can you open an issue at corfu on this? Minad and I discussed whether to more fully emulate the old `corfu-quit-at-boundary` = `nil` approach. These are better defaults for people who use corfu-auto (which seems to be most).
JDRiverRun · 2022-02-28 21:17
Couple other benefits of corfu, in addition to the speed and simpler backend setup you mention:
* Unlike company, it is a complete completion-in-region UI. So anytime you'd invoke old school completion, you get corfu instead.
* Completions are in a miniframe, so you can even use them from the minibuffer (which I love with `M-: eval-expression`).
* Ordlerless! Once you get used to it in the minibuffer (e.g. with vertico), it's hard to go without.
FluentFelicity · 2022-02-28 21:20
All great points! Thank you. I'll be sure to put these in the article (with a link to your comment) later today
FluentFelicity · 2022-02-28 21:21
Ok, I'll do that sometime in the next few days. `corfu-quit-at-boundary` to `nil` was indeed my preference before the changes.
karthink · 2022-02-28 22:08
`corfu-doc-toggle` turns on `corfu-doc-mode` and leaves it on. I assumed this command is for toggling the documentation manually, not toggling `corfu-doc-mode` itself. Which, as you point out, is slow and laggy.
FluentFelicity · 2022-02-28 22:09
Ah, yes, that is correct. I miswrote it -- I will correct it
karthink · 2022-02-28 22:11
But your config doesn't make sense in light of this. I thought you didn't want `corfu-doc-mode` running.
Also, is there no command for just toggling corfu-doc manually when you need it? `corfu-doc-manually` does not do this.
FluentFelicity · 2022-02-28 22:21
Hm. I've just checked, and `corfu-doc-toggle` does indeed toggle `corfu-doc-mode` itself (it's value is flipped from every invocation of `corfu-doc-toggle`).
What I do is manually call `corfu-doc-toggle` in corfu popups, which does toggle the mode itself, alongside the documentation popups. Does that clear up the inconsistency you described?
karthink · 2022-02-28 22:24
No, because it leaves `corfu-doc-mode` on.
Try this: call `completion-at-point` on a symbol, then look at the completion's doc using `corfu-doc-toggle`. Now press esc or `C-g`. Try another completion. You'll notice that this time the doc appears automatically. It doesn't clean up after itself.
EDIT: Tempered my remarks about this function.
FluentFelicity · 2022-02-28 22:58
You are correct about this. I'll investigate this later and ask why Im observing the behavior I am.
[deleted] · 2022-02-28 23:02
[deleted]
karthink · 2022-02-28 23:13
Here's a much simpler solution:
(defun corfu-doc--cleanup ()
(advice-remove 'corfu--popup-hide #'corfu-doc--cleanup)
(advice-remove 'corfu--popup-show #'corfu-doc--set-timer)
(corfu-doc--hide))
(defun corfu-doc-toggle ()
(interactive)
(advice-add 'corfu--popup-hide :after #'corfu-doc--cleanup)
(if (and corfu-doc--frame (frame-visible-p corfu-doc--frame))
(progn (corfu-doc--hide)
(advice-remove 'corfu--popup-show #'corfu-doc--set-timer))
(corfu-doc--show)
(advice-add 'corfu--popup-show :after #'corfu-doc--set-timer)))
JDRiverRun · 2022-02-28 23:32
You can get the docs in a Help buffer on any candidate with `M-h`.
karthink · 2022-02-28 23:42
Yeah, but this doesn't toggle corfu-doc. Also `corfu-show-documentation` is not a toggle.
JDRiverRun · 2022-02-28 23:57
Yes as mentioned it show in a Help buffer (no corfu-doc required). Not sure what you mean by toggling — the next command buries the help buffer.
karthink · 2022-03-01 00:16
By toggling I meant pressing `M-h` again to hide the help buffer.
> the next command buries the help buffer.
This is true assuming you don't have certain behaviors (like `body-function`) prescribed for help buffers in `display-buffer-alist`. Otherwise it fails. It can even exit the corfu session entirely. I've had to advise `corfu-show-documentation` to get around these issues.
Even when it works as intended it does not update the help buffer as I use `corfu-next` and `corfu-previous`, the way `corfu-doc` does.
> Also, is there no command for just toggling corfu-doc manually when you need it?
In any case, I wasn't making a case for corfu-doc here. I don't use corfu-doc. Just pointing out that `corfu-doc-toggle` does not work as a manual documentation toggle, it's bugged.
guitmz · 2022-03-01 00:19
Nice! I started moving to those packages recently. Do you have your eMacs config somewhere public? I’d love to see it
JDRiverRun · 2022-03-01 00:28
I understand that you want to "open Help buffer and retain until dismissed" with live updating. Sounds like a possible feature or config addition. I'm sure minad would also appreciate your opening issues for doc-toggle and special cases of display-buffer-alist vis-a-vis the Help buffer.
karthink · 2022-03-01 01:07
My `display-buffer-alist` settings are quite esoteric, so I didn't think it might be a common problem. However adding in live-updating the help-buffer as a corfu setting sounds good, I'll raise a github issue about it.
FluentFelicity · 2022-03-01 01:24
Unfortunately not. I may consider making it public in the future, though it's quite large and I may have security risks in there lol
Additionally, some of it is sloppy or works in janky ways only immediately evident to me, and I worry that those on the internet will copy and paste code that becomes problematic.
guitmz · 2022-03-01 08:09
Yeah that’s totally ok. Mine is also not public. But i see in your posts that you make the relevant code available. That’s enough I suppose, sharing relevant blocks like this is what in the end is useful