Reputation: 14660
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.
Upvotes: 5
Views: 1712
Reputation: 3236
You can also apply highlight-changes-mode. That way you can see which text is changed as it is in different color. narrow-to-region is a good solution. You can also use that with 2 buffer, so you can see the read-only text too, if needed.
Upvotes: 0
Reputation: 4026
Use text properties:
(defun set-region-read-only (begin end)
(interactive "r")
(add-text-properties begin end '(read-only t)))
Relevant Docs:
Special Properties (like read-only)
Upvotes: 10
Reputation: 5742
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.
Upvotes: 3