emacs-devel
[Top][All Lists]
Advanced

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

buffer-modified-tick and text properties


From: JD Smith
Subject: buffer-modified-tick and text properties
Date: Sat, 20 Apr 2024 08:47:42 -0400

I've read plenty of older threads discussing why text property changes mark buffers as modified, recommending people use 

(with-silent-modifications (code-which-modifies-text-properties)) 

in most cases.  This prevents buffer-modified-p from flipping, but it surprised me that this does not prevent changes to the buffer-modified-tick:

>>>>>>>>>>>>>>>>>>>>>>>>
;; Testing buffer-tick with text props

(let ((msg '()))
  (set-buffer-modified-p nil)
  (push (format
"Before: BMT: %d BMP: %s"
(buffer-modified-tick)
(buffer-modified-p))
msg)
  (with-silent-modifications
    (put-text-property 1 2 'display "T"))
  (push (format
"After: BMT: %d BMP: %s"
(buffer-modified-tick)
(buffer-modified-p))
msg)
  (insert "\n;;" (string-join (nreverse msg) "\n;;")))
;;Before: BMT: 5380 BMP: nil
;;After: BMT: 5381 BMP: nil
<<<<<<<<<<<<<<<<<<<<<<<<<

I had hoped to compare a saved and current buffer-modified-tick in a post-command-hook, to tell me whether the command that lead to it had modified the buffer text, but this is not a reliable way to do so when text properties are being changed as a result of non-edit commands (like motion).

Plenty of modes compare the buffer tick against a saved value to infer whether the buffer text has been modified since the last update.  That logic will be defeated if other modes make text property changes.  Is there a way to inhibit changes in the buffer-tick when you are just changing simple text properties?

reply via email to

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