diff options
Diffstat (limited to 'autoload/zig/fmt.vim')
-rw-r--r-- | autoload/zig/fmt.vim | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/autoload/zig/fmt.vim b/autoload/zig/fmt.vim index 3474f34a..7d7872f9 100644 --- a/autoload/zig/fmt.vim +++ b/autoload/zig/fmt.vim @@ -12,11 +12,13 @@ function! zig#fmt#Format() abort " Save cursor position and many other things. let view = winsaveview() - let current_buf = bufnr('') + if !executable('zig') + echohl Error | echomsg "no zig binary found in PATH" | echohl None + return + endif - let bin_path = get(g:, 'zig_bin_path', 'zig') - let stderr_file = tempname() - let cmdline = printf('%s fmt --stdin 2> %s', bin_path, stderr_file) + let cmdline = 'zig fmt --stdin' + let current_buf = bufnr('') " The formatted code is output on stdout, the errors go on stderr. if exists('*systemlist') @@ -42,7 +44,7 @@ function! zig#fmt#Format() abort call setloclist(0, [], 'r') lclose elseif get(g:, 'zig_fmt_parse_errors', 1) - let errors = s:parse_errors(expand('%'), readfile(stderr_file)) + let errors = s:parse_errors(expand('%'), out) call setloclist(0, [], 'r', { \ 'title': 'Errors', @@ -53,11 +55,9 @@ function! zig#fmt#Format() abort " Prevent the loclist from becoming too long. let win_height = min([max_win_height, len(errors)]) " Open the loclist, but only if there's at least one error to show. - execute 'lwindow ' . win_height + execute 'silent! lwindow ' . win_height endif - call delete(stderr_file) - call winrestview(view) if err != 0 |