Merge pull request #193 from mmlb/yapf-conf-file

YAPF conf file
This commit is contained in:
Chiel ten Brinke 2017-07-31 10:44:17 +02:00 committed by GitHub
commit 16ba1a843b
2 changed files with 13 additions and 4 deletions

View File

@ -135,7 +135,10 @@ Here is a list of formatprograms that are supported by default, and thus will be
And here the link to its page on the python website: http://pypi.python.org/pypi/autopep8/0.5.2.
* `yapf` for __Python__ (supports formatting ranges).
It is readily available through PIP. Most users can install with the terminal command `sudo pip install yapf` or `pip install --user yapf`.
Vim-autoformat checks whether there exists a `.style.yapf` or a `setup.cfg` file up in the current directory's ancestry.
Based on that it either uses that file or tries to match vim options as much as possible.
It is readily available through PIP.
Most users can install with the terminal command `sudo pip install yapf` or `pip install --user yapf`.
YAPF has one optional configuration variable to control the formatter style.
For example:

View File

@ -42,9 +42,15 @@ if !exists('g:formatter_yapf_style')
let g:formatter_yapf_style = 'pep8'
endif
if !exists('g:formatdef_yapf')
let g:formatdef_yapf = "'yapf --style=\"{based_on_style:'.g:formatter_yapf_style.',indent_width:'.&shiftwidth.(&textwidth ? ',column_limit:'.&textwidth : '').'}\" -l '.a:firstline.'-'.a:lastline"
let s:configfile_def = "'yapf -l '.a:firstline.'-'.a:lastline"
let s:noconfigfile_def = "'yapf --style=\"{based_on_style:'.g:formatter_yapf_style.',indent_width:'.&shiftwidth.(&textwidth ? ',column_limit:'.&textwidth : '').'}\" -l '.a:firstline.'-'.a:lastline"
let g:formatdef_yapf = "g:YAPFFormatConfigFileExists() ? (" . s:configfile_def . ") : (" . s:noconfigfile_def . ")"
endif
function! g:YAPFFormatConfigFileExists()
return len(findfile(".style.yapf", expand("%:p:h").";")) || len(findfile("setup.cfg", expand("%:p:h").";"))
endfunction
if !exists('g:formatters_python')
let g:formatters_python = ['autopep8','yapf']
endif
@ -185,10 +191,10 @@ if !exists('g:formatdef_eslint_local')
if verbose
return "(>&2 echo 'No local ESLint program and/or config found')"
endif
return
return
endif
" This formatter uses a temporary file as ESLint has not option to print
" This formatter uses a temporary file as ESLint has not option to print
" the formatted source to stdout without modifieing the file.
let l:eslint_js_tmp_file = fnameescape(tempname().".js")
let content = getline('1', '$')