zig.vim icon indicating copy to clipboard operation
zig.vim copied to clipboard

`g:zig_fmt_autoswitch`: Configure automatic switching to location list upon `zig fmt` error

Open atweiden opened this issue 3 years ago • 2 comments

Set g:zig_fmt_autoswitch to 0 in your vimrc to disable automatically switching to the location list if/when zig fmt encounters code formatting errors.

When set to 0, g:zig_fmt_autoswitch configures the Vim cursor to remain where it was prior to running zig fmt. The location list — which gets populated with code formatting errors as per normal — can then be viewed at a glance, without losing focus.

Either don’t set g:zig_fmt_autoswitch at all, or set it to 1, to keep the current behaviour of this plugin.

atweiden avatar Nov 19 '22 02:11 atweiden

I think the logic would be clearer if the call to wincmd p was right after lwindow. Then you don't need the if or multiple points of return.

idbrii avatar Dec 21 '23 21:12 idbrii

Can you provide example code? I’m open to making that change, but I don’t see how to restrict calling wincmd p without a conditional check of the err variable. For example, after setting g:zig_fmt_autoswitch to 0, this would result in calling wincmd p even if no location list were present:

execute 'silent! lwindow ' . win_height
if !get(g:, 'zig_fmt_autoswitch', 1)
  wincmd p
endif

I also don’t see what to do with the echohl Error line without conditionally checking the err variable.

atweiden avatar Dec 28 '23 01:12 atweiden