2016-04-23 22:08:46 -04:00
|
|
|
;;; core-yasnippet.el
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
|
|
(use-package yasnippet
|
2015-09-30 13:47:57 -04:00
|
|
|
:mode ("emacs\\.d/private/\\(snippets\\|templates\\)/.+$" . snippet-mode)
|
2015-06-15 09:05:52 +02:00
|
|
|
:commands (yas-minor-mode
|
|
|
|
yas-minor-mode-on
|
|
|
|
yas-expand
|
|
|
|
yas-insert-snippet
|
|
|
|
yas-new-snippet
|
|
|
|
yas-visit-snippet-file)
|
|
|
|
:init
|
|
|
|
(setq yas-verbosity 0
|
|
|
|
yas-indent-line 'auto
|
|
|
|
yas-also-auto-indent-first-line t
|
|
|
|
yas-wrap-around-region nil
|
|
|
|
;; Only load personal snippets
|
2016-04-21 00:46:02 -04:00
|
|
|
yas-snippet-dirs narf-snippet-dirs
|
2015-06-15 09:05:52 +02:00
|
|
|
yas-prompt-functions '(yas-ido-prompt yas-no-prompt))
|
|
|
|
|
2015-11-30 05:31:20 -05:00
|
|
|
(map! :i [(tab)] 'yas-expand
|
|
|
|
:v "<backtab>" 'narf/yas-insert-snippet)
|
2015-06-15 09:05:52 +02:00
|
|
|
|
2016-04-21 00:46:02 -04:00
|
|
|
(add-hook! (text-mode prog-mode snippet-mode markdown-mode org-mode)
|
|
|
|
'yas-minor-mode-on)
|
|
|
|
|
2015-06-15 09:05:52 +02:00
|
|
|
(defvar yas-minor-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(evil-define-key 'insert map [(tab)] 'yas-expand)
|
|
|
|
(evil-define-key 'visual map (kbd "<backtab>") 'narf/yas-insert-snippet)
|
|
|
|
map))
|
|
|
|
|
2016-04-21 00:46:02 -04:00
|
|
|
:config
|
2015-06-15 09:05:52 +02:00
|
|
|
(yas-reload-all)
|
|
|
|
|
2016-04-21 00:46:02 -04:00
|
|
|
(associate! snippet-mode :match "emacs\\.d/private/\\(snippets\\|templates\\)/.+$")
|
|
|
|
|
2015-06-15 09:05:52 +02:00
|
|
|
;; Undo global maps
|
2016-04-21 00:46:02 -04:00
|
|
|
(map! :i [(tab)] nil
|
2015-11-30 05:31:20 -05:00
|
|
|
:v "<backtab>" nil)
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
|
|
;; keybinds
|
2015-11-30 05:31:20 -05:00
|
|
|
(map! :map yas-keymap
|
|
|
|
"C-e" 'narf/yas-goto-end-of-field
|
|
|
|
"C-a" 'narf/yas-goto-start-of-field
|
|
|
|
"<M-right>" 'narf/yas-goto-end-of-field
|
|
|
|
"<M-left>" 'narf/yas-goto-start-of-field
|
|
|
|
"<S-tab>" 'yas-prev-field
|
|
|
|
"<M-backspace>" 'narf/yas-clear-to-sof
|
2015-06-15 09:05:52 +02:00
|
|
|
|
2015-11-30 05:31:20 -05:00
|
|
|
"<escape>" 'evil-normal-state
|
|
|
|
[backspace] 'narf/yas-backspace
|
|
|
|
"<delete>" 'narf/yas-delete)
|
2015-06-15 09:05:52 +02:00
|
|
|
|
2016-04-21 00:46:02 -04:00
|
|
|
;; Prevents evil's visual-line from gobbling up the newline on the right due to an
|
|
|
|
;; off-by-one issue.
|
|
|
|
(defadvice yas-expand-snippet (around yas-expand-snippet-visual-line activate)
|
|
|
|
(when (narf/evil-visual-line-state-p)
|
|
|
|
(ad-set-arg 2 (1- (ad-get-arg 2)))) ad-do-it)
|
|
|
|
|
2015-06-15 09:05:52 +02:00
|
|
|
;; Once you're in normal mode, you're out
|
2016-04-21 00:46:02 -04:00
|
|
|
(add-hook 'evil-normal-state-entry-hook 'yas-abort-snippet)
|
2015-06-15 09:05:52 +02:00
|
|
|
;; Strip out the shitespace before a line selection
|
2016-04-21 00:46:02 -04:00
|
|
|
(add-hook 'yas-before-expand-snippet-hook 'narf|yas-before-expand)
|
2015-06-15 09:05:52 +02:00
|
|
|
;; Previous hook causes yas-selected-text to persist between expansions.
|
2016-03-29 18:12:15 -04:00
|
|
|
;; This little hack fixes that.
|
2016-04-21 00:46:02 -04:00
|
|
|
(add-hook 'yas-after-exit-snippet-hook 'narf|yas-after-expand)
|
2015-06-15 09:05:52 +02:00
|
|
|
|
|
|
|
;; Exit snippets on ESC in normal mode
|
|
|
|
(advice-add 'evil-force-normal-state :before 'yas-exit-all-snippets)
|
2015-12-27 02:51:05 -05:00
|
|
|
|
|
|
|
;; Fix an issue with smartparens' keybindings interfering with yasnippet keybindings.
|
2016-04-21 00:46:02 -04:00
|
|
|
(advice-add 'yas-expand :before 'sp-remove-active-pair-overlay))
|
2015-06-15 09:05:52 +02:00
|
|
|
|
2016-02-26 17:59:14 -05:00
|
|
|
(use-package auto-yasnippet
|
|
|
|
:commands (aya-create aya-expand aya-open-line aya-persist-snippet)
|
|
|
|
:init
|
|
|
|
(map! :i "<C-tab>" 'aya-expand
|
|
|
|
:nv "<C-tab>" 'aya-create)
|
|
|
|
:config
|
|
|
|
(setq aya-persist-snippets-dir (concat narf-private-dir "auto-snippets/")))
|
2016-01-30 21:16:10 -05:00
|
|
|
|
2015-06-15 09:05:52 +02:00
|
|
|
(provide 'core-yasnippet)
|
|
|
|
;;; core-yasnippet.el ends here
|