gcv / julia-snail

An Emacs development environment for Julia
GNU General Public License v3.0
231 stars 21 forks source link

Resumbable remote sessions #77

Open MasonProtter opened 2 years ago

MasonProtter commented 2 years ago

I do a lot of work on a remote machine that has very hefty startup costs, and there's at least two different client machines I find myself accessing the remote machine from.

One thing I do to work around this is I will start up a Pluto or Jupyter notebook in a tmux session on the remote machine and then ssh -L into that machine so I can access those notebooks from my local browser. I want to move away from this workflow, and keep more stuff within emacs.

Is there an easy way we can support connecting julia-snail to an already existing Julia session on a remote machine? I've gotten remote stuff working on that machine, but I'll lose my session if I restart the client or switch clients.

gcv commented 2 years ago

I’ve thought about this before. Two moving parts have to be made to work. One is the REPL display and connecting to it. The second is to sync the Emacs state of the Snail connection with the Julia side.

There might be a trick possible where a remote Julia REPL runs under tmux, and reconnects to an existing session. I have not thought about the ssh tunnel + tmux + julia incantation required to pull it off. A better solution is to implement the Julia REPL in Elisp, but that’s a lot of work. In either case, state resync should be approachable once that works.

I won’t have time to work on this feature in the coming months, unfortunately. I can help with ideas and should be able to review PRs if someone wants to tackle this work.

MasonProtter commented 2 years ago

I'm pretty skeptical of the idea of implementing the repl in elisp. Sounds like anything other than a tremendous amount of effort would result in a subpar experience. I suspect that instead we could just log and store information in the JuliaSnail module and then we'd just need emacs to query that module, right?

gcv commented 2 years ago

I don’t know about “tremendous”, but I agree that a REPL reimplementation needs a good level of polish before it’s useful (Pkg and help integration are a must, but don’t seem that daunting to me). SLIME and CIDER do a good job of reimplementing REPLs for Common Lisp and Clojure, though starting from a much lower baseline than Julia. Emacs has a comint-mode from which to start building such things. But yeah, it’ll all take time I don’t have right now.

With luck, it might be simpler than that to sync state. Based on a superficial look at where I expect to find problems, the only place where state has to get managed in a weird way is julia-snail--cache-proc-implicit-file-module for implicit module support.

Because xref and autocomplete rely on Julia-side code, that should work fine, though their caches might have to be force-reset on a reconnect.

If you want to give it a shot, take a look at julia-snail--launch-command. If there’s a good incantation that can either create or connect to a configurable named tmux session, that function can be modified to use it. Once that works, JuliaSnail.start will have to be made smarter (detect that it’s already running or something — I’m not sure off-hand).