Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to change the write permissions on a file from inside emacs, without killing/re-opening the buffer?

Sometimes I forget to modify the permissions on a file before opening it. I can modify the permissions from inside emacs (M-! chmod u+w filename) but this doesn't update the buffer which remains write protected and refuses to modify the file.

Is there a way to update permissions inside the buffer? Bonus point if I can assign this to a shortcut!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

After changing the file mode, and before doing any edit, run M-x revert-buffer to reload the file. If the file is now writable, the buffer will no longer be read-only.

Alternatively, type C-x C-q (toggle-read-only). This makes the buffer no longer read-only. You can edit and even save, but you'll get a confirmation prompt asking whether you want to overwrite the read-only file.

share|improve this answer
add comment

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

share|improve this answer
2  
Apparently, you've missed dired-jump (normally bound to C-x C-j). It runs dired and jumps to the line for the file you're editing. –  cjm Sep 10 '12 at 16:33
2  
@cjm: It does not work for me unless I load dired-x. –  choroba Sep 10 '12 at 16:47
    
Sorry, I'd forgotten that I'd set up an autoload for dired-jump about 20 years ago. I recommend it. –  cjm Sep 10 '12 at 17:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.