I am annotating parts of text in an emacs buffer using text properties. The code I am using looks something like this:
(set-text-properties beg end nil) ; clear properties
(add-face-text-property beg end city-name-face)
(put-text-property beg end 'field "city-name")
where beg
and end
are the markers in-between of which the property is set, and city-name-face
is defined elsewhere in code.
Everything works fine, except when I occasionally press a wrong key and modify the text in the file. However, I want the text (as sequence of characters) to be immutable and modify only its properties.
Is it possible?
read-only-mode
. However, that prevents you from setting properties. Fortunately, this can be fixed by using something like(let ((buffer-read-only nil)) YOUR-CODE-GOES-HERE)
.