From 1e761ea8af276caa2ff605cb4d7d0a63fac51a36 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 16 Jul 2022 15:01:26 +0300 Subject: [PATCH] Take fmt errors into account --- vim/.vim/autoload/fmt.vim | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/vim/.vim/autoload/fmt.vim b/vim/.vim/autoload/fmt.vim index 5e7a001..0aafcbc 100644 --- a/vim/.vim/autoload/fmt.vim +++ b/vim/.vim/autoload/fmt.vim @@ -2,6 +2,22 @@ vim9script export def Do() var view = winsaveview() - normal gg=G + silent execute ":%!" .. &equalprg + if v:shell_error != 0 + var errs = [] + for line in getline(1, line("$")) + var cols = matchlist(line, '^.*:\(\d\+\):\(\d\+\):\s*\(.*\)$') + if empty(cols) | continue | endif + errs = add(errs, { + filename: @%, + lnum: str2nr(cols[1]), + col: str2nr(cols[2]), + text: cols[3], + }) + endfor + silent undo + if !empty(errs) | setqflist(errs, "r") | endif + echohl Error | echomsg "fmt error" | echohl None + endif winrestview(view) enddef -- 2.44.0