diff options
| author | Andrew L. Moore | 2017-07-22 10:34:18 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-07-22 10:34:18 +0300 |
| commit | 2ec8f28c59902ee1b533f9042c08f782422c2d86 (patch) | |
| tree | 77b642f86d546041c1763d13cade772ac5d69cc2 /lisp/progmodes/executable.el | |
| parent | 959fcb113a4680175db5274efb1e0e23fdd69cfe (diff) | |
| download | emacs-2ec8f28c59902ee1b533f9042c08f782422c2d86.tar.gz emacs-2ec8f28c59902ee1b533f9042c08f782422c2d86.zip | |
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.
Diffstat (limited to 'lisp/progmodes/executable.el')
| -rw-r--r-- | lisp/progmodes/executable.el | 36 |
1 files changed, 25 insertions, 11 deletions
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." | |||
| 83 | :type 'regexp | 83 | :type 'regexp |
| 84 | :group 'executable) | 84 | :group 'executable) |
| 85 | 85 | ||
| 86 | |||
| 87 | (defcustom executable-prefix "#!" | 86 | (defcustom executable-prefix "#!" |
| 88 | "Interpreter magic number prefix inserted when there was no magic number." | 87 | "Interpreter magic number prefix inserted when there was no magic number. |
| 89 | :version "24.3" ; "#! " -> "#!" | 88 | Use of `executable-prefix-env' is preferable to this option." |
| 89 | :version "26.1" ; deprecated | ||
| 90 | :type 'string | 90 | :type 'string |
| 91 | :group 'executable) | 91 | :group 'executable) |
| 92 | 92 | ||
| 93 | (defcustom executable-prefix-env nil | ||
| 94 | "If non-nil, use \"/usr/bin/env\" in interpreter magic number. | ||
| 95 | If this variable is non-nil, the interpreter magic number inserted | ||
| 96 | by `executable-set-magic' will be \"#!/usr/bin/env INTERPRETER\", | ||
| 97 | otherwise it will be \"#!/path/to/INTERPRETER\"." | ||
| 98 | :version "26.1" | ||
| 99 | :type 'boolean | ||
| 100 | :group 'executable) | ||
| 93 | 101 | ||
| 94 | (defcustom executable-chmod 73 | 102 | (defcustom executable-chmod 73 |
| 95 | "After saving, if the file is not executable, set this mode. | 103 | "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 | |||
| 199 | (defun executable-set-magic (interpreter &optional argument | 207 | (defun executable-set-magic (interpreter &optional argument |
| 200 | no-query-flag insert-flag) | 208 | no-query-flag insert-flag) |
| 201 | "Set this buffer's interpreter to INTERPRETER with optional ARGUMENT. | 209 | "Set this buffer's interpreter to INTERPRETER with optional ARGUMENT. |
| 202 | The variables `executable-magicless-file-regexp', `executable-prefix', | 210 | The variables `executable-magicless-file-regexp', `executable-prefix-env', |
| 203 | `executable-insert', `executable-query' and `executable-chmod' control | 211 | `executable-insert', `executable-query' and `executable-chmod' control |
| 204 | when and how magic numbers are inserted or replaced and scripts made | 212 | when and how magic numbers are inserted or replaced and scripts made |
| 205 | executable." | 213 | executable." |
| @@ -220,6 +228,14 @@ executable." | |||
| 220 | (and argument (string< "" argument) " ") | 228 | (and argument (string< "" argument) " ") |
| 221 | argument)) | 229 | argument)) |
| 222 | 230 | ||
| 231 | ;; For backward compatibilty, allow `executable-prefix-env' to be | ||
| 232 | ;; overriden by custom `executable-prefix'. | ||
| 233 | (if (string-match "#!\\([ \t]*/usr/bin/env[ \t]*\\)?$" executable-prefix) | ||
| 234 | (if executable-prefix-env | ||
| 235 | (setq argument (concat "/usr/bin/env " | ||
| 236 | (file-name-nondirectory argument)))) | ||
| 237 | (setq argument (concat (substring executable-prefix 2) argument))) | ||
| 238 | |||
| 223 | (or buffer-read-only | 239 | (or buffer-read-only |
| 224 | (if buffer-file-name | 240 | (if buffer-file-name |
| 225 | (string-match executable-magicless-file-regexp | 241 | (string-match executable-magicless-file-regexp |
| @@ -241,15 +257,13 @@ executable." | |||
| 241 | ;; Make buffer visible before question. | 257 | ;; Make buffer visible before question. |
| 242 | (switch-to-buffer (current-buffer)) | 258 | (switch-to-buffer (current-buffer)) |
| 243 | (y-or-n-p (format-message | 259 | (y-or-n-p (format-message |
| 244 | "Replace magic number by `%s%s'? " | 260 | "Replace magic number by `#!%s'? " |
| 245 | executable-prefix argument)))) | 261 | argument)))) |
| 246 | (progn | 262 | (progn |
| 247 | (replace-match argument t t nil 1) | 263 | (replace-match argument t t nil 1) |
| 248 | (message "Magic number changed to `%s'" | 264 | (message "Magic number changed to `#!%s'" argument)))) |
| 249 | (concat executable-prefix argument))))) | 265 | (insert "#!" argument ?\n) |
| 250 | (insert executable-prefix argument ?\n) | 266 | (message "Magic number changed to `#!%s'" argument)))) |
| 251 | (message "Magic number changed to `%s'" | ||
| 252 | (concat executable-prefix argument))))) | ||
| 253 | interpreter) | 267 | interpreter) |
| 254 | 268 | ||
| 255 | 269 | ||