mirror of
1
0
Fork 0
ultimate-vim/sources_non_forked/vim-go/autoload/go/template.vim

32 lines
919 B
VimL

let s:current_file = expand("<sfile>")
function! go#template#create()
let l:root_dir = fnamemodify(s:current_file, ':h:h:h')
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
execute cd . fnameescape(expand("%:p:h"))
let l:package_name = go#tool#PackageName()
" if we can't figure out any package name(no Go files or non Go package
" files) from the directory create the template
if l:package_name == -1
let l:template_file = get(g:, 'go_template_file', "hello_world.go")
let l:template_path = go#util#Join(l:root_dir, "templates", l:template_file)
exe '0r ' . l:template_path
$delete _
else
let l:content = printf("package %s", l:package_name)
call append(0, l:content)
$delete _
endif
" Remove the '... [New File]' message line from the command line
echon
execute cd . fnameescape(dir)
endfunction
" vim: sw=2 ts=2 et