]> git.eshelyaron.com Git - emacs.git/commitdiff
* progmodes/python.el:
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 24 Sep 2012 23:15:40 +0000 (20:15 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 24 Sep 2012 23:15:40 +0000 (20:15 -0300)
(python-shell-send-buffer): Better handling of "if __name__ ==
'__main__':" conditionals when sending the buffer.

lisp/ChangeLog
lisp/progmodes/python.el

index 270d548b71854daaed86fcce21139ea5b70b7812..5539ee41b26c75e822886765b60d38a68aeac8f9 100644 (file)
@@ -1,3 +1,9 @@
+2012-09-24  Fabián Ezequiel Gallina  <fgallina@cuca>
+
+       * progmodes/python.el:
+       (python-shell-send-buffer): Better handling of "if __name__ ==
+       '__main__':" conditionals when sending the buffer.
+
 2012-09-24  Glenn Morris  <rgm@gnu.org>
 
        * eshell/esh-cmd.el (eshell-find-alias-function):
index cc835ca79ac35c865c1d860a20a588b904c70202..e99e6bda4b830b1fe447322a01df68ca311a09f1 100644 (file)
@@ -1919,19 +1919,18 @@ Returns the output.  See `python-shell-send-string-no-output'."
 
 (defun python-shell-send-buffer (&optional arg)
   "Send the entire buffer to inferior Python process.
-
-With prefix ARG include lines surrounded by \"if __name__ == '__main__':\""
+With prefix ARG allow execution of code inside blocks delimited
+by \"if __name__== '__main__':\""
   (interactive "P")
   (save-restriction
     (widen)
-    (python-shell-send-region
-     (point-min)
-     (or (and
-          (not arg)
-          (save-excursion
-            (re-search-forward (python-rx if-name-main) nil t))
-          (match-beginning 0))
-         (point-max)))))
+    (let ((str (buffer-substring (point-min) (point-max))))
+      (and
+       (not arg)
+       (setq str (replace-regexp-in-string
+                  (python-rx if-name-main)
+                  "if __name__ == '__main__ ':" str)))
+      (python-shell-send-string str))))
 
 (defun python-shell-send-defun (arg)
   "Send the current defun to inferior Python process.