utop icon indicating copy to clipboard operation
utop copied to clipboard

Emacs' utop `Goto BOL` jumps to the front of the prompt instead the front of my code

Open bokwoon95 opened this issue 5 years ago • 5 comments

I'm using utop in Emacs. When I use the OCaml repl instead, pressing C-a will go to the front of my line, allowing me to kill the entire line with C-k. C-a ignores the prompt as part of the line

ocaml

However with utop, pressing C-a will go to the front of the prompt instead, meaning when I try to kill with C-k it gets rejected because you can't delete the prompt. C-a recognizes the prompt as part of the line. I have to goto BOL, move my cursor past the prompt manually then I can kill the rest of the line

utop

Is it possible to change the utop repl to behave like ocaml's instead, where going to the BOL will ignore the prompt? Thanks.

bokwoon95 avatar Nov 02 '18 02:11 bokwoon95

I think this would be a mistake, given that people expect C-a to behave the way it does now. However, it should be pretty straightforward to get it to behave the way you want and rebind it. Better yet, however, almost all commmand interpreter modes in emacs use C-c C-a as the command meaning "go to the end of the prompt at the start of the line", and probably what you want is for this binding to be added and to use that instead.

@diml I'm also curious why utop's emacs mode doesn't seem to inherit from comint mode?

pmetzger avatar Nov 02 '18 12:11 pmetzger

Previously, I had a look at converting utop's mode to comint but have found it difficult. The main difficulty is that utop mode's interaction isn't a true repl. In the sense that it uses stdin/stdout interaction to handle non repl concerns as well. Most importantly, this covers auto completion and other less important concerns such history.

You could in theory makes things work with comint but making use of comint's various filter functions. But when I've looked at this, it was far too difficult.

I think the way to go forward with using comint would be to make utop in emacs a normal repl and then add all the extra functionality (completion, history) out of band. This would require some RPC between utop and emacs, and the last time I've looked for solutions in this area I could not find anything satisfactory. If anyone has suggestions here, then I'm all ears.

rgrinberg avatar Nov 02 '18 16:11 rgrinberg

@rgrinberg So making it use comint is a wider topic. Meanwhile, though, we could adopt a couple of comint's key bindings like C-c C-a pretty easily to make things behave in the "expected" manner.

pmetzger avatar Nov 02 '18 17:11 pmetzger

Makes sense. If anyone wants to contribute these bindings, we should accept them.

rgrinberg avatar Nov 02 '18 18:11 rgrinberg

Previously, I had a look at converting utop's mode to comint but have found it difficult. The main difficulty is that utop mode's interaction isn't a true repl. In the sense that it uses stdin/stdout interaction to handle non repl concerns as well. Most importantly, this covers auto completion and other less important concerns such history.

You could in theory makes things work with comint but making use of comint's various filter functions. But when I've looked at this, it was far too difficult.

I think the way to go forward with using comint would be to make utop in emacs a normal repl and then add all the extra functionality (completion, history) out of band. This would require some RPC between utop and emacs, and the last time I've looked for solutions in this area I could not find anything satisfactory. If anyone has suggestions here, then I'm all ears.

@rgrinberg Would there be any difficulty in just doing it exactly as it is done in Elpy? Basically, just spin up a very light rpc which just handles dumb-simple json message passing between utop and emacs. I would love to help work on something like this but am interested to hear more about what made it difficult. I also know that it has been ~5 years since you left that comment, so no hard feelings if you don't recall :)

Nonetheless, I'd love to give this a try (and by extension #332).

benbellick avatar Dec 20 '23 19:12 benbellick