You can clean up the *Messages* buffer the same way you always could, with the kill-buffer command.
The next time a message is signaled, the buffer will be recreated anew.
The reason that this buffer is read-only now, is that it has been granted
its own major-mode, which inherits from
which is read-only. The advantages behind that are several.
read-only-mode is a minor mode, and should not be set that way.
It's true that using mode: with minor modes used to work. I'm not sure offhand if it still does, but it's definitely deprecated (and if it's clobbering org-mode, then maybe it no longer works at all).
Only use mode: to set the major mode, and use eval: to enable minor modes:
You can probably ...
To add a bit to @Juancho's answer, which is correct:
The default value of read-only-mode depends on the buffer. In particular, if it is visiting a file, and if the file itself is read-only, then the default value of read-only-mode will be on.
You can toggle such a buffer, as @Juancho said, to turn off read-only-mode. But if you try to save the buffer ...
In your original buffer, where you want to keep editing it :
This would create another buffer, and by default open it in another window too. Initially both of these are editable. But a buffer specific mode change can be made in the second one - which will now become read only after you do the following :
Like all minor mode hooks, read-only-mode-hook runs when entering or leaving read-only mode. So you only need to make the setting of the cursor a bit smarter, probably by checking the value of buffer-read-only and acting appropriately.
The normal way would be to make the file read-only in your operating system. With the file open, run M-x set-file-modes RET (or its alias chmod), press down RET to enter the name of the current file, and enter a=r (for “all becomes read” — see file permissions for details). You can also do this from Dired or any other file manager.
Alternatively, if you ...
If you can add a header to your files, the following should work (it should be the first line in the file):
-*- buffer-read-only: t -*-
If there is a comment convention (e.g. '# ' for a shell script), you should put it in a comment:
# -*- buffer-read-only: t -*-
For shell scripts that must have a hash-bang line as the first line, you can put the header ...
If you want this to act in any buffer, not just a file-visiting buffer then find-file-hook is not appropriate. (You said "all buffers", but you also spoke of editable/non-editable "files".)
If you want it to work in all buffers then this is one solution:
(defun my-show-trailing-ws ()
"Show trailing whitespace in the current buffer, unless it is read-only....
You can also do this using using dir locals and associating one or more directories with a directory class. For example:
;; Define a read-only directory class
'((nil . ((buffer-read-only . t)))))
;; Associate directories with the read-only class
(dolist (dir (list "/some/dir" "/some/other/dir"))
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
It is bound to C-x C-...
(erase-buffer) won't work on comint and shell buffers if they are read-only.
Here's the defun I use quite often for clearing shellish buffers:
(defun clear-comint-buffer ()
(let ((old-max comint-buffer-maximum-size))
(setq comint-buffer-maximum-size 0)
(setq comint-buffer-maximum-size old-max)
The reason for the error is that you did not use the correct format to add a text property.
quote from manual:
Function: add-text-properties start end props &optional object
The argument props specifies which properties to add. It should have the form of a property list (see Property Lists): a list whose elements include the property names followed ...
You can use the following commands to set the read-only text property for the marked region. The code is based on https://stackoverflow.com/questions/7410125
(defun set-region-read-only (begin end)
"Sets the read-only text property on the marked region.
Use `set-region-writeable' to remove this property."
;; See https://stackoverflow.com/questions/...
(defface my-read-only '((default . (:background "beige")))
"Face for `my-read-only-region'")
(defun my-read-only-region (begin end)
"Make the marked region read-only. See also `my-writeable-region'.
Read-only text is given the face `my-read-only'."
(let ((inhibit-read-only t))
Use M-w, not C-w. You want to copy the text to the kill-ring, not kill it. Trying to kill the text raises an error in a read-only buffer. Copying the text does not modify the buffer.
C-h k M-w tells you:
M-w runs the command kill-ring-save (found in global-map), which is an
interactive compiled Lisp function in simple.el.
It is bound to M-delete,...
First, this is untrue, assuming I understand what you mean:
On the other hand, pretty much any command can be made a no-op by a zero prefix argument
Beyond that, the answer, IMO, is that you do what you like when defining commands. The point of the * and its doc is to let you know what it does. How/when you decide to use it is up to you.
It's you who ...
I like very much to click on the buffer-read-only indicator % in the mode line for that purpose. It is marked with a red ellipse in the following Figure.
It just feels natural to toggle the read only state where it is indicated.
Note that you can also toggle the buffer-modified-p flag on the right side of the buffer-read-only flag. This is sometimes handy ...
The interactive code * is used to: "Signal an error if the current buffer is read-only. Special."
Thus, the line that reads (interactive "*p") can be changed to eliminate the asterisk.
NOTE: In the example, the optional argument ARG is not used. Thus, consider changing (&...
You can customize recentf-menu-action, from C-h v recentf-menu-action:
recentf-menu-action is a variable defined in ‘recentf.el’. Its value
Documentation: Function to invoke with a filename item of the recentf
menu. The default is to call ‘find-file’ to edit the selected file.
the default value is find-file, so if you always want ...
I'm not sure what you're asking, but I think you're asking how you might make certain parts of a buffer read-only.
You can do that by putting text-property read-only on the text you want to be read-only. See the Elisp manual, node Special Properties. See also node Changing Properties.
The very simple way of inserting new read-only text is demonstrated in ...
It sounds like you very specifically want this for rectangles, rather than for "specific regions".
You can combine https://emacs.stackexchange.com/a/10093/454 (which works on a region) with these rectangle commands:
(defun set-rectangle-read-only (begin end)
"`set-region-read-only' on a rectangle."
Is this true for buffers where buffer-read-only is t and inhibit-read-only is nil? Is it true for text that has non-nil property read-only?
Check each of those situations, and if you still see a problem then consider filing a bug: M-x report-emacs-bug.
If strike Ctrl + V in this text area, there are no text are pasted.
The (default) key sequence to paste (or "yank", in the Emacs parlance) the copied text is C-y not C-v.
Your C-w to kill the text in a read-only buffer ought to have still copied it to the kill ring, even though it could not actually delete it from the buffer; so I think your bigger problem ...
If it is the position of the key that is the problem, then you can unbind the key so that it does not enable overwrite-mode any longer:
(global-set-key (kbd "<insert>") nil)
If you still want to be able to enable the mode with a key, you can bind some other key to it, perhaps a function key:
(global-set-key (kbd "<f8>") #'...
The following minor-mode wo-ctrl-c-mode frees all active keybindings from the control modifier insofar there are no other modifiers such as meta or shift and the resulting key-binding is not already occupied.
That minor mode is activated along with read-only-mode and when opening files without write-permission with find-file.
At least in Emacs 26.2 one ...
You could use find-file-hook and check the read only status of the buffer:
(defun my/read-only-whitespace ()
(setq-local show-trailing-whitespace (not buffer-read-only))))
(add-hook 'find-file-hook 'my/read-only-whitespace)
I don't see the problem you mention. Maybe I miss the recipe. I did this, in a session from emacs -Q:
a. In buffer *scratch* I typed your code and evaluated it.
b. I visited buffer *scratch-demo*. The text of the second line was read-only (could not modify it). I copied the text there using M-w.
c. I visited a buffer in Emacs Lisp mode and yanked the ...