Closed zbelial closed 3 years ago
Right now there is no Ivy support, since Ivy users generally rely on the special Counsel commands. However in principle there is nothing preventing us from having Ivy support here and it would be nice if all the packages could work together.
consult--completion-candidate-hook
must be provided. I tried this once and it worked but I observed a few performance issues, due to Ivy handling some things differently than Icomplete/Selectrum.consult--completion-refresh-hook
must be provided. The Consult narrowing is implemented via the completion predicate. Maybe it works directly but maybe it requires additional advices or modifications on the side of Ivy.consult--completion-refresh-hook
must be provided. Additionally requires advices on Ivy functions or modifications of Ivy since Ivy does not reload completion tables. Ivy implements its own async functionality, but it deviates from the standard API. Ivy's :dynamic-collection
argument allows async collections but the collections are not standard completion tables. Consult assumes that standard completion tables are used. This should be adaptable without much work.consult--completion-match-hook
to find the location of the match. I think this also needs a special Ivy version.x-group-function
(See #234 and https://github.com/abo-abo/swiper/issues/2892)Bringing Ivy support here will require someone with Ivy experience. I looked in it for a while but could not figure it out quickly. Ivy is a complex system and deviates at a few places from the reference Icomplete/default completion system. Furthermore it will be difficult to make modifications to Ivy since it is a widely used system. I hope no changes are actually necessary, but there is no guarantee that we can get Consult to work without changes to Ivy. Note that one can replace functions completely via advices but at this point it may be better to request changes on the side of Ivy as long as the changes are minimally invasive. As a starting point one can look into consult-selectrum.el.
Furthermore it would be nice to have Marginalia support for Ivy. See https://github.com/abo-abo/swiper/issues/2780. As far as I know Embark already has full Ivy support.
UPDATE 08/2021: Ivy supports Marginalia now.
Thanks for you reply and all the detailed information, @minad . I must say that implementing all of these functions is beyond my ability now, but maybe I can give it a try, eg. to implement narrow as the first step, which I like very much. I guess this is a time-consuming task for me, so you cannot see good results soon.
@zbelial Sure, give it a try. Note that I will only merge a version here which provides full support. I added two more points regarding consult-line and consult--async which may also require special casing. While this sounds a lot, in the end it should be doable in 50 lines, if you look at consult-selectrum. But you must know precisely what you should use from Ivy :)
Small progress: Preview and narrow work now, but the code is ugly as it use some of ivy's internal functions and variables, and I'm not sure whether it's effective enough. Here is the code:
(with-eval-after-load 'ivy
(defun consult-ivy--candidate ()
"Return current ivy candidate."
(and ivy-mode (nth ivy--index (ivy--filter ivy-text ivy--all-candidates)))
)
(defun consult-ivy--refresh ()
"Refresh ivy view, keep current candidate selected if possible."
(when ivy-mode
(let ((ivy-old-text ivy-text)
(cands nil))
(let ((completion-regexp-list nil))
(setq cands (all-completions "" minibuffer-completion-table minibuffer-completion-predicate))
(ivy-set-text ivy-old-text)
(setq ivy--old-cands nil)
(ivy-update-candidates cands)))))
(add-hook 'consult--completion-candidate-hook #'consult-ivy--candidate)
(add-hook 'consult--completion-refresh-hook #'consult-ivy--refresh)
)
It is okay to use internals for the integration. For async support this library could be used as reference: https://codeberg.org/jao/espotify.
Closing due to inactivity. I have no intention to implement this currently since there are multiple strong Ivy alternatives (Selectrum, Vertico, Icomplete-vertical by oantolin, icomplete-vertical-mode in Emacs 28) and Ivy deviates from these completion systems, which complicates the implementation. So far only @zbelial stated interest in having Consult available for Ivy. The lack of general interest is understandable given the comprehensive Counsel package. Furthermore the Marginalia support in Ivy is still incomplete.
UPDATE 08/2021: Ivy supports Marginalia now.
@minad Can we use consult
with, e.g., Vetico
automatically when ivy
is detected? Or even through some config. I don't want to abandon ivy
, but I see no reason why I should not also use consult
but with another completor.
You can try something like the following if you want to use Ivy by default and Vertico, Mct or default completion only for Consult. You have to activate both vertico-mode
and ivy-mode
. But may I ask why you want to do this? Is there functionality in Ivy that you would want to see in Vertico/Consult? I don't recommend such mixed setups since it will be quite incoherent in the end. Nevertheless it should be possible to do this. But I haven't tested if it works.
(advice-add #'consult--read
:around
(lambda (&rest app)
(let ((completing-read-function #'completing-read-default))
(apply app))))
I have a lot of customizations and custom Ivy functions, and I use quite a few counsel
functions. helm
works absolutely fine together with Ivy
, so I am willing to try consult
, too. I am mostly interested in the implemented functions, not the completor.
consult-man
still doesn't find any man pages?
I have a lot of customizations and custom Ivy functions, and I use quite a few counsel functions. helm works absolutely fine together with Ivy, so I am willing to try consult, too. I am mostly interested in the implemented functions, not the completor.
I see. But then why not just stick to what you have, since I assume Helm and Ivy variants exist for most Consult commands? Which commands are particularly interesting for you?
consult-man still doesn't find any man pages?
I am afraid I cannot help you with that. You have to try to reproduce the issues in an emacs -Q setup. You could also try to use default completion (or Vertico which is essentially default completion) for most commands and use Ivy/Helm only for Ivy- and Helm-specific commands. Commands based on ivy-read
or helm
will automatically use Ivy/Helm. Also you could try to port Consult to Ivy :)
@NightMachinery I just remembered that Ivy has a way to opt out, see ivy-completing-read-handlers-alist
in https://github.com/abo-abo/swiper/blob/c97ea72285f2428ed61b519269274d27f2b695f9/ivy.el#L159-L171. I think it should be possible to register the Consult functions there to use completing-read-default
. Then Vertico will be used for those commands if you have vertico-mode
enabled.
Thanks. I got this working:
(require 'orderless)
(setq completion-styles '(orderless basic)
completion-category-overrides '((file (styles basic partial-completion))))
;;;
(provide 'night-orderless)
(after! (ivy night-ivy night-orderless)
(require 'vertico)
(vertico-mode)
;;;
(map! :map vertico-map
:g "M-<down>" #'vertico-scroll-up
:g "M-<up>" #'vertico-scroll-down
)
;;;
(dolist (fn
'(consult-line
consult-yank-pop
consult-yank-from-kill-ring))
(add-to-list 'ivy-completing-read-handlers-alist
`(,fn . completing-read-default)))
;;;
)
I just tried consult with
completing-read-function
set toivy-compelting-read
, but I found that narrowing inconsult-buffer
does not work.File
consult-icomplete.el
provides a functionconsult-icomplete--refresh
to refresh candidates, so to implement a similar function is enough? If so, what this function should do?Thanks.