1
0
Fork 0
mirror of synced 2024-11-30 04:35:35 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/template.vim

43 lines
1.2 KiB
VimL
Raw Normal View History

2016-07-03 07:53:59 -04:00
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
2016-08-02 08:48:32 -04:00
" files) from the directory create the template
2016-07-03 07:53:59 -04:00
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)
2016-08-02 08:48:32 -04:00
exe '0r ' . fnameescape(l:template_path)
2016-07-03 07:53:59 -04:00
$delete _
2016-08-02 08:48:32 -04:00
else
2016-07-03 07:53:59 -04:00
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
2016-08-02 08:48:32 -04:00
function! go#template#ToggleAutoCreate()
if get(g:, "go_template_autocreate", 1)
let g:go_template_autocreate = 0
call go#util#EchoProgress("auto template create disabled")
return
end
let g:go_template_autocreate = 1
call go#util#EchoProgress("auto template create enabled")
endfunction
2016-07-03 07:53:59 -04:00
" vim: sw=2 ts=2 et