7

The readonly status of the current buffer can be toggled with (read-only-mode) or pressing C-x C-q but I intend to make a buffer which is not current, writable. The below is what I am using

(with-current-buffer (get-buffer-create "*some*")
    (read-only-mode nil))

hoping that it would remove the readonly status applied on the buffer '*some*', however it only sets the readonly status again to the buffer. Visiting the buffer and pressing C-x C-q does work but that is not what I intend to do, I need to do it remotely.

Drew
  • 75,699
  • 9
  • 109
  • 225
myTerminal
  • 417
  • 1
  • 5
  • 15

1 Answers1

7

Use (read-only-mode -1), not (read-only-mode nil).

See the doc string of macro define-minor-mode (C-h f define-minor-mode) for more info about the argument to a minor-mode function.

And see the doc string of read-only-mode for some good info about its use:

read-only-mode is an interactive compiled Lisp function in simple.el.

It is bound to C-x C-q.

(read-only-mode &optional ARG)

Change whether the current buffer is read-only.

With prefix argument ARG, make the buffer read-only if ARG is positive, otherwise make it writable. 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 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.

Drew
  • 75,699
  • 9
  • 109
  • 225