]> git.eshelyaron.com Git - emacs.git/commitdiff
with-buffer-unmodified-if-unchanged: Tweak the implementation
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 May 2022 19:35:47 +0000 (15:35 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 3 May 2022 19:35:47 +0000 (15:35 -0400)
* lisp/emacs-lisp/subr-x.el (with-buffer-unmodified-if-unchanged):
Skip the hash if the buffer was not modified at all.
Use `restore-buffer-modified-p`.
Also mention that it's imperative that the current buffer is preserved.

lisp/emacs-lisp/subr-x.el

index afa0423d90eafc1490ceca9fcba5109ff5a78ecd..8e763b613eedc521db6c1378ebcf9996e00f783f 100644 (file)
@@ -426,7 +426,9 @@ modification status:
 
   (with-buffer-unmodified-if-unchanged
     (insert \"a\")
-    (delete-char -1))"
+    (delete-char -1))
+
+BODY must preserve the current buffer."
   (declare (debug t) (indent 0))
   (let ((hash (gensym)))
     `(let ((,hash (and (not (buffer-modified-p))
@@ -437,9 +439,9 @@ modification status:
          ;; 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
+         (when (and ,hash (buffer-modified-p)
                     (equal ,hash (buffer-hash)))
-           (set-buffer-modified-p nil))))))
+           (restore-buffer-modified-p nil))))))
 
 (provide 'subr-x)