tpope / vim-fireplace

fireplace.vim: Clojure REPL support
https://www.vim.org/scripts/script.php?script_id=4978
1.75k stars 139 forks source link

How to specify a different default host #183

Closed icambron closed 7 years ago

icambron commented 10 years ago

I'm sure I'm missing something, but I can't seem to find a way to automatically connect to a different host. My particular issue is that I run the repl in Docker (itself in a VM on my Mac), so nrepl has a different IP. I have the repl set up to always run on the same port, so I think I should just be able to tell Fireplace to default to looking there, i.e. Connect nrepl://172.16.42.43:44553, but without me having to type that each time I run Vim. I'd like to set it in, say, my project-local .vimrc file. Is there a way to do that?

cedrictools commented 10 years ago

Hello, I'm pretty new to vim, sorry if that's a crappy solution.

function! Myconnect()
    :Connect nrepl://127.0.0.1:3000 .
    :Require weasel.repl.websocket
    :Piggieback (weasel.repl.websocket/repl-env :ip "0.0.0.0" :port 9001)
endfunction

I've added this to my vimrc and use the command :call Myconnect() ... not sure if that helps...

tpope commented 10 years ago

Every time it fireplace needs to eval, it fires off doautocmd User FireplacePreConnect. You can hook into that event to do whatever you like. But be aware that you'll need some sort of guard against connecting over and over again. fireplace#register_port_file is how this is done for the built-in autoconnect mechanism.

tpope commented 10 years ago

fireplace#register_port_file currently enforces the file must contain a port number only, but we could fudge it a bit and also allow host:port, if that would help.

icambron commented 10 years ago

Thanks for the quick response. I saw fireplace#register_port_file, but between the code and the fact that the portfiles Lein writes being just port numbers, I figured that was a no go. So that change would be nice. If I'm reading this right, ireplace#nrepl_connection#open will use a host if it's provided, so is the solution here just to pass the contents of the port file in directly?

tpope commented 10 years ago

fireplace#nrepl_connection#open will work fine, but if you're not careful you'll end up connecting over and over again.

icambron commented 10 years ago

I meant as an edit to fireplace#register_port_file, simply not doing the matchstring before passing the result on would do the trick. (I should disclaim that my comprehension of Vimscript is questionable.)

tpope commented 10 years ago

Yes, try that and see if you can cobble together something that works.

icambron commented 10 years ago

Hmm, can't seem to get anything working. I modified fireplace#register_port_file to take in an optional host (used \(\S\+:\)\?\d\+) and set up a hook in .vimrc:

autocmd User FireplacePreConnect call fireplace#register_port_file('Portfile', 'code')

where Portfile just looks like "172.16.42.43:44553".

By sprinkling in echo calls I was able to confirm that it was calling fireplace#nrepl_connection#open with the right stuff and the host and port get pulled apart correctly there, but I couldn't actually get Fireplace to work. I also confirmed that I can use :Connect and type in the host and port and it works fine, so it's not just that my setup is busted.

Before I dig deeper, am I missing something obvious?