* Fixed a bug where using `yas/also-auto-indent-first-line' would

likely mess up undo.
This commit is contained in:
capitaomorte 2009-11-13 10:31:39 +00:00
parent 859ae946da
commit 3dae4c6db3

View File

@ -3030,9 +3030,18 @@ will be deleted before inserting template."
;; the new snippet (without the "key") followed by an apply of ;; the new snippet (without the "key") followed by an apply of
;; `yas/take-care-of-redo' on the newly inserted snippet boundaries ;; `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)))) (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) (push `(apply yas/take-care-of-redo ,start ,end ,snippet)
buffer-undo-list)) buffer-undo-list))
;; Now, move to the first field ;; Now, move to the first field