From 8d2809242cc2c6bc34d25a004173e624ab425bc7 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 4 Jul 2017 13:00:12 -0400 Subject: [PATCH 1/4] defaults: remove trailing whitespace --- plugin/defaults.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/defaults.vim b/plugin/defaults.vim index 9a08304..74d2647 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -185,10 +185,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', '$') From 3e7f7a6874b81636e1e38896c718a1161db6ac22 Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 4 Jul 2017 13:03:13 -0400 Subject: [PATCH 2/4] defaults/yapf: handle yapf config file YAPF has clang-format like config file for customisation of the applied style. vim-autoformat was previously ignoring any user customisation. --- plugin/defaults.vim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugin/defaults.vim b/plugin/defaults.vim index 74d2647..561a658 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -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.'}\" -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 From 989aa62e946c3ca1269b39b818c0ec677edea64e Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Tue, 4 Jul 2017 13:14:20 -0400 Subject: [PATCH 3/4] README: document yapf config file search --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 23f7d9c..3bb3978 100644 --- a/README.md +++ b/README.md @@ -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: From e80935baff4221c34af0c9f200f9b48404dacdfa Mon Sep 17 00:00:00 2001 From: Manuel Mendez Date: Thu, 27 Jul 2017 10:51:23 -0400 Subject: [PATCH 4/4] fixup! defaults/yapf: handle yapf config file --- plugin/defaults.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/defaults.vim b/plugin/defaults.vim index 561a658..20f4266 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -43,7 +43,7 @@ if !exists('g:formatter_yapf_style') endif if !exists('g:formatdef_yapf') 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.'}\" -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