* Python mode, suggestion for command @ 2023-07-29 22:08 chiel 2023-07-30 5:26 ` Eli Zaretskii 0 siblings, 1 reply; 7+ messages in thread From: chiel @ 2023-07-29 22:08 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 716 bytes --] Dear python-mode maintainers, I'd like to suggest adding the following command to python.el, and binding it to C-<return> by default. I'd love to hear your thoughts. (defun python-shell-send-paragraph (&optional send-main msg) "Send all lines of code between two white lines to inferior Python process. SEND-MAIN defaults to nil and MSG to t. See `python-shell-send-region for more information. Interactively, SEND-MAIN is the prefix argument" (interactive "Pi") (python-shell-send-region (or (save-excursion (re-search-backward "^[:blank:]*$" nil t)) (point-min)) (or (save-excursion (re-search-forward "^[:blank:]*$" nil t)) (point-max)) send-main (not msg) t)) With kind regards. Machiel Kroon [-- Attachment #2: Type: text/html, Size: 946 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python mode, suggestion for command 2023-07-29 22:08 Python mode, suggestion for command chiel @ 2023-07-30 5:26 ` Eli Zaretskii 2023-07-30 6:29 ` Eshel Yaron 0 siblings, 1 reply; 7+ messages in thread From: Eli Zaretskii @ 2023-07-30 5:26 UTC (permalink / raw) To: chiel, kobarity, Augusto Stoffel; +Cc: emacs-devel > From: chiel <machiel.kroon@gmail.com> > Date: Sun, 30 Jul 2023 00:08:50 +0200 > > Dear python-mode maintainers, > > I'd like to suggest adding the following command to python.el, > and binding it to C-<return> by default. I'd love to hear your thoughts. > > (defun python-shell-send-paragraph (&optional send-main msg) > "Send all lines of code between two white lines to inferior > Python process. SEND-MAIN defaults to nil and MSG to t. > See `python-shell-send-region for more information. > Interactively, SEND-MAIN is the prefix argument" > (interactive "Pi") > (python-shell-send-region > (or (save-excursion (re-search-backward "^[:blank:]*$" nil t)) > (point-min)) > (or (save-excursion (re-search-forward "^[:blank:]*$" nil t)) > (point-max)) > send-main (not msg) t)) Thanks. Adding the relevant developers to the discussion. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python mode, suggestion for command 2023-07-30 5:26 ` Eli Zaretskii @ 2023-07-30 6:29 ` Eshel Yaron 2023-07-30 6:35 ` chiel 0 siblings, 1 reply; 7+ messages in thread From: Eshel Yaron @ 2023-07-30 6:29 UTC (permalink / raw) To: Eli Zaretskii; +Cc: chiel, kobarity, Augusto Stoffel, emacs-devel Hi there, >> Dear python-mode maintainers, I'm not a `python-mode` maintainer, just a user, but here are my two cents: >> I'd like to suggest adding the following command to python.el, >> and binding it to C-<return> by default. I'd love to hear your >> thoughts. Regardless of the command, I'd consider picking another binding (perhaps along side this one) since some users (including yours truly) are used to press `C-m` instead of the `<return>` key. >> (defun python-shell-send-paragraph (&optional send-main msg) >> "Send all lines of code between two white lines to inferior >> Python process. SEND-MAIN defaults to nil and MSG to t. >> See `python-shell-send-region for more information. I'd say something like "SEND-MAIN and MSG have the same meaning as in `python-shell-send-paragraph', which see." to make this more obvious. >> Interactively, SEND-MAIN is the prefix argument" >> (interactive "Pi") This is probably supposed to be `(interactive "P\ni")`? >> (python-shell-send-region >> (or (save-excursion (re-search-backward "^[:blank:]*$" nil t)) (point-min)) >> (or (save-excursion (re-search-forward "^[:blank:]*$" nil t)) (point-max)) This method of finding the boundaries of the paragraph at point seems slightly ad-hoc and fragile, I wonder what happens if there's a blank line in the middle of a multi-line string? >> send-main (not msg) t)) Just a couple of thoughts :) Best, -- Eshel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python mode, suggestion for command 2023-07-30 6:29 ` Eshel Yaron @ 2023-07-30 6:35 ` chiel 2023-07-30 12:45 ` chiel 0 siblings, 1 reply; 7+ messages in thread From: chiel @ 2023-07-30 6:35 UTC (permalink / raw) To: Eshel Yaron; +Cc: Eli Zaretskii, kobarity, Augusto Stoffel, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1822 bytes --] Right, I hadn't thought about empty lines in any kind of statement. I guess I got too excited after learning a little bit of lisp, and thinking the function was so beautiful. I'll think about making it more robust. Thanks for the response! On Sun, 30 Jul 2023, 08:29 Eshel Yaron, <me@eshelyaron.com> wrote: > Hi there, > > >> Dear python-mode maintainers, > > I'm not a `python-mode` maintainer, just a user, but here are my two cents: > > >> I'd like to suggest adding the following command to python.el, > >> and binding it to C-<return> by default. I'd love to hear your > >> thoughts. > > Regardless of the command, I'd consider picking another binding > (perhaps along side this one) since some users (including yours truly) > are used to press `C-m` instead of the `<return>` key. > > >> (defun python-shell-send-paragraph (&optional send-main msg) > >> "Send all lines of code between two white lines to inferior > >> Python process. SEND-MAIN defaults to nil and MSG to t. > >> See `python-shell-send-region for more information. > > I'd say something like "SEND-MAIN and MSG have the same meaning as in > `python-shell-send-paragraph', which see." to make this more obvious. > > >> Interactively, SEND-MAIN is the prefix argument" > >> (interactive "Pi") > > This is probably supposed to be `(interactive "P\ni")`? > > >> (python-shell-send-region > >> (or (save-excursion (re-search-backward "^[:blank:]*$" nil t)) > (point-min)) > >> (or (save-excursion (re-search-forward "^[:blank:]*$" nil t)) > (point-max)) > > This method of finding the boundaries of the paragraph at point seems > slightly ad-hoc and fragile, I wonder what happens if there's a blank > line in the middle of a multi-line string? > > >> send-main (not msg) t)) > > Just a couple of thoughts :) > > Best, > > -- > Eshel > [-- Attachment #2: Type: text/html, Size: 2428 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python mode, suggestion for command 2023-07-30 6:35 ` chiel @ 2023-07-30 12:45 ` chiel 2023-07-31 15:52 ` kobarity 0 siblings, 1 reply; 7+ messages in thread From: chiel @ 2023-07-30 12:45 UTC (permalink / raw) To: Eshel Yaron; +Cc: Eli Zaretskii, kobarity, Augusto Stoffel, emacs-devel [-- Attachment #1: Type: text/plain, Size: 2848 bytes --] Update: I've been using the following this afternoon and haven't run into any issues so far. However, it looks a bit messy. (defun python-shell-send-paragraph (&optional send-main msg) "Send blocks between two white lines to inferior Python process. See `python-shell-send-region' for SEND-MAIN and MSG." (interactive "P\ni") (let ((start (save-excursion (if (re-search-backward "^[:blank:]*$" nil t) (let ((pos (point))) (python-nav-end-of-block) (if (< (point) pos) pos (progn (python-nav-beginning-of-block) (point)))) (point-min)))) (end (save-excursion (if (re-search-forward "^[:blank:]*$" nil t) (progn (python-nav-end-of-block) (point)) (point-max))))) (python-shell-send-region start end send-main (not msg) nil))) Op zo 30 jul 2023 om 08:35 schreef chiel <machiel.kroon@gmail.com>: > Right, I hadn't thought about empty lines in any kind of statement. I > guess I got too excited after learning a little bit of lisp, and thinking > the function was so beautiful. I'll think about making it more robust. > Thanks for the response! > > On Sun, 30 Jul 2023, 08:29 Eshel Yaron, <me@eshelyaron.com> wrote: > >> Hi there, >> >> >> Dear python-mode maintainers, >> >> I'm not a `python-mode` maintainer, just a user, but here are my two >> cents: >> >> >> I'd like to suggest adding the following command to python.el, >> >> and binding it to C-<return> by default. I'd love to hear your >> >> thoughts. >> >> Regardless of the command, I'd consider picking another binding >> (perhaps along side this one) since some users (including yours truly) >> are used to press `C-m` instead of the `<return>` key. >> >> >> (defun python-shell-send-paragraph (&optional send-main msg) >> >> "Send all lines of code between two white lines to inferior >> >> Python process. SEND-MAIN defaults to nil and MSG to t. >> >> See `python-shell-send-region for more information. >> >> I'd say something like "SEND-MAIN and MSG have the same meaning as in >> `python-shell-send-paragraph', which see." to make this more obvious. >> >> >> Interactively, SEND-MAIN is the prefix argument" >> >> (interactive "Pi") >> >> This is probably supposed to be `(interactive "P\ni")`? >> >> >> (python-shell-send-region >> >> (or (save-excursion (re-search-backward "^[:blank:]*$" nil t)) >> (point-min)) >> >> (or (save-excursion (re-search-forward "^[:blank:]*$" nil t)) >> (point-max)) >> >> This method of finding the boundaries of the paragraph at point seems >> slightly ad-hoc and fragile, I wonder what happens if there's a blank >> line in the middle of a multi-line string? >> >> >> send-main (not msg) t)) >> >> Just a couple of thoughts :) >> >> Best, >> >> -- >> Eshel >> > [-- Attachment #2: Type: text/html, Size: 3948 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python mode, suggestion for command 2023-07-30 12:45 ` chiel @ 2023-07-31 15:52 ` kobarity 2023-07-31 17:08 ` Matthias Meulien 0 siblings, 1 reply; 7+ messages in thread From: kobarity @ 2023-07-31 15:52 UTC (permalink / raw) To: chiel; +Cc: Eshel Yaron, Eli Zaretskii, Augusto Stoffel, emacs-devel chiel wrote: > Update: I've been using the following this afternoon and haven't run into any issues so far. However, it looks a bit > messy. > > (defun python-shell-send-paragraph (&optional send-main msg) > "Send blocks between two white lines to inferior Python process. > See `python-shell-send-region' for SEND-MAIN and MSG." > (interactive "P\ni") > (let ((start > (save-excursion > (if (re-search-backward "^[:blank:]*$" nil t) > (let ((pos (point))) > (python-nav-end-of-block) > (if (< (point) pos) pos > (progn (python-nav-beginning-of-block) (point)))) > (point-min)))) > (end > (save-excursion > (if (re-search-forward "^[:blank:]*$" nil t) > (progn (python-nav-end-of-block) (point)) > (point-max))))) > (python-shell-send-region start end send-main (not msg) nil))) > >> I'd like to suggest adding the following command to python.el, >> and binding it to C-<return> by default. I'd love to hear your thoughts. Hi, it would be better to clarify what a paragraph in Python-mode is and explain why it would be useful to be able to send it to Python shell. For example, is the line "b = 2" a stand-alone paragraph? def func(): a = 1 b = 2 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Python mode, suggestion for command 2023-07-31 15:52 ` kobarity @ 2023-07-31 17:08 ` Matthias Meulien 0 siblings, 0 replies; 7+ messages in thread From: Matthias Meulien @ 2023-07-31 17:08 UTC (permalink / raw) To: kobarity; +Cc: chiel, Eshel Yaron, Eli Zaretskii, Augusto Stoffel, emacs-devel kobarity <kobarity@gmail.com> writes: > Hi, it would be better to clarify what a paragraph in Python-mode is > and explain why it would be useful to be able to send it to Python > shell. For example, is the line "b = 2" a stand-alone paragraph? > > def func(): > a = 1 > > b = 2 > It's not clear to me how the proposed function differs from M-h followed by C-c C-r (mark-paragraph then python-shell-region). When developping in Python, I sometime use this sequence but I wouldn't learn a new key binding for this. Still, it's only a user pov, I am not a python-mode maintainer. -- Matthias ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-07-31 17:08 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-07-29 22:08 Python mode, suggestion for command chiel 2023-07-30 5:26 ` Eli Zaretskii 2023-07-30 6:29 ` Eshel Yaron 2023-07-30 6:35 ` chiel 2023-07-30 12:45 ` chiel 2023-07-31 15:52 ` kobarity 2023-07-31 17:08 ` Matthias Meulien
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).