Skip to content

Commit 33b62b6

Browse files
LemonBoyhaze
authored andcommitted
Minor fixes to fmt implementation
* Use zig binary in PATH (as done in the ftplugin) * Avoid useless detour to a temporary file, system() merges stdin and stdout * Avoid silly 'Press enter to continue' message when opening the loclist
1 parent ead2193 commit 33b62b6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

autoload/zig/fmt.vim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ function! zig#fmt#Format() abort
88
" Save cursor position and many other things.
99
let view = winsaveview()
1010

11-
let current_buf = bufnr('')
11+
if !executable('zig')
12+
echohl Error | echomsg "no zig binary found in PATH" | echohl None
13+
return
14+
endif
1215

13-
let bin_path = get(g:, 'zig_bin_path', 'zig')
14-
let stderr_file = tempname()
15-
let cmdline = printf('%s fmt --stdin 2> %s', bin_path, stderr_file)
16+
let cmdline = 'zig fmt --stdin'
17+
let current_buf = bufnr('')
1618

1719
" The formatted code is output on stdout, the errors go on stderr.
1820
if exists('*systemlist')
@@ -38,7 +40,7 @@ function! zig#fmt#Format() abort
3840
call setloclist(0, [], 'r')
3941
lclose
4042
elseif get(g:, 'zig_fmt_parse_errors', 1)
41-
let errors = s:parse_errors(expand('%'), readfile(stderr_file))
43+
let errors = s:parse_errors(expand('%'), out)
4244

4345
call setloclist(0, [], 'r', {
4446
\ 'title': 'Errors',
@@ -49,11 +51,9 @@ function! zig#fmt#Format() abort
4951
" Prevent the loclist from becoming too long.
5052
let win_height = min([max_win_height, len(errors)])
5153
" Open the loclist, but only if there's at least one error to show.
52-
execute 'lwindow ' . win_height
54+
execute 'silent! lwindow ' . win_height
5355
endif
5456

55-
call delete(stderr_file)
56-
5757
call winrestview(view)
5858

5959
if err != 0

0 commit comments

Comments
 (0)