mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +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$>
|
||||
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
|
||||
test guard against any misnavigations that might be introduced by
|
||||
an incorrect implementation of mirror auto-indentation"
|
||||
(ert-deftest snippet-with-multiline-mirrors-issue-665 ()
|
||||
"In issue 665, a multi-line mirror is attempted."
|
||||
(with-temp-buffer
|
||||
(ruby-mode)
|
||||
(yas-minor-mode 1)
|
||||
@ -246,8 +255,8 @@ mapconcat #'(lambda (arg)
|
||||
(ert-simulate-command '(yas-next-field))
|
||||
(let ((expected (mapconcat #'identity
|
||||
'("@bla = bla"
|
||||
"[[:blank:]]*@ble = ble"
|
||||
"[[:blank:]]*@bli = bli")
|
||||
" @ble = ble"
|
||||
" @bli = bli")
|
||||
"\n")))
|
||||
(should (looking-at expected))
|
||||
(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))
|
||||
;; super-special advance
|
||||
(yas--advance-end-of-parents-maybe mirror-parent-field (point)))
|
||||
(let ((yas--inhibit-overlay-hooks t))
|
||||
(yas--indent-region (yas--mirror-start mirror)
|
||||
(yas--mirror-end mirror)
|
||||
snippet)))))
|
||||
(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))))))
|
||||
|
||||
(defun yas--field-update-display (field)
|
||||
"Much like `yas--mirror-update-display', but for fields."
|
||||
|
Loading…
x
Reference in New Issue
Block a user