mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
Closes #351: sort mirrors by nesting depth when updating
This commit is contained in:
parent
04970abf30
commit
74e8f43f06
@ -105,6 +105,13 @@
|
|||||||
(should (string= (yas--buffer-contents)
|
(should (string= (yas--buffer-contents)
|
||||||
"<%= f.submit \"Send\", :disable_with => 'Sending...' %>")))
|
"<%= f.submit \"Send\", :disable_with => 'Sending...' %>")))
|
||||||
|
|
||||||
|
(ert-deftest deep-nested-mirroring-issue-351 ()
|
||||||
|
(with-temp-buffer
|
||||||
|
(yas-minor-mode 1)
|
||||||
|
(yas-expand-snippet "${1:FOOOOOOO}${2:$1}${3:$2}${4:$3}")
|
||||||
|
(ert-simulate-command `(yas-mock-insert "abc"))
|
||||||
|
(should (string= (yas--buffer-contents) "abcabcabcabc"))))
|
||||||
|
|
||||||
;; (ert-deftest in-snippet-undo ()
|
;; (ert-deftest in-snippet-undo ()
|
||||||
;; (with-temp-buffer
|
;; (with-temp-buffer
|
||||||
;; (yas-minor-mode 1)
|
;; (yas-minor-mode 1)
|
||||||
|
26
yasnippet.el
26
yasnippet.el
@ -2923,7 +2923,8 @@ Use this in primary and mirror transformations to tget."
|
|||||||
start end
|
start end
|
||||||
(transform nil)
|
(transform nil)
|
||||||
parent-field
|
parent-field
|
||||||
next)
|
next
|
||||||
|
depth)
|
||||||
|
|
||||||
(defstruct (yas--exit (:constructor yas--make-exit (marker)))
|
(defstruct (yas--exit (:constructor yas--make-exit (marker)))
|
||||||
marker
|
marker
|
||||||
@ -4155,6 +4156,26 @@ When multiple expressions are found, only the last one counts."
|
|||||||
#'(lambda (r1 r2)
|
#'(lambda (r1 r2)
|
||||||
(>= (car r1) (car r2))))))
|
(>= (car r1) (car r2))))))
|
||||||
|
|
||||||
|
(defun yas--calculate-mirror-depth (mirror &optional traversed)
|
||||||
|
(let* ((parent (yas--mirror-parent-field mirror))
|
||||||
|
(parents-mirrors (and parent
|
||||||
|
(yas--field-mirrors parent))))
|
||||||
|
(or (yas--mirror-depth mirror)
|
||||||
|
(setf (yas--mirror-depth mirror)
|
||||||
|
(cond ((memq mirror traversed)
|
||||||
|
0)
|
||||||
|
((and parent parents-mirrors)
|
||||||
|
(1+ (reduce #'max
|
||||||
|
(mapcar #'(lambda (m)
|
||||||
|
(yas--calculate-mirror-depth m
|
||||||
|
(cons mirror
|
||||||
|
traversed)))
|
||||||
|
parents-mirrors))))
|
||||||
|
(parent
|
||||||
|
1)
|
||||||
|
(t
|
||||||
|
0))))))
|
||||||
|
|
||||||
(defun yas--update-mirrors (snippet)
|
(defun yas--update-mirrors (snippet)
|
||||||
"Updates all the mirrors of SNIPPET."
|
"Updates all the mirrors of SNIPPET."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
@ -4173,7 +4194,8 @@ When multiple expressions are found, only the last one counts."
|
|||||||
;; another mirror to need reupdating
|
;; another mirror to need reupdating
|
||||||
;;
|
;;
|
||||||
#'(lambda (field-and-mirror1 field-and-mirror2)
|
#'(lambda (field-and-mirror1 field-and-mirror2)
|
||||||
(yas--mirror-parent-field (cdr field-and-mirror1)))))
|
(> (yas--calculate-mirror-depth (cdr field-and-mirror1))
|
||||||
|
(yas--calculate-mirror-depth (cdr field-and-mirror2))))))
|
||||||
(let* ((field (car field-and-mirror))
|
(let* ((field (car field-and-mirror))
|
||||||
(mirror (cdr field-and-mirror))
|
(mirror (cdr field-and-mirror))
|
||||||
(parent-field (yas--mirror-parent-field mirror)))
|
(parent-field (yas--mirror-parent-field mirror)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user