4

I have a strange behavior - sometimes while editing, permissions of .rs files are changed from 0644 to 0755. I'm not sure if it is specific for rust-mode or not as so far it is the only mode I regularly use. The most annoying thing is that it happens absolutely randomly.

6

What causes files to automatically become executable

Emacs auto-sets the file permissions to 0755 when the following 2 conditions meet:

  1. The file has hash-bang/shebang #! at the start of file.
  2. The following is added to init.el to take effect globally or in particular major modes.
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)

I use this to auto-add execute permissions to my shell and perl scripts.

I think that the 0755 permission is auto set for you only for the files that have something like #!/usr/bin/env rustx in the beginning of the file and you have the above hook added globally or only for rust-mode.

Customizing the hook for a particular major mode

Below will remove the executable-make-buffer-file-executable-if-script-p function from the after-save-hook only when rust-mode-hook is activated.

(defun my-rust-mode-customizations()
  (remove-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p :local))
(add-hook 'rust-mode-hook 'my-rust-mode-customizations)

I would recommend keeping this hook at least for the shell script modes.

2
  • Ohh, that's definitely is the case by a coincidence. I mean rust files might have compiler "settings" like #![allow(dead_code)] and so on. So while it is technically not the shebang, emacs can't see the difference as checks just for #!. And that hook is enabled globally as I use Prelude. Is there a way to disable that hook just for rust-mode? Nov 17 '14 at 7:55
  • 1
    @ValeriiHiora I have updated my answer with how to customize that hook for rust-mode. Nov 17 '14 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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