How does one make a specific region in a text file read only when using emacs. I know ctrl+X+Q to make the whole file a read only.
I am currently writing a code and I do not want to modify by accident the first 40 lines of my code while working on lines 41 and upwards.
Use text properties:
(defun set-region-read-only (begin end)
(interactive "r")
(add-text-properties begin end '(read-only t)))
Relevant Docs:
Text-Properties
Changing Properties
Special Properties (like read-only)
You can use narrow-to-region
(C-x n n
) to narrow the buffer just to the part you want to change. Then you won't see or be able to change the region you don't want to change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With