aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-09-24 20:15:40 -0300
committerFabián Ezequiel Gallina2012-09-24 20:15:40 -0300
commitdc4f818b02a02ec6f93977885e2ff75f8210c14b (patch)
treee92b5bf8e606bdcd1185eb68abea6a93432be879
parent22e8cf4a89aeb9f0a31f8676f0ab177c28ab473f (diff)
downloademacs-dc4f818b02a02ec6f93977885e2ff75f8210c14b.tar.gz
emacs-dc4f818b02a02ec6f93977885e2ff75f8210c14b.zip
* progmodes/python.el:
(python-shell-send-buffer): Better handling of "if __name__ == '__main__':" conditionals when sending the buffer.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/python.el19
2 files changed, 15 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 270d548b718..5539ee41b26 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12012-09-24 Fabián Ezequiel Gallina <fgallina@cuca>
2
3 * progmodes/python.el:
4 (python-shell-send-buffer): Better handling of "if __name__ ==
5 '__main__':" conditionals when sending the buffer.
6
12012-09-24 Glenn Morris <rgm@gnu.org> 72012-09-24 Glenn Morris <rgm@gnu.org>
2 8
3 * eshell/esh-cmd.el (eshell-find-alias-function): 9 * eshell/esh-cmd.el (eshell-find-alias-function):
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index cc835ca79ac..e99e6bda4b8 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1919,19 +1919,18 @@ Returns the output. See `python-shell-send-string-no-output'."
1919 1919
1920(defun python-shell-send-buffer (&optional arg) 1920(defun python-shell-send-buffer (&optional arg)
1921 "Send the entire buffer to inferior Python process. 1921 "Send the entire buffer to inferior Python process.
1922 1922With prefix ARG allow execution of code inside blocks delimited
1923With prefix ARG include lines surrounded by \"if __name__ == '__main__':\"" 1923by \"if __name__== '__main__':\""
1924 (interactive "P") 1924 (interactive "P")
1925 (save-restriction 1925 (save-restriction
1926 (widen) 1926 (widen)
1927 (python-shell-send-region 1927 (let ((str (buffer-substring (point-min) (point-max))))
1928 (point-min) 1928 (and
1929 (or (and 1929 (not arg)
1930 (not arg) 1930 (setq str (replace-regexp-in-string
1931 (save-excursion 1931 (python-rx if-name-main)
1932 (re-search-forward (python-rx if-name-main) nil t)) 1932 "if __name__ == '__main__ ':" str)))
1933 (match-beginning 0)) 1933 (python-shell-send-string str))))
1934 (point-max)))))
1935 1934
1936(defun python-shell-send-defun (arg) 1935(defun python-shell-send-defun (arg)
1937 "Send the current defun to inferior Python process. 1936 "Send the current defun to inferior Python process.