unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: <lin.sun@zoom.us>
To: "'Eli Zaretskii'" <eliz@gnu.org>
Cc: larsi@gnus.org, 38426@debbugs.gnu.org
Subject: bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
Date: Sun, 15 Dec 2019 16:43:58 +0800	[thread overview]
Message-ID: <001001d5b323$cc784900$6568db00$@zoom.us> (raw)
In-Reply-To: <834ky36r03.fsf@gnu.org>

From cbdd2e034fcc438e4c6464f96667a74627d7426b Mon Sep 17 00:00:00 2001
From: "lin.sun" <lin.sun@zoom.us>
Date: Fri, 29 Nov 2019 03:10:12 -0500
Subject: [PATCH] Add new function `python-shell-send-statement' in python.el

* python.el: Add new function `python-shell-send-statement' and bind
to key "C-c C-e" for sending statement under cursor to inferior Python
process.   (Bug#38426)
---
 etc/NEWS                 |  4 ++++
 lisp/progmodes/python.el | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 61d5115..36cf8d2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1059,6 +1059,10 @@ located and whether GnuPG's option '--homedir' is
used or not.
 It controls the depth of indentation of arguments inside multi-line
 function signatures.
 
+*** The new function 'python-shell-send-region' has been added.
+It send the statement delimited by `python-nav-beginning-of-statement' and
+`python-nav-end-of-statement' to inferior Python process.
+
 ** Tramp
 
 *** The method part of remote file names is mandatory now.
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 8e7d9f2..f53a92f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -318,6 +318,7 @@ python-mode-map
     ;; 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)
@@ -357,6 +358,8 @@ python-mode-map
          :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
@@ -3123,6 +3126,24 @@ python-shell-send-region
     (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'. When optional argument SEND-MAIN is non-nil,
+allow execution of code inside inside blocks delimited by \"if __name__==
+\\='__main__\\=':\". When called interactively SEND-MAIN defaults to nil,
+unless it's called with prefix argument. When optional argument MSG is
+non-nil, forces display of a user-friendly message if there's no process
+running; default to t when called interactively. If there is region be
+activated, it present as `python-shell-send-region'."
+  (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
-- 
2.2.0







  reply	other threads:[~2019-12-15  8:43 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29  8:40 bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement lin.sun
2019-12-07  9:45 ` Eli Zaretskii
2019-12-10  2:46 ` bug#38426: " LinSun
2019-12-10  3:25   ` Eli Zaretskii
2019-12-13  2:08     ` lin.sun
2019-12-13  7:28       ` Eli Zaretskii
2019-12-13  7:56         ` lin.sun
2019-12-14 12:17 ` Eli Zaretskii
2019-12-15  8:43   ` lin.sun [this message]
2019-12-21  9:19     ` Eli Zaretskii
2019-12-23  1:29       ` lin.sun
2019-12-15  8:52   ` lin.sun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001001d5b323$cc784900$6568db00$@zoom.us' \
    --to=lin.sun@zoom.us \
    --cc=38426@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).