]> code.delx.au - gnu-emacs-elpa/commitdiff
Don't indent empty lines in snippet expansion
authorNoam Postavsky <github.10.npostavs@spamgourmet.com>
Wed, 4 May 2016 16:35:48 +0000 (12:35 -0400)
committerNoam Postavsky <github.10.npostavs@spamgourmet.com>
Wed, 4 May 2016 16:35:48 +0000 (12:35 -0400)
* yasnippet.el (yas--indent-region): Indent only non-empty lines.
* yasnippet-tests.el (basic-indentation): Add empy and non-empty (but
blank) lines in test snippet.

yasnippet-tests.el
yasnippet.el

index 828d71a968597a3d1e30b3133a1d1f90deb9739b..8ba4632d3af865dd63411daee1a6ca42e796f9a4 100644 (file)
     (set (make-local-variable 'yas-indent-line) 'auto)
     (set (make-local-variable 'yas-also-auto-indent-first-line) t)
     (yas-expand-snippet "def ${1:method}${2:(${3:args})}\n$0\nend")
+    ;; Note that empty line is not indented.
+    (should (string= "def method(args)
+
+end" (buffer-string)))
     (cl-loop repeat 3 do (ert-simulate-command '(yas-next-field)))
     (yas-mock-insert (make-string (random 5) ?\ )) ; purposedly mess up indentation
-    (yas-expand-snippet "class << ${self}\n$0\nend")
+    (yas-expand-snippet "class << ${self}\n  $0\nend")
     (ert-simulate-command '(yas-next-field))
     (should (string= "def method(args)
   class << self
index 5aa53c61178e5082748fd12c0b9cc8888526cbf4..2da30625d34049110392e1fac7ff8cf83d3cd512 100644 (file)
@@ -3918,7 +3918,8 @@ The SNIPPET's markers are preserved."
       (goto-char from)
       (save-restriction
         (widen)
-        (cl-loop do
+        ;; Indent each non-empty line.
+        (cl-loop if (/= (line-beginning-position) (line-end-position)) do
                  (back-to-indentation)
                  (let ((trouble-markers ; The markers at (point).
                         (cl-remove (point) snippet-markers :test #'/=)))