Convert +snippets/expand-on-region to advice
It's meant to be corrective, not alternative behavior.
This commit is contained in:
parent
ff25e3c08f
commit
dcdebdb283
3 changed files with 23 additions and 19 deletions
|
@ -1,16 +0,0 @@
|
|||
;;; editor/snippets/autoload/evil.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! :editor evil)
|
||||
|
||||
;;;###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))
|
||||
(when (yas-active-snippets)
|
||||
(evil-insert-state +1)))
|
||||
|
|
@ -110,6 +110,26 @@ buggy behavior when <delete> is pressed in an empty field."
|
|||
(message "This is a built-in snippet, enabling read only mode. Use `yas-new-snippet' to redefine snippets")))
|
||||
|
||||
|
||||
;;
|
||||
;;; Advice
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets*expand-on-region (orig-fn &optional no-condition)
|
||||
"Fix off-by-one issue with expanding snippets on an evil visual region, and
|
||||
switches to insert mode.
|
||||
|
||||
If evil-local-mode isn't enabled, run ORIG-FN as is."
|
||||
(if (not (and (bound-and-true-p evil-local-mode)
|
||||
(evil-visual-state-p)))
|
||||
(funcall orig-fn no-condition)
|
||||
(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)))
|
||||
(funcall orig-fn no-condition))
|
||||
(when (yas-active-snippets)
|
||||
(evil-insert-state +1))))
|
||||
|
||||
|
||||
;;
|
||||
;; Commands
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue