diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2021-03-01 13:44:50 +0100 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2021-03-01 13:44:50 +0100 |
commit | cc63193ce82c1e7b9ee2ad7d0ddd14e8394211ef (patch) | |
tree | 260360b1a32ca19635f8c8884b81fcec9ed51168 /ftplugin/vlang.vim | |
parent | 4c10562d2cc9b084518284c49a158558da5180a7 (diff) | |
download | vim-polyglot-cc63193ce82c1e7b9ee2ad7d0ddd14e8394211ef.tar.gz vim-polyglot-cc63193ce82c1e7b9ee2ad7d0ddd14e8394211ef.zip |
Update
Diffstat (limited to 'ftplugin/vlang.vim')
-rw-r--r-- | ftplugin/vlang.vim | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ftplugin/vlang.vim b/ftplugin/vlang.vim index cda16cba..fbc0a711 100644 --- a/ftplugin/vlang.vim +++ b/ftplugin/vlang.vim @@ -2,5 +2,36 @@ if polyglot#init#is_disabled(expand('<sfile>:p'), 'v', 'ftplugin/vlang.vim') finish endif +if exists("b:did_ftplugin") + finish +endif + setlocal commentstring=//\ %s setlocal makeprg=v\ % + +if exists('b:undo_ftplugin') + let b:undo_ftplugin .= "|setlocal commentstring< makeprg<" +else + let b:undo_ftplugin = "setlocal commentstring< makeprg<" +endif + +function! _VFormatFile() + if exists('g:v_autofmt_bufwritepre') && g:v_autofmt_bufwritepre || exists('b:v_autofmt_bufwritepre') && b:v_autofmt_bufwritepre + let substitution = system("v fmt -", join(getline(1, line('$')), "\n")) + if v:shell_error != 0 + echoerr "While formatting the buffer via vfmt, the following error occurred:" + echoerr printf("ERROR(%d): %s", v:shell_error, substitution) + else + let [_, lnum, colnum, _] = getpos('.') + %delete + call append(0, split(substitution, "\n")) + call cursor(lnum, colnum) + endif + endif +endfunction + +if has('autocmd') + augroup v_fmt + autocmd BufWritePre *.v call _VFormatFile() + augroup END +endif |