Skip to content

Commit

Permalink
Add g:go_fmt_options setting. Closes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih committed Apr 7, 2014
1 parent e5fd6ea commit 13a71b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 7 additions & 1 deletion doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ with |:GoPlay|. By default it's enabled. >
let g:go_play_open_browser = 1
<

*'g:go_fmt_autosave'*

Use this option to auto |:GoFmt| on save. By default it's enabled >
Expand All @@ -318,6 +317,13 @@ Use this option to define which tool is used to gofmt. By default `goimports`
is used >
let g:go_fmt_command = "goimports"
<
*'g:go_fmt_options'*

Use this option to add additional options to the |g:go_fmt_command|. Default
is empty. >
let g:go_fmt_options = ''
<
*'g:go_fmt_fail_silently'*

Expand Down
10 changes: 8 additions & 2 deletions ftplugin/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ if !exists('g:go_fmt_fail_silently')
let g:go_fmt_fail_silently = 0
endif

if !exists('g:go_fmt_options')
let g:go_fmt_options = ''
endif

if g:go_fmt_autosave
autocmd BufWritePre <buffer> :GoFmt
endif
Expand All @@ -71,12 +75,14 @@ function! s:GoFormat()
let l:curw=winsaveview()
let l:tmpname=tempname()
call writefile(getline(1,'$'), l:tmpname)
let out = system(g:go_fmt_command . " " . l:tmpname)

let command = g:go_fmt_command . ' ' . g:go_fmt_options
let out = system(command . " " . l:tmpname)

"if there is no error on the temp file, gofmt our original file
if v:shell_error == 0
try | silent undojoin | catch | endtry
silent execute "%!" . g:go_fmt_command
silent execute "%!" . command
call setqflist([])
elseif g:go_fmt_fail_silently == 0
"otherwise get the errors and put them to quickfix window
Expand Down
2 changes: 1 addition & 1 deletion plugin/gotools.vim
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function! s:GoVet()
endfunction

" Execute the command with system() in the current files directory instead of
" in current directory. Returns the result.
" in current directory. Returns the result.
function! s:ExecuteInCurrentDir(cmd) abort
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
Expand Down

0 comments on commit 13a71b0

Please sign in to comment.