unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
@ 2019-11-29  8:40 lin.sun
  2019-12-07  9:45 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: lin.sun @ 2019-11-29  8:40 UTC (permalink / raw)
  To: 38426, larsi

From 61db0e91094297ddca302eaf691cf5b4ff82ebf6 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] * 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







^ permalink raw reply related	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  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-14 12:17 ` Eli Zaretskii
  2 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2019-12-07  9:45 UTC (permalink / raw)
  To: lin.sun; +Cc: larsi, 38426

severity 38426 wishlist
thanks

> From: <lin.sun@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@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: Re: bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  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 ` LinSun
  2019-12-10  3:25   ` Eli Zaretskii
  2019-12-14 12:17 ` Eli Zaretskii
  2 siblings, 1 reply; 12+ messages in thread
From: LinSun @ 2019-12-10  2:46 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi@gnus.org, 38426@debbugs.gnu.org

[-- Attachment #1: Type: text/html, Size: 3578 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-10  2:46 ` bug#38426: " LinSun
@ 2019-12-10  3:25   ` Eli Zaretskii
  2019-12-13  2:08     ` lin.sun
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2019-12-10  3:25 UTC (permalink / raw)
  To: LinSun; +Cc: larsi, 38426

> Date: Tue, 10 Dec 2019 10:46:02 +0800
> From: LinSun <lin.sun@zoom.us>
> Cc: "38426@debbugs.gnu.org" <38426@debbugs.gnu.org>, 
> 	"larsi@gnus.org" <larsi@gnus.org>
> 
> No problem. I’m an Emacs fan, and glad to contribute the code. 

Thanks, I sent the form off-list.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-10  3:25   ` Eli Zaretskii
@ 2019-12-13  2:08     ` lin.sun
  2019-12-13  7:28       ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: lin.sun @ 2019-12-13  2:08 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: larsi, 38426

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






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-13  2:08     ` lin.sun
@ 2019-12-13  7:28       ` Eli Zaretskii
  2019-12-13  7:56         ` lin.sun
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2019-12-13  7:28 UTC (permalink / raw)
  To: lin.sun; +Cc: larsi, 38426

> From: <lin.sun@zoom.us>
> Cc: <38426@debbugs.gnu.org>,
> 	<larsi@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-13  7:28       ` Eli Zaretskii
@ 2019-12-13  7:56         ` lin.sun
  0 siblings, 0 replies; 12+ messages in thread
From: lin.sun @ 2019-12-13  7:56 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: larsi, 38426

> From: Eli Zaretskii <eliz@gnu.org> 
> Please wait, your patch is in my queue.
Okay, thank you.






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  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-14 12:17 ` Eli Zaretskii
  2019-12-15  8:43   ` lin.sun
  2019-12-15  8:52   ` lin.sun
  2 siblings, 2 replies; 12+ messages in thread
From: Eli Zaretskii @ 2019-12-14 12:17 UTC (permalink / raw)
  To: lin.sun; +Cc: larsi, 38426

> From: <lin.sun@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@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-14 12:17 ` Eli Zaretskii
@ 2019-12-15  8:43   ` lin.sun
  2019-12-21  9:19     ` Eli Zaretskii
  2019-12-15  8:52   ` lin.sun
  1 sibling, 1 reply; 12+ messages in thread
From: lin.sun @ 2019-12-15  8:43 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: larsi, 38426

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







^ permalink raw reply related	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-14 12:17 ` Eli Zaretskii
  2019-12-15  8:43   ` lin.sun
@ 2019-12-15  8:52   ` lin.sun
  1 sibling, 0 replies; 12+ messages in thread
From: lin.sun @ 2019-12-15  8:52 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: larsi, 38426

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@gnu.org> 
Sent: Saturday, December 14, 2019 20:17
To: lin.sun@zoom.us
Cc: 38426@debbugs.gnu.org; larsi@gnus.org
Subject: Re: 27.0.50; [PATCH] * python.el: new function
python-shell-send-statement

> From: <lin.sun@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@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.






^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-15  8:43   ` lin.sun
@ 2019-12-21  9:19     ` Eli Zaretskii
  2019-12-23  1:29       ` lin.sun
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2019-12-21  9:19 UTC (permalink / raw)
  To: lin.sun; +Cc: larsi, 38426-done

> From: <lin.sun@zoom.us>
> Cc: <38426@debbugs.gnu.org>,
> 	<larsi@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@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.





^ permalink raw reply	[flat|nested] 12+ messages in thread

* bug#38426: 27.0.50; [PATCH] * python.el: new function python-shell-send-statement
  2019-12-21  9:19     ` Eli Zaretskii
@ 2019-12-23  1:29       ` lin.sun
  0 siblings, 0 replies; 12+ messages in thread
From: lin.sun @ 2019-12-23  1:29 UTC (permalink / raw)
  To: 'Eli Zaretskii'; +Cc: larsi, 38426-done

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@gnu.org> 
Sent: Saturday, December 21, 2019 17:19
To: lin.sun@zoom.us
Cc: 38426-done@debbugs.gnu.org; larsi@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.






^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-12-23  1:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2019-12-21  9:19     ` Eli Zaretskii
2019-12-23  1:29       ` lin.sun
2019-12-15  8:52   ` lin.sun

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).