From: Andrew L. Moore Date: Sat, 22 Jul 2017 07:34:18 +0000 (+0300) Subject: Introduce defcustom 'executable-prefix-env' X-Git-Tag: emacs-26.0.90~518^2~37 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2ec8f28c59902ee1b533f9042c08f782422c2d86;p=emacs.git Introduce defcustom 'executable-prefix-env' * lisp/progmodes/executable.el (executable-prefix): Update the doc string. (executable-prefix-env): New defcustom. (executable-set-magic): Use executable-prefix-env. * etc/NEWS: Document the new variable. --- diff --git a/etc/NEWS b/etc/NEWS index 5c52dc0ccae..460b40d2660 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -105,6 +105,16 @@ required capabilities are found in terminfo. See the FAQ node This argument, when non-nil, is used for comparison instead of 'equal'. +--- +** New variable 'executable-prefix-env' for inserting magic signatures. +This variable affects the format of the interpreter magic number +inserted by 'executable-set-magic'. If non-nil, the magic number now +takes the form "#!/usr/bin/env interpreter", otherwise the value +determined by 'executable-prefix', which is by default +"#!/path/to/interpreter". By default, 'executable-prefix-env' is nil, +so the default behavior is not changed. + ++++ ** The variable 'emacs-version' no longer includes the build number. This is now stored separately in a new variable, 'emacs-build-number'. diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el index da148bd39aa..7c040e74955 100644 --- a/lisp/progmodes/executable.el +++ b/lisp/progmodes/executable.el @@ -83,13 +83,21 @@ When this is `function', only ask when called non-interactively." :type 'regexp :group 'executable) - (defcustom executable-prefix "#!" - "Interpreter magic number prefix inserted when there was no magic number." - :version "24.3" ; "#! " -> "#!" + "Interpreter magic number prefix inserted when there was no magic number. +Use of `executable-prefix-env' is preferable to this option." + :version "26.1" ; deprecated :type 'string :group 'executable) +(defcustom executable-prefix-env nil + "If non-nil, use \"/usr/bin/env\" in interpreter magic number. +If this variable is non-nil, the interpreter magic number inserted +by `executable-set-magic' will be \"#!/usr/bin/env INTERPRETER\", +otherwise it will be \"#!/path/to/INTERPRETER\"." + :version "26.1" + :type 'boolean + :group 'executable) (defcustom executable-chmod 73 "After saving, if the file is not executable, set this mode. @@ -199,7 +207,7 @@ command to find the next error. The buffer is also in `comint-mode' and (defun executable-set-magic (interpreter &optional argument no-query-flag insert-flag) "Set this buffer's interpreter to INTERPRETER with optional ARGUMENT. -The variables `executable-magicless-file-regexp', `executable-prefix', +The variables `executable-magicless-file-regexp', `executable-prefix-env', `executable-insert', `executable-query' and `executable-chmod' control when and how magic numbers are inserted or replaced and scripts made executable." @@ -220,6 +228,14 @@ executable." (and argument (string< "" argument) " ") argument)) + ;; For backward compatibilty, allow `executable-prefix-env' to be + ;; overriden by custom `executable-prefix'. + (if (string-match "#!\\([ \t]*/usr/bin/env[ \t]*\\)?$" executable-prefix) + (if executable-prefix-env + (setq argument (concat "/usr/bin/env " + (file-name-nondirectory argument)))) + (setq argument (concat (substring executable-prefix 2) argument))) + (or buffer-read-only (if buffer-file-name (string-match executable-magicless-file-regexp @@ -241,15 +257,13 @@ executable." ;; Make buffer visible before question. (switch-to-buffer (current-buffer)) (y-or-n-p (format-message - "Replace magic number by `%s%s'? " - executable-prefix argument)))) + "Replace magic number by `#!%s'? " + argument)))) (progn (replace-match argument t t nil 1) - (message "Magic number changed to `%s'" - (concat executable-prefix argument))))) - (insert executable-prefix argument ?\n) - (message "Magic number changed to `%s'" - (concat executable-prefix argument))))) + (message "Magic number changed to `#!%s'" argument)))) + (insert "#!" argument ?\n) + (message "Magic number changed to `#!%s'" argument)))) interpreter)