doomemacs/modules/feature/snippets/config.el

51 lines
1.8 KiB
EmacsLisp
Raw Normal View History

;;; feature/snippets/config.el -*- lexical-binding: t; -*-
2017-02-11 06:59:49 -05:00
(def-package! yasnippet
:commands (yas-minor-mode yas-minor-mode-on yas-expand yas-expand-snippet
yas-lookup-snippet yas-insert-snippet yas-new-snippet
yas-visit-snippet-file snippet-mode)
2017-02-11 06:59:49 -05:00
:preface
(defvar yas-minor-mode-map
(let ((map (make-sparse-keymap)))
(when (featurep! :feature evil)
(define-key map [remap yas-insert-snippet] #'+snippets/expand-on-region))
map))
2017-02-19 18:32:09 -05:00
2017-02-11 06:59:49 -05:00
: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)
2017-02-19 18:32:09 -05:00
:config
2017-12-27 18:19:56 -05:00
(setq yas-verbosity (if doom-debug-mode 3 0)
2017-02-11 06:59:49 -05:00
yas-also-auto-indent-first-line t
2018-05-08 01:01:21 +02:00
yas-prompt-functions (delq #'yas-dropdown-prompt yas-prompt-functions)
;; Allow nested snippets
yas-triggers-in-field t)
2017-02-11 06:59:49 -05:00
2018-05-08 01:01:21 +02:00
(cl-pushnew (expand-file-name "snippets/" doom-private-dir) yas-snippet-dirs
:test #'string=)
(defun +snippets|enable-project-modes (mode &rest _)
"Enable snippets for project modes."
(if (symbol-value mode)
(yas-activate-extra-mode mode)
(yas-deactivate-extra-mode mode)))
(add-hook 'doom-project-hook #'+snippets|enable-project-modes)
2017-02-19 18:32:09 -05:00
;; fix an error caused by smartparens interfering with yasnippet bindings
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay)
2017-02-11 06:59:49 -05:00
;; Exit snippets on ESC from normal mode
(add-hook 'doom-escape-hook #'yas-abort-snippet))
2017-02-11 06:59:49 -05:00
(def-package! auto-yasnippet
2017-02-11 06:59:49 -05:00
:commands (aya-create aya-expand aya-open-line aya-persist-snippet)
:config
(setq aya-persist-snippets-dir (concat doom-local-dir "auto-snippets/")))