* 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.
(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))
;; 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)