Mercurial > emacs
diff lisp/subr.el @ 104880:02bf3383a22f
(with-silent-modifications): New macro.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 08 Sep 2009 19:42:21 +0000 |
parents | 8224438aa3cd |
children | 566d2dc55a9d |
line wrap: on
line diff
--- a/lisp/subr.el Mon Sep 07 15:25:38 2009 +0000 +++ b/lisp/subr.el Tue Sep 08 19:42:21 2009 +0000 @@ -2749,6 +2749,29 @@ (and (buffer-name ,temp-buffer) (kill-buffer ,temp-buffer))))))) +(defmacro with-silent-modifications (&rest body) + "Execute BODY, pretending it does not modifies the buffer. +If BODY performs real modifications to the buffer's text, other +than cosmetic ones, undo data may become corrupted. +Typically used around modifications of text-properties which do not really +affect the buffer's content." + (declare (debug t) (indent 0)) + (let ((modified (make-symbol "modified"))) + `(let* ((,modified (buffer-modified-p)) + (buffer-undo-list t) + (inhibit-read-only t) + (inhibit-modification-hooks t) + deactivate-mark + ;; Avoid setting and removing file locks and checking + ;; buffer's uptodate-ness w.r.t the underlying file. + buffer-file-name + buffer-file-truename) + (unwind-protect + (progn + ,@body) + (unless ,modified + (restore-buffer-modified-p nil)))))) + (defmacro with-output-to-string (&rest body) "Execute BODY, return the text it sent to `standard-output', as a string." (declare (indent 0) (debug t))