Send emacs buffer to arbitrary Python process

I like the python-send-buffer command, however I very often use Python built-in to applications, or run Python through a custom package management system (to run Python with certain dependencies). In other words, I can't just run "python" and get a useful Python instance (what python-send-buffer relies on)

I would like to achieve:

  • in any Python interpreter (or application that allows you to evaluate Python code), import the magic_emacs_python_server.py module (add sys.path if necessary)
  • In emacs, run magic-emacs-python-send-buffer

This will evaluate the buffer in the remote Python instance.

It seems like it should be pretty simple - the Python module listens on the socket in the stream. It is evaluated in the main thread and returns repr() result (or, possibly, captures stdout / stderr, or, possibly, both). The emacs module simply sends the text to the socket, waits for the response line, and displays it in the buffer.

It sounds so simple, something like this should already exist ... IPython has ipy_vimserver , but it is not. There is also swank , although it seems very Lisp-specific, there is a Javascript backend that is very similar to what I want .. but the search finds almost nothing, except for some vague (possibly true) statements that SLIME does not work well with non-w131> languages

In short:

  • Is there a project to send code from an emacs buffer to an existing Python process?
  • If not, how would you recommend writing such a thing (you are not very familiar with elisp) - SWANK? IPython server code? Simple TCP server from scratch?
+4
source share
2 answers

comint provides most of the infrastructure for such things. There are tons of good examples out there like this or this.

It allows you to run a command, provides comint-send-string stuff to easily implement commands like send-region .

dbr / remoterepl on Github is a rough proof of what I described in the question.

It does not have any varnish, but it basically works - you import the replify.py module in the target interpreter, and then evaluate emacs-remote-repl.el after fixing the stupid emacs-remote-repl.el path to client.py

+2
source

Doesn't shell-command give you what you are looking for? You can write a wrapper script or adjust #! accordingly #! and sys.path .

+1
source

Source: https://habr.com/ru/post/1337318/


All Articles