;; Copyright (C) 1994, 1995, 1996 by Free Software Foundation, Inc.
-;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
+;; Author: Daniel Pfeiffer <occitan@esperanto.org>
;; Keywords: languages, unix
;; This file is part of GNU Emacs.
;;; Code:
-(defvar executable-insert 'not-modified
- "*What to do when newly found file has no or wrong magic number:
- nil do nothing
- t insert or update magic number
- other insert or update magic number, but mark as unmodified.
-When the insertion is marked as unmodified, you can save it with \\[write-file] RET.
-This variable is used when `executable-set-magic' is called as a function,
-e.g. when Emacs sets some Un*x interpreter script mode.
-With \\[executable-set-magic], this is always treated as if it were `t'.")
+(defgroup executable nil
+ "Base functionality for executable interpreter scripts"
+ :group 'processes)
+(defcustom executable-insert '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)
+ :group 'executable)
-(defvar executable-query 'function
- "*If non-`nil', ask user before inserting or changing magic number.
-When this is `function', only ask when called non-interactively.")
+(defcustom executable-query 'function
+ "*If non-nil, ask user before changing an existing magic number.
+When this is `function', only ask when called non-interactively."
+ :type '(choice (const :tag "Don't Ask" nil)
+ (const :tag "Ask when non-interactive" function)
+ (other :tag "Ask" t))
+ :group 'executable)
-(defvar executable-magicless-file-regexp "/[Mm]akefile$\\|/\\.\\(z?profile\\|bash_profile\\|z?login\\|bash_login\\|z?logout\\|bash_logout\\|.+shrc\\|esrc\\|rcrc\\|[kz]shenv\\)$"
- "*On files with this kind of name no magic is inserted or changed.")
+(defcustom executable-magicless-file-regexp "/[Mm]akefile$\\|/\\.\\(z?profile\\|bash_profile\\|z?login\\|bash_login\\|z?logout\\|bash_logout\\|.+shrc\\|esrc\\|rcrc\\|[kz]shenv\\)$"
+ "*On files with this kind of name no magic is inserted or changed."
+ :type 'regexp
+ :group 'executable)
-(defvar executable-prefix "#! "
- "*Interpreter magic number prefix inserted when there was no magic number.")
+(defcustom executable-prefix "#! "
+ "*Interpreter magic number prefix inserted when there was no magic number."
+ :type 'string
+ :group 'executable)
-(defvar executable-chmod 73
+(defcustom executable-chmod 73
"*After saving, if the file is not executable, set this mode.
This mode passed to `set-file-modes' is taken absolutely when negative, or
relative to the files existing modes. Do nothing if this is nil.
-Typical values are 73 (+x) or -493 (rwxr-xr-x).")
+Typical values are 73 (+x) or -493 (rwxr-xr-x)."
+ :type '(choice integer
+ (const nil))
+ :group 'executable)
(defvar executable-command nil)
-(defvar executable-self-display "tail"
+(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)
(defvar executable-font-lock-keywords
See `compilation-error-regexp-alist'.")
;; The C function openp slightly modified would do the trick fine
+(defvar executable-binary-suffixes
+ (if (memq system-type '(ms-dos windows-nt))
+ '(".exe" ".com" ".bat" ".cmd" ".btm" "")
+ '("")))
(defun executable-find (command)
- "Search for COMMAND in $PATH and return the absolute file name.
-Return nil if COMMAND is not found anywhere in $PATH."
+ "Search for COMMAND in exec-path and return the absolute file name.
+Return nil if COMMAND is not found anywhere in `exec-path'."
(let ((list exec-path)
file)
(while list
- (setq list (if (and (setq file (expand-file-name command (car list)))
- (file-executable-p file)
- (not (file-directory-p file)))
- nil
- (setq file nil)
- (cdr list))))
+ (setq list
+ (if (and (setq file (expand-file-name command (car list)))
+ (let ((suffixes executable-binary-suffixes)
+ candidate)
+ (while suffixes
+ (setq candidate (concat file (car suffixes)))
+ (if (and (file-executable-p candidate)
+ (not (file-directory-p candidate)))
+ (setq suffixes nil)
+ (setq suffixes (cdr suffixes))
+ (setq candidate nil)))
+ (setq file candidate)))
+ nil
+ (setq file nil)
+ (cdr list))))
file))
-
(defun executable-chmod ()
"This gets called after saving a file to assure that it be executable.
You can set the absolute or relative mode in variable `executable-chmod' for
(progn
(replace-match argument t t nil 1)
(message "Magic number changed to `%s'"
- (concat executable-prefix argument)))
- ;; Add a space at the end of the line
- ;; so we do not ask again about changing it.
- (end-of-line)
- (insert " ")))
+ (concat executable-prefix argument)))))
(insert executable-prefix argument ?\n)
(message "Magic number changed to `%s'"
(concat executable-prefix argument)))