ziglang / zig.vim

Vim configuration for Zig
MIT License
448 stars 56 forks source link

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

Open atweiden opened 1 year ago

atweiden commented 1 year ago

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.

idbrii commented 8 months ago

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.

atweiden commented 8 months ago

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.