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.
This commit is contained in:
Noam Postavsky 2016-06-24 16:26:14 -04:00
commit 8ca8c7de4f
2 changed files with 20 additions and 8 deletions

View File

@ -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")))

View File

@ -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."