Don't leave unreadable objects in the undo list

* yasnippet.el (yas--commit-snippet): Remove overlay object after
deleting it.
(yas--markers-to-points): Drop marker object.
(yas--points-to-markers): Create a new marker object.
This commit is contained in:
Noam Postavsky 2017-04-13 08:15:40 -04:00
parent c3a94478b4
commit 462f5667fc

View File

@ -3293,7 +3293,8 @@ This renders the snippet as ordinary text."
(overlay-buffer control-overlay)) (overlay-buffer control-overlay))
(setq yas-snippet-beg (overlay-start control-overlay)) (setq yas-snippet-beg (overlay-start control-overlay))
(setq yas-snippet-end (overlay-end control-overlay)) (setq yas-snippet-end (overlay-end control-overlay))
(delete-overlay control-overlay)) (delete-overlay control-overlay)
(setf (yas--snippet-control-overlay snippet) nil))
(let ((yas--inhibit-overlay-hooks t)) (let ((yas--inhibit-overlay-hooks t))
(when yas--active-field-overlay (when yas--active-field-overlay
@ -3448,8 +3449,9 @@ If so cleans up the whole snippet up."
;; ;;
;; This was found useful for performance reasons, so that an excessive ;; This was found useful for performance reasons, so that an excessive
;; number of live markers aren't kept around in the ;; number of live markers aren't kept around in the
;; `buffer-undo-list'. We reuse the original marker object, although ;; `buffer-undo-list'. We don't reuse the original marker object
;; that's probably not necessary. ;; because that leaves an unreadable object in the history list and
;; undo-tree persistence has trouble with that.
;; ;;
;; This shouldn't bring horrible problems with undo/redo, but you ;; This shouldn't bring horrible problems with undo/redo, but you
;; never know. ;; never know.
@ -3457,16 +3459,13 @@ If so cleans up the whole snippet up."
(defun yas--markers-to-points (snippet) (defun yas--markers-to-points (snippet)
"Save all markers of SNIPPET as positions." "Save all markers of SNIPPET as positions."
(yas--snippet-map-markers (lambda (m) (yas--snippet-map-markers (lambda (m)
(prog1 (cons (marker-position m) m) (prog1 (marker-position m)
(set-marker m nil))) (set-marker m nil)))
snippet)) snippet))
(defun yas--points-to-markers (snippet) (defun yas--points-to-markers (snippet)
"Restore SNIPPET's marker positions, saved by `yas--markers-to-points'." "Restore SNIPPET's marker positions, saved by `yas--markers-to-points'."
(yas--snippet-map-markers (lambda (p-m) (yas--snippet-map-markers #'copy-marker snippet))
(set-marker (cdr p-m) (car p-m))
(cdr p-m))
snippet))
(defun yas--maybe-move-to-active-field (snippet) (defun yas--maybe-move-to-active-field (snippet)
"Try to move to SNIPPET's active (or first) field and return it if found." "Try to move to SNIPPET's active (or first) field and return it if found."