unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* python-shell-send-string changes break continued Python commands
@ 2023-02-11 14:39 JD Smith
  0 siblings, 0 replies; only message in thread
From: JD Smith @ 2023-02-11 14:39 UTC (permalink / raw)
  To: emacs-devel


I’ve noticed some breaking changes to the function python-shell-send-string in the recent past, related to continued commands.  

Example of a continued Python command:

>>> for i in range(12):
… 

I maintain a package called python-mls [1] which enables sending multi-line statements to the inferior python process.  It works by noticing the “…” continuation prompt python provides on continued commands, interrupting, and allowing Emacs to format and send its own multiline command (check the link for a GIF of it in action).

Unfortunately, the new logic of `python-shell-send-string’ defeats all continued commands, since it wraps even simple single line statements like “if True:” in the helper function __PYTHON_EL_eval().  This helper will attempt to compile the statement, breaking “continued commands” as above.  

Single-line commands do not need any special treatment when sending to the python interpreter, and are likely the most common type of command sent.

To reenable continued command functionality as well as for efficiency, simply using `comint-send-string' for single-line command input, as before, would be a suitable fix.   Pseudo-code:

(if (string-match ".\n+." string)   ;Multiline.
    (new-PYTHON_EL_eval_functionality…) 
  (comint-send-string process string))

I’m happy to put a patch together if this sounds sensible. 

[1] https://github.com/jdtsmith/python-mls


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-11 14:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-11 14:39 python-shell-send-string changes break continued Python commands JD Smith

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