开发者

Emacs specific region read only

开发者 https://www.devze.com 2023-04-04 21:36 出处:网络
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.

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 开发者_如何学Pythoncode 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号