1

Config:

(use-package yasnippet
  :ensure t
  :hook
  (prog-mode . yas-minor-mode)
  )

(use-package yasnippet-snippets
  :ensure t
  :after yas)

(use-package common-lisp-snippets
  :ensure t
  :after yas
  :hook lisp-mode-hook)

(use-package slime-company
  :ensure t
  :after (slime company)
  :hook
  (lisp-mode
         . (lambda ()
             (set (make-local-variable 'company-backends)
                  '((company-slime company-yasnippet company-semantic)))))
  (slime-editing-mode-hook
         . (lambda ()
             (set (make-local-variable 'company-backends)
                  '((company-slime company-yasnippet company-semantic)))))
  :config
  (setq slime-company-completion 'fuzzy
        slime-company-after-completion 'slime-company-just-one-space))

In a lisp file, "defpackage"(imported by common-lisp-snippets) is show when using:

yas-insert-snippet

but company doesn't show for it. How to config company-yasnippet to find it?

C-Entropy
  • 143
  • 5

1 Answers1

1

Firstly, (make-local-variable 'company-backends) is outdated, with newest company and other packages, we only need to set one global company-backends.
That's because all backends do check whether it's the right major-mode etc. for it to take responsibility. In other words, company-slime checks whether it's in common lisp code, and step out of the way if not, so it's fine to just put it in a global company-backends.

To find out why company-yasnippet isn't working, check whether it's really in the backends, with describe-variable. Also see whether some other backend is giving some unhelpful candidates while company-yasnippet is queued after that. (if any backend gives any result, the ones after it won't be used at all.) (with newest company you can see the current candidate-giving backend in the completion UI.)

You may want to mix results of two or more backends, you can refer to the document for how to do this. But it's usually unnecessary, because you likely just need to put lightweight backend before others and they'll work only when it really think it should (company-files for example)

JJPandari
  • 251
  • 1
  • 9
  • It seems that I have use the wrong keyword for company-yasnippet. It should be defp instead of defpackage. But it comes all the way down. Hmm, how could I change the sort of predict to put it in the front? – C-Entropy Oct 16 '20 at 08:12
  • This seems to be another question, better post a new one with the completion list you get. – JJPandari Oct 16 '20 at 08:51