all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* buffer-modified-tick and text properties
@ 2024-04-20 12:47 JD Smith
  2024-04-20 14:09 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: JD Smith @ 2024-04-20 12:47 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1491 bytes --]

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?

[-- Attachment #2: Type: text/html, Size: 2853 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-20 16:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-20 12:47 buffer-modified-tick and text properties JD Smith
2024-04-20 14:09 ` Eli Zaretskii
2024-04-20 15:11   ` JD Smith
2024-04-20 16:10     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.