]> git.eshelyaron.com Git - emacs.git/commitdiff
(with-silent-modifications): New macro.
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 8 Sep 2009 19:42:21 +0000 (19:42 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 8 Sep 2009 19:42:21 +0000 (19:42 +0000)
etc/NEWS
lisp/ChangeLog
lisp/subr.el

index ffab85e0650e25876f3b432b0a089d6bdae32a85..fa7f01d1bc48ac5cd213f79580151c1666632561 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -200,6 +200,8 @@ functions and variables.
 \f
 * 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.
 
index 9742ad3bfb694c48d3b330194ecba5779fbc79af..53e0cd9825bd813e90e860cd39cbeca4242ceca1 100644 (file)
@@ -1,3 +1,7 @@
+2009-09-08  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * subr.el (with-silent-modifications): New macro.
+
 2009-09-07  Juanma Barranquero  <lekktu@gmail.com>
 
        * files.el (top-level): Require `cl' when compiling.
index 43bce3055b6ecbbf566054057a59548a343c90d3..23bb63dc85d14fd520f891ca1b10b1c261562484 100644 (file)
@@ -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))