From: chiel <machiel.kroon@gmail.com>
To: Eshel Yaron <me@eshelyaron.com>
Cc: Eli Zaretskii <eliz@gnu.org>, kobarity <kobarity@gmail.com>,
Augusto Stoffel <arstoffel@gmail.com>,
emacs-devel@gnu.org
Subject: Re: Python mode, suggestion for command
Date: Sun, 30 Jul 2023 14:45:03 +0200 [thread overview]
Message-ID: <CAPZr=9FGq_qxU9SDgT3Yxixib1skUJ7agxd3LNkQmPpE1A-Vqw@mail.gmail.com> (raw)
In-Reply-To: <CAPZr=9GwENDTKih8yR37etH_iTypTwc2vC6KukdV++9JBA37NA@mail.gmail.com>
[-- 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 --]
next prev parent reply other threads:[~2023-07-30 12:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2023-07-31 15:52 ` kobarity
2023-07-31 17:08 ` Matthias Meulien
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='CAPZr=9FGq_qxU9SDgT3Yxixib1skUJ7agxd3LNkQmPpE1A-Vqw@mail.gmail.com' \
--to=machiel.kroon@gmail.com \
--cc=arstoffel@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=kobarity@gmail.com \
--cc=me@eshelyaron.com \
/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).