From 518e53deab49eba1a7752a6423d39e17ccc11628 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 31 May 2019 20:11:56 -0400 Subject: [PATCH] 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. --- modules/lang/org/autoload/org.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/lang/org/autoload/org.el b/modules/lang/org/autoload/org.el index e6b74a67b..08cdf82ca 100644 --- a/modules/lang/org/autoload/org.el +++ b/modules/lang/org/autoload/org.el @@ -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