[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Python mode, suggestion for command

From: chiel
Subject: Re: Python mode, suggestion for command
Date: Sun, 30 Jul 2023 14:45:03 +0200

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
           (if (re-search-backward "^[:blank:]*$" nil t)
               (let ((pos (point)))
                 (if (< (point) pos) pos
                   (progn (python-nav-beginning-of-block) (point))))
           (if (re-search-forward  "^[:blank:]*$" nil t)
               (progn (python-nav-end-of-block) (point))
    (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 :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]