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'.
: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.
(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."
(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
;; 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)