diff options
Diffstat (limited to 'lisp/progmodes/executable.el')
| -rw-r--r-- | lisp/progmodes/executable.el | 37 |
1 files 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 @@ | |||
| 1 | ;;; executable.el --- base functionality for executable interpreter scripts | 1 | ;;; executable.el --- base functionality for executable interpreter scripts -*- byte-compile-dynamic: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1994, 1995, 1996 by Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1994, 1995, 1996, 2000 by Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Daniel Pfeiffer <occitan@esperanto.org> | 5 | ;; Author: Daniel Pfeiffer <occitan@esperanto.org> |
| 6 | ;; Keywords: languages, unix | 6 | ;; Keywords: languages, unix |
| @@ -56,15 +56,18 @@ | |||
| 56 | "Base functionality for executable interpreter scripts" | 56 | "Base functionality for executable interpreter scripts" |
| 57 | :group 'processes) | 57 | :group 'processes) |
| 58 | 58 | ||
| 59 | (defcustom executable-insert 'other | 59 | ;; This used to default to `other', but that doesn't seem to have any |
| 60 | ;; significance. fx 2000-02-11. | ||
| 61 | (defcustom executable-insert t ; 'other | ||
| 60 | "*Non-nil means offer to add a magic number to a file. | 62 | "*Non-nil means offer to add a magic number to a file. |
| 61 | This takes effect when you switch to certain major modes, | 63 | This takes effect when you switch to certain major modes, |
| 62 | including Shell-script mode (`sh-mode'). | 64 | including Shell-script mode (`sh-mode'). |
| 63 | When you type \\[executable-set-magic], it always offers to add or | 65 | When you type \\[executable-set-magic], it always offers to add or |
| 64 | update the magic number." | 66 | update the magic number." |
| 65 | :type '(choice (const :tag "off" nil) | 67 | ;;; :type '(choice (const :tag "off" nil) |
| 66 | (const :tag "on" t) | 68 | ;;; (const :tag "on" t) |
| 67 | symbol) | 69 | ;;; symbol) |
| 70 | :type 'boolean | ||
| 68 | :group 'executable) | 71 | :group 'executable) |
| 69 | 72 | ||
| 70 | 73 | ||
| @@ -103,7 +106,7 @@ Typical values are 73 (+x) or -493 (rwxr-xr-x)." | |||
| 103 | 106 | ||
| 104 | (defcustom executable-self-display "tail" | 107 | (defcustom executable-self-display "tail" |
| 105 | "*Command you use with argument `+2' to make text files self-display. | 108 | "*Command you use with argument `+2' to make text files self-display. |
| 106 | Note that the like of `more' doesn't work too well under Emacs \\[shell]." | 109 | Note that the like of `more' doesn't work too well under Emacs \\[shell]." |
| 107 | :type 'string | 110 | :type 'string |
| 108 | :group 'executable) | 111 | :group 'executable) |
| 109 | 112 | ||
| @@ -139,6 +142,8 @@ See `compilation-error-regexp-alist'.") | |||
| 139 | (if (memq system-type '(ms-dos windows-nt)) | 142 | (if (memq system-type '(ms-dos windows-nt)) |
| 140 | '(".exe" ".com" ".bat" ".cmd" ".btm" "") | 143 | '(".exe" ".com" ".bat" ".cmd" ".btm" "") |
| 141 | '(""))) | 144 | '(""))) |
| 145 | |||
| 146 | ;;;###autoload | ||
| 142 | (defun executable-find (command) | 147 | (defun executable-find (command) |
| 143 | "Search for COMMAND in exec-path and return the absolute file name. | 148 | "Search for COMMAND in exec-path and return the absolute file name. |
| 144 | Return nil if COMMAND is not found anywhere in `exec-path'." | 149 | 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." | |||
| 261 | (setq this-command 'executable-set-magic)) | 266 | (setq this-command 'executable-set-magic)) |
| 262 | (executable-set-magic executable-self-display "+2")) | 267 | (executable-set-magic executable-self-display "+2")) |
| 263 | 268 | ||
| 264 | 269 | ;;;###autoload | |
| 270 | (defun make-buffer-file-executable-if-script-p () | ||
| 271 | "Make file executable according to umask if not already executable. | ||
| 272 | If file already has any execute bits set at all, do not change existing | ||
| 273 | file modes." | ||
| 274 | (and (save-excursion | ||
| 275 | (save-restriction | ||
| 276 | (widen) | ||
| 277 | (goto-char (point-min)) | ||
| 278 | (save-match-data | ||
| 279 | (looking-at "^#!")))) | ||
| 280 | (let* ((current-mode (file-modes (buffer-file-name))) | ||
| 281 | (add-mode (logand ?\111 (default-file-modes)))) | ||
| 282 | (or (/= (logand ?\111 current-mode) 0) | ||
| 283 | (zerop add-mode) | ||
| 284 | (set-file-modes (buffer-file-name) | ||
| 285 | (logior current-mode add-mode)))))) | ||
| 265 | 286 | ||
| 266 | (provide 'executable) | 287 | (provide 'executable) |
| 267 | 288 | ||