Search code examples
emacsspacemacsyasnippet

Adding a custom yasnippet directory to `Spacemacs`


Sorry for the very newb question, but was just trying to configure a separate directory for yasnippets in spacemacs. I am not familar with emacs lisp at all. So it says that I can put the directory in

(setq-default dotspacemacs-configuration-layers '(
(auto-completion :variables
auto-completion-return-key-behavior 'complete
auto-completion-tab-key-behavior 'cycle
auto-completion-complete-with-key-sequence nil
auto-completion-complete-with-key-sequence-delay 0.1
auto-completion-private-snippets-directory nil)
))

so I have to set the auto-completion-private-snippets-directory, but I was not sure how to configure a custom directory like "~/Dropbox/snippets". I tried the code below with the added directory, but it was not working.

dotspacemacs-configuration-layers '(
...
auto-completion-private-snippets-directory "~/Dropbox/snippets")
))

I was not sure if I need to try pushing the new directory to the variable, etc. Any suggestions.


Solution

  • I figured out how to do this. Basically just needed to append directories to the yas-snippet-dirs variable. These additional directories are then added to the list of directories from which yasnippet gathers snippets.

    ;; Snippet configuration
    (setq-default dotspacemacs-configuration-layers '(
      (auto-completion :variables
                       auto-completion-return-key-behavior 'complete
                       auto-completion-tab-key-behavior 'cycle
                       auto-completion-complete-with-key-sequence nil
                       auto-completion-complete-with-key-sequence-delay 0.1
               auto-completion-enable-snippets-in-popup t
               auto-completion-enable-sort-by-usage t
               auto-completion-enable-help-tooltip t
                       auto-completion-private-snippets-directory nil)
                       ))
    
    ;; add extra snippet directories
    (setq yas-snippet-dirs (append yas-snippet-dirs
                                   '("/home/<username>/Dropbox/.../snippets")))
    
    (setq yas-snippet-dirs (append yas-snippet-dirs
                                   '("/home/<username>/Dropbox/.../more_snippets")))