I don't find this warning particularly helpful and pretty distracting because it hides the current text in the echo area for a brief moment. Is also seems unnecessary, because I will notice anyway that I cannot write in read-only areas. Is there a way to disable it?
2 Answers
Yes, you can disable these messages by setting command-error-function
to a function that ignores buffer-read-only
signals.
(defun my-command-error-function (data context caller)
"Ignore the buffer-read-only signal; pass the rest to the default handler."
(when (not (eq (car data) 'buffer-read-only))
(command-error-default-function data context caller)))
(setq command-error-function #'my-command-error-function)
(Tested using GNU Emacs 24.5.1.)

- 25,203
- 3
- 74
- 179

- 9,072
- 1
- 34
- 49
-
Out of curiosity, won't overriding the `command-error-function` value affect all errors, and not just the "buffer read-only" errors? I cannot exactly figure out what all this change will impact from the source code. – Kaushal Modi Jan 21 '16 at 19:28
-
1Yes, it would. That's exactly why I have the `(when ...)` form in the code snippet: this way signals we don't care about are passed to the default handler and `buffer-read-only` is ignored. – Constantine Jan 21 '16 at 19:33
-
Ah OK, I totally missed that call to `command-error-default-function`. – Kaushal Modi Jan 21 '16 at 19:34
-
Thanks! Could one also separate minibuffer and echo area this way, or would it require a change to the C code? http://stackoverflow.com/questions/10063410/is-it-possible-to-separate-minibuffer-and-echo-area-in-emacs – Lenar Hoyt Jan 21 '16 at 22:17
-
1Sweet, I've been looking for an easy way to get rid of that "Text is read-only" garbage only in the minibuffer and this does the trick. – whacka Jan 21 '16 at 22:35
-
1@mcb: As far as I know it is not possible to separate the echo area and mini-buffer. I believe that [the answer by `phils` that you linked to](http://stackoverflow.com/a/10067948) is correct, i.e. we would need new C code for this. – Constantine Jan 21 '16 at 23:42
Source of the 'buffer read-only' error
I believe that the source of that error: Buffer is read-only: <#BUFFER-NAME>
is in the C source code.
So the solution to this would be to tweak the source code and build emacs locally by commenting out this specific line.
For reference, here is that code snippet that throws that error:
if (!NILP (BVAR (current_buffer, read_only))
&& NILP (Vinhibit_read_only)
&& NILP (Fget_text_property (pos, Qinhibit_read_only, Qnil)))
xsignal1 (Qbuffer_read_only, Fcurrent_buffer ());
return Qnil;
.. and commenting out that xsignal
line should do the trick.
Suggested Approach
There is a much easier way to avert this annoyance for the duration you are working in a read-only buffer .. you can temporarily NOT make it read-only.
- Doing
M-x read-only-mode
(bound by default toC-x C-q
) toggles any buffer between read-only mode and editable mode.
So if you are getting a lot of these errors, simply make the buffer temporarily editable by hitting C-x C-q
.
A note of warning: Doing the C source hack could be a major source of confusion in future. So I wouldn't do it.

- 25,203
- 3
- 74
- 179
-
1As far as I can tell `(defun barf-if-buffer-read-only () nil)` has the same effect as commenting out the `xsignal1` call and re-building Emacs. :-) – Constantine Jan 21 '16 at 19:03
-
@Constantine TIL that we can override C functions in elisp. Thanks! – Kaushal Modi Jan 21 '16 at 19:11
-
Regarding modifying things using elisp: this reminds me of this old question about `nil`: http://emacs.stackexchange.com/questions/2935/how-can-i-bring-back-nil – Constantine Jan 21 '16 at 19:45