GNU bug report logs - #38426
27.0.50; [PATCH] * python.el: new function python-shell-send-statement

Previous Next

Package: emacs;

Reported by: <lin.sun <at> zoom.us>

Date: Fri, 29 Nov 2019 15:06:01 UTC

Severity: wishlist

Tags: patch

Found in version 27.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: <lin.sun <at> zoom.us>
Subject: bug#38426: closed (Re: 27.0.50; [PATCH] * python.el: new function
 python-shell-send-statement)
Date: Sat, 21 Dec 2019 09:20:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 38426 <at> debbugs.gnu.org.

-- 
38426: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=38426
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
To: lin.sun <at> zoom.us
Cc: larsi <at> gnus.org, 38426-done <at> debbugs.gnu.org
Subject: Re: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
Date: Sat, 21 Dec 2019 11:19:00 +0200
> From: <lin.sun <at> zoom.us>
> Cc: <38426 <at> debbugs.gnu.org>,
> 	<larsi <at> gnus.org>
> Date: Sun, 15 Dec 2019 16:43:58 +0800
> 
> >From cbdd2e034fcc438e4c6464f96667a74627d7426b Mon Sep 17 00:00:00 2001
> From: "lin.sun" <lin.sun <at> zoom.us>
> Date: Fri, 29 Nov 2019 03:10:12 -0500
> Subject: [PATCH] Add new function `python-shell-send-statement' in python.el

Thanks, I pushed this, and I'm closing the bug report.

A few minor tweaks were still needed, please see the actual commit for
what I needed to change, and try to avoid these gotchas in the future.

Also, the patch didn't apply automatically due to some lines being
wrapped by your email client; please either change your MUA or send
patches as attachments in the future.

[Message part 3 (message/rfc822, inline)]
From: <lin.sun <at> zoom.us>
To: <bug-gnu-emacs <at> gnu.org>,
	"'Lars Ingebrigtsen'" <larsi <at> gnus.org>
Subject: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
Date: Fri, 29 Nov 2019 16:40:55 +0800
From 61db0e91094297ddca302eaf691cf5b4ff82ebf6 Mon Sep 17 00:00:00 2001
From: "lin.sun" <lin.sun <at> zoom.us>
Date: Fri, 29 Nov 2019 03:10:12 -0500
Subject: [PATCH] * python.el: new function python-shell-send-statement

Add new function `python-shell-send-statement' and bind to key "C-c
C-e" for sending statement under cursor to inferior Python process.
---
 lisp/progmodes/python.el | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 8e7d9f2..24216af 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,23 @@ 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 delimited by `python-nav-beginning-of-statement' and
+`python-nav-end-of-statement' to inferior Python process. When optional
+argument SEND-MAIN is non-nil, allow execution of code 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





This bug report was last modified 5 years and 149 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.