jackkamm / ob-reticulate

GNU General Public License v3.0
4 stars 1 forks source link

support for reticulate::repl_python? #1

Open fkgruber opened 8 months ago

fkgruber commented 8 months ago

Hello, Thank you for putting together this package. Very useful.

It would be nice to be able to enter the interactive python interpreter with reticulate::repl_python, go into python edit mode (C-c ') and recognize the R buffer as a python inferior so we can interact with it with with elpy commands like elpy-shell-send-statement and so on.

Do yo have any insights on how to achieve this? thanks FKG

fkgruber commented 8 months ago

So far the closest I have gotten is to define the variables in python-shell-eval-setup-code and python-shell-eval-file-setup-code and change the buffer to inferior-python-mode. This lets you interact (although for reason it behave really slow)

The problem is that when I exit it still thinks you are in python. I have to manually change to inferior-ess-mode. Could this be automated.Can inferior-ess-mode be called when you do exit?

Perhaps when you do C-c ' in ob-reticulate mode on a python block we can activate teh repl_python and those setup codes and when we exit we can exit it and activate inferior-ess-mode

jackkamm commented 8 months ago

I've also thought that it would be great to have this feature but never looked into implementing it. I was a bit pessimistic because switching major modes clears buffer-local variables/hooks which can cause problems. I had thought it might be easier to use a separate buffer for the Python interaction (though I hadn't looked into implementing that either).

So far the closest I have gotten is to define the variables in python-shell-eval-setup-code and python-shell-eval-file-setup-code and change the buffer to inferior-python-mode. This lets you interact (although for reason it behave really slow)

The problem is that when I exit it still thinks you are in python. I have to manually change to inferior-ess-mode.

Actually you already got further than I would have expected to be easily possible. Could you share your setup/code?

Could this be automated.Can inferior-ess-mode be called when you do exit?

Easier solution would be to have an emacs command/keybind that sends exit to the repl and then changes mode. Monitoring the repl output for the exit command is also possible but more work and error-prone.

And yes also your idea to link this to C-c ' is also a good one

fkgruber commented 8 months ago

Hi, I think I got it working I made a repository with a series of R python and orgmode utilities that I've been developing. I added support to ob-reticulate. See the test.org https://github.com/fkgruber/r_python_orgmode_utils

It will automatically run repl_python() when you go into a python edit src window and will activate inferior-python-mode. When you exit is will exit the repl and activate inferior-ess-r-mode as well as set some necessary variables.

Seems to be working.