Last active
August 29, 2015 14:01
-
-
Save cursork/c4cec824638f2afac217 to your computer and use it in GitHub Desktop.
Creating a new ns from Vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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