lang/org: fix snippet expansion on visual region
Fixes two issues: 1. Evil users would be left in visual mode after expanding a snippet on a region, making it awkward to insert text. It now switches to insert state. 2. While yasnippet reindent the snippet's contents post-expansion, org's mode-specific indentation (see `org-src-tab-acts-natively`) can throw errors for arbitrary reasons. We don't need smart indentation when expanding snippets, so we turn it off only in this case.
This commit is contained in:
parent
dcdebdb283
commit
518e53deab
1 changed files with 7 additions and 3 deletions
|
@ -405,13 +405,17 @@ Made for `org-tab-first-hook' in evil-mode."
|
||||||
"Tries to expand a yasnippet snippet, if one is available. Made for
|
"Tries to expand a yasnippet snippet, if one is available. Made for
|
||||||
`org-tab-first-hook'."
|
`org-tab-first-hook'."
|
||||||
(when (bound-and-true-p yas-minor-mode)
|
(when (bound-and-true-p yas-minor-mode)
|
||||||
(cond ((and (or (not (bound-and-true-p evil-mode))
|
(cond ((and (or (not (bound-and-true-p evil-local-mode))
|
||||||
(eq evil-state 'insert))
|
(evil-insert-state-p))
|
||||||
(yas--templates-for-key-at-point))
|
(yas--templates-for-key-at-point))
|
||||||
(call-interactively #'yas-expand)
|
(call-interactively #'yas-expand)
|
||||||
t)
|
t)
|
||||||
((use-region-p)
|
((use-region-p)
|
||||||
(call-interactively #'yas-insert-snippet)
|
;; Triggering mode-specific indentation is expensive in src blocks
|
||||||
|
;; (if `org-src-tab-acts-natively' is non-nil), and can cause errors,
|
||||||
|
;; so we avoid smart indentation in this case.
|
||||||
|
(let ((yas-indent-line 'fixed))
|
||||||
|
(call-interactively #'yas-insert-snippet))
|
||||||
t))))
|
t))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue