6

I have a buffer in read-only mode.

Killing the buffer and reopening it does not do the job while restarting emacs does.

How to exit the read-only mode without restarting emacs?

Viesturs
  • 805
  • 8
  • 19

3 Answers3

13

Calling read-only-mode toggles between read-only and edit mode for the current buffer.

You can call this via M-x read-only-mode or with C-x C-q.

Juancho
  • 5,395
  • 15
  • 20
8

To add a bit to @Juancho's answer, which is correct:

The default value of read-only-mode depends on the buffer. In particular, if it is visiting a file, and if the file itself is read-only, then the default value of read-only-mode will be on.

You can toggle such a buffer, as @Juancho said, to turn off read-only-mode. But if you try to save the buffer after changing it you'll be prompted to confirm, like this:

File foo.el is write-protected; try to save anyway? (yes or no)

And if you answer yes you may be presented with an error such as this:

Opening output file: Permission denied, /path/to/foo.el
NickD
  • 27,023
  • 3
  • 23
  • 42
Drew
  • 75,699
  • 9
  • 109
  • 225
  • I don't observe this problem with `GNU Emacs 24.3.1` – Viesturs Nov 15 '19 at 22:49
  • 2
    Dunno what you mean by "this problem". But note that I said *you **may** be presented with an error such as this."* Whether you do or not depends... – Drew Nov 15 '19 at 22:54
4

I like very much to click on the buffer-read-only indicator % in the mode line for that purpose. It is marked with a red ellipse in the following Figure.

enter image description here

It just feels natural to toggle the read only state where it is indicated.

Note that you can also toggle the buffer-modified-p flag on the right side of the buffer-read-only flag. This is sometimes handy when you just want to kill a modified buffer avoiding backup copies.

Tobias
  • 32,569
  • 1
  • 34
  • 75