Skip to content

Instantly share code, notes, and snippets.

@cursork
Last active August 29, 2015 14:01
Show Gist options
  • Save cursork/c4cec824638f2afac217 to your computer and use it in GitHub Desktop.
Save cursork/c4cec824638f2afac217 to your computer and use it in GitHub Desktop.
Creating a new ns from Vim
" Initial workings for creating a new namespace from Vim:
" * Transform - to _ (I *still* always forget and have to do a mv)
" * Make directories if needed
" TODO auto-completion would be ah-maaazing!
" TODO only copes with typical src / src/clj setups
" TODO handle cljs
" TODO currently assumes use of Rooter to go to git root directory
" Requires classpath.vim
if !exists('*EditNamespace')
function EditNamespace(ns) abort
let path = tr(a:ns, '.-', '/_') . '.clj'
let cps = split(classpath#detect(), ',')
let to_match = '/src/clj$'
let found = filter(copy(cps), 'v:val =~# to_match')
if empty(found)
let to_match = '/src$'
let found = filter(copy(cps), 'v:val =~# to_match')
endif
if !empty(found)
let filepath = found[0] . '/' . path
let directory = fnamemodify(filepath, ':h')
if !isdirectory(directory)
execute '!mkdir -p ' . directory
endif
execute 'tabnew ' . filepath
endif
endfunction
endif
command! -nargs=1 NS call EditNamespace('<args>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment