Skip to content

Commit

Permalink
Merge pull request #2613 from hdonnay/master
Browse files Browse the repository at this point in the history
fmt: respect buffer-level go_fmt_options
  • Loading branch information
bhcleek authored Dec 7, 2019
2 parents 106edc8 + be9535c commit c640518
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoload/go/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function! go#config#FmtCommand() abort
endfunction

function! go#config#FmtOptions() abort
return get(g:, "go_fmt_options", {})
return get(b:, "go_fmt_options", get(g:, "go_fmt_options", {}))
endfunction

function! go#config#FmtFailSilently() abort
Expand Down
13 changes: 13 additions & 0 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,19 @@ The dictionary version allows you to define options for multiple binaries:
\ 'gofmt': '-s',
\ 'goimports': '-local mycompany.com',
\ }
<
*'b:go_fmt_options'*

This option is identical to |'g:go_fmt_options'|, but a buffer-level setting.
If present, it's used instead of the global setting. By default it is not set.

As an example, the following autocmd will configure goimports to put imports
of packages from the current module in their own group:
>
autocmd FileType go let b:go_fmt_options = {
\ 'goimports': '-local ' .
\ trim(system('{cd '. shellescape(expand('%:h')) .' && go list -m;}')),
\ }
<
*'g:go_fmt_fail_silently'*

Expand Down

0 comments on commit c640518

Please sign in to comment.