Skip to content

Commit

Permalink
make requested changes to documentation and setting name
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyfrasche committed Nov 27, 2016
1 parent 9e88616 commit 66ce0c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions autoload/go/template.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let s:current_file = expand("<sfile>")

function! go#template#create() abort
let l:go_template_no_file = get(g:, 'go_template_no_file', 0)
let l:go_template_use_pkg = get(g:, 'go_template_use_pkg', 0)
let l:root_dir = fnamemodify(s:current_file, ':h:h:h')

let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand All @@ -13,12 +13,12 @@ function! go#template#create() abort
" if we can't figure out any package name(no Go files or non Go package
" files) from the directory create the template or use the cwd
" as the name
if l:package_name == -1 && l:go_template_no_file != 1
if l:package_name == -1 && l:go_template_use_pkg != 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 ' . fnameescape(l:template_path)
$delete _
elseif l:package_name == -1 && l:go_template_no_file == 1
elseif l:package_name == -1 && l:go_template_use_pkg == 1
" cwd is now the dir of the package
let l:path = fnamemodify(getcwd(), ':t')
let l:content = printf("package %s", l:path)
Expand Down
17 changes: 9 additions & 8 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1438,14 +1438,13 @@ with a Go code template. By default the template under
`templates/hello_world.go` is used. This can be changed with the
|'g:go_template_file'| setting.

To use the package's directory as the name of the package instead of a template
when new Go file is created in a directory with no Go files, enable the
|'g:go_template_no_file'| setting.

If the new file is created in an already prepopulated package (with other Go
files), in this case a Go code template with only the Go package declaration
(which is automatically determined according to the current package) is added.

To always use the package name instead of the template, enable the
|`g:go_template_use_pkg`| setting.

By default it is enabled.
>
let g:go_template_autocreate = 1
Expand All @@ -1458,12 +1457,14 @@ the `hello_world.go` file is used.
>
let g:go_template_file = "hello_world.go"
<
*'g:go_template_no_file'*
*'g:go_template_use_pkg'*

Specifies that, rather than using a template, the package name is used if a new
Go file is created. Checkout |'g:go_template_autocreate'| for more info. By
default the template file specified by |'g:go_template_file'| is used.

Specifies that, rather than using a template, the directory name is used as the
package name if a new Go file is created. Checkout |'g:go_template_autocreate'| for more info. By default it is disabled.
>
let g:go_template_no_file = 0
let g:go_template_use_pkg = 0
<
*'g:go_decls_includes'*

Expand Down

0 comments on commit 66ce0c0

Please sign in to comment.