+2012-07-13 Chong Yidong <cyd@gnu.org>
+
+ * buffers.texi (Misc Buffer): Document view-read-only.
+
2012-07-07 Chong Yidong <cyd@gnu.org>
* custom.texi (Init File): Index site-lisp (Bug#11435).
whose access control says you cannot write it.
@findex toggle-read-only
+@vindex view-read-only
The command @kbd{C-x C-q} (@code{toggle-read-only}) makes a read-only
buffer writable, and makes a writable buffer read-only. This works by
setting the variable @code{buffer-read-only}, which has a local value
in each buffer and makes the buffer read-only if its value is
-non-@code{nil}.
+non-@code{nil}. If you change the option @code{view-read-only} to a
+non-@code{nil} value, making the buffer read-only with @kbd{C-x C-q}
+also enables View mode in the buffer (@pxref{View Mode}).
@findex rename-buffer
@kbd{M-x rename-buffer} changes the name of the current buffer. You
+2012-07-13 Chong Yidong <cyd@gnu.org>
+
+ * buffers.texi (Read Only Buffers): Document toggle-read-only
+ changes. Reword to account for the fact that read-only is
+ currently not supported in overlay properties.
+
2012-07-07 Chong Yidong <cyd@gnu.org>
* loading.texi (Library Search): Index site-lisp directories.
@defvar inhibit-read-only
If this variable is non-@code{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
-non-@code{nil} @code{read-only} properties (either text properties or
-overlay properties). @xref{Special Properties}, for more information
-about text properties. @xref{Overlays}, for more information about
-overlays and their properties.
+modified. Read-only characters in a buffer are those that have a
+non-@code{nil} @code{read-only} text property. @xref{Special
+Properties}, for more information about text properties.
If @code{inhibit-read-only} is @code{t}, all @code{read-only} character
properties have no effect. If @code{inhibit-read-only} is a list, then
of the list (comparison is done with @code{eq}).
@end defvar
-@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 (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
-the numeric value of that prefix argument is positive and to
-@code{nil} otherwise. @xref{Prefix Command Arguments}.
+@deffn Command toggle-read-only &optional arg message
+This command toggles whether the current buffer is read-only, by
+setting the variable @code{buffer-read-only}. If @var{arg} is
+non-@code{nil}, it should be a raw prefix argument; the command then
+makes the buffer read-only if the numeric value of that prefix
+argument is positive, and makes the buffer writable otherwise.
+@xref{Prefix Command Arguments}.
+
+If called interactively, or if called from Lisp with @var{message} is
+non-@code{nil}, the command prints a message reporting the buffer's
+new read-only status.
+
+When making the buffer read-only, this command also enables View mode
+if the option @code{view-read-only} is non-@code{nil}. @xref{Misc
+Buffer,,Miscellaneous Buffer Operations, emacs, The GNU Emacs Manual}.
+When making the buffer writable, it disables View mode if View mode
+was enabled.
+
+Lisp programs should only call @code{toggle-read-only} if they really
+intend to do the same thing as the user command, including possibly
+enabling or disabling View mode. Note also that this command works by
+setting @code{buffer-read-only}, so even if you make the buffer
+writable, characters with non-@code{nil} @code{read-only} text
+properties will remain read-only. To temporarily ignore all read-only
+states, bind @code{inhibit-read-only}, as described above.
@end deffn
@defun barf-if-buffer-read-only
\f
* Lisp changes in Emacs 24.2
+** `toggle-read-only' accepts a second argument specifying whether to
+print a message, if called from Lisp.
+
** CL-style generalized variables are now in core Elisp.
`setf' is autoloaded and `push' and `pop' accept generalized variables.
+2012-07-13 Chong Yidong <cyd@gnu.org>
+
+ * files.el (toggle-read-only): Doc fix and code cleanup. New arg
+ to allow printing the message when called from Lisp.
+
+ * emacs-lisp/bytecomp.el (byte-compile-interactive-only-functions):
+ Remove toggle-read-only.
+
+ * bs.el (bs-toggle-readonly):
+ * buff-menu.el (Buffer-menu-toggle-read-only): Remove
+ with-no-warnings around toggle-read-only.
+
+ * ffap.el (ffap--toggle-read-only): Accept a list of buffers.
+ Remove with-no-warnings around toggle-read-only.
+ (ffap-read-only, ffap-read-only-other-window)
+ (ffap-read-only-other-frame): Callers changed.
+
+ * help-mode.el: Don't require view package.
+ (help-mode-finish): Set buffer-read-only instead of calling
+ toggle-read-only.
+
+ * bindings.el (mode-line-toggle-read-only):
+ * dired.el (dired-toggle-read-only):
+ * ibuffer.el (ibuffer-do-toggle-read-only): Call toggle-read-only
+ with non-nil second arg.
+
+ * emacs-lisp/eieio-custom.el (eieio-customize-object):
+ * vc/ediff.el (ediff-set-read-only-in-buf-A): Set buffer-read-only
+ directly.
+
2012-07-12 Eli Zaretskii <eliz@gnu.org>
* emacs-lisp/bytecomp.el (byte-recompile-directory): Use cl-incf,
(interactive "e")
(save-selected-window
(select-window (posn-window (event-start event)))
- (with-no-warnings (toggle-read-only))
+ (toggle-read-only nil t)
(force-mode-line-update)))
(defun mode-line-toggle-modified (event)
Uses function `toggle-read-only'."
(interactive)
(with-current-buffer (bs--current-buffer)
- (call-interactively 'toggle-read-only))
+ (toggle-read-only))
(bs--update-current-line))
(defun bs-clear-modified ()
(bury-buffer menu)))
(defun Buffer-menu-toggle-read-only ()
- "Toggle read-only status of buffer on this line."
+ "Toggle read-only status of buffer on this line.
+This behaves like invoking \\[toggle-read-only] in that buffer."
(interactive)
(let (read-only)
(with-current-buffer (Buffer-menu-buffer t)
- (with-no-warnings (toggle-read-only))
+ (toggle-read-only)
(setq read-only buffer-read-only))
(tabulated-list-set-col 1 (if read-only "%" " ") t)))
Actual changes in files cannot be undone by Emacs."))
(defun dired-toggle-read-only ()
- "Edit dired buffer with Wdired, or set it read-only.
-Call `wdired-change-to-wdired-mode' in dired buffers whose editing is
-supported by Wdired (the major mode of the dired buffer is `dired-mode').
-Otherwise, for buffers inheriting from dired-mode, call `toggle-read-only'."
+ "Edit Dired buffer with Wdired, or make it read-only.
+If the current buffer can be edited with Wdired, (i.e. the major
+mode is `dired-mode'), call `wdired-change-to-wdired-mode'.
+Otherwise, call `toggle-read-only'."
(interactive)
(if (eq major-mode 'dired-mode)
(wdired-change-to-wdired-mode)
- (with-no-warnings
- (toggle-read-only))))
+ (toggle-read-only nil t)))
(defun dired-next-line (arg)
"Move down lines then position at filename.
(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 toggle-read-only)
+ goto-line comint-run delete-backward-char)
"List of commands that are not meant to be called from Lisp.")
(defvar byte-compile-not-obsolete-vars nil
(concat "*CUSTOMIZE "
(object-name obj) " "
(symbol-name g) "*")))
- (toggle-read-only -1)
+ (setq buffer-read-only nil)
(kill-all-local-variables)
(erase-buffer)
(let ((all (overlay-lists)))
;;; Start of automatically extracted autoloads.
\f
;;;### (autoloads (customize-object) "eieio-custom" "eieio-custom.el"
-;;;;;; "9cf80224540c52045d515a4c2c833543")
+;;;;;; "928623502e8bf40454822355388542b5")
;;; Generated autoloads from eieio-custom.el
(autoload 'customize-object "eieio-custom" "\
(set-window-dedicated-p win wdp))
value))
-(defun ffap--toggle-read-only (buffer)
- (with-current-buffer buffer
- (with-no-warnings
+(defun ffap--toggle-read-only (buffer-or-list)
+ (dolist (buffer (if (listp buffer-or-list)
+ buffer-or-list
+ (list buffer-or-list)))
+ (with-current-buffer buffer
(toggle-read-only 1))))
(defun ffap-read-only ()
(let ((value (call-interactively 'ffap)))
(unless (or (bufferp value) (bufferp (car-safe value)))
(setq value (current-buffer)))
- (mapc #'ffap--toggle-read-only
- (if (listp value) value (list value)))
+ (ffap--toggle-read-only value)
value))
(defun ffap-read-only-other-window ()
Only intended for interactive use."
(interactive)
(let ((value (ffap-other-window)))
- (mapc #'ffap--toggle-read-only
- (if (listp value) value (list value)))
+ (ffap--toggle-read-only value)
value))
(defun ffap-read-only-other-frame ()
Only intended for interactive use."
(interactive)
(let ((value (ffap-other-frame)))
- (mapc #'ffap--toggle-read-only
- (if (listp value) value (list value)))
+ (ffap--toggle-read-only value)
value))
(defun ffap-alternate-file ()
"Modification-flag cleared"))
(set-buffer-modified-p arg))
-(defun toggle-read-only (&optional arg)
- "Change whether this buffer is read-only.
+(defun toggle-read-only (&optional arg message)
+ "Toggle the read-only state of the current buffer.
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.
-
-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'."
+positive; otherwise make it writable.
+
+When making the buffer read-only, enable View mode if
+`view-read-only' is non-nil. When making the buffer writable,
+disable View mode if View mode is enabled.
+
+If called interactively, or if called from Lisp with MESSAGE
+non-nil, print a message reporting the buffer's new read-only
+status.
+
+Do not call this from a Lisp program unless you really intend to
+do the same thing as the \\[toggle-read-only] 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."
(interactive "P")
- (if (and arg
- (if (> (prefix-numeric-value arg) 0) buffer-read-only
- (not buffer-read-only))) ; If buffer-read-only is set correctly,
- nil ; do nothing.
- ;; Toggle.
- (progn
- (cond
- ((and buffer-read-only view-mode)
- (View-exit-and-edit)
- (make-local-variable 'view-read-only)
- (setq view-read-only t)) ; Must leave view mode.
- ((and (not 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))
- (t (setq buffer-read-only (not buffer-read-only))
- (force-mode-line-update))))
- (if (called-interactively-p 'interactive)
- (message "Read-only %s for this buffer"
- (if buffer-read-only "enabled" "disabled")))))
+ (cond
+ ;; Do nothing if `buffer-read-only' already matches the state
+ ;; specified by ARG.
+ ((and arg
+ (if (> (prefix-numeric-value arg) 0)
+ buffer-read-only
+ (not buffer-read-only))))
+ ;; If View mode is enabled, exit it.
+ ((and buffer-read-only view-mode)
+ (View-exit-and-edit)
+ (set (make-local-variable 'view-read-only) t))
+ ;; If `view-read-only' is non-nil, enable View mode.
+ ((and view-read-only
+ (not buffer-read-only)
+ (not view-mode)
+ (not (eq (get major-mode 'mode-class) 'special)))
+ (view-mode-enter))
+ ;; The usual action: flip `buffer-read-only'.
+ (t (setq buffer-read-only (not buffer-read-only))
+ (force-mode-line-update)))
+ (if (or message (called-interactively-p 'interactive))
+ (message "Read-only %s for this buffer"
+ (if buffer-read-only "enabled" "disabled"))))
(defun insert-file (filename)
"Insert contents of file FILENAME into buffer after point.
+2012-07-13 Chong Yidong <cyd@gnu.org>
+
+ * smime.el (smime-certificate-info): Set buffer-read-only directly,
+ instead of calling toggle-read-only with a (bogus) argument.
+
2012-07-09 Tassilo Horn <tassilo@member.fsf.org>
* gnus-sum.el (gnus-summary-limit-to-author): Use default value instead
"x509" "-in" (expand-file-name certfile) "-text")
(fundamental-mode)
(set-buffer-modified-p nil)
- (toggle-read-only t)
+ (setq buffer-read-only t)
(goto-char (point-min))))
(defun smime-draw-buffer ()
;;; Code:
(require 'button)
-(require 'view)
(eval-when-compile (require 'easymenu))
(defvar help-mode-map
;;;###autoload
(defun help-mode-finish ()
(when (eq major-mode 'help-mode)
- ;; View mode's read-only status of existing *Help* buffer is lost
- ;; by with-output-to-temp-buffer.
- (toggle-read-only 1)
-
+ (setq buffer-read-only t)
(save-excursion
(goto-char (point-min))
(let ((inhibit-read-only t))
(:opstring "toggled read only status in"
:interactive "P"
:modifier-p t)
- (toggle-read-only arg))
+ (toggle-read-only arg t))
(define-ibuffer-op ibuffer-do-delete ()
"Kill marked buffers as with `kill-this-buffer'."
;; Used as a startup hook to set `_orig' patch file read-only.
(defun ediff-set-read-only-in-buf-A ()
(ediff-with-current-buffer ediff-buffer-A
- (toggle-read-only 1)))
+ (setq buffer-read-only t)))
;; Return a plausible default for ediff's first file:
;; In dired, return the file number FILENO (or 0) in the list