doomemacs/core/core-yasnippet.el

54 lines
2.1 KiB
EmacsLisp
Raw Normal View History

;;; core-yasnippet.el
2015-06-15 15:05:52 +08:00
(use-package yasnippet
2015-10-01 01:47:57 +08:00
:mode ("emacs\\.d/private/\\(snippets\\|templates\\)/.+$" . snippet-mode)
2015-06-15 15:05:52 +08:00
:commands (yas-minor-mode
yas-minor-mode-on
yas-expand
yas-insert-snippet
yas-new-snippet
yas-visit-snippet-file)
:init
2016-05-21 07:08:02 +08:00
(defvar yas-minor-mode-map (make-sparse-keymap))
2015-06-15 15:05:52 +08:00
(setq yas-verbosity 0
yas-indent-line 'auto
yas-also-auto-indent-first-line t
2016-10-03 18:10:52 +08:00
yas-prompt-functions '(yas-ido-prompt yas-no-prompt)
2015-06-15 15:05:52 +08:00
;; Only load personal snippets
2016-05-24 05:12:54 +08:00
yas-snippet-dirs (list (concat doom-private-dir "/snippets")
(concat doom-private-dir "/templates")))
2015-06-15 15:05:52 +08:00
2016-04-21 12:46:02 +08:00
(add-hook! (text-mode prog-mode snippet-mode markdown-mode org-mode)
'yas-minor-mode-on)
:config
2015-06-15 15:05:52 +08:00
(yas-reload-all)
2016-05-21 07:08:02 +08:00
(map! :map yas-keymap
2016-05-21 10:37:30 +08:00
"C-e" 'doom/yas-goto-end-of-field
"C-a" 'doom/yas-goto-start-of-field
"<M-right>" 'doom/yas-goto-end-of-field
"<M-left>" 'doom/yas-goto-start-of-field
2016-05-21 07:08:02 +08:00
"<S-tab>" 'yas-prev-field
2016-05-21 10:37:30 +08:00
"<M-backspace>" 'doom/yas-clear-to-sof
2016-05-21 07:08:02 +08:00
"<escape>" 'evil-normal-state
2016-05-21 10:37:30 +08:00
[backspace] 'doom/yas-backspace
"<delete>" 'doom/yas-delete)
2015-06-15 15:05:52 +08:00
2016-09-26 22:26:11 +08:00
;; Fix an error caused by smartparens interfering with yasnippet bindings
(advice-add 'yas-expand :before 'sp-remove-active-pair-overlay)
2016-05-21 07:08:02 +08:00
;; Exit snippets on ESC in normal mode
(advice-add 'evil-force-normal-state :before 'yas-exit-all-snippets)
2015-06-15 15:05:52 +08:00
;; Once you're in normal mode, you're out
2016-04-21 12:46:02 +08:00
(add-hook 'evil-normal-state-entry-hook 'yas-abort-snippet)
2016-05-18 14:14:44 +08:00
;; Strip out whitespace before a line selection
2016-05-21 10:37:30 +08:00
(add-hook 'yas-before-expand-snippet-hook 'doom|yas-before-expand)
2016-05-18 14:14:44 +08:00
;; Fix previous hook persisting yas-selected-text between expansions
2016-06-09 02:43:40 +08:00
(add-hook 'yas-after-exit-snippet-hook 'doom|yas-after-expand))
2015-06-15 15:05:52 +08:00
2016-02-27 06:59:14 +08:00
(use-package auto-yasnippet
:commands (aya-create aya-expand aya-open-line aya-persist-snippet)
2016-06-05 12:11:46 +08:00
:config (setq aya-persist-snippets-dir (concat doom-private-dir "auto-snippets/")))
2016-01-31 10:16:10 +08:00
2015-06-15 15:05:52 +08:00
(provide 'core-yasnippet)
;;; core-yasnippet.el ends here