tpapp / julia-repl

Run an inferior Julia REPL in a terminal inside Emacs
Other
171 stars 35 forks source link

[WIP] add a comint-based backend for the Julia REPL #51

Closed dellison closed 3 years ago

dellison commented 5 years ago

See issue #26

I'm happy to say that this turned out to be less effort than I was expecting!

My basic approach here is to try isolate the term-specific stuff from the rest of the package, and then reimplement that functionality with comint. There's a new custom setting julia-repl-buffer-backend that can either be 'term (the default) or 'comint, and the appropriate backend for the REPL buffer is used accordingly.

A couple notes:

I've marked this as a work-in-progress because I think it probably needs a little more work before it's ready to be merged (if you do decide you want to merge it, that is). I haven't really used julia-repl all that much, so I thought it would be good to get some feedback early.

I'm not at all in a big hurry to get this merged, so please feel free to take your time reviewing it. If you want to try it out, I would especially appreciate to see use cases where the term implementation does something better than the comint version so that I can ideally bring it up to feature parity (but any other feedback you have about other things or just in general would be great too, of course).

Thanks! :)

tpapp commented 5 years ago

Thanks for this PR and #52. I am very busy now and may not get to review this this week, though I will do my best. I appreciate your patience.

dellison commented 5 years ago

Not a problem at all! Take all the time you need.

tpapp commented 5 years ago

Thank you very much for this PR. I am testing it now, and I find it is very nice, I find the string filtering a nice solution.

That said, I am worried about the code duplication becoming a burden in the long run. I am wondering if there would be a more minimal way to implement this, which I need to think about. Specifically (I am not asking you to do this, just thinking about it), would it make sense to switch a running julia process back and forth between comint and term modes? this could be advantageous, especially if one could toggle it with a keybinding, as it would allow the smooth experience of comint (no messed up terminals etc) yet switch back to terminal mode for those processes that require it. The only thing preventing this would be the fact that the terminal type is fixed (AFAIK) when Julia starts up. However, if it works, we could make the backend buffer-local for the inferior buffer.

I find commit exciting because it would also enable us to write commands to the Julia process, and optionally parse the output. This could make editor messages like #52 or package activation not echo in the prompt (potentially invisible), allow us to start up a LanguageServer process, etc.

I ask for your kind patience while I think about this. I will eventually merge the contents of this PR in some form.

dellison commented 5 years ago

You're welcome! It may surprise you, but I've actually been really enjoying working on this :)

I am worried about the code duplication becoming a burden in the long run. I am wondering if there would be a more minimal way to implement this, which I need to think about.

Yes, I totally agree. I've been thinking of this branch as sort of a proof-of-concept or prototype implementation, just to show that it's possible to get a more "emacs-y" Julia repl buffer that still keeps a lot (potentially all, given enough effort and elisp) of the great features in Julia's built-in terminal interface. Now that it's useable, I think it makes a lot of sense to take a step back and think carefully about how this relates to the project's longer-term goals, and then probably rework things based on those ideas.

Specifically (I am not asking you to do this, just thinking about it), would it make sense to switch a running julia process back and forth between comint and term modes?

This is an interesting idea! As far as I know, the only "entrypoint" into comint is make-comint-in-buffer, which takes a program argument that could be either (from the version 26.1 docstring):

- a string, denoting an executable program to create via
  ‘start-file-process’
- a cons pair of the form (HOST . SERVICE), denoting a TCP
  connection to be opened via ‘open-network-stream’
- nil, denoting a newly-allocated pty.

So it sounds like attaching to an already-running process should be possible to do with comint, through the second option. Beyond that, I'm not really sure. I don't know as much about term.

Anyway, yeah, there's definitely a lot to think about here. Of course, in the meantime, please do feel free to let me know if there are any changes that you'd like to see, or anything else. :)

nverno commented 5 years ago

An unsolicited idea: You could conditionally bind the mode changing keys to only be active when immediately following the comint prompt using a menu filter, eg. conditonal bindings.

dellison commented 5 years ago

Cool, thanks @nverno. I'll look into using a similar macro for those keybindings and see if I like it better.

tecosaur commented 3 years ago

This sounds like it's rather promising, @dellison I can't see why you closed this PR?

dellison commented 2 years ago

@tecosaur Sorry for the late reply! As I remember it, I wasn't using julia-repl myself anymore and was no longer keeping the PR up to date. Now that I reread the thread I see @tpapp asking for patience and an intention to merge eventually, which I must have forgotten about when I closed this- sorry about that! I'd be glad to reopen this if there's any interest. I can't promise to work on bringing it up to date again, but who knows.