Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable orderless for company or corfu #136

Closed
ydzhou opened this issue Mar 29, 2023 · 8 comments
Closed

How to disable orderless for company or corfu #136

ydzhou opened this issue Mar 29, 2023 · 8 comments

Comments

@ydzhou
Copy link

ydzhou commented Mar 29, 2023

Hi

How can I disable orderless for autocompletion plugin e.g. company-mode or corfu? But still keep it enabled for consult.

@oantolin
Copy link
Owner

One simple way to do it would be to set completion-styles to whatever you want to use for corfu and company, and add to minibuffer-mode-hook a function that set the completion-styles locally in the minibuffer to something that includes orderless. Like this:

(setq completion-styles '(basic partial-completion)) ; styles for corfu & company

(defun use-orderless ()
  (setq-local completion-styles '(orderless))) ; styles for minibuffer commands such as consult commands

(add-hook 'minibuffer-mode-hook #'use-orderless)

But maybe, in case this is an XY problem, let me ask: why do you want to disable orderless for corfu and company?

@ydzhou
Copy link
Author

ydzhou commented Apr 2, 2023

Hi @oantolin , yeah I prefer company/corfu use substring for completion. When I type something, normally I can remember the prefix of what I am trying to type, so orderless is an overkill for me.

@minad
Copy link
Collaborator

minad commented Apr 2, 2023

@oantolin

One simple way to do it would be to set completion-styles to whatever you want to use for corfu and company, and add to minibuffer-mode-hook a function that set the completion-styles locally in the minibuffer to something that includes orderless.

That's not such a good fix actually, when taking more packages like Consult into account. I haven't found the ideal fix for Corfu yet to be honest. The problem with activating orderless only within the minibuffer is that it doesn't play nicely with consult-line which uses the completion-styles to jump to the position of the match (even after closing the minibuffer). One could then work around this problem by setting completion-category-overrides for consult-location but that's also not great. For Company the solution is to modify the completion styles with an advice around company-capf. Such an advice does not work for Corfu since Corfu uses completion-all-completions and completion-try-completion at many more places.

@oantolin
Copy link
Owner

oantolin commented Apr 2, 2023

Fair enough, @ydzhou.

I obviously hadn't checked all the consequences, @minad. Thanks for pointing those issues out. As for a good way to control completion-styles for Corfu, is there any way to detect if Corfu is currently open, some varíable or something? If so, one could write a new completion style that simply delegates to one completion style or another depending on whether Corfu is asking or not.

@oantolin
Copy link
Owner

oantolin commented Apr 2, 2023

Also, consult-line already stores a marker in a text property, right? Isn't that marker obtained while the minibuffer is open? Why does it need to use completion again. Or am I just wrong about the location being stored in a text property, @minad ?

@minad
Copy link
Collaborator

minad commented Apr 3, 2023

In order to highlight the matches.

@oantolin
Copy link
Owner

oantolin commented Apr 3, 2023

In order to highlight the matches.

Oh, right!

@failable
Copy link

This works, but messy.

  (defvar osfva-default-completion-styles
    (let ((sv (get 'completion-styles 'standard-value)))
      (and (consp sv)
           (condition-case nil
               (eval (car sv) t)
             (error completion-styles)))))

  (defvar osfva-enable-orderless-in-company nil)

  (defun osfva-toggle-enable-orderless-in-company ()
    (interactive)
    (setq osfva-enable-orderless-in-company
          (not osfva-enable-orderless-in-company)))

  (defun osfva-company-disable-orderless (orig-fun &rest args)
    "Diable orderless completion style when company is doing the completion."
    (let ((completion-styles (if osfva-enable-orderless-in-company
                                 completion-styles
                               osfva-default-completion-styles)))
      (apply orig-fun args)))
  (advice-add #'company--perform :around #'osfva-company-disable-orderless)

https://osfva.com/20210721000000-%E5%9C%A8company_mode%E8%A1%A5%E5%85%A8%E8%BF%87%E7%A8%8B%E4%B8%AD%E7%A6%81%E7%94%A8orderless/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants