-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fill the content of a new file automatically based on the context
This is a new feature that fills the content of a new file according the to current directories context. If there are no Go files, a simple hello main package is created, otherwise a file with package declaration basedon the current package is created.
- Loading branch information
Showing
6 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("vim-go") | ||
} |