0

Company doesn't show snippets in some modes e.g. python or sh. Yet yas/describe-tables displays all snippets. In other modes e.g. org,emacs-lisp, snippets are shown as expected.

Looking at company-diag I don't see company-yasnippets loaded anywhere in python-mode.

Used backend: company-capf

While in the working org mode it returns

Used backend: (company-capf :with company-yasnippet)

Testing this variable (as proposed in spacemac docu) didn't change anything:

spacemacs-default-company-backends '(company-yasnippet)

Environment:

yas-snippet-dirs:

("/home/user/.emacs.d/private/snippets/" yasnippet-snippets-dir)

yas-global-mode t

 (auto-completion :variables
                  auto-completion-enable-snippets-in-popup t
                  auto-completion-enable-help-tooltip t)
 (python :variables
         python-backend 'lsp
         python-lsp-server 'pyright
         python-test-runner 'pytest
         python-enable-yapf-format-on-save t
         )

Where should I start looking?


Update:

Custom created snippets e.g. /private/snippets/python-mode/foo.snippet appear in a second list. In a different color and out-of-line position. It looks like multiple completion systems are interfering.

Gif: Python after enabling auto-complete-mode alongside company-mode

screenshot

Gif: Expected behavior (as in org mode and company-mode only): expected_gif

3
  • 2
    Do you have any snippet files stored in the folders (within the snippets folder) labeled python-mode and/or sh-mode, or do you have a snippet inherit file .yas-parents in either of those folders so that snippets from other modes are inherited? Have you enabled yasnippet globally as described in the README.md file?: github.com/joaotavora/yasnippet
    – lawlist
    Aug 6, 2021 at 7:52
  • @lawlist No parents in neither directories. Does my question update help?
    – jjk
    Aug 6, 2021 at 10:28
  • 1
    Do the snippets work correctly if you revert to the default spacemacs settings of auto-completion-enable-snippets-in-popup having a nil value? Yasnippet comes with its own mechanism for triggering snippets when the user presses the tab key, and if more than one snippet matches the key at point, the available snippets to choose from are displayed. See the section "Multiples snippet with the same key" github.com/joaotavora/yasnippet/blob/master/doc/… See also the function yas-insert-snippet ... "Prompts you for possible snippet expansion ..."
    – lawlist
    Aug 6, 2021 at 17:39

2 Answers 2

2

Remove the extension .snippet from the name of any new snippet created . No snippets have such extension.

Assuming you have some python snippets, take into account the execution order - if your python mode is enabled after yasnippets-snippets package, then at the end of your python configuration add the expression (yas-reload-all) to reload all snippets.

0

[Solved] Auto-completion support

Disclaimer: The configuration and setup mentioned in this guide are specific to Spacemacs only. The instructions provided may not be applicable or compatible with other Emacs setups or configurations.

I have finally been able to use all sorts of completions in spacemacs. I have tried several combinations and finally, I got it. So I put this one here in case anyone stumbled into this dilemma.

Yasnippet Auto-completion

The back-end of yasnippet is company-yasnippet and you can add it to your spacemacs using. There are two ways to make it works (choose only one of these two, I used the second option)

  1. At your dotspacemacs-configuration-layers add
     (auto-completion :variables
                      auto-completion-enable-snippets-in-popup t
                      auto-completion-enable-help-tooltip t
                      auto-completion-return-key-behavior 'complete
                      auto-completion-tab-key-behavior 'cycle ;;'complete 'cycle
                      auto-completion-enable-sort-by-usage t
                      auto-completion-idle-delay 0.0)
                      :config
                      add-to-list 'company-backends '(company-yasnippet  company-lsp company-capf company-anaconda))

  1. You can add to dotspacemacs/user-config the following
  ;; -------------------------------------------------------------
  ;;            Auto-completion - Back End Support
  ;; -------------------------------------------------------------
  (require 'company-yasnippet)
    (add-to-list 'company-backends '(company-yasnippet company-lsp company-capf company-anaconda))

[Optional][bonus] Tabnine Auto-completion support

I like also to add company-tabnine to my back-ends completions. Here is how I did it.

  1. Ensure you already installed the tabnine in dotspacemacs-additional-packages as:
   dotspacemacs-additional-packages '(
                (company-tabnine) ;; for using tab-nine AI auto-assistance
)
  1. Put in your dotspacemacs/user-config (similar to before)
  ;; -------------------------------------------------------------
  ;;            Auto-completion - Back End Support
  ;; -------------------------------------------------------------
  (require 'company-yasnippet)
  (require 'company-tabnine)
  (add-to-list 'company-backends '(company-yasnippet company-tabnine company-lsp company-capf company-anaconda))

  1. Install tabnine binary using M-x: company-tabnine-install-binary ( twice in spacemacs then write this command). It will be installed in your home directory (e.g. for my machine M1 macOS, it will be downloaded here ~/.TabNine/4.4.321/aarch64-apple-darwin. Make sure it is executable by running the command below in this directory (read more here).
chmod +x ~/.TabNine/4.4.321/aarch64-apple-darwin/*

It works now as you can see auto-completion support in action

NOTE:

  • [I think] changing the order of the company backends in the company-backends list will affect their order in the popup menu. Make sure to set auto-completion-enable-snippets-in-popup t (read more here)

  • To investigate your back-end company support, you can use <space-space> and type (M-x: describe-variable) then search for company-backends and you will see a doc popup showing all back-ends supported. For me they are

Value:
((company-capf company-dabbrev-code . #1=(:with company-yasnippet))
 (company-semantic company-dabbrev-code company-gtags company-etags company-keywords . #1#)
 (company-files . #1#)
 (company-dabbrev . #1#))
Original value was 
(company-bbdb company-semantic company-cmake company-capf company-clang company-files
              (company-dabbrev-code company-gtags company-etags company-keywords)
              company-oddmuse company-dabbrev)
Local in buffer .spacemacs; global value is 
((company-yasnippet company-tabnine company-lsp company-capf company-anaconda)
 company-bbdb company-semantic company-cmake company-capf company-clang company-files
 (company-dabbrev-code company-gtags company-etags company-keywords)
 company-oddmuse company-dabbrev)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.