minad / cape

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

Cannot make multiple completion backends work #62

Closed dppascual closed 1 year ago

dppascual commented 1 year ago

First of all, thanks for your time implementing both corfu and cape packages. As the title says, I cannot reproduce the workflow that I had by using company-mode + childframes. As you can see in the below image, company-mode pops up automatically a frame with completion candidates taken from lsp and yasnippet (I'm just interested in the autocompleter shows automatically candidates from those two completion backends, the others can be triggerred manually).

Screenshot 2022-09-07 at 11 49 00

My corfu config:

(use-package! corfu
  :bind (:map corfu-map
            ("C-j" . corfu-next)
            ("C-k" . corfu-previous)
            ("<escape>" . corfu-quit)
            ("<return>" . corfu-insert)
            ("SPC" . corfu-insert-separator)
            ("M-d" . corfu-show-documentation)
            ("M-l" . corfu-show-location))
  :custom
  (corfu-auto t)
  (corfu-auto-prefix 1)
  (corfu-auto-delay 0)
  (corfu-min-width 80)
  (corfu-max-width corfu-min-width)
  (corfu-count 14)
  (corfu-scroll-margin 4)
  (corfu-cycle t)

  ;; `nil' means to ignore `corfu-separator' behavior, that is, use the older
  ;; `corfu-quit-at-boundary' = nil behavior. Set this to separator if using
  ;; `corfu-auto' = `t' workflow (in that case, make sure you also set up
  ;; `corfu-separator' and a keybind for `corfu-insert-separator', which my
  ;; configuration already has pre-prepared). Necessary for manual corfu usage with
  ;; orderless, otherwise first component is ignored, unless `corfu-separator'
  ;; is inserted.
  (corfu-quit-at-boundary 'separator)
  (corfu-separator ?\s)            ; Use space
  (corfu-quit-no-match 'separator) ; Don't quit if there is `corfu-separator' inserted
  (corfu-preview-current 'insert)  ; Preview first candidate. Insert on input if only one
  (corfu-preselect-first t)        ; Preselect first candidate?
  (corfu-echo-documentation t)        ; Already use corfu-doc
  (tab-always-indent 'complete)
  (completion-cycle-threshold 1) ; Always show candidates in menu
  :config
  (after! evil
    (advice-add 'cortu--setup :after 'evil-normalize-keymaps)
    (advice-add 'corfu--teardown :after 'evil-normalize-keymaps)
    (evil-make-overriding-map corfu-map))
  :init
  (global-corfu-mode))

Multiple configs of cape that I've tried with no success:

(use-package! cape
  :init
  (defun dpp/cape-capf-setup-lsp ()
  "Replace the default `lsp-completion-at-point' with its
`cape-capf-buster' version. Also add `cape-dabbrev' and
`company-yasnippet' backends."
  (setf (elt (cl-member 'lsp-completion-at-point completion-at-point-functions) 0)
        (cape-capf-buster #'lsp-completion-at-point))
  (require 'company-yasnippet)
  (add-to-list 'completion-at-point-functions (cape-company-to-capf #'company-yasnippet))
  (add-to-list 'completion-at-point-functions #'cape-dabbrev t))
  :hook
  (lsp-completion-mode . dpp/cape-capf-setup-lsp))

With this config I cannot get candidates from company-yasnippet

I've tried multiple configs with cape-company-to-capf but nothing works. I moved from yasnippet to tempel

Config with tempel

(use-package! tempel
  :config
  (setq tempel-path "~/.config/emacs/templates")

(use-package! cape
  :init
  (defun dpp/cape-capf-setup-lsp ()
    (add-to-list 'completion-at-point-functions
                 (cape-super-capf #'tempel-complete #'cape-dabbrev)))
  :hook
  (go-mode . dpp/cape-capf-setup-lsp))

With this config I can insert templates from tempel but I cannot choose a candidate from a pop up, I mean, if I write down into the buffer the entire key, and press `TAB, it automatically converts such key into the expected template; it forces me remember all keys per programming language.

Do you know if it is possible to get the same behaviour than I explained previously with company-mode? If so, could you point me to the right config to be able to get it?

Thanks in advance

minad commented 1 year ago

How does your company config look like? It should be possible to convert it equivalently to Capfs.

Besides that I cannot give you a precise recipe since I neither use Yasnippet nor Lsp-mode. I am afraid you have to fiddle a bit more on your own :)