There might be a better way to do this, but I got this draft of work (see below for equalprg). It basically redirects gq
, rewriting it to print the error, and then undo it.
set formatprg=~/test.sh nnoremap gq :setl opfunc=FormatPrg<cr> g@ fun! FormatPrg(...) silent exe "'[,']!".&formatprg if v:shell_error == 1 let format_error = join(getline(line("'["), line("']")), "\n") undo echo format_error end endfun
This is what is in ~/test.sh
:
echo "error!! alskdjf alskdf alskdj flaskdjf" 1>&2 exit 1
Edit:
I only realized that I did not answer your question haha ββat all. My solution for equalprg
even less elegant, but it can satisfy your needs. To use this , you must install equalprg . Either comment out the nnoremap line, or set indentexpr=EqualPrg()
if you want to switch between an external tool and internal indentation formatting.
set equalprg=~/test.sh nnoremap = :setl opfunc=EqualPrg<cr> g@ fun! EqualPrg(...) if &equalprg != "" silent exe "'[,']!".&equalprg else set indentexpr= exe "norm! `[=`]" set indentexpr=EqualPrg() endif if v:shell_error == 1 let format_error = join(getline(line("'["), line("']")), "\n") undo echo format_error endif endfun
source share