From 3dae4c6db325c188744486b3602c054a0a7049d2 Mon Sep 17 00:00:00 2001 From: capitaomorte Date: Fri, 13 Nov 2009 10:31:39 +0000 Subject: [PATCH] * Fixed a bug where using `yas/also-auto-indent-first-line' would likely mess up undo. --- yasnippet.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/yasnippet.el b/yasnippet.el index 71ffd83..853bf76 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3030,9 +3030,18 @@ will be deleted before inserting template." ;; the new snippet (without the "key") followed by an apply of ;; `yas/take-care-of-redo' on the newly inserted snippet boundaries ;; - (let ((start (overlay-start (yas/snippet-control-overlay snippet))) + ;; A small exception, if `yas/also-auto-indent-first-line' + ;; is t and `yas/indent' decides to indent the line to a + ;; point before the actual expansion point, undo would be + ;; messed up. We call the early point "newstart"". case, + ;; and attempt to fix undo. + ;; + (let ((newstart (overlay-start (yas/snippet-control-overlay snippet))) (end (overlay-end (yas/snippet-control-overlay snippet)))) - (push (cons start end) buffer-undo-list) + (when (< newstart start) + + (push (cons (make-string (- start newstart) ? ) newstart) buffer-undo-list)) + (push (cons newstart end) buffer-undo-list) (push `(apply yas/take-care-of-redo ,start ,end ,snippet) buffer-undo-list)) ;; Now, move to the first field