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:
Henrik Lissner 2019-05-31 20:11:56 -04:00
parent dcdebdb283
commit 518e53deab
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -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
`org-tab-first-hook'."
(when (bound-and-true-p yas-minor-mode)
(cond ((and (or (not (bound-and-true-p evil-mode))
(eq evil-state 'insert))
(cond ((and (or (not (bound-and-true-p evil-local-mode))
(evil-insert-state-p))
(yas--templates-for-key-at-point))
(call-interactively #'yas-expand)
t)
((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))))
;;;###autoload