;;; executable.el --- base functionality for executable interpreter scripts -*- byte-compile-dynamic: t -*-
-;; Copyright (C) 1994, 1995, 1996, 2000 by Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 1996, 2000, 2003, 2004 by Free Software Foundation, Inc.
;; Author: Daniel Pfeiffer <occitan@esperanto.org>
;; Keywords: languages, unix
See `compilation-error-regexp-alist'.")
;; The C function openp slightly modified would do the trick fine
-(defvar executable-binary-suffixes
- (if (memq system-type '(ms-dos windows-nt))
- '(".exe" ".com" ".bat" ".cmd" ".btm" "")
- '("")))
+(defvaralias 'executable-binary-suffixes 'exec-suffixes)
+
+;;;###autoload
+(defun executable-command-find-posix-p (&optional program)
+ "Check if PROGRAM handles arguments Posix-style.
+If PROGRAM is non-nil, use that instead of \"find\"."
+ ;; Pick file to search from location we know
+ (let* ((dir (file-truename data-directory))
+ (file (car (directory-files dir nil "^[^.]"))))
+ (with-temp-buffer
+ (call-process (or program "find")
+ nil
+ (current-buffer)
+ nil
+ dir
+ "-name"
+ file
+ "-maxdepth"
+ "1")
+ (goto-char (point-min))
+ (if (search-forward file nil t)
+ t))))
;;;###autoload
(defun executable-find (command)
- "Search for COMMAND in exec-path and return the absolute file name.
+ "Search for COMMAND in `exec-path' and return the absolute file name.
Return nil if COMMAND is not found anywhere in `exec-path'."
(let ((list exec-path)
file)
(while list
(setq list
(if (and (setq file (expand-file-name command (car list)))
- (let ((suffixes executable-binary-suffixes)
+ (let ((suffixes exec-suffixes)
candidate)
(while suffixes
(setq candidate (concat file (car suffixes)))
(let* ((name (read-string "Name or file name of interpreter: "))
(arg (read-string (format "Argument for %s: " name))))
(list name arg (eq executable-query 'function) t)))
+
(setq interpreter (if (file-name-absolute-p interpreter)
interpreter
(or (executable-find interpreter)
- (error "Interpreter %s not recognized" interpreter)))
- argument (concat interpreter
+ (error "Interpreter %s not recognized"
+ interpreter))))
+
+ (setq argument (concat (if (string-match "\\`/:" interpreter)
+ (replace-match "" nil nil interpreter)
+ interpreter)
(and argument (string< "" argument) " ")
argument))
+
(or buffer-read-only
(if buffer-file-name
(string-match executable-magicless-file-regexp
(not (or insert-flag executable-insert))
(> (point-min) 1)
(save-excursion
- (let ((point (point-marker))
- (buffer-modified-p (buffer-modified-p)))
- (goto-char (point-min))
- (make-local-hook 'after-save-hook)
- (add-hook 'after-save-hook 'executable-chmod nil t)
- (if (looking-at "#![ \t]*\\(.*\\)$")
- (and (goto-char (match-beginning 1))
- ;; If the line ends in a space,
- ;; don't offer to change it.
- (not (= (char-after (1- (match-end 1))) ?\ ))
- (not (string= argument
- (buffer-substring (point) (match-end 1))))
- (if (or (not executable-query) no-query-flag
- (save-window-excursion
- ;; Make buffer visible before question.
- (switch-to-buffer (current-buffer))
- (y-or-n-p (concat "Replace magic number by `"
- executable-prefix 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)))
-;;; (or insert-flag
-;;; (eq executable-insert t)
-;;; (set-buffer-modified-p buffer-modified-p))
- )))
- interpreter)
+ (goto-char (point-min))
+ (add-hook 'after-save-hook 'executable-chmod nil t)
+ (if (looking-at "#![ \t]*\\(.*\\)$")
+ (and (goto-char (match-beginning 1))
+ ;; If the line ends in a space,
+ ;; don't offer to change it.
+ (not (= (char-after (1- (match-end 1))) ?\ ))
+ (not (string= argument
+ (buffer-substring (point) (match-end 1))))
+ (if (or (not executable-query) no-query-flag
+ (save-window-excursion
+ ;; Make buffer visible before question.
+ (switch-to-buffer (current-buffer))
+ (y-or-n-p (concat "Replace magic number by `"
+ executable-prefix 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)))))
+ interpreter)
(and (>= (buffer-size) 2)
(save-restriction
(widen)
- (string= "#!" (buffer-substring 1 3)))
+ (string= "#!" (buffer-substring (point-min) (+ 2 (point-min)))))
(let* ((current-mode (file-modes (buffer-file-name)))
(add-mode (logand ?\111 (default-file-modes))))
(or (/= (logand ?\111 current-mode) 0)
(provide 'executable)
-;; executable.el ends here
+;;; arch-tag: 58458d1c-d9db-45ec-942b-8bbb1d5e319d
+;;; executable.el ends here