I'm extending an existing Emacs package and I want to make a part of the buffer not editable (read only). In fact, I want to make only one line in the middle of the buffer editable and I use the following snippet for achieving that:

(put-text-property (point-min) point-before-editable-text 'read-only t)
;; (put-text-property point-after-editable-text (point-max) 'read-only t)

However, I can still put cursor at the beginning of buffer and insert some text which is not the desired behavior.

How can I prevent insertions at the beginning of the buffer?


1 Answer 1


You need to (before adding property read-only), make the first character have a value that includes read-only for property front-sticky:

(put-text-property 1 2 'front-sticky '(read-only)) ; Do this one first.
(put-text-property (point-min) 50 'read-only t)

See the Elisp manual, node Sticky Properties. The problem was that although the first char had a non-nil property read-only, insertion before it did not inherit that property, because read-only was not a front-sticky property value for the first character.

  • I updated the Sticky Properties link as the earlier version with # tag wasn't working on phone. Oct 14, 2014 at 3:37

Your Answer

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

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