diff --git a/README.md b/README.md index 0234bbe..3c25e72 100644 --- a/README.md +++ b/README.md @@ -351,9 +351,11 @@ contact me by creating an issue in this repository. ## 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 -* We don't use the option formatprg internally anymore, to always have the possible of using the default `gq` - command. +* We don't use the option formatprg internally anymore, to always have the possible of using the default `gq` command. * More fallback options have been added. ### June 2015 diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index aed24bd..c08c4d3 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -206,11 +206,14 @@ env=newenv p = subprocess.Popen(formatprg, env=env, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) stdoutdata, stderrdata = p.communicate(text) +formattername = vim.eval('b:formatters[s:index]') if stderrdata: if verbose: - formattername = vim.eval('b:formatters[s:index]') print('Formatter {} has errors: {}'.format(formattername, stderrdata)) vim.command('return 1') +elif p.returncode > 0: + if verbose: + print('Formatter {} gives nonzero returncode: {}'.format(formattername, p.returncode)) else: # 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. @@ -262,10 +265,13 @@ except (BrokenPipeError, IOError): if verbose: raise else: + formattername = vim.eval('b:formatters[s:index]') if stderrdata: if verbose: - formattername = vim.eval('b:formatters[s:index]') 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: if verbose: print('Formatter {} gives empty result: {}'.format(formattername, stderrdata)) @@ -297,6 +303,7 @@ endfunction " Create a command for formatting the entire buffer " 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|,call s:TryAllFormatters()|call winrestview(winview)|rviminfo