Test and fix problem with mirror+autofill

cc-mode fill paragraph narrows to the paragraph being filled.  This
causes problems if there is a mirror needing to be updated outside of
the current paragraph.

* yasnippet-tests.el: New test.
* yasnippet.el (yas--update-mirrors): Widen while updating the mirrors.
This commit is contained in:
Noam Postavsky 2016-04-28 21:16:30 -04:00
parent 7799aa908b
commit bfe14f19ac
2 changed files with 58 additions and 36 deletions

View File

@ -68,6 +68,26 @@
(should (string= (yas--buffer-contents)
"bla from another BLA"))))
(ert-deftest mirror-with-transformation-and-autofill ()
"Test interaction of autofill with mirror transforms"
(let ((words "one two three four five")
filled-words)
(with-temp-buffer
(c-mode) ; In `c-mode' filling comments works by narrowing.
(yas-minor-mode +1)
(setq fill-column 10)
(auto-fill-mode +1)
(yas-expand-snippet "/* $0\n */")
(yas-mock-insert words)
(setq filled-words (delete-and-extract-region (point-min) (point-max)))
(yas-expand-snippet "/* $1\n */\n$2$2")
(should (string= (yas--buffer-contents)
"/* \n */\n"))
(yas-mock-insert words)
(should (string= (yas--buffer-contents)
(concat filled-words "\n"))))))
(ert-deftest primary-field-transformation ()
(with-temp-buffer
(yas-minor-mode 1)

View File

@ -4192,6 +4192,8 @@ When multiple expressions are found, only the last one counts."
(defun yas--update-mirrors (snippet)
"Update all the mirrors of SNIPPET."
(save-restriction
(widen)
(save-excursion
(dolist (field-and-mirror
(sort
@ -4227,7 +4229,7 @@ When multiple expressions are found, only the last one counts."
;; in `yas--mirror-update-display'
;;
(when (eq field (yas--snippet-active-field snippet))
(yas--place-overlays snippet field))))))
(yas--place-overlays snippet field)))))))
(defun yas--mirror-update-display (mirror field)
"Update MIRROR according to FIELD (and mirror transform)."