diff Misc/python-mode.el @ 23223:f5aeeaaf0397 legacy-trunk

(py-execute-region): If the line at the beginning of the region is a #! line, use the command on that line as the shell command to use to execute the region. I.e. if the region looks like ---------------- #! /usr/bin/env python1.5 print 'hello world'.startswith('hello') ---------------- you'll get an exception! :) This closes SF bug #232398.
author Barry Warsaw <barry@python.org>
date Mon, 22 Apr 2002 16:23:29 +0000
parents ab4fa78afddf
children ed5d75912d60
line wrap: on
line diff
--- a/Misc/python-mode.el	Mon Apr 22 15:29:27 2002 +0000
+++ b/Misc/python-mode.el	Mon Apr 22 16:23:29 2002 +0000
@@ -1359,10 +1359,16 @@
       (let ((needs-if (/= (py-point 'bol) (py-point 'boi))))
 	(set-buffer buf)
 	(python-mode)
-	(setq shell py-which-shell)
 	(when needs-if
 	  (insert "if 1:\n"))
-	(insert-buffer-substring cur start end)))
+	(insert-buffer-substring cur start end)
+	;; Set the shell either to the #! line command, or to the
+	;; py-which-shell buffer local variable.
+	(goto-char (point-min))
+	(if (looking-at "^#!\\s *\\(.*\\)$")
+	    (setq shell (match-string 1))
+	  ;; No useable #! line
+	  (setq shell py-which-shell))))
     (cond
      ;; always run the code in its own asynchronous subprocess
      (async
@@ -1392,10 +1398,9 @@
       (setq py-file-queue (append py-file-queue (list file)))
       (setq py-exception-buffer (cons file (current-buffer))))
      (t
-      ;; TBD: a horrible hack, buy why create new Custom variables?
-      (let ((cmd (concat shell
-			 (if (string-equal py-which-bufname "JPython")
-			     " -" ""))))
+      ;; TBD: a horrible hack, but why create new Custom variables?
+      (let ((cmd (concat shell (if (string-equal py-which-bufname "JPython")
+				   " -" ""))))
 	;; otherwise either run it synchronously in a subprocess
 	(save-excursion
 	  (set-buffer buf)