jorgenschaefer/elpy

How to convert shell to python shell?

Opened this issue · 2 comments

Hi
I would like to run python on a shell buffer and then convert this shell to a python buffer so I can use elpy with it.
Essentially I'm looking for something equivalent to ess-remote for R where you can can convert a shell buffer running R into an R inferior.

By the way, the reason I want to do this is that I want to run python inside a screen session.

So far the best I have is to add the python-shell-eval-setup-code and python-shell-eval-file-setup-code and change the name of the buffer. This kind of work but sending a line to the inferior is super slow. takes several seconds so something is not right. But I don't know what other variables we should be setting.

(defun python-remote()
  (interactive)
  "convert python running on a shell into an python inferior so you can use elpy"
  (end-of-buffer)
  (insert python-shell-eval-setup-code)
  (comint-send-input)
  (comint-send-input)
  (end-of-buffer)
  (insert python-shell-eval-file-setup-code)
  (comint-send-input)
  (comint-send-input)
  (end-of-buffer)
  (inferior-python-mode)
  )

Not sure I understand, but there is a built in command run-python that will open up a python shell. Having elpy running a pyhton shell (from what I remember) isn't suitable b/c of lag/issues that have come up (again, my memory is fuzzy on this).

If you need to customize shell things, they're available via python-shell-* variables.

I will be working on a remote machine. I want to start a shell, and run screen on it so it becomes persistent. Then I want to run python on that shell.

This way in the future when I reopen emacs I can connect to the remote server, open a shell, reattach to the screen and I will be back to the python session.

I don't see why it wold not be possible to convert the shell to a python inferior just like the one generated by run-python. I just don't know what variables need to be set and to what.