This commit is contained in:
Chiel ten Brinke 2017-06-26 09:29:22 +02:00
parent 889665717c
commit f65c4c88af
2 changed files with 16 additions and 7 deletions

View File

@ -224,7 +224,7 @@ Here is a list of formatprograms that are supported by default, and thus will be
* `fprettify` for modern __Fortran__. * `fprettify` for modern __Fortran__.
Download from [official repository](https://github.com/pseewald/fprettify). Install with `./setup.py install` or `./setup.py install --user`. Download from [official repository](https://github.com/pseewald/fprettify). Install with `./setup.py install` or `./setup.py install --user`.
## It doesn't work! ## Help, the formatter doesn't work as expected!
If you're struggling with getting a formatter to work, it may help to set vim-autoformat in If you're struggling with getting a formatter to work, it may help to set vim-autoformat in
verbose-mode. Vim-autoformat will then output errors on formatters that failed. verbose-mode. Vim-autoformat will then output errors on formatters that failed.
@ -238,6 +238,13 @@ let verbose=1
To read all messages in a vim session type `:messages`. Since one cannot always easily copy To read all messages in a vim session type `:messages`. Since one cannot always easily copy
the contents of messages (e.g. for posting it in an issue), vim-autoformats command `:PutMessages` may the contents of messages (e.g. for posting it in an issue), vim-autoformats command `:PutMessages` may
help. It puts the messages in the current buffer, allowing you to do whatever you want. help. It puts the messages in the current buffer, allowing you to do whatever you want.
#### Reporting bugs
Please report bugs by creating an issue in this repository.
When there are problems with getting a certain formatter to work, provide the output of verbose
mode in the issue.
## How can I change the behaviour of formatters, or add one myself? ## How can I change the behaviour of formatters, or add one myself?
If you need a formatter that is not among the defaults, or if you are not satisfied with the default formatting behaviour that is provided by vim-autoformat, you can define it yourself. If you need a formatter that is not among the defaults, or if you are not satisfied with the default formatting behaviour that is provided by vim-autoformat, you can define it yourself.

View File

@ -105,6 +105,11 @@ function! s:TryAllFormatters(...) range
" once for getting the final expression " once for getting the final expression
let b:formatprg = eval(eval(formatdef_var)) let b:formatprg = eval(eval(formatdef_var))
if verbose
echomsg "Trying definition from ".formatdef_var
echomsg "Evaluated formatprg: ".b:formatprg
endif
" Detect if +python or +python3 is available, and call the corresponding function " Detect if +python or +python3 is available, and call the corresponding function
if !has("python") && !has("python3") if !has("python") && !has("python3")
echohl WarningMsg | echohl WarningMsg |
@ -209,8 +214,7 @@ stdoutdata, stderrdata = p.communicate(text)
if stderrdata: if stderrdata:
if verbose: if verbose:
formattername = vim.eval('b:formatters[s:index]') formattername = vim.eval('b:formatters[s:index]')
print('Formatter {} has errors: {} Skipping.'.format(formattername, stderrdata)) print('Formatter {} has errors: {}'.format(formattername, stderrdata))
print('Failing config: {}'.format(repr(formatprg), stderrdata))
vim.command('return 1') vim.command('return 1')
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.
@ -265,12 +269,10 @@ else:
if stderrdata: if stderrdata:
if verbose: if verbose:
formattername = vim.eval('b:formatters[s:index]') formattername = vim.eval('b:formatters[s:index]')
print('Formatter {} has errors: {} Skipping.'.format(formattername, stderrdata)) print('Formatter {} has errors: {}'.format(formattername, stderrdata))
print('Failing config: {}'.format(repr(formatprg), stderrdata))
elif not stdoutdata: elif not stdoutdata:
if verbose: if verbose:
print('Formatter {} gives empty result: {} Skipping.'.format(formattername, stderrdata)) print('Formatter {} gives empty result: {}'.format(formattername, stderrdata))
print('Failing config: {}'.format(repr(formatprg), stderrdata))
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.