mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
Add yas-also-indent-empty-lines to allow old indent behavior
* yasnippet.el (yas-also-auto-indent-first-line): New option. (yas--indent-region): Also indent empty lines if it's set. * yasnippet-tests.el (yas-also-indent-empty-lines): New test.
This commit is contained in:
parent
e371c119ec
commit
c79c8df599
@ -384,6 +384,23 @@ end" (buffer-string)))
|
|||||||
end" (buffer-string)))
|
end" (buffer-string)))
|
||||||
(should (= 4 (current-column)))))
|
(should (= 4 (current-column)))))
|
||||||
|
|
||||||
|
(ert-deftest yas-also-indent-empty-lines ()
|
||||||
|
"Respect `yas-also-indent-empty-lines' setting."
|
||||||
|
(with-temp-buffer
|
||||||
|
(ruby-mode)
|
||||||
|
(yas-minor-mode 1)
|
||||||
|
(set (make-local-variable 'yas-indent-line) 'auto)
|
||||||
|
(set (make-local-variable 'yas-also-auto-indent-first-line) t)
|
||||||
|
(set (make-local-variable 'yas-also-indent-empty-lines) t)
|
||||||
|
(yas-expand-snippet "def foo\n\nend")
|
||||||
|
(should (string= "def foo\n \nend" (buffer-string)))
|
||||||
|
;; Test that it keeps working without setting
|
||||||
|
;; `yas-also-auto-indent-first-line'.
|
||||||
|
(setq yas-also-auto-indent-first-line nil)
|
||||||
|
(erase-buffer)
|
||||||
|
(yas-expand-snippet "def foo\n\nend")
|
||||||
|
(should (string= "def foo\n \nend" (buffer-string)))))
|
||||||
|
|
||||||
(ert-deftest indentation-markers ()
|
(ert-deftest indentation-markers ()
|
||||||
"Test a snippet with indentation markers (`$<')."
|
"Test a snippet with indentation markers (`$<')."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
|
10
yasnippet.el
10
yasnippet.el
@ -261,7 +261,11 @@ applies)."
|
|||||||
(defcustom yas-also-auto-indent-first-line nil
|
(defcustom yas-also-auto-indent-first-line nil
|
||||||
"Non-nil means also auto indent first line according to mode.
|
"Non-nil means also auto indent first line according to mode.
|
||||||
|
|
||||||
Naturally this is only valid when `yas-indent-line' is `auto'"
|
Naturally this is only valid when `yas-indent-line' is `auto'."
|
||||||
|
:type 'boolean)
|
||||||
|
|
||||||
|
(defcustom yas-also-indent-empty-lines nil
|
||||||
|
"Non-nil means also indent empty lines according to mode."
|
||||||
:type 'boolean)
|
:type 'boolean)
|
||||||
|
|
||||||
(defcustom yas-snippet-revival t
|
(defcustom yas-snippet-revival t
|
||||||
@ -4227,7 +4231,9 @@ The SNIPPET's markers are preserved."
|
|||||||
(goto-char from)
|
(goto-char from)
|
||||||
(cl-loop for bol = (line-beginning-position)
|
(cl-loop for bol = (line-beginning-position)
|
||||||
for eol = (line-end-position)
|
for eol = (line-end-position)
|
||||||
if (/= bol eol) do
|
if (or yas-also-indent-empty-lines
|
||||||
|
(/= bol eol))
|
||||||
|
do
|
||||||
;; Indent each non-empty line.
|
;; Indent each non-empty line.
|
||||||
(let ((remarkers nil))
|
(let ((remarkers nil))
|
||||||
(dolist (m snippet-markers)
|
(dolist (m snippet-markers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user