[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making a region read-only
From: |
Omar Polo |
Subject: |
Re: Making a region read-only |
Date: |
Thu, 24 Dec 2020 14:32:10 +0100 |
User-agent: |
mu4e 1.4.13; emacs 27.1 |
michael-franzese@gmx.com writes:
> I aw writing a function to make a region read only. I am using
> "put-text-property", but I have seen the variable "inhibit-read-only".
> What shall I do with it, shall I use it?
>
> (defvar region-rwcycle-state 1)
> (defun region-read-write-cycle (start end)
> "Cycles read-only status of a region in a buffer."
> (interactive "*r")
>
> (pcase region-rwcycle-state
> (1 (message "Disable: Region Read Only")
> (put-text-property start end 'read-only nil)
this will fail because if the region is read only you can't change its
contents (this includes adding/removing/changing properties AFAIK).
inhibit-read-only is to ignore the read-only status.
In a function like this, I believe you want to wrap the pcase in a let
like this
(let ((inhibit-read-only t))
...)
HTH
> (setq region-rwcycle-state 2))
>
> (2 (message "Enable: Region Read Only")
> (put-text-property start end 'read-only t)
> (setq region-rwcycle-state 1)) ))