Only for the Emacs region

How to create a specific region in a text file that is read only when using emacs. I know ctrl + X + Q so that the entire file is read-only.

I am currently writing code, and I do not want to accidentally change the first 40 lines of my code when working on lines 41 and above.

+5
source share
3 answers

Use text properties:

(defun set-region-read-only (begin end)
  (interactive "r")
  (add-text-properties begin end '(read-only t)))

Relevant documents:

Text properties

Change Properties

Special properties (e.g. read-only)

+8
source

narrow-to-region (C-x n n), , . , .

+3

You can also apply highlight-change mode. This way you can see which text is changing because it has a different color. narrow to the region is a good solution. You can also use this with 2 buffers, so you can also see read-only text.

0
source

All Articles