summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-05-03 22:04:39 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-05-03 22:04:39 +0200
commitb7ddd0f2fd08c9dca0b75493e9e809bb5dab40d9 (patch)
tree3d4da9e1a6c7de63e2b1de431fe12163b1e73fd7 /lisp/emacs-lisp
parentb5db5a64435b86de6e5277d1d173c57784783e5e (diff)
downloademacs-b7ddd0f2fd08c9dca0b75493e9e809bb5dab40d9.tar.gz
emacs-b7ddd0f2fd08c9dca0b75493e9e809bb5dab40d9.tar.bz2
emacs-b7ddd0f2fd08c9dca0b75493e9e809bb5dab40d9.zip
Make with-buffer-unmodified-if-unchanged more resilient
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged): Make more resilient.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/subr-x.el18
1 files changed, 10 insertions, 8 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 8e763b613ee..a416059df62 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -426,22 +426,24 @@ modification status:
(with-buffer-unmodified-if-unchanged
(insert \"a\")
- (delete-char -1))
-
-BODY must preserve the current buffer."
+ (delete-char -1))."
(declare (debug t) (indent 0))
- (let ((hash (gensym)))
+ (let ((hash (gensym))
+ (buffer (gensym)))
`(let ((,hash (and (not (buffer-modified-p))
- (buffer-hash))))
+ (buffer-hash)))
+ (,buffer (current-buffer)))
(prog1
(progn
,@body)
;; If we didn't change anything in the buffer (and the buffer
;; was previously unmodified), then flip the modification status
;; back to "unchanged".
- (when (and ,hash (buffer-modified-p)
- (equal ,hash (buffer-hash)))
- (restore-buffer-modified-p nil))))))
+ (when (buffer-live-p ,buffer)
+ (with-current-buffer ,buffer
+ (when (and ,hash (buffer-modified-p)
+ (equal ,hash (buffer-hash)))
+ (restore-buffer-modified-p nil))))))))
(provide 'subr-x)