Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change read/write mode for a file using Emacs?

People also ask

How do I change modes in Emacs?

A buffer may have multiple minor modes. To get a list of the all the available modes, both major and minor, on your system's version of Emacs, look up "mode" using Emacs' apropos command. Do this by pressing C-h a and entering the word mode .

How do I change Emacs from read-only?

To change the read-only status of a buffer, use C-x C-q (toggle read-only-mode ). To change file permissions, you can run dired on the file's directory ( C-x d ), search for the file by C-s and use M to change its mode.

How do I open and edit a file in Emacs?

Working with files Emacs will ask you for the name of the file. As you type the name of the file, it will be displayed in the mini buffer. When you have entered the file name, press the return key, and emacs will load the file into a buffer, and display it in the text window.

Why is buffer read-only Emacs?

A buffer visiting a write-protected file is normally read-only. Here, the purpose is to inform the user that editing the buffer with the aim of saving it in the file may be futile or undesirable. The user who wants to change the buffer text despite this can do so after clearing the read-only flag with C-x C-q .


M-x toggle-read-only

or in more recent versions of Emacs

M-x read-only-mode

On my Windows box, that amounts to Alt-x to bring up the meta prompt and typing "toggle-read-only" to call the correct elisp function.

If you are using the default keyboard bindings,

C-x C-q

(which you read aloud as "Control-X Control-Q") will have the same effect. Remember, however, given that emacs is essentially infinitely re-configurable, your mileage may vary.

Following up from the commentary: you should note that the writeable status of the buffer does not change the writeable permission of the file. If you try to write out to a read only file, you'll see a confirmation message. However, if you own the file, you can write out your changes without changing the permissions on the file.

This is very convenient if you'd like to make a quick change to a file without having to go through the multiple steps of add write permission, write out changes, remove write permission. I tend to forget that last step, leaving potentially critical files open for accidental changes later on.


Be sure you're not confusing 'file' with 'buffer'. You can set buffers to read-only and back again with C-x C-q (toggle-read-only). If you have permission to read, but not write, a file, the buffer you get when you visit the file (C-x C-f or find-file) will be put in read-only mode automatically. If you want to change the permissions on a file in the file system, perhaps start with dired on the directory that contains the file. Documentation for dired can be found in info; C-h i (emacs)dired RET.


What I found is M-x set-file-modes filename mode

It worked at my Windows Vista box. For example: M-x set-file-modes <RET> ReadOnlyFile.txt <RET> 0666


As mentioned up there by somebody else: M-x toggle-read-only would work.

However, this is now deprecated and M-x read-only-mode is the current way to do it, that it is set to C-x C-q keybinding.