]> git.eshelyaron.com Git - emacs.git/commitdiff
Update buffer's chars-modified tick when inserting from gap
authorEli Zaretskii <eliz@gnu.org>
Thu, 21 Jul 2022 09:40:28 +0000 (12:40 +0300)
committerEli Zaretskii <eliz@gnu.org>
Thu, 21 Jul 2022 09:40:28 +0000 (12:40 +0300)
* src/insdel.c (insert_from_gap): Update buffer's chars-modified
tick.  (Bug#56393)

* test/src/buffer-tests.el (test-buffer-chars-modified-ticks): New
test.

src/insdel.c
test/src/buffer-tests.el

index 6f180ac5800e3cb0ecef9ffd50d9e6cb946cc689..9b2923985371e7592fb7f52b91910d3e5ca87f7b 100644 (file)
@@ -1123,6 +1123,7 @@ insert_from_gap (ptrdiff_t nchars, ptrdiff_t nbytes, bool text_at_gap_tail)
   invalidate_buffer_caches (current_buffer, GPT, GPT);
   record_insert (GPT, nchars);
   modiff_incr (&MODIFF);
+  CHARS_MODIFF = MODIFF;
 
   insert_from_gap_1 (nchars, nbytes, text_at_gap_tail);
 
index cba10a050252faef5b7704d4d84b5ea33b3d3ee6..3c6a9208ffa51e998e0ff46111c6859d10b9d674 100644 (file)
@@ -1535,4 +1535,24 @@ with parameters from the *Messages* buffer modification."
       (restore-buffer-modified-p 'autosaved)
       (should (eq (buffer-modified-p) 'autosaved)))))
 
+(ert-deftest test-buffer-chars-modified-ticks ()
+  "Test `buffer-chars-modified-tick'."
+  (setq temporary-file-directory (file-truename temporary-file-directory))
+  (let ((text "foobar")
+        f1 f2)
+    (unwind-protect
+        (progn
+          (setq f1 (make-temp-file "buf-modiff-tests")
+                f2 (make-temp-file "buf-modiff-tests"))
+          (with-current-buffer (find-file f1)
+            (should (= (buffer-chars-modified-tick) 1))
+            (should (= (buffer-chars-modified-tick) (buffer-modified-tick)))
+            (write-region text nil f2 nil 'silent)
+            (insert-file-contents f2)
+            (should (= (buffer-chars-modified-tick) (buffer-modified-tick)))
+            (should (> (buffer-chars-modified-tick) 1))))
+      (if f1 (delete-file f1))
+      (if f2 (delete-file f2))
+      )))
+
 ;;; buffer-tests.el ends here