2014-09-05 17:08:40 -04:00
|
|
|
(provide 'init-snippets)
|
|
|
|
|
2014-08-29 22:37:25 -04:00
|
|
|
(use-package yasnippet
|
2014-11-29 20:21:03 -05:00
|
|
|
:mode (("emacs\\.d/.+/snippets/" . snippet-mode))
|
|
|
|
: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)))
|
|
|
|
(bind 'insert map [(tab)] 'yas-expand)
|
|
|
|
(bind 'insert map (kbd "TAB") 'yas-expand)
|
|
|
|
(bind 'visual map (kbd "<backtab>") 'yas-insert-snippet)
|
|
|
|
map)))
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(defadvice evil-force-normal-state (before evil-esc-quit-yasnippet activate)
|
|
|
|
(shut-up (yas-exit-all-snippets)))
|
2014-09-20 16:54:04 -04:00
|
|
|
|
2014-11-29 20:21:03 -05:00
|
|
|
;; Only load personal snippets
|
|
|
|
(setq yas-snippet-dirs `(,*snippets-dir))
|
|
|
|
(setq yas-prompt-functions '(yas-ido-prompt yas-no-prompt))
|
|
|
|
(setq yas-also-auto-indent-first-line t)
|
2014-08-10 19:40:44 -04:00
|
|
|
|
2014-11-29 20:21:03 -05: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))))
|
2014-09-20 16:54:04 -04:00
|
|
|
|
2014-11-29 20:21:03 -05:00
|
|
|
(bind yas-keymap (kbd "DEL") 'my/yas-clear-field)
|
2014-08-07 18:35:22 -04:00
|
|
|
|
2014-11-29 20:21:03 -05:00
|
|
|
(yas-reload-all))
|
|
|
|
:init
|
|
|
|
(progn
|
|
|
|
(add-hook 'snippet-mode-hook 'disable-final-newline)
|
|
|
|
(add-hook 'text-mode-hook 'yas-minor-mode)
|
|
|
|
(add-hook 'prog-mode-hook 'yas-minor-mode)
|
|
|
|
(add-hook 'snippet-mode-hook 'yas-minor-mode)
|
|
|
|
;; (add-hook 'markdown-mode-hook 'yas-minor-mode)
|
|
|
|
(add-hook 'org-mode-hook 'yas-minor-mode)))
|
2014-08-07 18:35:22 -04:00
|
|
|
|
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)))))
|
2014-11-29 20:21:03 -05:00
|
|
|
|
|
|
|
;; yas snippet helpers
|
|
|
|
(defvaralias '% 'yas-selected-text)
|
|
|
|
(defun %! () (if % (s-trim-right %)))
|
|
|
|
(defun !% () (if % (s-trim-left %)))
|
|
|
|
(defun !%! () (if % (s-trim %)))
|
|
|
|
(defun --newline-maybe () (if % "\n"))
|