emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e8488bcc9c: Avoid having font locking triggering unnecessary auto


From: Lars Ingebrigtsen
Subject: master e8488bcc9c: Avoid having font locking triggering unnecessary auto-saving
Date: Sat, 7 May 2022 06:06:05 -0400 (EDT)

branch: master
commit e8488bcc9cbbeafe6307a73b2386ced986327618
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Avoid having font locking triggering unnecessary auto-saving
    
    * lisp/subr.el (with-silent-modifications): Use it to restore the
    ticks (bug#11303).
    
    * src/buffer.c (Finternal__set_buffer_modified_tick): New function.
---
 etc/NEWS     |  9 +++++++++
 lisp/subr.el |  7 ++++++-
 src/buffer.c | 13 +++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index f7dddd36de..b595eae7e1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1507,6 +1507,15 @@ Emacs buffers, like indentation and the like.  The new 
ert function
 
 * Incompatible Lisp Changes in Emacs 29.1
 
+---
+** 'with-silent-modifications' also restores buffer modification ticks.
+'with-silent-modifications' is a macro meant to be used by the font
+locking machinery to allow applying text properties without changing
+the modification status of the buffer.  However, it didn't restore the
+buffer modification ticks, so applying font locking to a modified
+buffer that had already been auto-saved would trigger another
+auto-saving.  This is no longer the case.
+
 ---
 ** 'prin1' doesn't always escape "." and "?" in symbols any more.
 Previously, symbols like 'foo.bar' would be printed by 'prin1' as
diff --git a/lisp/subr.el b/lisp/subr.el
index 5af802fa18..01549cc6f7 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4594,14 +4594,19 @@ like `buffer-modified-p', checking whether the file is 
locked by
 someone else, running buffer modification hooks, and other things
 of that nature."
   (declare (debug t) (indent 0))
-  (let ((modified (make-symbol "modified")))
+  (let ((modified (make-symbol "modified"))
+        (tick (make-symbol "tick")))
     `(let* ((,modified (buffer-modified-p))
+            (,tick (buffer-modified-tick))
             (buffer-undo-list t)
             (inhibit-read-only t)
             (inhibit-modification-hooks t))
        (unwind-protect
            (progn
              ,@body)
+         ;; We restore the buffer tick count, too, because otherwise
+         ;; we'll trigger a new auto-save.
+         (internal--set-buffer-modified-tick ,tick)
          (unless ,modified
            (restore-buffer-modified-p nil))))))
 
diff --git a/src/buffer.c b/src/buffer.c
index f8a7a4f510..6334e197f0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1499,6 +1499,18 @@ use current buffer as BUFFER.  */)
   return modiff_to_integer (BUF_MODIFF (decode_buffer (buffer)));
 }
 
+DEFUN ("internal--set-buffer-modified-tick",
+       Finternal__set_buffer_modified_tick, 
Sinternal__set_buffer_modified_tick,
+       1, 2, 0,
+       doc: /* Set BUFFER's tick counter to TICK.
+No argument or nil as argument means use current buffer as BUFFER.  */)
+  (Lisp_Object tick, Lisp_Object buffer)
+{
+  CHECK_FIXNUM (tick);
+  BUF_MODIFF (decode_buffer (buffer)) = XFIXNUM (tick);
+  return Qnil;
+}
+
 DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick,
        Sbuffer_chars_modified_tick, 0, 1, 0,
        doc: /* Return BUFFER's character-change tick counter.
@@ -6418,6 +6430,7 @@ will run for `clone-indirect-buffer' calls as well.  */);
   defsubr (&Sforce_mode_line_update);
   defsubr (&Sset_buffer_modified_p);
   defsubr (&Sbuffer_modified_tick);
+  defsubr (&Sinternal__set_buffer_modified_tick);
   defsubr (&Sbuffer_chars_modified_tick);
   defsubr (&Srename_buffer);
   defsubr (&Sother_buffer);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]