yas-also-auto-indent-first-line = nil

Stop yasnippet from aggressively reindenting the whole snippet; assume
the user is expanding the snippet exactly where they want it.

Half-fixes #3211
This commit is contained in:
Henrik Lissner 2020-05-24 13:31:29 -04:00
parent a262527a7f
commit d8fda76c7d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 17 additions and 8 deletions

View file

@ -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))

View file

@ -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)