all repos — dotfiles @ 7aea05e57ad97627f5907f1e8e220b61cc467254

my *nix dotfiles

config/nvim/ftplugin/go.vim (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
setlocal noexpandtab
setlocal autoindent
setlocal smarttab
setlocal formatoptions=croql

" stolen from https://go.googlesource.com/go/+/c4f5421/misc/vim/ftplugin/go/fmt.vim

if exists("b:did_ftplugin_go_fmt")
    finish
endif
if !exists("g:go_fmt_commands")
    let g:go_fmt_commands = 1
endif
if !exists("g:gofmt_command")
    if executable("goimports")
        let g:gofmt_command = "goimports"
    else
        let g:gofmt_command = "gofmt"
    endif
endif
if g:go_fmt_commands
    command! -buffer Fmt call s:GoFormat()
endif
function! s:GoFormat()
    let view = winsaveview()
    silent execute "%!" . g:gofmt_command
    if v:shell_error
        let errors = []
        for line in getline(1, line('$'))
            let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
            if !empty(tokens)
                call add(errors, {"filename": @%,
                                 \"lnum":     tokens[2],
                                 \"col":      tokens[3],
                                 \"text":     tokens[4]})
            endif
        endfor
        if empty(errors)
            % | " Couldn't detect gofmt error format, output errors
        endif
        undo
        if !empty(errors)
            call setloclist(0, errors, 'r')
        endif
        echohl Error | echomsg "Gofmt returned error" | echohl None
    endif
    call winrestview(view)
endfunction
let b:did_ftplugin_go_fmt = 1
" vim:ts=4:sw=4:et