Skip to content

Multiple connections with ConjureClientState

Oliver Caldwell edited this page Aug 12, 2021 · 1 revision

Conjure has a feature called ConjureClientState that allows you to hop between parallel universes of Conjure state, this means you can have completely different connections and logs in the same Neovim instance.

The basics

The default state is just default, we can look that up with :ConjureClientState with no arguments, which just prints default. You can try this out yourself by connecting to a REPL in some Conjure client than swapping to another state with :ConjureClientState some-other-state-name.

Now you’re in a fresh state that doesn’t have a REPL (although this depends on the client you’re using), you can connect to another REPL or start another REPL process. To get back to the original one you can run :ConjureClientState default, now you’re back on your original connection!

Making it usable

This is handy but we can improve the UX dramatically by adding some mappings, this is left as an exercise for the reader since they way you define your mappings and the keys you want to use are very personal. You just need to map to calling the ConjureClientState command with a key of your choosing, the key can be basically anything, including a file path!

A technique I like to use is an autocommand that fires as I change my current working directory in Neovim. It sets the client state key to the current directory which means I can use :cd modules/cljs and :cd ../modules/clj to hop between sub-trees and nREPLs.

augroup conjure_set_state_key_on_dir_changed
  autocmd!
  autocmd DirChanged * execute "ConjureClientState " . getcwd()
augroup END

You could also set this based on the file extension such as .clj, .cljs and .cljc. Maybe set the key to clj for .clj and .cljc then cljs for .cljs.

Why doesn’t it "just work"?

I normally aim to make Conjure features as automatic as possible, but this feature is just far too dependant on the desired UX and project constraints. There’s no right answer, so I want to give you a powerful tool that’s easy to invoke then let you call it at a time that suits you.

If you come up with some nice autocmds and mappings, feel free to add them to this wiki page!