Skip to content

Commit

Permalink
auto-completion: refactor yasnippet config
Browse files Browse the repository at this point in the history
- Move all setq outside of spacemacs/load-yasnippet
- Explicitly add each snippet dirs, even the one in elpa dir

Before this commit I still get error on yasnippet loading, with this
commit the error is gone.

I hope we get yasnippet loading right this time! :-)
  • Loading branch information
syl20bnr committed Jan 7, 2016
1 parent 70db376 commit da94a25
Showing 1 changed file with 33 additions and 41 deletions.
74 changes: 33 additions & 41 deletions layers/auto-completion/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -202,50 +202,42 @@
(progn
;; We don't want undefined variable errors
(defvar yas-global-mode nil)

(setq yas-triggers-in-field t
yas-wrap-around-region t
helm-yas-display-key-on-candidate t)
;; on multiple keys, fall back to completing read
;; typically this means helm
(setq yas-prompt-functions '(yas-completing-prompt))
;; disable yas minor mode map
;; use hippie-expand instead
(setq yas-minor-mode-map (make-sparse-keymap))

;; allow nested expansions
(setq yas-triggers-in-field t)

;; this makes it easy to get out of a nested expansion
(define-key yas-minor-mode-map
(kbd "M-s-/") 'yas-next-field)

;; on multiple keys, fall back to completing read
;; typically this means helm
(setq yas-prompt-functions '(yas-completing-prompt))

;; add key into candidate list
(setq helm-yas-display-key-on-candidate t)
(setq spacemacs--auto-completion-dir
(configuration-layer/get-layer-property 'auto-completion :dir))
(define-key yas-minor-mode-map (kbd "M-s-/") 'yas-next-field)
;; configure snippet directories
(let* ((spacemacs--auto-completion-dir
(configuration-layer/get-layer-property 'auto-completion :dir))
(yasnippet--elpa-dir (spacemacs//get-package-directory 'yasnippet))
(private-yas-dir (if auto-completion-private-snippets-directory
auto-completion-private-snippets-directory
(concat
configuration-layer-private-directory
"snippets/")))
(spacemacs-snippets-dir (expand-file-name
"snippets"
spacemacs--auto-completion-dir))
(yasnippet-snippets-dir (expand-file-name
"snippets"
yasnippet--elpa-dir)))
(setq yas-snippet-dirs
(append (if (listp private-yas-dir)
private-yas-dir
(list private-yas-dir))
(list spacemacs-snippets-dir)
(list yasnippet-snippets-dir))))

(defun spacemacs/load-yasnippet ()
(unless yas-global-mode
(progn
(require 'yasnippet)
(let ((private-yas-dir (if auto-completion-private-snippets-directory
auto-completion-private-snippets-directory
(concat
configuration-layer-private-directory
"snippets/")))
(spacemacs-snippets-dir (expand-file-name
"snippets"
spacemacs--auto-completion-dir)))
(setq yas-snippet-dirs
(append (if (listp private-yas-dir)
private-yas-dir
(list private-yas-dir))
(when (boundp 'yas-snippet-dirs)
(remove yas--default-user-snippets-dir yas-snippet-dirs))
(list spacemacs-snippets-dir)))
(yas-global-mode 1)
(setq yas-wrap-around-region t))))
(unless yas-global-mode (yas-global-mode 1))
(yas-minor-mode 1))

(spacemacs/add-to-hooks 'spacemacs/load-yasnippet '(prog-mode-hook
markdown-mode-hook
org-mode-hook))
Expand All @@ -259,10 +251,10 @@
(defun spacemacs/force-yasnippet-off ()
(yas-minor-mode -1)
(setq yas-dont-activate t))

(spacemacs/add-to-hooks 'spacemacs/force-yasnippet-off '(term-mode-hook
shell-mode-hook
eshell-mode-hook)))
(spacemacs/add-to-hooks
'spacemacs/force-yasnippet-off '(term-mode-hook
shell-mode-hook
eshell-mode-hook)))
:config (spacemacs|diminish yas-minor-mode "" " y")))

(defun auto-completion/init-auto-yasnippet ()
Expand Down

1 comment on commit da94a25

@TheBB
Copy link
Collaborator

@TheBB TheBB commented on da94a25 Jan 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with this way of doing it we don't even need the global mode.

I did not get the error though, even before this. :-P

Please sign in to comment.