Inspect returncode of formatters as well.
This commit is contained in:
parent
fc01fdf90f
commit
8da4de80fb
@ -351,9 +351,11 @@ contact me by creating an issue in this repository.
|
|||||||
|
|
||||||
## Major Change Log
|
## Major Change Log
|
||||||
|
|
||||||
|
### October 2018
|
||||||
|
* We also take the returncode of the formatter process into account, not just the presence of output on stderr.
|
||||||
|
|
||||||
### March 2016
|
### March 2016
|
||||||
* We don't use the option formatprg internally anymore, to always have the possible of using the default `gq`
|
* We don't use the option formatprg internally anymore, to always have the possible of using the default `gq` command.
|
||||||
command.
|
|
||||||
* More fallback options have been added.
|
* More fallback options have been added.
|
||||||
|
|
||||||
### June 2015
|
### June 2015
|
||||||
|
@ -206,11 +206,14 @@ env=newenv
|
|||||||
p = subprocess.Popen(formatprg, env=env, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
p = subprocess.Popen(formatprg, env=env, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||||
stdoutdata, stderrdata = p.communicate(text)
|
stdoutdata, stderrdata = p.communicate(text)
|
||||||
|
|
||||||
|
formattername = vim.eval('b:formatters[s:index]')
|
||||||
if stderrdata:
|
if stderrdata:
|
||||||
if verbose:
|
if verbose:
|
||||||
formattername = vim.eval('b:formatters[s:index]')
|
|
||||||
print('Formatter {} has errors: {}'.format(formattername, stderrdata))
|
print('Formatter {} has errors: {}'.format(formattername, stderrdata))
|
||||||
vim.command('return 1')
|
vim.command('return 1')
|
||||||
|
elif p.returncode > 0:
|
||||||
|
if verbose:
|
||||||
|
print('Formatter {} gives nonzero returncode: {}'.format(formattername, p.returncode))
|
||||||
else:
|
else:
|
||||||
# It is not certain what kind of line endings are being used by the format program.
|
# It is not certain what kind of line endings are being used by the format program.
|
||||||
# Therefore we simply split on all possible eol characters.
|
# Therefore we simply split on all possible eol characters.
|
||||||
@ -262,10 +265,13 @@ except (BrokenPipeError, IOError):
|
|||||||
if verbose:
|
if verbose:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
|
formattername = vim.eval('b:formatters[s:index]')
|
||||||
if stderrdata:
|
if stderrdata:
|
||||||
if verbose:
|
if verbose:
|
||||||
formattername = vim.eval('b:formatters[s:index]')
|
|
||||||
print('Formatter {} has errors: {}'.format(formattername, stderrdata))
|
print('Formatter {} has errors: {}'.format(formattername, stderrdata))
|
||||||
|
elif p.returncode > 0:
|
||||||
|
if verbose:
|
||||||
|
print('Formatter {} gives nonzero returncode: {}'.format(formattername, p.returncode))
|
||||||
elif not stdoutdata:
|
elif not stdoutdata:
|
||||||
if verbose:
|
if verbose:
|
||||||
print('Formatter {} gives empty result: {}'.format(formattername, stderrdata))
|
print('Formatter {} gives empty result: {}'.format(formattername, stderrdata))
|
||||||
@ -297,6 +303,7 @@ endfunction
|
|||||||
|
|
||||||
" Create a command for formatting the entire buffer
|
" Create a command for formatting the entire buffer
|
||||||
" Save and recall window state to prevent vim from jumping to line 1
|
" Save and recall window state to prevent vim from jumping to line 1
|
||||||
|
" Write and read viminfo to restore marks
|
||||||
command! -nargs=? -range=% -complete=filetype -bar Autoformat let winview=winsaveview()|wviminfo|<line1>,<line2>call s:TryAllFormatters(<f-args>)|call winrestview(winview)|rviminfo
|
command! -nargs=? -range=% -complete=filetype -bar Autoformat let winview=winsaveview()|wviminfo|<line1>,<line2>call s:TryAllFormatters(<f-args>)|call winrestview(winview)|rviminfo
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user