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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 38426 in the body.
You can then email your comments to 38426 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Fri, 29 Nov 2019 15:06:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to <lin.sun <at> zoom.us>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 29 Nov 2019 15:06:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

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






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Sun, 08 Dec 2019 06:00:02 GMT) Full text and rfc822 format available.

Message #8 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: <lin.sun <at> zoom.us>
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: Re: bug#38426: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
Date: Sat, 07 Dec 2019 11:45:13 +0200
severity 38426 wishlist
thanks

> From: <lin.sun <at> zoom.us>
> 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(+)

Thanks, but for us to accept a contribution this large we need a
copyright assignment from you.  Would you like to start the legal
paperwork at this time?  If so, I will send you the form to fill and
email.




Severity set to 'wishlist' from 'normal' Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 08 Dec 2019 06:00:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Tue, 10 Dec 2019 02:47:01 GMT) Full text and rfc822 format available.

Message #13 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: LinSun <lin.sun <at> zoom.us>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: "larsi <at> gnus.org" <larsi <at> gnus.org>,
 "38426 <at> debbugs.gnu.org" <38426 <at> debbugs.gnu.org>
Subject: RE: Re: bug#38426: 27.0.50; [PATCH] * python.el: new function
 python-shell-send-statement
Date: Tue, 10 Dec 2019 10:46:02 +0800
[Message part 1 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Tue, 10 Dec 2019 03:27:01 GMT) Full text and rfc822 format available.

Message #16 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: LinSun <lin.sun <at> zoom.us>
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: Re: bug#38426: 27.0.50; [PATCH] * python.el: new function
 python-shell-send-statement
Date: Tue, 10 Dec 2019 05:25:45 +0200
> Date: Tue, 10 Dec 2019 10:46:02 +0800
> From: LinSun <lin.sun <at> zoom.us>
> Cc: "38426 <at> debbugs.gnu.org" <38426 <at> debbugs.gnu.org>, 
> 	"larsi <at> gnus.org" <larsi <at> gnus.org>
> 
> No problem. I’m an Emacs fan, and glad to contribute the code. 

Thanks, I sent the form off-list.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Fri, 13 Dec 2019 02:09:02 GMT) Full text and rfc822 format available.

Message #19 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: <lin.sun <at> zoom.us>
To: "'Eli Zaretskii'" <eliz <at> gnu.org>
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: RE: bug#38426: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
Date: Fri, 13 Dec 2019 10:08:35 +0800
Hi Eli,

> Thanks, I sent the form off-list.
I already finish the contributing assignment process, and got the executed PDF "Sun.1456824.GNU.EMACS.pdf".

What should I do next to continue merging the patch #38426 into the repo please?

Thanks





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Fri, 13 Dec 2019 07:29:01 GMT) Full text and rfc822 format available.

Message #22 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: <lin.sun <at> zoom.us>
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: Re: bug#38426: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
Date: Fri, 13 Dec 2019 09:28:23 +0200
> From: <lin.sun <at> zoom.us>
> Cc: <38426 <at> debbugs.gnu.org>,
> 	<larsi <at> gnus.org>
> Date: Fri, 13 Dec 2019 10:08:35 +0800
> 
> > Thanks, I sent the form off-list.
> I already finish the contributing assignment process, and got the executed PDF "Sun.1456824.GNU.EMACS.pdf".
> 
> What should I do next to continue merging the patch #38426 into the repo please?

Please wait, your patch is in my queue.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Fri, 13 Dec 2019 07:58:02 GMT) Full text and rfc822 format available.

Message #25 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: <lin.sun <at> zoom.us>
To: "'Eli Zaretskii'" <eliz <at> gnu.org>
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: RE: bug#38426: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
Date: Fri, 13 Dec 2019 15:56:51 +0800
> From: Eli Zaretskii <eliz <at> gnu.org> 
> Please wait, your patch is in my queue.
Okay, thank you.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Sat, 14 Dec 2019 12:18:02 GMT) Full text and rfc822 format available.

Message #28 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: lin.sun <at> zoom.us
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: Re: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
Date: Sat, 14 Dec 2019 14:17:16 +0200
> From: <lin.sun <at> zoom.us>
> 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.

Thanks.  A few comments below:

> +(defun python-shell-send-statement (&optional send-main msg)
> +  "Send the statement delimited by `python-nav-beginning-of-statement' and

The first line of a doc string should be a complete sentence, and it
should mention the function's arguments.

> +`python-nav-end-of-statement' to inferior Python process. When optional
                                                           ^^
Our convention is to leave 2 spaces between sentences in documentation
and comments, per US English rules.

> +                                                         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'."

These lines are too long, please wrap them to make them shorter,
preferably no more than 75 characters.

Please also provide a ChangeLog style commit log message, as described
in CONTRIBUTE, and please mention the bug number there.

And finally, this new command needs to be mentioned in NEWS, under
"Python mode".

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Sun, 15 Dec 2019 08:45:01 GMT) Full text and rfc822 format available.

Message #31 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: <lin.sun <at> zoom.us>
To: "'Eli Zaretskii'" <eliz <at> gnu.org>
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: RE: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
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

* 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






Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Sun, 15 Dec 2019 08:54:01 GMT) Full text and rfc822 format available.

Message #34 received at 38426 <at> debbugs.gnu.org (full text, mbox):

From: <lin.sun <at> zoom.us>
To: "'Eli Zaretskii'" <eliz <at> gnu.org>
Cc: larsi <at> gnus.org, 38426 <at> debbugs.gnu.org
Subject: RE: 27.0.50;
 [PATCH] * python.el: new function python-shell-send-statement
Date: Sun, 15 Dec 2019 16:52:51 +0800
Hi Eli,

Thank you for your comments, they're very helpful, I had change the
modifications according your comments.
An individual mail with patch only is send, please check and review it
again. Thanks.

-----Original Message-----
From: Eli Zaretskii <eliz <at> gnu.org> 
Sent: Saturday, December 14, 2019 20:17
To: lin.sun <at> zoom.us
Cc: 38426 <at> debbugs.gnu.org; larsi <at> gnus.org
Subject: Re: 27.0.50; [PATCH] * python.el: new function
python-shell-send-statement

> From: <lin.sun <at> zoom.us>
> 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.

Thanks.  A few comments below:

> +(defun python-shell-send-statement (&optional send-main msg)
> +  "Send the statement delimited by 
> +`python-nav-beginning-of-statement' and

The first line of a doc string should be a complete sentence, and it should
mention the function's arguments.

> +`python-nav-end-of-statement' to inferior Python process. When 
> +optional
                                                           ^^ Our convention
is to leave 2 spaces between sentences in documentation and comments, per US
English rules.

> +                                                         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'."

These lines are too long, please wrap them to make them shorter, preferably
no more than 75 characters.

Please also provide a ChangeLog style commit log message, as described in
CONTRIBUTE, and please mention the bug number there.

And finally, this new command needs to be mentioned in NEWS, under "Python
mode".

Thanks.





Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 21 Dec 2019 09:20:02 GMT) Full text and rfc822 format available.

Notification sent to <lin.sun <at> zoom.us>:
bug acknowledged by developer. (Sat, 21 Dec 2019 09:20:02 GMT) Full text and rfc822 format available.

Message #39 received at 38426-done <at> debbugs.gnu.org (full text, mbox):

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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#38426; Package emacs. (Mon, 23 Dec 2019 01:30:02 GMT) Full text and rfc822 format available.

Message #42 received at 38426-done <at> debbugs.gnu.org (full text, mbox):

From: <lin.sun <at> zoom.us>
To: "'Eli Zaretskii'" <eliz <at> gnu.org>
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: Mon, 23 Dec 2019 09:29:35 +0800
Hi Eli,

Thank you so much.  And I'll check the actual commit with my local to avoid
the gotchas. Thanks again.

Best Regards
Lin Sun
-----Original Message-----
From: Eli Zaretskii <eliz <at> gnu.org> 
Sent: Saturday, December 21, 2019 17:19
To: lin.sun <at> zoom.us
Cc: 38426-done <at> debbugs.gnu.org; larsi <at> gnus.org
Subject: Re: 27.0.50; [PATCH] * python.el: new function
python-shell-send-statement

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.





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 20 Jan 2020 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 98 days ago.

Previous Next


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