简体   繁体   中英

emacs remove region read-only

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.

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))))

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)))
  )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM