13

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 special-mode, which is read-only. The advantages behind that are several. ...


11

Calling read-only-mode toggles between read-only and edit mode for the current buffer. You can call this via M-x read-only-mode or with C-x C-q.


10

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 ...


8

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 ...


8

In your original buffer, where you want to keep editing it : M-x clone-indirect-buffer 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 : M-x read-only-mode Now ...


6

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.


6

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 ...


6

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 ...


6

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....


5

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 (dir-locals-set-class-variables 'read-only '((nil . ((buffer-read-only . t))))) ;; Associate directories with the read-only class (dolist (dir (list "/some/dir" "/some/other/dir")) (dir-locals-set-...


5

(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 () (interactive) (let ((old-max comint-buffer-maximum-size)) (setq comint-buffer-maximum-size 0) (comint-truncate-buffer) (setq comint-buffer-maximum-size old-max) (...


4

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 ...


4

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/...


4

(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'." (interactive "r") (let ((inhibit-read-only t)) (with-silent-modifications (add-text-...


4

C-hv inhibit-read-only e.g.: (let ((inhibit-read-only t)) (insert "Hello world"))


4

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,...


3

The interactive code * is used to: "Signal an error if the current buffer is read-only. Special." https://www.gnu.org/software/emacs/manual/html_node/elisp/Interactive-Codes.html 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 (&...


3

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 ...


2

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 ...


2

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 is ‘find-file’ 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 ...


2

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-...


2

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 ...


2

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." (interactive "r") (save-excursion (apply-on-...


2

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.


2

@phils said how to deal with the problem programmatically. Here is how to deal with it interactively: Select the region Menu Edit -> Text Properties -> Special Properties -> Read-Only


1

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 ...


1

You could use find-file-hook and check the read only status of the buffer: (defun my/read-only-whitespace () (when buffer-read-only (setq-local show-trailing-whitespace (not buffer-read-only)))) (add-hook 'find-file-hook 'my/read-only-whitespace)


1

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 ...


1

That zone of text probably has a non-nil value for text property read-only. Commands such as read-only-mode (and toggle-read-only) have no effect on this, as their doc tells you. C-h f read-only-mode says: Also, note that this command works by setting the variable buffer-read-only, which does not affect read-only regions caused by text properties. ...


Only top voted, non community-wiki answers of a minimum length are eligible