mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
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
This commit is contained in:
parent
ee6e7a9602
commit
351c1e3dcb
@ -227,13 +227,22 @@ end" (buffer-string)))
|
|||||||
No indent$>
|
No indent$>
|
||||||
end" (buffer-string)))))
|
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
|
(ert-deftest snippet-with-multiline-mirrors-issue-665 ()
|
||||||
test guard against any misnavigations that might be introduced by
|
"In issue 665, a multi-line mirror is attempted."
|
||||||
an incorrect implementation of mirror auto-indentation"
|
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(ruby-mode)
|
(ruby-mode)
|
||||||
(yas-minor-mode 1)
|
(yas-minor-mode 1)
|
||||||
@ -246,8 +255,8 @@ 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"
|
||||||
"[[:blank:]]*@ble = ble"
|
" @ble = ble"
|
||||||
"[[:blank:]]*@bli = bli")
|
" @bli = bli")
|
||||||
"\n")))
|
"\n")))
|
||||||
(should (looking-at expected))
|
(should (looking-at expected))
|
||||||
(yas-mock-insert "blo")
|
(yas-mock-insert "blo")
|
||||||
|
11
yasnippet.el
11
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))
|
(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)
|
||||||
(yas--indent-region (yas--mirror-start mirror)
|
(beg (save-excursion (goto-char (yas--mirror-start mirror))
|
||||||
(yas--mirror-end mirror)
|
(forward-line 1)
|
||||||
snippet)))))
|
(point)))
|
||||||
|
(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