From b2621720c318257be0d4100d695b62986db88b4f Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Wed, 9 Nov 2011 21:17:45 -0500 Subject: [PATCH] toggle-read-only fixes for bugs#7292, 10006. * doc/lispref/buffers.texi (Read Only Buffers): Expand a bit on why toggle-read-only should only be used interactively. * lisp/files.el (toggle-read-only): Mention that it should only be used interactively. * lisp/emacs-lisp/bytecomp.el (byte-compile-interactive-only-functions): Add toggle-read-only. --- doc/lispref/ChangeLog | 5 +++++ doc/lispref/buffers.texi | 9 +++++---- lisp/ChangeLog | 7 +++++++ lisp/emacs-lisp/bytecomp.el | 2 +- lisp/files.el | 10 +++++++++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 238ce9838b0..2abed9f870c 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,8 @@ +2011-11-10 Glenn Morris + + * buffers.texi (Read Only Buffers): Expand a bit on why + toggle-read-only should only be used interactively. (Bug#7292) + 2011-11-09 Chong Yidong * windows.texi (Window Sizes): Document window-pixel-edges, diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index 816d0f9faa8..ee2ce2e2001 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi @@ -748,10 +748,11 @@ of the list (comparison is done with @code{eq}). @deffn Command toggle-read-only &optional arg This command toggles whether the current buffer is read-only. It is -intended for interactive use; do not use it in programs. At any given -point in a program, you should know whether you want the read-only flag -on or off; so you can set @code{buffer-read-only} explicitly to the -proper value, @code{t} or @code{nil}. +intended for interactive use; do not use it in programs (it may have +side-effects, such as enabling View mode, and does not affect +read-only text properties). To change the read-only state of a buffer in +a program, explicitly set @code{buffer-read-only} to the proper value. +To temporarily ignore a read-only state, bind @code{inhibit-read-only}. If @var{arg} is non-@code{nil}, it should be a raw prefix argument. @code{toggle-read-only} sets @code{buffer-read-only} to @code{t} if diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 795d0e8702a..1617736593b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2011-11-10 Glenn Morris + + * emacs-lisp/bytecomp.el (byte-compile-interactive-only-functions): + Add toggle-read-only. (Bug#7292) + * files.el (toggle-read-only): Mention that it should only + be used interactively. (Bug#10006) + 2011-11-09 Stefan Monnier * progmodes/compile.el (compilation-error-regexp-alist-alist): diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index fae402d4215..84aaf8718ed 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -355,7 +355,7 @@ else the global value will be modified." (defvar byte-compile-interactive-only-functions '(beginning-of-buffer end-of-buffer replace-string replace-regexp insert-file insert-buffer insert-file-literally previous-line next-line - goto-line comint-run delete-backward-char) + goto-line comint-run delete-backward-char toggle-read-only) "List of commands that are not meant to be called from Lisp.") (defvar byte-compile-not-obsolete-vars nil diff --git a/lisp/files.el b/lisp/files.el index acff3395019..aac415c1a96 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4686,7 +4686,15 @@ prints a message in the minibuffer. Instead, use `set-buffer-modified-p'." "Change whether this 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." +and `view-read-only' is non-nil, enter view mode. + +This function is usually the wrong thing to use in a Lisp program. +It can have side-effects beyond changing the read-only status of a buffer +\(e.g., enabling view mode), and does not affect read-only regions that +are caused by text properties. To make a buffer read-only in Lisp code, +set `buffer-read-only'. To ignore read-only status (whether due to text +properties or buffer state) and make changes, temporarily bind +`inhibit-read-only'." (interactive "P") (if (and arg (if (> (prefix-numeric-value arg) 0) buffer-read-only -- 2.39.2