From 208b1bdda22e7cd11249938c5535975e9eccbb96 Mon Sep 17 00:00:00 2001 From: Andy Weidenbaum Date: Sat, 19 Nov 2022 13:12:40 +1100 Subject: [PATCH] g:zig_fmt_autoswitch: cfg location list autoswitch ```vim " don't automatically switch to location list if zig fmt encounters errors let g:zig_fmt_autoswitch = 0 ``` --- README.md | 8 ++++++++ autoload/zig/fmt.vim | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2286101..e0e7f88 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,14 @@ This plugin enables automatic code formatting on save by default using let g:zig_fmt_autosave = 0 ``` +If `zig fmt` encounters a code formatting error, this plugin populates +the location list with relevant errors. To disable automatically switching +to the location list, use this configuration in vimrc: + +``` +let g:zig_fmt_autoswitch = 0 +``` + The default compiler which gets used by `:make` (`:help :compiler` for details) is `zig_build` and it runs `zig build`. The other options are: * `:compiler zig_test` which runs `zig test` on the current file. diff --git a/autoload/zig/fmt.vim b/autoload/zig/fmt.vim index e1c6bba..8bf93e9 100644 --- a/autoload/zig/fmt.vim +++ b/autoload/zig/fmt.vim @@ -69,7 +69,12 @@ function! zig#fmt#Format() abort if err != 0 echohl Error | echomsg "zig fmt returned error" | echohl None - return + if get(g:, 'zig_fmt_autoswitch', 1) + return + else + wincmd p + return + endif endif " Run the syntax highlighter on the updated content and recompute the folds if