December 29, 2006

Emacs tips #3 : automatically making scripts executable

Posted in Emacs at 15:01 by theBlackDragon

I don’t remember where I found this snippet (maybe comp.emacs) but it’s mighty useful so I thought I’d share it with you:

; Sets +x on scripts stating with a shebang
(if (< emacs-major-version 22)
       (add-hook 'after-save-hook
                 '(lambda ()
                      (and (save-excursion
                               (goto-char (point-min))
                         (looking-at "^#!"))))
                           (shell-command (concat "chmod u+x "
                           (message (concat "Saved as script: "
       (add-hook 'after-save-hook

Emacs versions below 22 need the former, longer method while Emacs 22 can use the oneliner in the last line.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s