diff --git a/modules/editor/snippets/autoload/snippets.el b/modules/editor/snippets/autoload/snippets.el index f2b49f266..5228f198e 100644 --- a/modules/editor/snippets/autoload/snippets.el +++ b/modules/editor/snippets/autoload/snippets.el @@ -288,16 +288,27 @@ shadow the default snippet)." ;;;###autoload (defun +snippets-expand-on-region-a (orig-fn &optional no-condition) - "Fix off-by-one issue with expanding snippets on an evil visual region, and -switches to insert mode. + "Fix off-by-one when expanding snippets on an evil visual region. -If evil-local-mode isn't enabled, run ORIG-FN as is." +Also strips whitespace out of selection. Also switches to insert mode. If +`evil-local-mode' isn't enabled, or we're not in visual mode, 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))) + ;; Trim whitespace in selected region, so as not to introduce extra + ;; whitespace into `yas-selected-text'. + (evil-visual-select (save-excursion + (goto-char evil-visual-beginning) + (skip-chars-forward " \t") + (point)) + (save-excursion + (goto-char evil-visual-end) + (skip-chars-backward " \t") + (point)) + 'inclusive) + (letf! ((defun region-beginning () evil-visual-beginning) + (defun region-end () evil-visual-end)) (funcall orig-fn no-condition))) (when (and (bound-and-true-p evil-local-mode) (yas-active-snippets)) diff --git a/modules/editor/snippets/config.el b/modules/editor/snippets/config.el index 6a9e6cc94..b888cfb13 100644 --- a/modules/editor/snippets/config.el +++ b/modules/editor/snippets/config.el @@ -39,8 +39,6 @@ ;; Reduce verbosity. 3 is too chatty about initializing yasnippet. 2 is just ;; right (only shows errors). (setq yas-verbosity (if doom-debug-mode 3 0)) - ;; Ensure the snippet is properly indented - (setq yas-also-auto-indent-first-line t) ;; default snippets library, if available (add-to-list 'load-path +snippets-dir)