]> Sergey Matveev's repositories - dotfiles.git/blob - vim/.vim/autoload/fmt.vim
Take fmt errors into account
[dotfiles.git] / vim / .vim / autoload / fmt.vim
1 vim9script
2
3 export def Do()
4     var view = winsaveview()
5     silent execute ":%!" .. &equalprg
6     if v:shell_error != 0
7         var errs = []
8         for line in getline(1, line("$"))
9             var cols = matchlist(line, '^.*:\(\d\+\):\(\d\+\):\s*\(.*\)$')
10             if empty(cols) | continue | endif
11             errs = add(errs, {
12                 filename: @%,
13                 lnum: str2nr(cols[1]),
14                 col: str2nr(cols[2]),
15                 text: cols[3],
16             })
17         endfor
18         silent undo
19         if !empty(errs) | setqflist(errs, "r") | endif
20         echohl Error | echomsg "fmt error" | echohl None
21     endif
22     winrestview(view)
23 enddef