changeset 29526:64d6ad22bce7

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.
author Dave Love <fx@gnu.org>
date Fri, 09 Jun 2000 09:38:58 +0000
parents 1b0629c98957
children d5b77185f216
files lisp/progmodes/executable.el
diffstat 1 files changed, 29 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/executable.el	Fri Jun 09 07:48:24 2000 +0000
+++ b/lisp/progmodes/executable.el	Fri Jun 09 09:38:58 2000 +0000
@@ -1,6 +1,6 @@
-;;; 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 @@
 
 (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 @@
   (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 @@
       (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)