8

I want to add properties to text (make it read-only temporarily) and I don't want “modification-status” change. In general, how do I perform some modifying action without Emacs noticing it?

Mark Karpov
  • 4,893
  • 1
  • 24
  • 53

1 Answers1

10

There is a built-in macro for this, with-silent-modifications.

Its intended usecase is for making changes to text properties of a buffer as text properties are part of the text and changes to them would otherwise be reflected in the buffer modification status and trigger the respective hooks. Despite there being rudimentary protection against more invasive changes of the text, you should ensure the body doesn't do anything weird:

If BODY performs real modifications to the buffer's text, other than cosmetic ones, undo data may become corrupted.

wasamasa
  • 21,803
  • 1
  • 65
  • 97