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

* Re: buffer-modified-tick and text properties
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-04-20 14:09 UTC (permalink / raw)
  To: JD Smith; +Cc: emacs-devel

> From: JD Smith <jdtsmith@gmail.com>
> Date: Sat, 20 Apr 2024 08:47:42 -0400
> 
> 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).

If you want to know only about changes to characters, perhaps
buffer-chars-modified-tick is a better function to use?

Or how about if you explain why the fact that buffer-modified-tick
changes even under with-silent-modifications gets in your way, and
what would you like to do that need that tick to be sensitive to what
with-silent-modifications does?

> 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?

You cannot do that without breaking redisplay, because the display
engine uses the tick value to know when it might need to redisplay
portions of a window.  But I'm still uncertain why this presents a
problem, given that we have buffer-chars-modified-tick.  What am I
missing?



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

* Re: buffer-modified-tick and text properties
  2024-04-20 14:09 ` Eli Zaretskii
@ 2024-04-20 15:11   ` JD Smith
  2024-04-20 16:10     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: JD Smith @ 2024-04-20 15:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel



> On Apr 20, 2024, at 10:09 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: JD Smith <jdtsmith@gmail.com>
>> Date: Sat, 20 Apr 2024 08:47:42 -0400
>> 
>> 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).
> 
> If you want to know only about changes to characters, perhaps
> buffer-chars-modified-tick is a better function to use?

Missed this function; it should work perfectly, thanks. I wonder, aside from text properties, are there any other changes within the buffer that cause buffer-modified-tick but not buffer-chars-modified-tick to be incremented?




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

* Re: buffer-modified-tick and text properties
  2024-04-20 15:11   ` JD Smith
@ 2024-04-20 16:10     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-04-20 16:10 UTC (permalink / raw)
  To: JD Smith; +Cc: emacs-devel

> From: JD Smith <jdtsmith@gmail.com>
> Date: Sat, 20 Apr 2024 11:11:10 -0400
> Cc: emacs-devel <emacs-devel@gnu.org>
> 
> > If you want to know only about changes to characters, perhaps
> > buffer-chars-modified-tick is a better function to use?
> 
> Missed this function; it should work perfectly, thanks. I wonder, aside from text properties, are there any other changes within the buffer that cause buffer-modified-tick but not buffer-chars-modified-tick to be incremented?

There's restore-buffer-modified-p and
internal--set-buffer-modified-tick, but that's all, AFAICT.



^ 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.