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). Commented Mar 17, 2022 at 13:53
  • @Lindydancer: Please consider posting that as an answer. Commented 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). 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.