diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2009-09-08 19:42:21 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2009-09-08 19:42:21 +0000 |
commit | 83a5aac556c598c1e925daad9583e79c4505824b (patch) | |
tree | 8842f84fb61780abbd19d42cb308096e3edf6ed2 /lisp/subr.el | |
parent | 3b814ebcdb769f0c22a7987ac0682efa3688b3ec (diff) | |
download | emacs-83a5aac556c598c1e925daad9583e79c4505824b.tar.gz |
(with-silent-modifications): New macro.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r-- | lisp/subr.el | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index 43bce3055b6..23bb63dc85d 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2749,6 +2749,29 @@ See also `with-temp-file' and `with-output-to-string'." (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)) |