changeset 16552:fe3d32bca2c5

(sh-set-shell): Pass args no-query-flag and insert-flag to executable-set-magic. Don't call executable-set-magic if insert-flag is nil. (sh-mode): Always call sh-set-shell, but use insert-flag arg to control whether to call executable-set-magic. No need to set comment-start-skip directly here. (sh-mode): Parse the interpreter from the file text.
author Richard M. Stallman <rms@gnu.org>
date Sat, 09 Nov 1996 22:17:58 +0000
parents 588a76a5a840
children 39aa8dd49637
files lisp/progmodes/sh-script.el
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/progmodes/sh-script.el	Sat Nov 09 21:48:25 1996 +0000
+++ b/lisp/progmodes/sh-script.el	Sat Nov 09 22:17:58 1996 +0000
@@ -622,7 +622,6 @@
 	paragraph-start (concat page-delimiter "\\|$")
 	paragraph-separate paragraph-start
 	comment-start "# "
-	comment-start-skip "#+[\t ]*"
 	comint-dynamic-complete-functions sh-dynamic-complete-functions
 	;; we can't look if previous line ended with `\'
 	comint-prompt-regexp "^[ \t]*"
@@ -638,13 +637,19 @@
 						(current-column)))))
 	skeleton-filter 'sh-feature
 	skeleton-newline-indent-rigidly t)
-  (save-excursion
-    ;; Parse or insert magic number for exec, and set all variables depending
-    ;; on the shell thus determined.
-    (goto-char (point-min))
-    (and (zerop (buffer-size))
-	 (not buffer-read-only)
-	 (sh-set-shell sh-shell-file)))
+  ;; Parse or insert magic number for exec, and set all variables depending
+  ;; on the shell thus determined.
+  (let ((interpreter
+	 (save-excursion
+	   (goto-char (point-min))
+	   (if (looking-at "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)")
+	       (buffer-substring (match-beginning 2)
+				 (match-end 2)))))
+	elt)
+    (if interpreter
+	(sh-set-shell interpreter nil
+		      (and (zerop (buffer-size))
+			   (not buffer-read-only)))))
   (run-hooks 'sh-mode-hook))
 ;;;###autoload
 (defalias 'shell-script-mode 'sh-mode)
@@ -691,7 +696,8 @@
 
 (defun sh-set-shell (shell &optional no-query-flag insert-flag)
   "Set this buffer's shell to SHELL (a string).
-Makes this script executable via `executable-set-magic'.
+Makes this script executable via `executable-set-magic', and sets up the
+proper starting #!-line, if INSERT-FLAG is non-nil.
 Calls the value of `sh-set-shell-hook' if set."
   (interactive (list (completing-read "Name or path of shell: "
 				      interpreter-mode-alist
@@ -701,7 +707,10 @@
   (setq sh-shell (intern (file-name-nondirectory shell))
 	sh-shell (or (cdr (assq sh-shell sh-alias-alist))
 		     sh-shell))
-  (setq sh-shell-file (executable-set-magic shell (sh-feature sh-shell-arg)))
+  (if insert-flag
+      (setq sh-shell-file
+	    (executable-set-magic shell (sh-feature sh-shell-arg)
+				  no-query-flag insert-flag)))
   (setq require-final-newline (sh-feature sh-require-final-newline)
 ;;;	local-abbrev-table (sh-feature sh-abbrevs)
 	font-lock-keywords nil		; force resetting