Function: executable-make-buffer-file-executable-if-script-p

executable-make-buffer-file-executable-if-script-p is an autoloaded and byte-compiled function defined in executable.el.gz.

Signature

(executable-make-buffer-file-executable-if-script-p)

Documentation

Make file executable according to umask if not already executable.

If file already has any execute bits set at all, do not change existing file modes.

Probably introduced at or before Emacs version 21.1.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/executable.el.gz
;;;###autoload
(defun executable-make-buffer-file-executable-if-script-p ()
  "Make file executable according to umask if not already executable.
If file already has any execute bits set at all, do not change existing
file modes."
  (and (>= (buffer-size) 2)
       (save-restriction
	 (widen)
	 (string= "#!" (buffer-substring (point-min) (+ 2 (point-min)))))
       ;; Eg file-modes can return nil (bug#9879).  It should not,
       ;; in this context, but we should handle it all the same.
       (with-demoted-errors "Unable to make file executable: %s"
         (let* ((current-mode (file-modes (buffer-file-name)))
                (add-mode (logand ?\111 (default-file-modes))))
           (or (/= (logand ?\111 current-mode) 0)
               (zerop add-mode)
               (set-file-modes (buffer-file-name)
                               (logior current-mode add-mode)))))))