branch: master commit 8ca8c7de4f0f898d4f29af800b83f5e8d79d9a66 Merge: 351c1e3 9c9952c Author: Noam Postavsky <npost...@users.sourceforge.net> Commit: Noam Postavsky <npost...@users.sourceforge.net>
Merge: a different fix for #712. "Don't indent first line of mirrors" had the drawback that sometimes we *want* to indent the first line of mirrors. So we fix the underlying problem in a different way and add a test to make sure we don't lose this behaviour again. --- yasnippet-tests.el | 11 +++++++++++ yasnippet.el | 17 +++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/yasnippet-tests.el b/yasnippet-tests.el index 8da5f7d..1d56fb8 100644 --- a/yasnippet-tests.el +++ b/yasnippet-tests.el @@ -240,6 +240,16 @@ $1 ------------------------") XXXXX ---------------- XXXXX ---- XXXXX ------------------------")))) +(ert-deftest indent-mirrors-on-update () + "Check that mirrors are always kept indented." + (with-temp-buffer + (ruby-mode) + (yas-minor-mode 1) + (yas-expand-snippet "def $1\n$1\nend") + (yas-mock-insert "xxx") + ;; Assuming 2 space indent. + (should (string= "def xxx\n xxx\nend" (buffer-string))))) + (ert-deftest snippet-with-multiline-mirrors-issue-665 () "In issue 665, a multi-line mirror is attempted." @@ -255,6 +265,7 @@ mapconcat #'(lambda (arg) (ert-simulate-command '(yas-next-field)) (let ((expected (mapconcat #'identity '("@bla = bla" + ;; assume ruby is always indented to 2 spaces " @ble = ble" " @bli = bli") "\n"))) diff --git a/yasnippet.el b/yasnippet.el index 57dcdbc..bfe5590 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -4247,7 +4247,11 @@ When multiple expressions are found, only the last one counts." (cl-mapcan #'(lambda (field) (mapcar #'(lambda (mirror) (cons field mirror)) - (yas--field-mirrors field))) + (cl-sort + (cl-copy-list + (yas--field-mirrors field)) + #'< + :key #'yas--mirror-start))) (yas--snippet-fields snippet)) ;; then sort this list so that entries with mirrors with parent ;; fields appear before. This was important for fixing #290, and @@ -4294,13 +4298,10 @@ 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) - (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)))))) + (let ((yas--inhibit-overlay-hooks t)) + (yas--indent-region (yas--mirror-start mirror) + (yas--mirror-end mirror) + snippet))))) (defun yas--field-update-display (field) "Much like `yas--mirror-update-display', but for fields."