Reputation: 2178
I'm writing a function designed to make whatever file is in the current buffer writable without being prompted for its name or for the mode (which I always want to be 644). I also want the buffer to be refreshed automatically to reflect the fact that its contents are now writable.
I have the following code in my .emacs file:
;; from http://www.stokebloke.com/wordpress/2008/04/17/emacs-refresh-f5-key/
(defun refresh-file ()
"Refresh the buffer from the disk (prompt if modified)."
(interactive)
(revert-buffer t (not (buffer-modified-p)) t))
(defun my-make-writable ()
"make file writable to owner"
(interactive)
(chmod buffer-file-name 644)
(refresh-file))
However, when I execute the function, emacs displays the following error message in the minibuffer:
File filename no longer readable
This is rather unnerving. However, I can still execute a "chmod" command to make the file readable and writable.
What can I do to make my function work correctly?
Upvotes: 0
Views: 94
Reputation: 21258
The unix permission bits are expressed in octal and you are feeding in a decimal number.
You are setting the file mode to 1204 (that is, "sticky-bit, user can write, group has no permissions, everyone else can read). If you use (chmod buffer-file-name #o644)
or (chmod buffer-file-name 420)
you will probably get the result you are expecting.
Upvotes: 4