emacs-diffs
[Top][All Lists]
Advanced

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

master 9b7f3b0: Add new function `python-shell-send-statement'


From: Eli Zaretskii
Subject: master 9b7f3b0: Add new function `python-shell-send-statement'
Date: Sat, 21 Dec 2019 04:16:34 -0500 (EST)

branch: master
commit 9b7f3b0f5774d994311af84d86465c77f00791e5
Author: lin.sun <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Add new function `python-shell-send-statement'
    
    * lisp/progmodes/python.el (python-shell-send-statement): New function.
    (python-mode-map): Bind it to key "C-c C-e", and define a python-menu
    item for it.  (Bug#38426)
---
 etc/NEWS                 |  6 ++++++
 lisp/progmodes/python.el | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 7a7f3f2..6e0b039 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1555,6 +1555,12 @@ The maximum level is used by default; customize
 If non-nil, the default, buffers opened during pdbtracking session are
 killed when pdbtracking session is finished.
 
+---
+*** New function 'python-shell-send-region'.
+It send the statement delimited by 'python-nav-beginning-of-statement' and
+'python-nav-end-of-statement' to the inferior Python process.
+
+
 ** Help
 
 ---
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 08ef471..2956bfa 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -329,6 +329,7 @@ It returns a file name which can be used directly as 
argument of
     ;; Shell interaction
     (define-key map "\C-c\C-p" 'run-python)
     (define-key map "\C-c\C-s" 'python-shell-send-string)
+    (define-key map "\C-c\C-e" 'python-shell-send-statement)
     (define-key map "\C-c\C-r" 'python-shell-send-region)
     (define-key map "\C-\M-x" 'python-shell-send-defun)
     (define-key map "\C-c\C-c" 'python-shell-send-buffer)
@@ -368,6 +369,8 @@ It returns a file name which can be used directly as 
argument of
          :help "Eval string in inferior Python session"]
         ["Eval buffer" python-shell-send-buffer
          :help "Eval buffer in inferior Python session"]
+        ["Eval statement" python-shell-send-statement
+         :help "Eval statement in inferior Python session"]
         ["Eval region" python-shell-send-region
          :help "Eval region in inferior Python session"]
         ["Eval defun" python-shell-send-defun
@@ -3162,6 +3165,25 @@ process running; defaults to t when called 
interactively."
     (message "Sent: %s..." (match-string 1 original-string))
     (python-shell-send-string string process)))
 
+(defun python-shell-send-statement (&optional send-main msg)
+  "Send the statement at point to inferior Python process.
+The statement is delimited by `python-nav-beginning-of-statement' and
+`python-nav-end-of-statement', but if the region  is active, the text
+in the region is sent instead via `python-shell-send-region'.
+Optional argument SEND-MAIN, if non-nil, means allow execution of code
+inside blocks delimited by \"if __name__ == \\='__main__\\=':\".
+Interactively, SEND-MAIN is the prefix argument.
+Optional argument MSG, if non-nil, forces display of a user-friendly
+message if there's no process running; it defaults to t when called
+interactively."
+  (interactive (list current-prefix-arg t))
+  (if (region-active-p)
+      (python-shell-send-region (region-beginning) (region-end) send-main msg)
+    (python-shell-send-region
+     (save-excursion (python-nav-beginning-of-statement))
+     (save-excursion (python-nav-end-of-statement))
+     send-main msg)))
+
 (defun python-shell-send-buffer (&optional send-main msg)
   "Send the entire buffer to inferior Python process.
 When optional argument SEND-MAIN is non-nil, allow execution of



reply via email to

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