aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorDan Davison2012-05-17 00:03:39 -0300
committerFabián Ezequiel Gallina2012-05-17 00:03:39 -0300
commit6da55e5931e899acb1b7da2206967aa56da3ca0f (patch)
treed7b666b7ef1e2f512f93b9bd02c863b417c2aaa9 /lisp/progmodes/python.el
parent39806de381d46f62c3bef1736a969b86015bf603 (diff)
downloademacs-6da55e5931e899acb1b7da2206967aa56da3ca0f.tar.gz
emacs-6da55e5931e899acb1b7da2206967aa56da3ca0f.zip
Don't send "if __name__ == '__main__':" to interpreter
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el21
1 files changed, 17 insertions, 4 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 59802cca623..16a3befc3f2 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -320,6 +320,10 @@
320 `(decorator . ,(rx line-start (* space) ?@ (any letter ?_) 320 `(decorator . ,(rx line-start (* space) ?@ (any letter ?_)
321 (* (any word ?_)))) 321 (* (any word ?_))))
322 `(defun . ,(rx symbol-start (or "def" "class") symbol-end)) 322 `(defun . ,(rx symbol-start (or "def" "class") symbol-end))
323 `(if-name-main . ,(rx line-start "if" (+ space) "__name__"
324 (+ space) "==" (+ space)
325 (any ?' ?\") "__main__" (any ?' ?\")
326 (* space) ?:))
323 `(symbol-name . ,(rx (any letter ?_) (* (any word ?_)))) 327 `(symbol-name . ,(rx (any letter ?_) (* (any word ?_))))
324 `(open-paren . ,(rx (or "{" "[" "("))) 328 `(open-paren . ,(rx (or "{" "[" "(")))
325 `(close-paren . ,(rx (or "}" "]" ")"))) 329 `(close-paren . ,(rx (or "}" "]" ")")))
@@ -1593,12 +1597,21 @@ Returns the output. See `python-shell-send-string-no-output'."
1593 (interactive "r") 1597 (interactive "r")
1594 (python-shell-send-string (buffer-substring start end) nil t)) 1598 (python-shell-send-string (buffer-substring start end) nil t))
1595 1599
1596(defun python-shell-send-buffer () 1600(defun python-shell-send-buffer (&optional arg)
1597 "Send the entire buffer to inferior Python process." 1601 "Send the entire buffer to inferior Python process.
1598 (interactive) 1602
1603With prefix arg include lines protected by \"if __name__ == '__main__':\""
1604 (interactive "P")
1599 (save-restriction 1605 (save-restriction
1600 (widen) 1606 (widen)
1601 (python-shell-send-region (point-min) (point-max)))) 1607 (python-shell-send-region
1608 (point-min)
1609 (or (and
1610 (not arg)
1611 (save-excursion
1612 (re-search-forward (python-rx if-name-main) nil t))
1613 (match-beginning 0))
1614 (point-max)))))
1602 1615
1603(defun python-shell-send-defun (arg) 1616(defun python-shell-send-defun (arg)
1604 "Send the current defun to inferior Python process. 1617 "Send the current defun to inferior Python process.