]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Double formatting
authorSergey Matveev <stargrave@stargrave.org>
Sat, 16 Jul 2022 13:22:09 +0000 (16:22 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 16 Jul 2022 13:49:09 +0000 (16:49 +0300)
vim/.vim/autoload/fmt.vim

index 0aafcbc0cbf265b4cf3cee5c6c205e9541cb9443..0ba912b5efbd56580ba58d92d4b861aefe087b98 100644 (file)
@@ -1,23 +1,21 @@
 vim9script
 
 export def Do()
-    var view = winsaveview()
-    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)
+    var lines = []
+    job_start(&equalprg, {
+        in_io: "buffer", in_buf: bufnr("%"),
+        callback: (chan, msg) => {
+            lines = add(lines, msg)
+        },
+        exit_cb: (job, status) => {
+            if status != 0
+                cgetexpr lines
+                copen
+                return
+            endif
+            var view = winsaveview()
+            silent execute ":%!" .. &equalprg
+            winrestview(view)
+        }
+    })
 enddef