# HG changeset patch # User Stefan Monnier # Date 1252438941 0 # Node ID 02bf3383a22f1c1096830053207b9a74c6c479d7 # Parent eccd5fb371c2a77e28390e650d3575875829eeb7 (with-silent-modifications): New macro. diff -r eccd5fb371c2 -r 02bf3383a22f etc/NEWS --- a/etc/NEWS Mon Sep 07 15:25:38 2009 +0000 +++ b/etc/NEWS Tue Sep 08 19:42:21 2009 +0000 @@ -200,6 +200,8 @@ * Lisp changes in Emacs 23.2 +** New macro with-silent-modifications to tweak text properties without +affecting the buffer's modification state. ** All the default-FOO variables that hold the default value of the FOO variable, are now declared obsolete. diff -r eccd5fb371c2 -r 02bf3383a22f lisp/ChangeLog --- a/lisp/ChangeLog Mon Sep 07 15:25:38 2009 +0000 +++ b/lisp/ChangeLog Tue Sep 08 19:42:21 2009 +0000 @@ -1,3 +1,7 @@ +2009-09-08 Stefan Monnier + + * subr.el (with-silent-modifications): New macro. + 2009-09-07 Juanma Barranquero * files.el (top-level): Require `cl' when compiling. diff -r eccd5fb371c2 -r 02bf3383a22f lisp/subr.el --- 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))