2014-09-05 17:08:40 -04:00
|
|
|
(provide 'init-snippets)
|
|
|
|
|
2014-08-29 22:37:25 -04:00
|
|
|
(use-package yasnippet
|
2014-08-07 18:35:22 -04:00
|
|
|
:mode (("emacs.+/snippets/" . snippet-mode))
|
2014-09-20 16:54:04 -04:00
|
|
|
:pre-load
|
|
|
|
(progn
|
|
|
|
;; Fix yasnippet keymaps so they only work in insert mode (why they
|
|
|
|
;; had to make this so complicated I don't know); must be defined
|
|
|
|
;; BEFORE we include yasnippet.
|
|
|
|
(defvar yas-minor-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(imap map [(tab)] 'yas-expand)
|
|
|
|
(imap map (kbd "TAB") 'yas-expand)
|
|
|
|
map)))
|
2014-08-07 18:35:22 -04:00
|
|
|
:config
|
|
|
|
(progn
|
2014-09-20 16:54:04 -04:00
|
|
|
(defadvice evil-force-normal-state (before evil-esc-quit-yasnippet activate)
|
|
|
|
(shut-up (yas-exit-all-snippets)))
|
|
|
|
|
2014-08-07 18:35:22 -04:00
|
|
|
;; Only load personal snippets
|
2014-09-05 17:08:40 -04:00
|
|
|
(setq yas-snippet-dirs `(,*snippets-dir))
|
2014-08-10 19:40:44 -04:00
|
|
|
(setq yas-prompt-functions '(yas-ido-prompt yas-no-prompt))
|
|
|
|
|
2014-09-20 16:54:04 -04:00
|
|
|
(after auto-complete
|
|
|
|
(add-hook! 'yas-before-expand-snippet-hook (auto-complete-mode -1))
|
|
|
|
(add-hook! 'yas-after-exit-snippet-hook (auto-complete-mode t))
|
|
|
|
(defadvice ac-expand (before advice-for-ac-expand activate)
|
|
|
|
(when (yas-expand) (ac-stop))))
|
|
|
|
|
|
|
|
(defmap yas-keymap (kbd "DEL") 'my/yas-clear-field)
|
2014-08-07 18:35:22 -04:00
|
|
|
|
|
|
|
(yas-reload-all))
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(add-hook 'prog-mode-hook 'yas-minor-mode)
|
2014-08-07 19:49:47 -04:00
|
|
|
(add-hook 'snippet-mode-hook 'yas-minor-mode)
|
2014-08-21 03:33:30 -04:00
|
|
|
(add-hook 'markdown-mode-hook 'yas-minor-mode)
|
2014-08-07 18:35:22 -04:00
|
|
|
(add-hook 'org-mode-hook 'yas-minor-mode)))
|
|
|
|
|
2014-09-20 16:54:04 -04:00
|
|
|
;; Prevents Yas from stepping on my toes when I use backspace
|
2014-09-05 17:08:40 -04:00
|
|
|
(defun my/yas-clear-field (&optional field)
|
|
|
|
(interactive)
|
|
|
|
(let ((field (or field
|
|
|
|
(and yas--active-field-overlay
|
|
|
|
(overlay-buffer yas--active-field-overlay)
|
|
|
|
(overlay-get yas--active-field-overlay 'yas--field)))))
|
|
|
|
(cond ((and field
|
|
|
|
(not (yas--field-modified-p field))
|
|
|
|
(eq (point) (marker-position (yas--field-start field))))
|
|
|
|
(yas--skip-and-clear field))
|
|
|
|
(t (delete-char -1)))))
|