doomemacs/modules/feature/snippets/autoload/evil.el

18 lines
754 B
EmacsLisp
Raw Normal View History

;;; 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)
(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)))
(let ((fields (yas--snippet-fields snippet)))
(evil-insert-state +1)
(unless fields (evil-change-state 'normal)))))