Fix for issue #2805 by using company-finish on counsel-company.
Simple change that makes counsel-company work more seamlessly with company-complete. By using company-finish instead of ivy-completion-in-region-action many behaviors expected from company, like 'keep-prefix' option and post-complete hooks now work.
This change needs that company-abort be called only if ivy-exit is nil when unwinding, otherwise company-finish does not work.
Hi, a few comments here if you don't mind.
-
I don't think we still need the variable
lenif we are not bothering withivy-completion-in-region-action. We also don't need to setivy-completion-{beg,end}. -
We could wrap the
ivy-readpart with(when company-candidates ...)so that it does nothing when there is no candidate, replicating the behavior ofcompany-complete. -
I suspect that the workaround is not needed. The problem is that we are dealing with outdated
company-candidatesbecausecompany-complete-commoninserted the common part without updating the variables. In fact, I think we could just callcompany-abortand thencompany-completebefore callingivy-readso that the variables are properly set. It also solves the problem that the text properties of the candidates are incorrect (the completed common part is not properly propertized).
I am also touching this, and I think my changes could be integrated into this PR:
https://github.com/abo-abo/swiper/pull/2849