emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r110187: * progmodes/python.el:


From: Fabián Ezequiel Gallina
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r110187: * progmodes/python.el:
Date: Mon, 24 Sep 2012 20:15:40 -0300
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 110187
committer: Fabián Ezequiel Gallina <address@hidden>
branch nick: trunk
timestamp: Mon 2012-09-24 20:15:40 -0300
message:
  * progmodes/python.el:
  (python-shell-send-buffer): Better handling of "if __name__ ==
  '__main__':" conditionals when sending the buffer.
modified:
  lisp/ChangeLog
  lisp/progmodes/python.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-09-24 18:22:10 +0000
+++ b/lisp/ChangeLog    2012-09-24 23:15:40 +0000
@@ -1,3 +1,9 @@
+2012-09-24  Fabián Ezequiel Gallina  <address@hidden>
+
+       * progmodes/python.el:
+       (python-shell-send-buffer): Better handling of "if __name__ ==
+       '__main__':" conditionals when sending the buffer.
+
 2012-09-24  Glenn Morris  <address@hidden>
 
        * eshell/esh-cmd.el (eshell-find-alias-function):

=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el  2012-09-24 17:54:46 +0000
+++ b/lisp/progmodes/python.el  2012-09-24 23:15:40 +0000
@@ -1919,19 +1919,18 @@
 
 (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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]