doomemacs/modules/feature/snippets/config.el
Henrik Lissner 8f76ee9a8a
Refactor feature/snippets
+ Don't clear yas-minor-mode-map; the default keybinds can be useful,
  esp to non-evil users.
+ Moved +snippets|enable-project-modes hook to autoloads file.
+ Reformat yasnippet config.
2018-06-19 13:49:15 +02:00

43 lines
1.7 KiB
EmacsLisp

;;; feature/snippets/config.el -*- lexical-binding: t; -*-
(defvar +snippets-dir (expand-file-name "snippets/" doom-private-dir)
"Directory where `yasnippet' will search for your private snippets.")
;;
;; Plugins
;;
(def-package! yasnippet
:commands (yas-minor-mode-on yas-expand yas-expand-snippet yas-lookup-snippet
yas-insert-snippet yas-new-snippet yas-visit-snippet-file)
:init
;; Ensure `yas-reload-all' is called as late as possible. Other modules could
;; have additional configuration for yasnippet. For example, file-templates.
(add-transient-hook! 'yas-minor-mode-hook (yas-reload-all))
(add-hook! (text-mode prog-mode snippet-mode)
#'yas-minor-mode-on)
:config
(setq yas-verbosity (if doom-debug-mode 3 0)
yas-also-auto-indent-first-line t
yas-prompt-functions (delq #'yas-dropdown-prompt yas-prompt-functions)
yas-triggers-in-field t) ; Allow nested snippets
(add-to-list 'yas-snippet-dirs '+snippets-dir nil #'eq)
;; Register `def-project-mode!' modes with yasnippet. This enables project
;; specific snippet libraries (e.g. for Laravel, React or Jekyll projects).
(add-hook 'doom-project-hook #'+snippets|enable-project-modes)
;; Exit snippets on ESC from normal mode
(add-hook 'doom-escape-hook #'yas-abort-snippet)
;; Fix an error caused by smartparens interfering with yasnippet bindings
(after! smartparens
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay))
;; Better `yas-insert-snippet' for evil users
(when (featurep! :feature evil)
(define-key yas-minor-mode-map [remap yas-insert-snippet] #'+snippets/expand-on-region)))
;; `auto-yasnippet'
(setq aya-persist-snippets-dir (concat doom-etc-dir "auto-snippets/"))