summaryrefslogtreecommitdiffstats
path: root/Misc/python-mode.el
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2002-04-22 16:23:29 (GMT)
committerBarry Warsaw <barry@python.org>2002-04-22 16:23:29 (GMT)
commita0113cd5cdb1e6c38ffa6ba7fb2ce6b775b1814c (patch)
tree36be64d3866031436feacc17d548b13b3f9ea62a /Misc/python-mode.el
parentb2d5e62d65c2277832441956b99224eefd9514f8 (diff)
downloadcpython-a0113cd5cdb1e6c38ffa6ba7fb2ce6b775b1814c.zip
cpython-a0113cd5cdb1e6c38ffa6ba7fb2ce6b775b1814c.tar.gz
cpython-a0113cd5cdb1e6c38ffa6ba7fb2ce6b775b1814c.tar.bz2
(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.
Diffstat (limited to 'Misc/python-mode.el')
-rw-r--r--Misc/python-mode.el17
1 files changed, 11 insertions, 6 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el
index aca7240..5a9bff1 100644
--- a/Misc/python-mode.el
+++ b/Misc/python-mode.el
@@ -1359,10 +1359,16 @@ is inserted at the end. See also the command `py-clear-queue'."
(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 @@ is inserted at the end. See also the command `py-clear-queue'."
(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)