Skip to content

markwoodhall/vim-cljreloaded

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Purpose

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.

Installation

Install using your favourite plugin manager, I use vim-plug

Plug 'markwoodhall/vim-cljreloaded'

Requirements

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"}))

Usage

The following functions are made available:

:ReloadedStart

Calls the (start) function defined by reloaded.repl.

Start example

:ReloadedStop

Calls the (stop) function defined by reloaded.repl.

Stop example

:ReloadedReset

Calls the (reset) function defined by reloaded.repl.

Reset example

:ReloadedResetAll

Calls the (reset-all) function defined by reloaded.repl.

Reset all example

:ReloadedInit

Calls the (init) function defined by reloaded.repl.

Init example

:ReloadedGo

Calls the (go) function defined by reloaded.repl.

Go example

:ReloadedSystem

Pretty prints the system.

System example

The functions below are not strictly reloaded.repl related but they may enhance a "reloaded" workflow in vim.

:ReloadedRefresh

Calls the (refresh) function defined by clojure.tools.namespace.repl

Refresh example

:ReloadedRefreshAll

Calls the (refresh-all) function defined by clojure.tools.namespace.repl

Refresh all example

:ReloadedInNs

Changes *ns* in the underlying nREPL session to be $namespace. Supports tab completion on the namespace using namespaces currently available on the classpath.

In ns example

:ReloadedInNsFzf

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.

In ns example

:ReloadedUseNs

Calls (use '$namespace) in the underlying nREPL session. Supports tab completion on the namespace using namespaces currently available on the classpath.

Use ns example

:ReloadedUseNsFzf

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

Use ns example

:ReloadedHotLoadDepUnderCursor

vim-cljreloaded can hot load dependencies into a running nREPL session using pomegranate.

Hot load example

In the above example I had the following mapping in place.

autocmd filetype clojure nnoremap <buffer> hld :ReloadedHotLoadDependencyUnderCursor<CR>

:ReloadedHotLoadDep

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 example

:ReloadedHotLoadDepFzf

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.

Hot load example

Note. This works best when your cursor is positioned on the closing square bracket of the :dependencies value.

:ReloadedHotLoadDepSilentFzf

This is the same as above but it will not output anything to the current buffer.

:ReloadedHotLoadDepNoSnapshotsFzf

This is the same as :ReloadedHotLoadDepFzf but SNAPSHOT jars are automatically filtered out.

Hot load example

:ReloadedHotLoadDepNoSnapshotSilentFzf

This is the same as above but it will not output anything to the current buffer.

:ReloadedNsPublicsFzf

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.

Publics example

:ReloadedNsFzf

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.

Ns list example

Bindings

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

Notes about hot loading and completion

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"

License

Copyright © Mark Woodhall. Distributed under the same terms as Vim itself. See :help license

About

A vim plugin to aid the Clojure "reloaded workflow"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published