From 778e1d17edb36cc53fd7419436311f2e2bc622ff Mon Sep 17 00:00:00 2001 From: Dave Love Date: Fri, 9 Jun 2000 09:38:58 +0000 Subject: [PATCH] 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. --- lisp/progmodes/executable.el | 37 ++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el index 6e999aed3b1..433ec730416 100644 --- a/lisp/progmodes/executable.el +++ b/lisp/progmodes/executable.el @@ -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 ;; 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) -- 2.39.2