[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master c79c8df 2/4: Add yas-also-indent-empty-lines to allow old
From: |
Noam Postavsky |
Subject: |
[elpa] master c79c8df 2/4: Add yas-also-indent-empty-lines to allow old indent behavior |
Date: |
Mon, 28 Aug 2017 22:21:48 -0400 (EDT) |
branch: master
commit c79c8df5999e3147170a45566ad2da4e71c80531
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
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.
---
yasnippet-tests.el | 17 +++++++++++++++++
yasnippet.el | 10 ++++++++--
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 748ba97..fc66de3 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -384,6 +384,23 @@ end" (buffer-string)))
end" (buffer-string)))
(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 ()
"Test a snippet with indentation markers (`$<')."
(with-temp-buffer
diff --git a/yasnippet.el b/yasnippet.el
index aa9fe5e..cfb0c08 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -261,7 +261,11 @@ applies)."
(defcustom yas-also-auto-indent-first-line nil
"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)
(defcustom yas-snippet-revival t
@@ -4227,7 +4231,9 @@ The SNIPPET's markers are preserved."
(goto-char from)
(cl-loop for bol = (line-beginning-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.
(let ((remarkers nil))
(dolist (m snippet-markers)