[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 682fdae: * lisp/subr.el (cancel-change-group): Rese
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] master 682fdae: * lisp/subr.el (cancel-change-group): Reset cell in case of error |
Date: |
Tue, 26 Jul 2016 17:12:31 +0000 (UTC) |
branch: master
commit 682fdae7efe5a36636539b953a657445f2f3382b
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>
* lisp/subr.el (cancel-change-group): Reset cell in case of error
Since the setcdr/setcdr is supposed to be temporary, use unwind-protect
to make sure we properly undo the temporary change even in case of error.
---
lisp/subr.el | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 937a050..2c0be20 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2535,26 +2535,27 @@ This finishes the change group by reverting all of its
changes."
;; Widen buffer temporarily so if the buffer was narrowed within
;; the body of `atomic-change-group' all changes can be undone.
(widen)
- (let ((old-car
- (if (consp elt) (car elt)))
- (old-cdr
- (if (consp elt) (cdr elt))))
- ;; Temporarily truncate the undo log at ELT.
- (when (consp elt)
- (setcar elt nil) (setcdr elt nil))
- (unless (eq last-command 'undo) (undo-start))
- ;; Make sure there's no confusion.
- (when (and (consp elt) (not (eq elt (last pending-undo-list))))
- (error "Undoing to some unrelated state"))
- ;; Undo it all.
- (save-excursion
- (while (listp pending-undo-list) (undo-more 1)))
- ;; Reset the modified cons cell ELT to its original content.
- (when (consp elt)
- (setcar elt old-car)
- (setcdr elt old-cdr))
- ;; Revert the undo info to what it was when we grabbed the state.
- (setq buffer-undo-list elt))))))
+ (let ((old-car (car-safe elt))
+ (old-cdr (cdr-safe elt)))
+ (unwind-protect
+ (progn
+ ;; Temporarily truncate the undo log at ELT.
+ (when (consp elt)
+ (setcar elt nil) (setcdr elt nil))
+ (unless (eq last-command 'undo) (undo-start))
+ ;; Make sure there's no confusion.
+ (when (and (consp elt) (not (eq elt (last pending-undo-list))))
+ (error "Undoing to some unrelated state"))
+ ;; Undo it all.
+ (save-excursion
+ (while (listp pending-undo-list) (undo-more 1)))
+ ;; Revert the undo info to what it was when we grabbed
+ ;; the state.
+ (setq buffer-undo-list elt))
+ ;; Reset the modified cons cell ELT to its original content.
+ (when (consp elt)
+ (setcar elt old-car)
+ (setcdr elt old-cdr))))))))
;;;; Display-related functions.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 682fdae: * lisp/subr.el (cancel-change-group): Reset cell in case of error,
Stefan Monnier <=