Do indent the first line of mirrors, but in correct order

This changes the strategy for fixing #712 to a simpler alternative,
which doesn't remove the benefits of indenting single line mirrors.

It reverts the functional parts of commit
351c1e3dcbb73e3154aae0755d5b7016f1561ebc, while keeping the tests.

* yasnippet.el (yas--update-mirrors): Sort mirrors to be updated by
  start position.
This commit is contained in:
João Távora 2016-06-24 13:11:40 +01:00
parent 351c1e3dcb
commit d218ed8b1b
2 changed files with 10 additions and 8 deletions

View File

@ -255,6 +255,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."