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 : > 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, 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- 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 `` 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 >> >