To have a better reloaded workflow when using vim.
This plugin makes available the functions defined by the reloaded.repl for use with Stuart Sierra's component.
For hot loading dependencies this plugin makes use of cemerick.pomegranate.
You can add these as dependencies using a :dev
profile in project.clj
or by adding them to ~/.lein/profiles.clj
.
Note. There is no hard requirement to use reloaded.repl and/or cemerick.pomegranate but certain functionality requires it. If you try to use some of this functionality without those dependencies being available you should get an error message indicating what is required.
Install using your favourite plugin manager, I use vim-plug
Plug 'markwoodhall/vim-cljreloaded'
This plugin makes use of vim-fireplace so you will need to install this as well.
Plug 'tpope/vim-fireplace'
As is typical for vim-fireplace you will need a running REPL, lein repl
.
It is typical to have a dev.clj
and a dev
namespace that exposes these functions and sets the function used to start the system. For example.
(ns dev
"Tools for interactive development with the REPL. This file should
not be included in a production build of the application."
(:require [com.stuartsierra.component :as component]
[component-test.system :refer [new-system]]
[reloaded.repl :refer [system init start stop go reset reset-all]]))
(reloaded.repl/set-init! #(new-system {:port 8080 :host "localhost"}))
The following functions are made available:
Calls the (start)
function defined by reloaded.repl
.
Calls the (stop)
function defined by reloaded.repl
.
Calls the (reset)
function defined by reloaded.repl
.
Calls the (reset-all)
function defined by reloaded.repl
.
Calls the (init)
function defined by reloaded.repl
.
Calls the (go)
function defined by reloaded.repl
.
Pretty prints the system
.
The functions below are not strictly reloaded.repl
related but they may enhance a "reloaded" workflow in vim.
Calls the (refresh)
function defined by clojure.tools.namespace.repl
Calls the (refresh-all)
function defined by clojure.tools.namespace.repl
Changes *ns*
in the underlying nREPL session to be $namespace
. Supports tab completion on the namespace using namespaces
currently available on the classpath.
Changes *ns*
in the underlying nREPL session to be $namespace
. Supports selection of the namespace using a list of available namespaces on the
classpath as a source for the fzf.vim selector.
Calls (use '$namespace)
in the underlying nREPL session. Supports tab completion on the namespace using namespaces
currently available on the classpath.
Calls (use '$namespace)
in the underlying nREPL session. Supports selection of the namespace using a list of available namepaces on the
classpath as a source for the
vim-cljreloaded can hot load dependencies into a running nREPL session using pomegranate.
In the above example I had the following mapping in place.
autocmd filetype clojure nnoremap <buffer> hld :ReloadedHotLoadDependencyUnderCursor<CR>
Hot load a specified dependency into a running nREPL session. Supports tab completions on the dependency using a list of jars from Clojars.
Hot load a specified dependency into a running nREPL session. Supports selection of the dependency using a list of jars from Clojars as a source for the fzf.vim selector.
Note. This works best when your cursor is positioned on the closing square bracket of the :dependencies
value.
This is the same as above but it will not output anything to the current buffer.
This is the same as :ReloadedHotLoadDepFzf
but SNAPSHOT
jars are automatically filtered out.
This is the same as above but it will not output anything to the current buffer.
This gets the result of calling (ns-publics $namepace)
and uses them as a source
for the fzf.vim selector. When selecting an option then (doc $option)
is shown.
This uses the list of namespaces available on the classpath as a source
for the fzf.vim selector when selecting an option then (doc $option)
is shown.
There are some keybindings setup by default that try to make things easy, if you wish to disable them you can do.
let g:cljreloaded_setbindings = 0
The default prefix for bindings is cr
, you can change this like so.
let g:cljreloaded_bindingprefix = "rr"
With the default settings the following bindings are available.
crg :ReloadedGo
crs :ReloadedStart
crq :ReloadedStop
crr :ReloadedReset
crra :ReloadedResetAll
crd :ReloadedHotLoadDepUnderCursor
crds :ReloadedHotLoadDepSilentFzf
crdp :ReloadedHotLoadDepFzf
crn :ReloadedNsFzf
crun :ReloadedUseNsFzf
crin :ReloadedInNsFzf
crrn :ReloadedRequireNsFzf
It is worth pointing out that as it currently stands any command that hot loads a dependency will block until the dependency and all its requirements have downloaded.
It is also worth noting that dependency completions are a bit of a hack at the moment. When enabled the plugin will request data from the all-jars.clj endpoint provided by Clojars. The data is currently just over 4mb and is built by Clojars every hour, it is loaded into a running nREPL session asynchronously, it is then used as a completion source. At somepoint it would be sensible to change to use "real time" searching of Clojars but this is working for me now, so I've made it available.
Once the data is downloaded it won't be downloaded again until the plugin is reloaded or you manually call :ReloadedLoadAvailableJars
.
Fetching data from Clojars is enabled by default but can be disabled with the following.
let g:cljreloaded_queryclojars = 0
If you need to use a different source for available jars then you can set the following.
let g:cljreloaded_clojarsurl = "http://clojars.org/repo/all-jars.clj"
Copyright © Mark Woodhall. Distributed under the same terms as Vim itself. See :help license