Skip to content

Instantly share code, notes, and snippets.

@michaelmrose
Last active October 12, 2018 23:42
Show Gist options
  • Save michaelmrose/fe9113ee4d1c7273c58a to your computer and use it in GitHub Desktop.
Save michaelmrose/fe9113ee4d1c7273c58a to your computer and use it in GitHub Desktop.
A Colored Clojure Repl Via Neovim, Fish, and Lein

A Colored Clojure Repl Via Neovim, Fish, and Lein

We'll start with the assumption that your cwd in vim is set to the directory of a clojure file perhaps via autochdir.

Now with some vimscript we'll start a terminal buffer, set the proper syntax coloring, turn on rainbow parens and only then run lein repl. Note it doesn't work if these aren't done before lein repl.

function! NvimRepl()
  terminal
  set syntax=clojure
  RainbowParentheses
  call feedkeys("lein repl\<Cr>\<c-\>\<c-n>")
endfunction

Next we'll define a few functions that will do the same thing in a vertical or split buffer or in a new tab. For conveinience bind to whatever keys please you.

function! NvimReplTab()
  tabnew
  call NvimRepl()
endfunction

function! NvimReplVS()
  vsp
  enew
  call NvimRepl()
endfunction

function! NvimReplS()
  sp
  enew
  call NvimRepl()
endfunction

Now you can easily from a clojure buffer start a repl in a split or new tab but sometimes it would be nice to just start such a repl from the terminal or via dmenu/rofi. Lets do that with some fish. Not shown are a few custom functions in-terminal exists and c.

function nr
  if in-terminal
    if exists $argv
      c $argv
    end
    nvim -c 'call NvimRepl()'
  else
    lilyterm -e ff nr $argv
  end
end

if pstree reports lilyterm is a parent of the process running this function cd to $argv or autojump if the dir doesn't exist then run nvim with the NvimRepl function. else start lilyterm and do the same. Or much better we can abstact the test for the terminal into a function in-terminal-or-out and do thus.

function nr
    c $argv
    in-terminal-or-out nvim -c \'call NvimRepl\(\)\'
end

screenshot

View post on imgur.com
<script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment