From d3d07cb23ec625271e1d6000c8ebbf5dc6e0c7db Mon Sep 17 00:00:00 2001 From: Chiel92 Date: Thu, 8 Oct 2015 18:15:41 +0200 Subject: [PATCH] Use shiftwidth() instead of &shiftwidth. --- README.md | 2 ++ plugin/defaults.vim | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 246075c..99bb67e 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,8 @@ For the default formatprogram definitions, the options `expandtab`, `shiftwidth` This means that the formatting style will match your current vim settings as much as possible. You can have look look at the exact default definitions for more examples. They are defined in `vim-autoformat/plugin/defaults.vim`. +As a small side note, in the actual defaults the function `shiftwidth()` is used instead of the +property. This is because it falls back to the value of `tabstop` if `shiftwidth` is 0. If you have a composite filetype with dots (like `django.python` or `php.wordpress`), vim-autoformat internally replaces the dots with underscores so you can specify formatters through `g:formatters_django_python` and so on. diff --git a/plugin/defaults.vim b/plugin/defaults.vim index bc310b5..11861de 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -15,7 +15,7 @@ endif " C# if !exists('g:formatdef_astyle_cs') - let g:formatdef_astyle_cs = '"astyle --mode=cs --style=ansi --indent-namespaces -pcH".(&expandtab ? "s".&shiftwidth : "t")' + let g:formatdef_astyle_cs = '"astyle --mode=cs --style=ansi --indent-namespaces -pcH".(&expandtab ? "s".shiftwidth() : "t")' endif if !exists('g:formatters_cs') @@ -25,14 +25,14 @@ endif " Generic C, C++, Objective-C if !exists('g:formatdef_clangformat') - let g:formatdef_clangformat = "'clang-format -lines='.a:firstline.':'.a:lastline.' --assume-filename='.bufname('%').' -style=\"{BasedOnStyle: WebKit, AlignTrailingComments: true, '.(&textwidth ? 'ColumnLimit: '.&textwidth.', ' : '').(&expandtab ? 'UseTab: Never, IndentWidth: '.&shiftwidth : 'UseTab: Always').'}\"'" + let g:formatdef_clangformat = "'clang-format -lines='.a:firstline.':'.a:lastline.' --assume-filename='.bufname('%').' -style=\"{BasedOnStyle: WebKit, AlignTrailingComments: true, '.(&textwidth ? 'ColumnLimit: '.&textwidth.', ' : '').(&expandtab ? 'UseTab: Never, IndentWidth: '.shiftwidth() : 'UseTab: Always').'}\"'" endif " C if !exists('g:formatdef_astyle_c') - let g:formatdef_astyle_c = '"astyle --mode=c --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")' + let g:formatdef_astyle_c = '"astyle --mode=c --style=ansi -pcH".(&expandtab ? "s".shiftwidth() : "t")' endif if !exists('g:formatters_c') @@ -42,7 +42,7 @@ endif " C++ if !exists('g:formatdef_astyle_cpp') - let g:formatdef_astyle_cpp = '"astyle --mode=c --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")' + let g:formatdef_astyle_cpp = '"astyle --mode=c --style=ansi -pcH".(&expandtab ? "s".shiftwidth() : "t")' endif if !exists('g:formatters_cpp') @@ -58,7 +58,7 @@ endif " Java if !exists('g:formatdef_astyle_java') - let g:formatdef_astyle_java = '"astyle --mode=java --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")' + let g:formatdef_astyle_java = '"astyle --mode=java --style=ansi -pcH".(&expandtab ? "s".shiftwidth() : "t")' endif if !exists('g:formatters_java') @@ -68,11 +68,11 @@ endif " Javascript if !exists('g:formatdef_jsbeautify_javascript') - let g:formatdef_jsbeautify_javascript = '"js-beautify -f - -".(&expandtab ? "s ".&shiftwidth : "t").(&textwidth ? " -w ".&textwidth : "")' + let g:formatdef_jsbeautify_javascript = '"js-beautify -f - -".(&expandtab ? "s ".shiftwidth() : "t").(&textwidth ? " -w ".&textwidth : "")' endif if !exists('g:formatdef_pyjsbeautify_javascript') - let g:formatdef_pyjsbeautify_javascript = '"js-beautify -".(&expandtab ? "s ".&shiftwidth : "t").(&textwidth ? " -w ".&textwidth : "")." -"' + let g:formatdef_pyjsbeautify_javascript = '"js-beautify -".(&expandtab ? "s ".shiftwidth() : "t").(&textwidth ? " -w ".&textwidth : "")." -"' endif if !exists('g:formatdef_jscs') @@ -90,11 +90,11 @@ endif " JSON if !exists('g:formatdef_jsbeautify_json') - let g:formatdef_jsbeautify_json = '"js-beautify -f - -".(&expandtab ? "s ".&shiftwidth : "t")' + let g:formatdef_jsbeautify_json = '"js-beautify -f - -".(&expandtab ? "s ".shiftwidth() : "t")' endif if !exists('g:formatdef_pyjsbeautify_json') - let g:formatdef_pyjsbeautify_json = '"js-beautify -".(&expandtab ? "s ".&shiftwidth : "t")." -"' + let g:formatdef_pyjsbeautify_json = '"js-beautify -".(&expandtab ? "s ".shiftwidth() : "t")." -"' endif if !exists('g:formatters_json') @@ -107,11 +107,11 @@ endif " HTML if !exists('g:formatdef_htmlbeautify') - let g:formatdef_htmlbeautify = '"html-beautify -f - -s ".&shiftwidth' + let g:formatdef_htmlbeautify = '"html-beautify -f - -s ".shiftwidth()' endif if !exists('g:formatdef_tidy_html') - let g:formatdef_tidy_html = '"tidy -q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -wrap ".&textwidth' + let g:formatdef_tidy_html = '"tidy -q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".shiftwidth()." --vertical-space yes --tidy-mark no -wrap ".&textwidth' endif if !exists('g:formatters_html') @@ -122,7 +122,7 @@ endif " XML if !exists('g:formatdef_tidy_xml') - let g:formatdef_tidy_xml = '"tidy -q -xml --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -wrap ".&textwidth' + let g:formatdef_tidy_xml = '"tidy -q -xml --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".shiftwidth()." --vertical-space yes --tidy-mark no -wrap ".&textwidth' endif if !exists('g:formatters_xml') @@ -132,7 +132,7 @@ endif " XHTML if !exists('g:formatdef_tidy_xhtml') - let g:formatdef_tidy_xhtml = '"tidy -q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -asxhtml -wrap ".&textwidth' + let g:formatdef_tidy_xhtml = '"tidy -q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".shiftwidth()." --vertical-space yes --tidy-mark no -asxhtml -wrap ".&textwidth' endif if !exists('g:formatters_xhtml') @@ -141,7 +141,7 @@ endif " Ruby if !exists('g:formatdef_rbeautify') - let g:formatdef_rbeautify = '"rbeautify ".(&expandtab ? "-s -c ".&shiftwidth : "-t")' + let g:formatdef_rbeautify = '"rbeautify ".(&expandtab ? "-s -c ".shiftwidth() : "-t")' endif if !exists('g:formatters_ruby') @@ -151,7 +151,7 @@ endif " CSS if !exists('g:formatdef_cssbeautify') - let g:formatdef_cssbeautify = '"css-beautify -f - -s ".&shiftwidth' + let g:formatdef_cssbeautify = '"css-beautify -f - -s ".shiftwidth()' endif if !exists('g:formatters_css') @@ -161,7 +161,7 @@ endif " SCSS if !exists('g:formatdef_sassconvert') - let g:formatdef_sassconvert = '"sass-convert -F scss -T scss --indent " . (&expandtab ? &shiftwidth : "t")' + let g:formatdef_sassconvert = '"sass-convert -F scss -T scss --indent " . (&expandtab ? shiftwidth() : "t")' endif if !exists('g:formatters_scss') @@ -183,7 +183,7 @@ endif " Two definitions are provided for two versions of gofmt. " See issue #59 if !exists('g:formatdef_gofmt_1') - let g:formatdef_gofmt_1 = '"gofmt -tabs=".(&expandtab ? "false" : "true")." -tabwidth=".&shiftwidth' + let g:formatdef_gofmt_1 = '"gofmt -tabs=".(&expandtab ? "false" : "true")." -tabwidth=".shiftwidth()' endif if !exists('g:formatdef_gofmt_2')