minad / cape

🦸cape.el - Completion At Point Extensions
GNU General Public License v3.0
573 stars 20 forks source link

corfu-prescient and cape-capf-super #99

Closed neurolit closed 6 months ago

neurolit commented 6 months ago

Hi!

First of all, I love Corfu and Cape, and it works very well. I'm using it with Orderless for filtering and Prescient for sorting.

However, I need some help in order to use prescient with cape-capf-super. I think it doesn't work (whereas it works with all other Corfu completions).

In my completion-at-point-functions, I use cape-capf-super in order to merge three completion tables:

(add-hook 'completion-at-point-functions (cape-capf-super #'my/people-completion #'cape-dabbrev #'cape-dict) 0 'local)

I noticed that when using this completion, results are sorted per function: all my/people-compltion results first, then cape-dabbrev ones, and eventually cape-dict ones. Prescient doesn't seem to be used. If I change the order of cape-capf-super parameters, it changes the order of completion results.

Here is my prescient configuration:

(use-package corfu-prescient
  :after (corfu prescient)
  :commands corfu-prescient-mode
  :custom
  (corfu-prescient-enable-sorting t)
  (corfu-prescient-override-sorting nil)
  (corfu-prescient-enable-filtering nil)
  )
(corfu-prescient-mode +1)

Do you know if there is a way to use prescient with cape-capf-super merged results?

minad commented 6 months ago

Thanks. It seems you can set corfu-prescient-override-sorting such that Prescient sorting takes precedence over the fixed order of cape-capf-super. Please let me know if it works.

minad commented 6 months ago

You can also use cape-capf-properties to override the sorting. Compare these two settings:

;; 1. Dabbrev candidates always come before Dict candidates
(setq completion-at-point-functions
      (list (cape-capf-super #'cape-dabbrev #'cape-dict)))

;; 2. Dabbrev and Dict candidates may be mixed, UI sorting dominates
(setq completion-at-point-functions
      (list (cape-capf-properties
             (cape-capf-super #'cape-dabbrev #'cape-dict)
             :sort t))) ;; Override: Enable sorting in the UI

(Note that this relies on an fix which I just pushed https://github.com/minad/cape/commit/80b41c67ab75eb57aa0fb527842f9d3d82002544 and which is not yet released.)

neurolit commented 6 months ago

Thank you so much for your answer and for 80b41c6 fix! I tried it with:

(add-hook 'completion-at-point-functions (cape-capf-properties
                                              (cape-capf-super #'my/people-completion #'cape-dabbrev #'cape-dict)
                                              :sort t) 0 'local)

and it works perfectly.

Merry Christmas to you!