Take fmt errors into account
authorSergey Matveev <stargrave@stargrave.org>
Sat, 16 Jul 2022 12:01:26 +0000 (15:01 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 16 Jul 2022 12:01:26 +0000 (15:01 +0300)
vim/.vim/autoload/fmt.vim

index 5e7a001c5b4fdd2e4204d8e867de0226976673db..0aafcbc0cbf265b4cf3cee5c6c205e9541cb9443 100644 (file)
@@ -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