aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/executable.el
diff options
context:
space:
mode:
authorKarl Heuer1996-01-09 23:17:18 +0000
committerKarl Heuer1996-01-09 23:17:18 +0000
commit291c92b777c2e291eb40a97ccc148d79053c1fc0 (patch)
treebc14593778f5183656856fe9da1273b03796f85e /lisp/progmodes/executable.el
parenta731bd48eae3483cfdd9d203eec44dd9e0d20406 (diff)
downloademacs-291c92b777c2e291eb40a97ccc148d79053c1fc0.tar.gz
emacs-291c92b777c2e291eb40a97ccc148d79053c1fc0.zip
(executable-find): Renamed from `executable'.
(executable-set-magic): Use new name `executable'. Fix messages. Add save-excursion. Don't test this-command--use interactive to get the information. Simplify considerably.
Diffstat (limited to 'lisp/progmodes/executable.el')
-rw-r--r--lisp/progmodes/executable.el87
1 files changed, 45 insertions, 42 deletions
diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el
index 2460891a8cf..6d2d0240ff8 100644
--- a/lisp/progmodes/executable.el
+++ b/lisp/progmodes/executable.el
@@ -101,19 +101,20 @@ This can be included in `font-lock-keywords' by modes that call `executable'.")
101 "Alist of regexps used to match script errors. 101 "Alist of regexps used to match script errors.
102See `compilation-error-regexp-alist'.") 102See `compilation-error-regexp-alist'.")
103 103
104;; The C function openp() slightly modified would do the trick fine 104;; The C function openp slightly modified would do the trick fine
105(defun executable (command) 105(defun executable-find (command)
106 "If COMMAND is an executable in $PATH its full name is returned. Else nil." 106 "Search for COMMAND in $PATH and return the absolute file name.
107Return nil if COMMAND is not found anywhere in $PATH."
107 (let ((list exec-path) 108 (let ((list exec-path)
108 path) 109 file)
109 (while list 110 (while list
110 (setq list (if (and (setq path (expand-file-name command (car list))) 111 (setq list (if (and (setq file (expand-file-name command (car list)))
111 (file-executable-p path) 112 (file-executable-p file)
112 (not (file-directory-p path))) 113 (not (file-directory-p file)))
113 nil 114 nil
114 (setq path nil) 115 (setq file nil)
115 (cdr list)))) 116 (cdr list))))
116 path)) 117 file))
117 118
118 119
119(defun executable-chmod () 120(defun executable-chmod ()
@@ -148,17 +149,21 @@ to find the next error."
148 149
149 150
150;;;###autoload 151;;;###autoload
151(defun executable-set-magic (interpreter &optional argument) 152(defun executable-set-magic (interpreter &optional argument
153 no-query-flag insert-flag)
152 "Set this buffer's interpreter to INTERPRETER with optional ARGUMENT. 154 "Set this buffer's interpreter to INTERPRETER with optional ARGUMENT.
153The variables `executable-magicless-file-regexp', `executable-prefix', 155The variables `executable-magicless-file-regexp', `executable-prefix',
154`executable-insert', `executable-query' and `executable-chmod' control 156`executable-insert', `executable-query' and `executable-chmod' control
155when and how magic numbers are inserted or replaced and scripts made 157when and how magic numbers are inserted or replaced and scripts made
156executable." 158executable."
157 (interactive "sName or path of interpreter: \nsArgument for %s: ") 159 (interactive
160 (let* ((name (read-string "Name or file name of interpreter: "))
161 (arg (read-string (format "Argument for %s: " name))))
162 (list name arg (eq executable-query 'function) t)))
158 (setq interpreter (if (file-name-absolute-p interpreter) 163 (setq interpreter (if (file-name-absolute-p interpreter)
159 interpreter 164 interpreter
160 (or (executable interpreter) 165 (or (executable-find interpreter)
161 (error "Cannot find %s." interpreter))) 166 (error "Interpreter %s not recognized" interpreter)))
162 argument (concat interpreter 167 argument (concat interpreter
163 (and argument (string< "" argument) " ") 168 (and argument (string< "" argument) " ")
164 argument)) 169 argument))
@@ -166,36 +171,34 @@ executable."
166 (if buffer-file-name 171 (if buffer-file-name
167 (string-match executable-magicless-file-regexp 172 (string-match executable-magicless-file-regexp
168 buffer-file-name)) 173 buffer-file-name))
169 (not (or (eq this-command 'executable-set-magic) 174 (not (or insert-flag executable-insert))
170 executable-insert))
171 (> (point-min) 1) 175 (> (point-min) 1)
172 (let ((point (point-marker)) 176 (save-excursion
173 (buffer-modified-p (buffer-modified-p))) 177 (let ((point (point-marker))
174 (goto-char (point-min)) 178 (buffer-modified-p (buffer-modified-p)))
175 (make-local-hook 'after-save-hook) 179 (goto-char (point-min))
176 (add-hook 'after-save-hook 'executable-chmod nil t) 180 (make-local-hook 'after-save-hook)
177 (if (looking-at "#![ \t]*\\(.*\\)$") 181 (add-hook 'after-save-hook 'executable-chmod nil t)
178 (and (goto-char (match-beginning 1)) 182 (if (looking-at "#![ \t]*\\(.*\\)$")
179 (not (string= argument 183 (and (goto-char (match-beginning 1))
180 (buffer-substring (point) (match-end 1)))) 184 (not (string= argument
181 (save-window-excursion 185 (buffer-substring (point) (match-end 1))))
182 ;; make buffer visible before question or message 186 (or (not executable-query) no-query-flag
183 (switch-to-buffer (current-buffer)) 187 (save-window-excursion
184 (if (or (not executable-query) 188 ;; Make buffer visible before question.
185 (and (eq executable-query 'function) 189 (switch-to-buffer (current-buffer))
186 (eq this-command 'executable-set-magic))) 190 (y-or-n-p (concat "Replace magic number by `"
187 (message "%s Magic number ``%s'' replaced." this-command 191 executable-prefix argument "'? "))))
188 (buffer-substring (point-min) (match-end 1))) 192 (progn
189 (y-or-n-p (concat "Replace magic number by ``" 193 (replace-match argument t t nil 1)
190 executable-prefix argument "''? ")))) 194 (message "Magic number changed to `%s'"
191 (not (delete-region (point) (match-end 1))) 195 (concat executable-prefix argument))))
192 (insert argument)) 196 (insert executable-prefix argument ?\n)
193 (insert executable-prefix argument ?\n)) 197 (message "Magic number changed to `%s'"
194 (or (< (marker-position point) (point)) 198 (concat executable-prefix argument)))
195 (goto-char point)) 199 (or insert-flag
196 (or (eq this-command 'executable-set-magic)) 200 (eq executable-insert t)
197 (eq executable-insert t) 201 (set-buffer-modified-p buffer-modified-p)))))
198 (set-buffer-modified-p buffer-modified-p)))
199 interpreter) 202 interpreter)
200 203
201 204