Text is read only?
Asked Answered
S

7

28

I was working in Emacs and then suddenly, the slime-repl sbcl says text is read only. Well that's great because now I can't type anything into it. How do I fix this?

Slake answered 4/7, 2014 at 0:17 Comment(6)
C-x C-q is how to enable or disable read-only mode. I'm not yet comfortable posting it as an answer, however, because you may be more interested in knowing what may have caused that behavior and I'm unfamiliar with the library you mentioned.Garibaldi
@Garibaldi I'd say go ahead and suggest it as an answer, as to how to disable read-only in the buffer. The OP can always search more to find out why the buffer was suddenly made read-only. That's a separate question (at least until more info to answer it is provided here).Nonpayment
If it says that "text" is read-only (rather than "buffer"), then there's probably a read-only text property in effect?Panga
@Nonpayment "Buffer is read only" is much, much different from "text is read-only." The C-x C-q command toggles "buffer is read only" while nothing seems to change "text is read only," which I got into because my finger hit the wrong key (I don't know which key I hit). Now I have to restart SLIME and lose my work. :(Magee
Yes, if it said "text is read-only" (which means error text-read-only) then the text at point has a read-only text property on it. The Elisp manual, node Special Properties, says this: " Since changing properties counts as modifying the buffer, it is not possible to remove a read-only property unless you know the special trick: bind inhibit-read-only to a non-nil value and then remove the property. *Note Read Only Buffers."Nonpayment
To others reading this question and confused: This question appears to be about an error text "text is read-only" received upon attempted edit of a piece of text in Emacs buffer - as Drew also assumed above, and provided a working fix in the accepted answer below.Southing
T
35

"Buffer is read-only" can be cured by C-x C-q but as Drew & phils said,
"Text is read-only" is very different -- it means some part of the buffer has a read-only property.
Try moving away from the read-only part, e.g., to the end of the buffer.

Emacs Lisp Manual > elisp.info > Text > Text Properties > Special Properties

 Since changing properties counts as modifying the buffer, it is not
 possible to remove a `read-only' property unless you know the
 special trick: bind `inhibit-read-only' to a non-`nil' value and
 then remove the property.  *Note Read Only Buffers::.

thus to erase the entire buffer regardless:

M-: (let ((inhibit-read-only t)) (erase-buffer)) RET

or to remove all properties:

(let ((inhibit-read-only t)) (set-text-properties (point-min) (point-max) ()))
Torhert answered 18/6, 2015 at 4:16 Comment(3)
This is the only answer that understand that it's not a read-only buffer, so C-x C-q doesn't solve the issue at all.Trickish
This is the real answerGargoyle
For new emacs users, devon above is running command: eval-expression . Its default key definition is M-: (usually escape-colon). After running eval-expression, it prompts you to type in (or paste) your lisp expression into the mini-buffer and hit <return>Doolittle
P
5

I can't offer any insight into why you ended up with undesirable read-only text properties, but I occasionally encounter similar situations and so find the following command useful.

Select the region in question (or C-xh for the entire buffer), and run M-x set-region-writeable to remove the read-only text properties.

(defun set-region-writeable (begin end)
  "Removes the read-only text property from the marked region."
  ;; See http://stackoverflow.com/questions/7410125
  (interactive "r")
  (let ((modified (buffer-modified-p))
        (inhibit-read-only t))
    (remove-text-properties begin end '(read-only t))
    (set-buffer-modified-p modified)))
Panga answered 16/3, 2017 at 8:41 Comment(2)
I prefer this answer to the most popular one on this thread. This was really easy to open my scratch buffer, paste in this code, evaluate it, then switch back to the buffer that had the problem. Then mark the region, and then M-x set-region-writable.Schrecklichkeit
See https://mcmap.net/q/504011/-emacs-remove-region-read-only for a slightly improved version of this function.Panga
C
3

Possible cause of such a message may be this: you are trying to print something over the REPL prompt, for example CL-US|ER> (+ 1 2). This text in the SLIME buffer is read-only. Note the space after >, it is the part of the prompt.

Cleave answered 4/7, 2014 at 11:46 Comment(0)
C
2

Try typing C-c M-o RET (it will clear the console and add a new line), I had a problem similar to yours and for it fixed it.

Coachman answered 14/10, 2017 at 22:25 Comment(0)
T
1

Q: How did I accidentally get a read-write buffer with a few lines that were read-only? A: Via (insert-buffer "*Occur*")

Q: How did I conquer the problem using a low-tech, but easy to remember solution? A: C-x C-v, which runs the command find-alternate-file. That's right, I simply wrote the file, then reopened it again, fresh from disk. All such weird properties get cleansed in the process.

Tena answered 6/7, 2024 at 6:54 Comment(0)
H
0

I solved this by first opening two frames, one with a .lisp file opened and the other with the slime-repl.

From the frame with the .lisp file, I applied C-c C-j on a line of code (e.g (+ 1 2)).

This copied the line of code down to the slime-repl and evaluated it.

This also somehow solved the problem with the "text is read only" problem.

Heckman answered 16/3, 2017 at 7:2 Comment(0)
R
-1

You can change read-only mode by doing: M-x -> toggle-read-only -> RET (in other words press enter)

Risner answered 4/7, 2014 at 11:7 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.