2017-06-08 17:47:56 +08:00
|
|
|
;;; feature/snippets/autoload/evil.el -*- lexical-binding: t; -*-
|
2017-02-20 07:32:09 +08: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 16:57:29 +08: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 14:19:20 +08:00
|
|
|
(when-let (snippet (car-safe (yas-active-snippets)))
|
2017-03-23 05:42:51 +08:00
|
|
|
(let ((fields (yas--snippet-fields snippet)))
|
|
|
|
(evil-insert-state +1)
|
|
|
|
(unless fields (evil-change-state 'normal)))))
|
2017-03-22 16:57:29 +08:00
|
|
|
|