branch: master commit 351c1e3dcbb73e3154aae0755d5b7016f1561ebc Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
Don't indent first line of mirrors * yasnippet.el (yas--mirror-update-display): Don't indent the first line of mirror output (meaning no indentation happens if there is a single line). * yasnippet-tests.el (single-line-multi-mirror-indentation): New test. (snippet-with-multiline-mirrors-issue-665): Renamed from navigate-a-snippet-with-multiline-mirrors-issue-665, test for precise indentation in addition to navigation (this was already implemented, contrary to its obsolete docstring). Fixes #712 --- yasnippet-tests.el | 23 ++++++++++++++++------- yasnippet.el | 11 +++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index 47b6e1f..8da5f7d 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -227,13 +227,22 @@ end" (buffer-string))) No indent$> end" (buffer-string))))) +(ert-deftest single-line-multi-mirror-indentation () + "Make sure not to indent with multiple mirrors per line." + ;; See also Github issue #712. + (with-temp-buffer + (text-mode) + (yas-minor-mode 1) + (yas-expand-snippet "${1:XXXXX} -------- +$1 ---------------- $1 ---- +$1 ------------------------") + (should (string= (yas--buffer-contents) "XXXXX -------- +XXXXX ---------------- XXXXX ---- +XXXXX ------------------------")))) -(ert-deftest navigate-a-snippet-with-multiline-mirrors-issue-665 () - "In issue 665, a multi-line mirror is attempted. -Indentation doesn't (yet) happen on these mirrors, but let this -test guard against any misnavigations that might be introduced by -an incorrect implementation of mirror auto-indentation" +(ert-deftest snippet-with-multiline-mirrors-issue-665 () + "In issue 665, a multi-line mirror is attempted." (with-temp-buffer (ruby-mode) (yas-minor-mode 1) @@ -246,8 +255,8 @@ mapconcat #'(lambda (arg) (ert-simulate-command '(yas-next-field)) (let ((expected (mapconcat #'identity '("@bla = bla" - "[[:blank:]]*@ble = ble" - "[[:blank:]]*@bli = bli") + " @ble = ble" + " @bli = bli") "\n"))) (should (looking-at expected)) (yas-mock-insert "blo") diff --git a/yasnippet.el b/yasnippet.el index 6573f36..57dcdbc 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -4294,10 +4294,13 @@ When multiple expressions are found, only the last one counts." (yas--advance-start-maybe (yas--mirror-next mirror) (point)) ;; super-special advance (yas--advance-end-of-parents-maybe mirror-parent-field (point))) - (let ((yas--inhibit-overlay-hooks t)) - (yas--indent-region (yas--mirror-start mirror) - (yas--mirror-end mirror) - snippet))))) + (let ((yas--inhibit-overlay-hooks t) + (beg (save-excursion (goto-char (yas--mirror-start mirror)) + (forward-line 1) + (point))) + (end (yas--mirror-end mirror))) + (when (< beg end) + (yas--indent-region beg end snippet)))))) (defun yas--field-update-display (field) "Much like `yas--mirror-update-display', but for fields."