Function: read-only-mode

read-only-mode is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(read-only-mode &optional ARG)

Documentation

Change whether the current buffer is read-only.

This is a minor mode. If called interactively, toggle the Read-Only mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate buffer-read-only.

The mode's hook is called both when the mode is enabled and when it is disabled.

If buffer is read-only and view-read-only is non-nil, enter view mode.

Do not call this from a Lisp program unless you really intend to do the same thing as the C-x C-q (read-only-mode) command, including possibly enabling or disabling View mode. Also, note that this command works by setting the variable buffer-read-only, which does not affect read-only regions caused by text properties. To ignore read-only status in a Lisp program (whether due to text properties or buffer state), bind inhibit-read-only temporarily to a non-nil value.

Probably introduced at or before Emacs version 24.3.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(define-minor-mode read-only-mode
  "Change whether the current buffer is read-only.

If buffer is read-only and `view-read-only' is non-nil, enter
view mode.

Do not call this from a Lisp program unless you really intend to
do the same thing as the \\[read-only-mode] command, including
possibly enabling or disabling View mode.  Also, note that this
command works by setting the variable `buffer-read-only', which
does not affect read-only regions caused by text properties.  To
ignore read-only status in a Lisp program (whether due to text
properties or buffer state), bind `inhibit-read-only' temporarily
to a non-nil value."
  :variable buffer-read-only
  (cond
   ((and (not buffer-read-only) view-mode)
    (View-exit-and-edit)
    (setq-local view-read-only t))		; Must leave view mode.
   ((and buffer-read-only view-read-only
         ;; If view-mode is already active, `view-mode-enter' is a nop.
         (not view-mode)
         (not (eq (get major-mode 'mode-class) 'special)))
    (view-mode-enter))))