monroe icon indicating copy to clipboard operation
monroe copied to clipboard

Support for multiple connections

Open technomancy opened this issue 7 years ago • 37 comments

It seems like right now monroe only supports connecting to a single nrepl instance at a time.

Are you interested in adding support for more than one active *monroe* buffer, or is it better to use separate Emacs instances for that?

technomancy avatar Dec 07 '16 19:12 technomancy

I was planning to add it (made a few attempts), just didn't have enough time to complete it. However, if you are able to do it, keeping the code simple, I'll be happy to accept the patch :)

sanel avatar Dec 07 '16 21:12 sanel

Good to know; thanks. No promises, but I might take a shot at this at some point.

technomancy avatar Dec 07 '16 22:12 technomancy

I'm thinking of making an attempt too. Maybe we can discuss a little about how to do it?

bbuccianti avatar Sep 13 '19 17:09 bbuccianti

Feel free @bbuccianti :) Maybe check inferior-lisp mode (inf-lisp.el in Emacs) for multiple processes support.

sanel avatar Sep 14 '19 12:09 sanel

@bbuccianti

For reference, if you want to see an existing attempt for a socket repl-based thing with multiple connections, I've had some luck w/:

  • https://github.com/sogaiu/acrepl/blob/arcadia-and-reconnect/acrepl-connect.el
  • https://github.com/sogaiu/acrepl/blob/arcadia-and-reconnect/acrepl.el

It's been working pretty well for me so far.

I started with sesman, but decided it was much more than I needed.

sogaiu avatar Oct 04 '19 08:10 sogaiu

@sanel @technomancy @sogaiu

Can you help me test this?

https://github.com/bbuccianti/monroe/

I'm sure there is a lot of ways to improve it, please help me!

bbuccianti avatar Nov 27 '19 23:11 bbuccianti

Do you mean the multiple-connections branch?

https://github.com/bbuccianti/monroe/tree/multiple-connections

sogaiu avatar Nov 28 '19 00:11 sogaiu

This is the correct commit:

https://github.com/bbuccianti/monroe/commit/38a1488f54596ccdb35769c83ce0def2380b233c

bbuccianti avatar Nov 28 '19 01:11 bbuccianti

Had success interacting with 2 separate processes from within a single emacs instance.

Opened two files -- each one from a different project -- ran M-x monroe in each and tried M-x monroe-eval-region. Seems to work :+1:

IIUC, there is at most one connection per project and at most one process per project. Is that correct?

sogaiu avatar Nov 28 '19 15:11 sogaiu

Yes, it's using the project folder as a pointer concatenating it with monroe and monroe-conn buffers.

I've created a pull request #33

bbuccianti avatar Nov 28 '19 15:11 bbuccianti

Thanks @bbuccianti for your work and @sogaiu for fast response!

Is #33 will add support for multiple connections? Title of PR confuses me :)

Also, does it handle reading .nrepl-port from project tree?

sanel avatar Nov 28 '19 18:11 sanel

It still uses monroe-locate-port-file.

The only change is that instead of naming the buffers *monroe* and *monroe-conn* I conj the project folder to it. Then, when you try to send code to the nrepl it searches for the correct buffers using the project folder.

bbuccianti avatar Nov 28 '19 19:11 bbuccianti

@sanel I just improved the title of the PR

bbuccianti avatar Nov 28 '19 19:11 bbuccianti

Thanks!

Here are few issues I found (my Emacs is 26.3).

After first expression is entered (in single or multiple REPL connections), prompt is not shown any more.

Next issue is connecting to REPLs outside of working directories. For example, you run REPL at localhost:7888 in project foo, then in external terminal run REPL in project baz at localhost:7889, but keep Emacs in project foo, it will connect to foo for both REPL and inputs and outputs will be shared.

The same applies if you connect Emacs to any multiple projects without entering to project folders.

Since you are calculating process name from working directory, I'd suggest to use combination of host+port instead, because they have to be unique on given system.

Also, I'd suggest to pop out exising monroe connection REPL if user attempt to connect to that session again. This will prevent multiple REPLs that will echo inputs and outputs between each other.

sanel avatar Nov 28 '19 23:11 sanel

I can't reproduce the issue with prompt. Maybe I'm evaluating trivial things, but seems to work fine for me.

https://github.com/bbuccianti/monroe/commit/05b37d975da409210762a343b131e9ccb41b9ab6

Now it's using the host:port combination to name buffers and also call (monroe-disconnect) before trying to attempt another connection.

Let me know!

bbuccianti avatar Nov 29 '19 00:11 bbuccianti

Thanks @bbuccianti for your work so far! However, I still have issue with prompt. What Emacs are you using?

Here is how to reproduce it:

  1. Run lein repl somewhere.
  2. In new Emacs session, run monroe, it will ask for connection.
  3. After you connect, you will see prompt. Enter something like (+ 1 2 3) in REPL. It will print result, but prompt is no longer visible.

Here is how it looks for me:

user=> (+ 1 2 3)                                                                                                                                                                                                    
6
;; no prompt here                                                                                                                                                                                                                   
(println "abc")                                                                                                                                                                                                     
abc
;; no prompt here

sanel avatar Dec 05 '19 15:12 sanel

Are you using this? https://github.com/sanel/monroe/pull/33

I'm currently using GNU Emacs 26.3 (build 1)

bbuccianti avatar Dec 05 '19 15:12 bbuccianti

Yes, using PR #33 and same Emacs version. Tried even with emacs -Q.

Can you try loading PR with emacs -Q please?

sanel avatar Dec 05 '19 15:12 sanel

Well, that works for reproducing the issue. Any suggestion on how to fix it?

bbuccianti avatar Dec 05 '19 16:12 bbuccianti

I'm curious how it worked for you - maybe some package "fixed" that :) This happened before for me and I believe it is up to comint-mode now as well (comint can break in weird ways if you messed up options or processes). I'll check this one.

sanel avatar Dec 05 '19 16:12 sanel

I've tested with commit https://github.com/sanel/monroe/commit/2f472fdc09c1b36c291ddb5ed9aecc331fd7e082 and it's not working in emacs -q !

bbuccianti avatar Dec 06 '19 01:12 bbuccianti

Hm... does it work for you if you revert to this: https://github.com/sanel/monroe/commit/a7cf37e6e29a1e31d9a6e9ce19d5324eca09465a ?

sanel avatar Dec 06 '19 08:12 sanel

Yeah! Can confirm that commit a7cf37e it's working as expected.

Also I want to tell that seems like a callback done with monroe-make-response-handler isn't running with the "done" status. Then monroe-requests isn't cleaned so the prompt is never added again.

But is really strange, because status is clearly truthy but can't go inside the (when status ;cleaning) code. I'm really new to those kind of callbacks and don't know really how monroe-dbind-response is doing is magic, but I'm learning a lot. Would be great if you @sanel can give some advice in how to debug that part.

Thanks!

bbuccianti avatar Dec 07 '19 15:12 bbuccianti

@sanel no advances on this?

bbuccianti avatar Jan 29 '20 23:01 bbuccianti

Hey Benjamín,

sadly I'm a bit busy currently :S If you have time to take a look at it, I'll be happy to review it.

sanel avatar Jan 30 '20 11:01 sanel

I force-pushed to #33

Thanks @sanel

bbuccianti avatar Mar 19 '20 19:03 bbuccianti

Thanks @bbuccianti ! Will take a look :)

sanel avatar Mar 21 '20 12:03 sanel

Implemented with https://github.com/sanel/monroe/pull/33

sanel avatar Jul 03 '20 12:07 sanel

Sorry @bbuccianti but this still doesn't work. To demonstrate:

  • Emacs 26.3
  • In separate run new nrepl server with lein repl
  • From emacs, run monroe and connect to nrepl address
  • In monroe buffer, enter + and press enter
  • It will print #object[clojure.core$_PLUS_ 0x4e0e22f4 "clojure.core$_PLUS_@4e0e22f4"] but prompt is not shown.

Worse, with multiple connections, it mess up where evaluation should go. To reproduce:

  • Run 2 different nrepl servers it separate terminals.
  • Connect from Emacs to both of them (running monroe and entering their addresses).
  • Enter + in one monroe buffer, it will evaluate in second.

How you manage to get this working?

sanel avatar Jul 03 '20 13:07 sanel

@technomancy after https://github.com/sanel/monroe/commit/1c2559b6862e1d4f8780d370973ee63b383b6122 prompt is no longer shown when you enter something like + in fresh monroe session. What is reasoning behind this change?

Does it work for you?

sanel avatar Jul 03 '20 13:07 sanel