[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 5170f05 42/51: Don't indent first and only line of expande
From: |
Noam Postavsky |
Subject: |
[elpa] master 5170f05 42/51: Don't indent first and only line of expanded snippet |
Date: |
Sun, 13 May 2018 13:11:46 -0400 (EDT) |
branch: master
commit 5170f051ad39353ed46ae7ff7b67e50e0e27324c
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Don't indent first and only line of expanded snippet
Unless yas-also-auto-indent-first-line applies.
* yasnippet.el (yas--indent): Check that forward-line successfully
moved 1 line forward before trying to indent.
* yasnippet-tests.el (yas-indent-first-line)
(yas-indent-first-line-fixed): New tests.
---
yasnippet-tests.el | 24 ++++++++++++++++++++++++
yasnippet.el | 31 +++++++++++++++++--------------
2 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index cc90361..f90372b 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -447,6 +447,30 @@ end" (buffer-string)))
(yas-expand-snippet "def foo\n\nend")
(should (string= "def foo\n \nend" (buffer-string)))))
+(ert-deftest yas-indent-first-line ()
+ (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) nil)
+ (set (make-local-variable 'yas-also-indent-empty-lines) nil)
+ (yas-expand-snippet "def foo\n$0\nend\n")
+ ;; First (and only) line should not indent.
+ (yas-expand-snippet "#not indented")
+ (should (equal "def foo\n#not indented\nend\n" (buffer-string)))))
+
+(ert-deftest yas-indent-first-line-fixed ()
+ (with-temp-buffer
+ (ruby-mode)
+ (yas-minor-mode 1)
+ (set (make-local-variable 'yas-indent-line) 'fixed)
+ (set (make-local-variable 'yas-also-auto-indent-first-line) nil)
+ (set (make-local-variable 'yas-also-indent-empty-lines) nil)
+ (yas-expand-snippet " def foo\n $0\n end\n")
+ ;; First (and only) line should not indent.
+ (yas-expand-snippet "#not more indented")
+ (should (equal " def foo\n #not more indented\n end\n"
(buffer-string)))))
+
(ert-deftest indentation-markers ()
"Test a snippet with indentation markers (`$<')."
(with-temp-buffer
diff --git a/yasnippet.el b/yasnippet.el
index 5f17465..b36c422 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -4302,23 +4302,26 @@ The SNIPPET's markers are preserved."
(setq yas--indent-markers nil))
;; Now do stuff for `fixed' and `auto'.
(save-excursion
+ ;; We need to be at end of line, so that `forward-line' will only
+ ;; report 0 if it actually moves over a newline.
+ (end-of-line)
(cond ((eq yas-indent-line 'fixed)
- (forward-line 1)
- (let ((indent-line-function
- (lambda ()
- ;; We need to be at beginning of line in order to
- ;; indent existing whitespace correctly.
- (beginning-of-line)
- (indent-to-column yas--indent-original-column))))
+ (when (= (forward-line 1) 0)
+ (let ((indent-line-function
+ (lambda ()
+ ;; We need to be at beginning of line in order to
+ ;; indent existing whitespace correctly.
+ (beginning-of-line)
+ (indent-to-column yas--indent-original-column))))
+ (yas--indent-region (line-beginning-position)
+ (point-max)
+ snippet))))
+ ((eq yas-indent-line 'auto)
+ (when (or yas-also-auto-indent-first-line
+ (= (forward-line 1) 0))
(yas--indent-region (line-beginning-position)
(point-max)
- snippet)))
- ((eq yas-indent-line 'auto)
- (unless yas-also-auto-indent-first-line
- (forward-line 1))
- (yas--indent-region (line-beginning-position)
- (point-max)
- snippet)))))
+ snippet))))))
(defun yas--collect-snippet-markers (snippet)
"Make a list of all the markers used by SNIPPET."
- [elpa] master cf23537 33/51: Fix expansion of commands snippet, (continued)
- [elpa] master cf23537 33/51: Fix expansion of commands snippet, Noam Postavsky, 2018/05/13
- [elpa] master fa6a71c 45/51: ; Wait until post-command, or bad auto-fill call to print stacktrace, Noam Postavsky, 2018/05/13
- [elpa] master c9277d3 32/51: Change yas-lookup-snippet to return a yas--template struct, Noam Postavsky, 2018/05/13
- [elpa] master 6066631 28/51: Fix typos in "Writing Templates" documentation, Noam Postavsky, 2018/05/13
- [elpa] master b0aa5c2 48/51: Tweak bug-reporting information slightly, Noam Postavsky, 2018/05/13
- [elpa] master fe9f8b6 21/51: ; yasnippet-debug.el: Update yas-debug-snippets arg for previous change., Noam Postavsky, 2018/05/13
- [elpa] master caf3dba 30/51: Don't use global variable for backquote expression locations, Noam Postavsky, 2018/05/13
- [elpa] master ff26e3b 19/51: Close #824: Simple fields can be parented like other fields or mirrors, Noam Postavsky, 2018/05/13
- [elpa] master ff8e833 23/51: ; yasnippet-debug.el: Fix deprecation warning., Noam Postavsky, 2018/05/13
- [elpa] master a0d2cff 44/51: ; Don't enter debugger for kill-all-local-variables case, Noam Postavsky, 2018/05/13
- [elpa] master 5170f05 42/51: Don't indent first and only line of expanded snippet,
Noam Postavsky <=
- [elpa] master 5a29fe6 50/51: Release 0.13.0, Noam Postavsky, 2018/05/13
- [elpa] master 8b421bc 20/51: Reinstate the old debug behaviour for yas-tryout-snippet, Noam Postavsky, 2018/05/13
- [elpa] master 074d670 26/51: Add yasnippet-unload-function, Noam Postavsky, 2018/05/13
- [elpa] master d364425 38/51: * yasnippet.el (yas-field-value): Fix docstring., Noam Postavsky, 2018/05/13
- [elpa] master 05ac1da 31/51: ; yasnippet-tests.el (yas-no-memory-of-bad-snippet): Fix docstring., Noam Postavsky, 2018/05/13
- [elpa] master 3032337 37/51: Improve rendering of docstrings in manual's reference section, Noam Postavsky, 2018/05/13
- [elpa] master ae95810 43/51: ; Try to get more info about 873/919, Noam Postavsky, 2018/05/13
- [elpa] master 15761e8 41/51: Adjust previous fix, Noam Postavsky, 2018/05/13
- [elpa] master 0afc638 35/51: Fix docs for new org mode, Noam Postavsky, 2018/05/13
- [elpa] master 1668607 46/51: Don't add to disabled undo list, Noam Postavsky, 2018/05/13