2017-06-08 11:47:56 +02:00
|
|
|
;;; feature/snippets/autoload/evil.el -*- lexical-binding: t; -*-
|
2017-02-19 18:32:09 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +snippets/expand-on-region ()
|
|
|
|
"Only use this with `evil-mode'. Expands a snippet around a selected region
|
|
|
|
and switches to insert mode if there are editable fields."
|
|
|
|
(interactive)
|
|
|
|
(when (evil-visual-state-p)
|
2017-03-22 04:57:29 -04:00
|
|
|
(evil-visual-select evil-visual-beginning evil-visual-end 'inclusive))
|
|
|
|
(cl-letf (((symbol-function 'region-beginning) (lambda () evil-visual-beginning))
|
|
|
|
((symbol-function 'region-end) (lambda () evil-visual-end)))
|
|
|
|
(yas-insert-snippet))
|
2017-04-17 02:19:20 -04:00
|
|
|
(when-let (snippet (car-safe (yas-active-snippets)))
|
2017-03-22 17:42:51 -04:00
|
|
|
(let ((fields (yas--snippet-fields snippet)))
|
|
|
|
(evil-insert-state +1)
|
|
|
|
(unless fields (evil-change-state 'normal)))))
|
2017-03-22 04:57:29 -04:00
|
|
|
|