mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
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:
commit
8ca8c7de4f
@ -240,6 +240,16 @@ $1 ------------------------")
|
|||||||
XXXXX ---------------- XXXXX ----
|
XXXXX ---------------- 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 ()
|
(ert-deftest snippet-with-multiline-mirrors-issue-665 ()
|
||||||
"In issue 665, a multi-line mirror is attempted."
|
"In issue 665, a multi-line mirror is attempted."
|
||||||
@ -255,6 +265,7 @@ mapconcat #'(lambda (arg)
|
|||||||
(ert-simulate-command '(yas-next-field))
|
(ert-simulate-command '(yas-next-field))
|
||||||
(let ((expected (mapconcat #'identity
|
(let ((expected (mapconcat #'identity
|
||||||
'("@bla = bla"
|
'("@bla = bla"
|
||||||
|
;; assume ruby is always indented to 2 spaces
|
||||||
" @ble = ble"
|
" @ble = ble"
|
||||||
" @bli = bli")
|
" @bli = bli")
|
||||||
"\n")))
|
"\n")))
|
||||||
|
17
yasnippet.el
17
yasnippet.el
@ -4247,7 +4247,11 @@ When multiple expressions are found, only the last one counts."
|
|||||||
(cl-mapcan #'(lambda (field)
|
(cl-mapcan #'(lambda (field)
|
||||||
(mapcar #'(lambda (mirror)
|
(mapcar #'(lambda (mirror)
|
||||||
(cons field 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))
|
(yas--snippet-fields snippet))
|
||||||
;; then sort this list so that entries with mirrors with parent
|
;; then sort this list so that entries with mirrors with parent
|
||||||
;; fields appear before. This was important for fixing #290, and
|
;; 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))
|
(yas--advance-start-maybe (yas--mirror-next mirror) (point))
|
||||||
;; super-special advance
|
;; super-special advance
|
||||||
(yas--advance-end-of-parents-maybe mirror-parent-field (point)))
|
(yas--advance-end-of-parents-maybe mirror-parent-field (point)))
|
||||||
(let ((yas--inhibit-overlay-hooks t)
|
(let ((yas--inhibit-overlay-hooks t))
|
||||||
(beg (save-excursion (goto-char (yas--mirror-start mirror))
|
(yas--indent-region (yas--mirror-start mirror)
|
||||||
(forward-line 1)
|
(yas--mirror-end mirror)
|
||||||
(point)))
|
snippet)))))
|
||||||
(end (yas--mirror-end mirror)))
|
|
||||||
(when (< beg end)
|
|
||||||
(yas--indent-region beg end snippet))))))
|
|
||||||
|
|
||||||
(defun yas--field-update-display (field)
|
(defun yas--field-update-display (field)
|
||||||
"Much like `yas--mirror-update-display', but for fields."
|
"Much like `yas--mirror-update-display', but for fields."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user