Skip to content

Commit da94a25

Browse files
committed
auto-completion: refactor yasnippet config
- 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! :-)
1 parent 70db376 commit da94a25

1 file changed

Lines changed: 33 additions & 41 deletions

File tree

layers/auto-completion/packages.el

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -202,50 +202,42 @@
202202
(progn
203203
;; We don't want undefined variable errors
204204
(defvar yas-global-mode nil)
205-
205+
(setq yas-triggers-in-field t
206+
yas-wrap-around-region t
207+
helm-yas-display-key-on-candidate t)
208+
;; on multiple keys, fall back to completing read
209+
;; typically this means helm
210+
(setq yas-prompt-functions '(yas-completing-prompt))
206211
;; disable yas minor mode map
207212
;; use hippie-expand instead
208213
(setq yas-minor-mode-map (make-sparse-keymap))
209-
210-
;; allow nested expansions
211-
(setq yas-triggers-in-field t)
212-
213214
;; this makes it easy to get out of a nested expansion
214-
(define-key yas-minor-mode-map
215-
(kbd "M-s-/") 'yas-next-field)
216-
217-
;; on multiple keys, fall back to completing read
218-
;; typically this means helm
219-
(setq yas-prompt-functions '(yas-completing-prompt))
220-
221-
;; add key into candidate list
222-
(setq helm-yas-display-key-on-candidate t)
223-
(setq spacemacs--auto-completion-dir
224-
(configuration-layer/get-layer-property 'auto-completion :dir))
215+
(define-key yas-minor-mode-map (kbd "M-s-/") 'yas-next-field)
216+
;; configure snippet directories
217+
(let* ((spacemacs--auto-completion-dir
218+
(configuration-layer/get-layer-property 'auto-completion :dir))
219+
(yasnippet--elpa-dir (spacemacs//get-package-directory 'yasnippet))
220+
(private-yas-dir (if auto-completion-private-snippets-directory
221+
auto-completion-private-snippets-directory
222+
(concat
223+
configuration-layer-private-directory
224+
"snippets/")))
225+
(spacemacs-snippets-dir (expand-file-name
226+
"snippets"
227+
spacemacs--auto-completion-dir))
228+
(yasnippet-snippets-dir (expand-file-name
229+
"snippets"
230+
yasnippet--elpa-dir)))
231+
(setq yas-snippet-dirs
232+
(append (if (listp private-yas-dir)
233+
private-yas-dir
234+
(list private-yas-dir))
235+
(list spacemacs-snippets-dir)
236+
(list yasnippet-snippets-dir))))
225237

226238
(defun spacemacs/load-yasnippet ()
227-
(unless yas-global-mode
228-
(progn
229-
(require 'yasnippet)
230-
(let ((private-yas-dir (if auto-completion-private-snippets-directory
231-
auto-completion-private-snippets-directory
232-
(concat
233-
configuration-layer-private-directory
234-
"snippets/")))
235-
(spacemacs-snippets-dir (expand-file-name
236-
"snippets"
237-
spacemacs--auto-completion-dir)))
238-
(setq yas-snippet-dirs
239-
(append (if (listp private-yas-dir)
240-
private-yas-dir
241-
(list private-yas-dir))
242-
(when (boundp 'yas-snippet-dirs)
243-
(remove yas--default-user-snippets-dir yas-snippet-dirs))
244-
(list spacemacs-snippets-dir)))
245-
(yas-global-mode 1)
246-
(setq yas-wrap-around-region t))))
239+
(unless yas-global-mode (yas-global-mode 1))
247240
(yas-minor-mode 1))
248-
249241
(spacemacs/add-to-hooks 'spacemacs/load-yasnippet '(prog-mode-hook
250242
markdown-mode-hook
251243
org-mode-hook))
@@ -259,10 +251,10 @@
259251
(defun spacemacs/force-yasnippet-off ()
260252
(yas-minor-mode -1)
261253
(setq yas-dont-activate t))
262-
263-
(spacemacs/add-to-hooks 'spacemacs/force-yasnippet-off '(term-mode-hook
264-
shell-mode-hook
265-
eshell-mode-hook)))
254+
(spacemacs/add-to-hooks
255+
'spacemacs/force-yasnippet-off '(term-mode-hook
256+
shell-mode-hook
257+
eshell-mode-hook)))
266258
:config (spacemacs|diminish yas-minor-mode "" " y")))
267259

268260
(defun auto-completion/init-auto-yasnippet ()

0 commit comments

Comments
 (0)