1

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?

2
  • You can use 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). Mar 17, 2022 at 13:53
  • @Lindydancer: Please consider posting that as an answer.
    – Drew
    Mar 17, 2022 at 14:46

1 Answer 1

2

You can use read-only-mode, this prevents you from editing the buffer.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.