Read-Only Buffers
If a buffer is read-only, then you cannot change its contents, although you may change your view of the contents by scrolling and narrowing.
Read-only buffers are used in two kinds of situations:
- A buffer visiting a write-protected file is normally read-only.
Here, the purpose is to inform the user that editing the buffer with the aim of saving it in the file may be futile or undesirable. The user who wants to change the buffer text despite this can do so after clearing the read-only flag with C-x C-q.
- Modes such as Dired and Rmail make buffers read-only when altering the contents with the usual editing commands would probably be a mistake.
The special commands of these modes bind
buffer-read-onlytonil(withlet) or bindinhibit-read-onlytotaround the places where they themselves change the text.
- Variable: buffer-read-only
This buffer-local variable specifies whether the buffer is read-only. The buffer is read-only if this variable is non-
nil. However, characters that have theinhibit-read-onlytext property can still be modified. See inhibit-read-only.
- Variable: inhibit-read-only
-
If this variable is non-
nil, then read-only buffers and, depending on the actual value, some or all read-only characters may be modified. Read-only characters in a buffer are those that have a non-nilread-onlytext property. See Special Properties, for more information about text properties.If
inhibit-read-onlyist, allread-onlycharacter properties have no effect. Ifinhibit-read-onlyis a list, thenread-onlycharacter properties have no effect if they are members of the list (comparison is done witheq).
- Command: read-only-mode &optional arg
-
This is the mode command for Read Only minor mode, a buffer-local minor mode. When the mode is enabled,
buffer-read-onlyis non-nilin the buffer; when disabled,buffer-read-onlyisnilin the buffer. The calling convention is the same as for other minor mode commands (see Minor Mode Conventions).This minor mode mainly serves as a wrapper for
buffer-read-only; unlike most minor modes, there is no separateread-only-modevariable. Even when Read Only mode is disabled, characters with non-nilread-onlytext properties remain read-only. To temporarily ignore all read-only states, bindinhibit-read-only, as described above.When enabling Read Only mode, this mode command also enables View mode if the option
view-read-onlyis non-nil. See Miscellaneous Buffer Operations in The GNU Emacs Manual. When disabling Read Only mode, it disables View mode if View mode was enabled.
- Function: barf-if-buffer-read-only &optional position
-
This function signals a
buffer-read-onlyerror if the current buffer is read-only. If the text at position (which defaults to point) has theinhibit-read-onlytext property set, the error will not be raised.See Using Interactive, for another way to signal an error if the current buffer is read-only.
Copyright © 1990-1996, 1998-2021 Free Software Foundation, Inc.
Licensed under the GNU GPL license.
https://www.gnu.org/software/emacs/manual/html_node/elisp/Read-Only-Buffers.html