Commit 778e1d17 authored by Dave Love's avatar Dave Love

Byte compile dynamic.

(executable-insert): Change custom type.
(executable-find): Add autoload cookie.
(make-buffer-file-executable-if-script-p): New function from Noah
Friedman.
parent e1ceff3a
;;; executable.el --- base functionality for executable interpreter scripts
;;; executable.el --- base functionality for executable interpreter scripts -*- byte-compile-dynamic: t -*-
;; Copyright (C) 1994, 1995, 1996 by Free Software Foundation, Inc.
;; Copyright (C) 1994, 1995, 1996, 2000 by Free Software Foundation, Inc.
;; Author: Daniel Pfeiffer <occitan@esperanto.org>
;; Keywords: languages, unix
......@@ -56,15 +56,18 @@
"Base functionality for executable interpreter scripts"
:group 'processes)
(defcustom executable-insert 'other
;; This used to default to `other', but that doesn't seem to have any
;; significance. fx 2000-02-11.
(defcustom executable-insert t ; 'other
"*Non-nil means offer to add a magic number to a file.
This takes effect when you switch to certain major modes,
including Shell-script mode (`sh-mode').
When you type \\[executable-set-magic], it always offers to add or
update the magic number."
:type '(choice (const :tag "off" nil)
(const :tag "on" t)
symbol)
;;; :type '(choice (const :tag "off" nil)
;;; (const :tag "on" t)
;;; symbol)
:type 'boolean
:group 'executable)
......@@ -103,7 +106,7 @@ Typical values are 73 (+x) or -493 (rwxr-xr-x)."
(defcustom executable-self-display "tail"
"*Command you use with argument `+2' to make text files self-display.
Note that the like of `more' doesn't work too well under Emacs \\[shell]."
Note that the like of `more' doesn't work too well under Emacs \\[shell]."
:type 'string
:group 'executable)
......@@ -139,6 +142,8 @@ See `compilation-error-regexp-alist'.")
(if (memq system-type '(ms-dos windows-nt))
'(".exe" ".com" ".bat" ".cmd" ".btm" "")
'("")))
;;;###autoload
(defun executable-find (command)
"Search for COMMAND in exec-path and return the absolute file name.
Return nil if COMMAND is not found anywhere in `exec-path'."
......@@ -261,7 +266,23 @@ The magic number of such a command displays all lines but itself."
(setq this-command 'executable-set-magic))
(executable-set-magic executable-self-display "+2"))
;;;###autoload
(defun 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 (save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(save-match-data
(looking-at "^#!"))))
(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))))))
(provide 'executable)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment