Reputation: 87376
Closely related to Emacs specific region read only how do you remove the read only property on a region of text in a buffer.
For example, if you are using a python shell in emacs and accidentally print out a huge list and would like to remove the output from your buffer.
Upvotes: 0
Views: 802
Reputation: 73274
I use the following. It's similar to tcaswell's answer, but deals with the buffer modification issue.
(defun set-region-read-only (begin end)
"Sets the read-only text property on the marked region.
Use `set-region-writeable' to remove this property."
;; See https://stackoverflow.com/questions/7410125
(interactive "r")
(with-silent-modifications
(put-text-property begin end 'read-only t)))
(defun set-region-writeable (begin end)
"Removes the read-only text property from the marked region.
Use `set-region-read-only' to set this property."
;; See https://stackoverflow.com/questions/7410125
(interactive "r")
(with-silent-modifications
(remove-text-properties begin end '(read-only t))))
Upvotes: 3
Reputation: 87376
Following the cryptic comment under read-only in the documentation, to remove read-only from a region you just need:
(defun remove-region-read-only (begin end)
(interactive "r")
(let ((inhibit-read-only t))
(remove-text-properties begin end '(read-only t)))
)
Upvotes: 2