reddit / emacs
how to tell completion-at-point to use other completion functions if the current completion has 0 candidates ?
ntrysii · 2022-12-02 09:14
I'm using lsp-mode and corfu for completions, how to make `compltion-at-point` run the next completion function if the current has no candidates.
konrad1977 · 2022-12-02 11:10
Buster or super-capf?
Imxset21 · 2022-12-02 13:48
Where is buster? I can only find https://melpa.org/#/buster-mode which looks unrelated
konrad1977 · 2022-12-02 14:05
`cape-capf-buster` or `cape-super-capf`
You can read more here: [https://github.com/minad/cape#other-capf-transformers](https://github.com/minad/cape#other-capf-transformers)
This is how I setup my auto completion for swift:
(defun mk/eglot-capf ()
(setq-local completion-at-point-functions
(list (cape-super-capf #'eglot-completion-at-point #'cape-dabbrev #'cape-line (cape-company-to-capf #'company-yasnippet)))))
(add-hook 'eglot-managed-mode-hook #'mk/eglot-capf))
I assumed you used cape/corfu.
Imxset21 · 2022-12-02 14:08
Holy moly cape looks amazing
konrad1977 · 2022-12-02 14:27
Its awesome. Still havent found out a way to add quick keys that company supports.
ntrysii · 2022-12-02 18:20
I used super-capf before but when working with lsp [this issue](https://github.com/minad/corfu/issues/59) arises, I have a fix for it but it doesn't work when using super-capf I don't know why.
cradlemann · 2022-12-02 18:21
This?
https://github.com/minad/corfu/blob/main/extensions/corfu-indexed.el
ntrysii · 2022-12-02 18:25
I have a workaround to solve my problem by using an advice around `corfu--popup-show` when candidates are 0 i run the custom completion function, the only problem is it inserts the candidate if it is the only match. maybe you could have some solution for that.
konrad1977 · 2022-12-02 18:25
Wow, thanks. Exactly what I wanted.
JDRiverRun · 2022-12-03 03:22
`cape-super-capf` is good for this, but first, are you sure you can't just add the function to `completion-at-point-functions`? Note that `completion-at-point` already supports a form of fallback — it moves on to further elements on the list if a CAPF refuses to try a completion in a given location. E.g. in strings, LSP and other code completion CAPFs will say "I can't complete here". Perfect chance to do some file or dabbrev completion. Doing it this way is faster/less error prone.
It might help to know that CAPF's are called by the completion system in two rounds:
1. Hey, can you complete in this position?
2. You can? Great. Can you give me some completions for the following string fragment?
The fallback I'm talking about is when a CAPF answers "No" to question 1. If it answers "Yes, I can", and then upon checking, comes up blank for #2, that's when super-capf could be useful.
For those in the know, super-capf turns on the \`:exclusive no\` property in the CAPF (and does a lot of wicked merging between the two sets of results).
JDRiverRun · 2022-12-03 03:32
`cape-capf-buster` is for a very different purpose: there is ambiguity in the CAPF standard \[1\]: it's not clear how long a "completion table function" (which the CAPF creates for the completion system to interact with) should hold onto its computed results. Some authors think it's Emacs job to ask for a *new* completion table if in-buffer input changes. Example: I'm completing `foobar` , then backspace a couple of times to `foob`. Other authors believe it's up to the CAPF's table function itself to keep track of when input has changed and keep its results always refresh. These authors simply don't agree on who has the correct interpretation. `cape-capf-buster` is a way to make CAPFs written with the former assumption behave like the latter: check if input has changed, and if so, roll a new completion table. Perhaps the most common CAPF where the author has made assumption #1 is eglot's.
\[1\] Perhaps not suprising since it's pretty lightly documented.
ntrysii · 2022-12-03 03:52
Thanks for your detailed comment, I tried super-capf but it gives me 90% of the time the wrong answer, also it has some issues related to caching when working with lsp.
I can solve the problem by advising the function `corfu--popup-show` but it inserts the completion when there is a single match, which is something you don't wanna have when autocompleting
JDRiverRun · 2022-12-03 04:11
I notice you haven't said what additional source beyond lsp-mode's capf you are trying to supplement its results with. I have pretty good success adding dabbrev results to eglot's capf with cape-super-capf.
ntrysii · 2022-12-03 04:27
I'm trying to use a custom completion function that does something like dabbrev but it includes member access and so on, for example I would use it to complete something like `seusern` to `self.username` it works fine after advising the corfu function, the only thing is that it would insert the completion instantly which sometimes it is not the behavior I want.
JDRiverRun · 2022-12-03 15:24
Definitely don't recommend hacking onto the UI. You want these results in addition to what LSP provides? If LSP's CAPF doesn't play well with super-capf, consider opening an issue on cape with the details.