oantolin / orderless

Emacs completion style that matches multiple regexps in any order
GNU General Public License v3.0
743 stars 27 forks source link

How to set `orderless-affix-dispatch-alist` for a certain function? #177

Closed rennsax closed 3 weeks ago

rennsax commented 1 month ago

I remove the & affix (orderless-annotation) from orderless-affix-dispatch-alist because it is really slow when there are a lot of candidates.

However in some cases, I still want to use this dispatcher. For example, use orderless-annotation when insert-char so I can match the Unicode.

I've tried:

(define-advice insert-char (:around (oldfun &rest args))
  (let ((orderless-affix-dispatch-alist
         (cons
          '(?& . orderless-annotation)
          orderless-affix-dispatch-alist)))
    (apply oldfun args)))

But it seems to have no effect.

oantolin commented 1 month ago

That looks like it should work, I'll try to see if I can figure out why it doesn't. But also, why remove the dispatch character instead of simply not using it?

rennsax commented 1 month ago

Thanks for reply! Yes, I can simply avoid using &, but since I use corfu and set corfu-auto to t, every time I type & in a general buffer, Emacs is stuck for a while.

minad commented 4 weeks ago

The main problem here is that Emacs doesn't offer good facilities to distinguish completion styles for in-buffer and minibuffer completion. Completion styles are considered global. In most cases it works when minibuffer-only completion styles are configured buffer locally in a minibuffer setup hook. The global settings could be more restricted such that they work better with in-buffer completion.

However there are commands which break like consult-line which assume that completion styles are global since it uses completion filtering inside and outside of the minibuffer. One can work around the resulting problems by configuring overrides globally for the consult-line category, but the configuration will be quite a mess in my opinion.

Nevertheless I do not observe the problems described by @rennsax. I suspect that the auto completion settings are too aggressive (e.g., corfu-auto-delay is too small or/and corfu-auto-prefix is too small).

minad commented 3 weeks ago

To come back to @rennsax's initial question: The reason why the advice doesn't work is that it doesn't wrap around the interactive block. If you look at the definition of insert-char, you have to add the advice around read-char-by-name instead.

In case you are using Vertico, you can also use vertico-multiform-mode to customize variables locally per command. See the Vertico README for details.