2015-05-23 08:25:29 -04:00
|
|
|
"
|
2015-12-15 07:15:05 -05:00
|
|
|
" This file contains default settings and all format program definitions and links these to filetypes
|
2015-05-23 08:25:29 -04:00
|
|
|
"
|
2015-05-23 04:02:05 -04:00
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
|
2015-12-15 07:15:05 -05:00
|
|
|
" Vim-autoformat configuration variables
|
|
|
|
if !exists('g:autoformat_autoindent')
|
2016-03-11 12:09:05 -05:00
|
|
|
let g:autoformat_autoindent = 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:autoformat_retab')
|
|
|
|
let g:autoformat_retab = 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:autoformat_remove_trailing_spaces')
|
|
|
|
let g:autoformat_remove_trailing_spaces = 1
|
2015-12-15 07:15:05 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:autoformat_verbosemode')
|
|
|
|
let g:autoformat_verbosemode = 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
" Python
|
2015-10-13 12:10:07 -04:00
|
|
|
if !exists('g:formatdef_autopep8')
|
2016-04-06 09:55:27 -04:00
|
|
|
" Autopep8 will not do indentation fixes when a range is specified, so we
|
|
|
|
" only pass a range when there is a visual selection that is not the
|
|
|
|
" entire file. See #125.
|
|
|
|
let g:formatdef_autopep8 = '"autopep8 -".(g:DoesRangeEqualBuffer(a:firstline, a:lastline) ? " --range ".a:firstline." ".a:lastline : "")." ".(&textwidth ? "--max-line-length=".&textwidth : "")'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2016-04-06 09:55:27 -04:00
|
|
|
" There doesn't seem to be a reliable way to detect if are in some kind of visual mode,
|
|
|
|
" so we use this as a workaround. We compare the length of the file against
|
|
|
|
" the range arguments. If there is no range given, the range arguments default
|
|
|
|
" to the entire file, so we return false if the range comprises the entire file.
|
|
|
|
function! g:DoesRangeEqualBuffer(first, last)
|
|
|
|
return line('$') != a:last - a:first + 1
|
|
|
|
endfunction
|
|
|
|
|
2016-04-28 21:57:04 -04:00
|
|
|
" Yapf supports multiple formatter styles: pep8, google, chromium, or facebook
|
|
|
|
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.'} -l '.a:firstline.'-'.a:lastline"
|
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_python')
|
2016-04-28 21:57:04 -04:00
|
|
|
let g:formatters_python = ['autopep8','yapf']
|
2015-05-23 04:02:05 -04:00
|
|
|
endif
|
|
|
|
|
2013-03-09 05:52:11 -05:00
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
" C#
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_astyle_cs')
|
2016-02-21 13:34:57 -05:00
|
|
|
if filereadable('.astylerc')
|
2016-05-12 23:10:39 -04:00
|
|
|
let g:formatdef_astyle_cs = '"astyle --mode=cs --options=.astylerc"'
|
2016-02-21 13:34:57 -05:00
|
|
|
elseif filereadable(expand('~/.astylerc')) || exists('$ARTISTIC_STYLE_OPTIONS')
|
|
|
|
let g:formatdef_astyle_cs = '"astyle --mode=cs"'
|
|
|
|
else
|
|
|
|
let g:formatdef_astyle_cs = '"astyle --mode=cs --style=ansi --indent-namespaces -pcH".(&expandtab ? "s".shiftwidth() : "t")'
|
|
|
|
endif
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_cs')
|
|
|
|
let g:formatters_cs = ['astyle_cs']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2015-05-30 05:02:07 -04:00
|
|
|
" Generic C, C++, Objective-C
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_clangformat')
|
2016-02-26 10:09:49 -05:00
|
|
|
let s:configfile_def = "'clang-format -lines='.a:firstline.':'.a:lastline.' --assume-filename=\"'.expand('%:p').'\" -style=file'"
|
|
|
|
let s:noconfigfile_def = "'clang-format -lines='.a:firstline.':'.a:lastline.' --assume-filename=\"'.expand('%:p').'\" -style=\"{BasedOnStyle: WebKit, AlignTrailingComments: true, '.(&textwidth ? 'ColumnLimit: '.&textwidth.', ' : '').(&expandtab ? 'UseTab: Never, IndentWidth: '.shiftwidth() : 'UseTab: Always').'}\"'"
|
2015-12-07 12:34:27 -05:00
|
|
|
let g:formatdef_clangformat = "g:ClangFormatConfigFileExists() ? (" . s:configfile_def . ") : (" . s:noconfigfile_def . ")"
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-12-07 12:34:27 -05:00
|
|
|
function! g:ClangFormatConfigFileExists()
|
|
|
|
return len(findfile(".clang-format", expand("%:p:h").";")) || len(findfile("_clang-format", expand("%:p:h").";"))
|
2015-12-04 03:59:23 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
2015-05-30 05:02:07 -04:00
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
" C
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_astyle_c')
|
2016-02-21 13:34:57 -05:00
|
|
|
if filereadable('.astylerc')
|
2016-05-12 23:10:39 -04:00
|
|
|
let g:formatdef_astyle_c = '"astyle --mode=c --options=.astylerc"'
|
2016-02-21 13:34:57 -05:00
|
|
|
elseif filereadable(expand('~/.astylerc')) || exists('$ARTISTIC_STYLE_OPTIONS')
|
|
|
|
let g:formatdef_astyle_c = '"astyle --mode=c"'
|
|
|
|
else
|
|
|
|
let g:formatdef_astyle_c = '"astyle --mode=c --style=ansi -pcH".(&expandtab ? "s".shiftwidth() : "t")'
|
|
|
|
endif
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_c')
|
2015-05-30 05:02:07 -04:00
|
|
|
let g:formatters_c = ['clangformat', 'astyle_c']
|
2015-05-23 08:25:29 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" C++
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_astyle_cpp')
|
2016-02-21 13:34:57 -05:00
|
|
|
if filereadable('.astylerc')
|
2016-05-12 23:10:39 -04:00
|
|
|
let g:formatdef_astyle_cpp = '"astyle --mode=c --options=.astylerc"'
|
2016-02-21 13:34:57 -05:00
|
|
|
elseif filereadable(expand('~/.astylerc')) || exists('$ARTISTIC_STYLE_OPTIONS')
|
|
|
|
let g:formatdef_astyle_cpp = '"astyle --mode=c"'
|
|
|
|
else
|
|
|
|
let g:formatdef_astyle_cpp = '"astyle --mode=c --style=ansi -pcH".(&expandtab ? "s".shiftwidth() : "t")'
|
|
|
|
endif
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_cpp')
|
2015-05-30 05:02:07 -04:00
|
|
|
let g:formatters_cpp = ['clangformat', 'astyle_cpp']
|
2015-05-23 08:25:29 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" Objective C
|
|
|
|
if !exists('g:formatters_objc')
|
2015-05-30 05:02:07 -04:00
|
|
|
let g:formatters_objc = ['clangformat']
|
2015-05-23 08:25:29 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" Java
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_astyle_java')
|
2016-02-21 13:34:57 -05:00
|
|
|
if filereadable('.astylerc')
|
2016-05-12 23:10:39 -04:00
|
|
|
let g:formatdef_astyle_java = '"astyle --mode=java --options=.astylerc"'
|
2016-02-21 13:34:57 -05:00
|
|
|
elseif filereadable(expand('~/.astylerc')) || exists('$ARTISTIC_STYLE_OPTIONS')
|
|
|
|
let g:formatdef_astyle_java = '"astyle --mode=java"'
|
|
|
|
else
|
|
|
|
let g:formatdef_astyle_java = '"astyle --mode=java --style=java -pcH".(&expandtab ? "s".shiftwidth() : "t")'
|
|
|
|
endif
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_java')
|
|
|
|
let g:formatters_java = ['astyle_java']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" Javascript
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_jsbeautify_javascript')
|
2016-02-22 14:55:23 -05:00
|
|
|
if filereadable('.jsbeautifyrc')
|
|
|
|
let g:formatdef_jsbeautify_javascript = '"js-beautify"'
|
|
|
|
elseif filereadable(expand('~/.jsbeautifyrc'))
|
|
|
|
let g:formatdef_jsbeautify_javascript = '"js-beautify"'
|
|
|
|
else
|
|
|
|
let g:formatdef_jsbeautify_javascript = '"js-beautify -f - -".(&expandtab ? "s ".shiftwidth() : "t").(&textwidth ? " -w ".&textwidth : "")'
|
|
|
|
endif
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatdef_pyjsbeautify_javascript')
|
2015-10-08 12:15:41 -04:00
|
|
|
let g:formatdef_pyjsbeautify_javascript = '"js-beautify -".(&expandtab ? "s ".shiftwidth() : "t").(&textwidth ? " -w ".&textwidth : "")." -"'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatdef_jscs')
|
|
|
|
let g:formatdef_jscs = '"jscs -x"'
|
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_javascript')
|
2015-05-20 08:56:29 -04:00
|
|
|
let g:formatters_javascript = [
|
|
|
|
\ 'jsbeautify_javascript',
|
2015-05-30 10:11:37 -04:00
|
|
|
\ 'pyjsbeautify_javascript',
|
2015-05-20 08:56:29 -04:00
|
|
|
\ 'jscs'
|
|
|
|
\ ]
|
2015-05-23 08:25:29 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" JSON
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_jsbeautify_json')
|
2016-02-25 11:33:02 -05:00
|
|
|
if filereadable('.jsbeautifyrc')
|
|
|
|
let g:formatdef_jsbeautify_json = '"js-beautify"'
|
|
|
|
elseif filereadable(expand('~/.jsbeautifyrc'))
|
|
|
|
let g:formatdef_jsbeautify_json = '"js-beautify"'
|
|
|
|
else
|
|
|
|
let g:formatdef_jsbeautify_json = '"js-beautify -f - -".(&expandtab ? "s ".shiftwidth() : "t")'
|
|
|
|
endif
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatdef_pyjsbeautify_json')
|
2015-10-08 12:15:41 -04:00
|
|
|
let g:formatdef_pyjsbeautify_json = '"js-beautify -".(&expandtab ? "s ".shiftwidth() : "t")." -"'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_json')
|
2015-05-31 14:58:14 -04:00
|
|
|
let g:formatters_json = [
|
|
|
|
\ 'jsbeautify_json',
|
|
|
|
\ 'pyjsbeautify_json',
|
|
|
|
\ ]
|
2015-05-23 08:25:29 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
2015-06-13 11:53:44 -04:00
|
|
|
" HTML
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_htmlbeautify')
|
2015-10-08 12:15:41 -04:00
|
|
|
let g:formatdef_htmlbeautify = '"html-beautify -f - -s ".shiftwidth()'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatdef_tidy_html')
|
2015-10-08 12:15:41 -04:00
|
|
|
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'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-06-13 11:53:44 -04:00
|
|
|
if !exists('g:formatters_html')
|
|
|
|
let g:formatters_html = ['htmlbeautify', 'tidy_html']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
" XML
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_tidy_xml')
|
2015-10-08 12:15:41 -04:00
|
|
|
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'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-06-13 11:53:44 -04:00
|
|
|
if !exists('g:formatters_xml')
|
|
|
|
let g:formatters_xml = ['tidy_xml']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" XHTML
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_tidy_xhtml')
|
2015-10-08 12:15:41 -04:00
|
|
|
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'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-06-13 11:53:44 -04:00
|
|
|
if !exists('g:formatters_xhtml')
|
|
|
|
let g:formatters_xhtml = ['tidy_xhtml']
|
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
" Ruby
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_rbeautify')
|
2015-10-08 12:15:41 -04:00
|
|
|
let g:formatdef_rbeautify = '"rbeautify ".(&expandtab ? "-s -c ".shiftwidth() : "-t")'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_ruby')
|
|
|
|
let g:formatters_ruby = ['rbeautify']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" CSS
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_cssbeautify')
|
2015-10-08 12:15:41 -04:00
|
|
|
let g:formatdef_cssbeautify = '"css-beautify -f - -s ".shiftwidth()'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_css')
|
|
|
|
let g:formatters_css = ['cssbeautify']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" SCSS
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_sassconvert')
|
2015-10-08 12:15:41 -04:00
|
|
|
let g:formatdef_sassconvert = '"sass-convert -F scss -T scss --indent " . (&expandtab ? shiftwidth() : "t")'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_scss')
|
|
|
|
let g:formatters_scss = ['sassconvert']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" Typescript
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_tsfmt')
|
2015-10-31 06:55:06 -04:00
|
|
|
let g:formatdef_tsfmt = "'tsfmt --stdin '.bufname('%')"
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
2015-05-23 08:25:29 -04:00
|
|
|
if !exists('g:formatters_typescript')
|
|
|
|
let g:formatters_typescript = ['tsfmt']
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2015-06-13 05:10:25 -04:00
|
|
|
" Golang
|
2015-08-01 00:35:59 -04:00
|
|
|
" Two definitions are provided for two versions of gofmt.
|
|
|
|
" See issue #59
|
2015-08-08 05:05:41 -04:00
|
|
|
if !exists('g:formatdef_gofmt_1')
|
2015-10-08 12:15:41 -04:00
|
|
|
let g:formatdef_gofmt_1 = '"gofmt -tabs=".(&expandtab ? "false" : "true")." -tabwidth=".shiftwidth()'
|
2015-08-08 05:05:41 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatdef_gofmt_2')
|
|
|
|
let g:formatdef_gofmt_2 = '"gofmt"'
|
|
|
|
endif
|
|
|
|
|
2016-02-21 00:39:06 -05:00
|
|
|
if !exists('g:formatdef_goimports')
|
|
|
|
let g:formatdef_goimports = '"goimports"'
|
|
|
|
endif
|
|
|
|
|
2015-06-13 05:10:25 -04:00
|
|
|
if !exists('g:formatters_go')
|
2016-02-21 00:39:06 -05:00
|
|
|
let g:formatters_go = ['gofmt_1', 'goimports', 'gofmt_2']
|
2015-06-13 05:10:25 -04:00
|
|
|
endif
|
|
|
|
|
2015-11-03 08:45:25 -05:00
|
|
|
" Rust
|
|
|
|
if !exists('g:formatdef_rustfmt')
|
|
|
|
let g:formatdef_rustfmt = '"rustfmt"'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatters_rust')
|
|
|
|
let g:formatters_rust = ['rustfmt']
|
|
|
|
endif
|
|
|
|
|
2015-11-05 09:32:43 -05:00
|
|
|
" Dart
|
|
|
|
if !exists('g:formatdef_dartfmt')
|
|
|
|
let g:formatdef_dartfmt = '"dartfmt"'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatters_dart')
|
|
|
|
let g:formatters_dart = ['dartfmt']
|
|
|
|
endif
|
2015-11-29 23:19:22 -05:00
|
|
|
|
|
|
|
" Perl
|
|
|
|
if !exists('g:formatdef_perltidy')
|
2016-02-10 22:49:16 -05:00
|
|
|
" use perltidyrc file if readable
|
|
|
|
if (has("win32") && (filereadable("perltidy.ini") ||
|
|
|
|
\ filereadable($HOMEPATH."/perltidy.ini"))) ||
|
|
|
|
\ ((has("unix") ||
|
|
|
|
\ has("mac")) && (filereadable(".perltidyrc") ||
|
|
|
|
\ filereadable("~/.perltidyrc") ||
|
|
|
|
\ filereadable("/usr/local/etc/perltidyrc") ||
|
|
|
|
\ filereadable("/etc/perltidyrc")))
|
|
|
|
let g:formatdef_perltidy = '"perltidy -q -st"'
|
|
|
|
else
|
|
|
|
let g:formatdef_perltidy = '"perltidy --perl-best-practices --format-skipping -q "'
|
|
|
|
endif
|
2015-11-29 23:19:22 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatters_perl')
|
2016-02-10 22:49:16 -05:00
|
|
|
let g:formatters_perl = ['perltidy']
|
2015-11-29 23:19:22 -05:00
|
|
|
endif
|
2015-12-05 16:10:58 -05:00
|
|
|
|
|
|
|
" Haskell
|
|
|
|
if !exists('g:formatdef_stylish_haskell')
|
|
|
|
let g:formatdef_stylish_haskell = '"stylish-haskell"'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatters_haskell')
|
|
|
|
let g:formatters_haskell = ['stylish_haskell']
|
|
|
|
endif
|
2016-03-17 23:36:32 -04:00
|
|
|
|
|
|
|
" Markdown
|
|
|
|
if !exists('g:formatdef_remark_markdown')
|
|
|
|
let g:formatdef_remark_markdown = '"remark --silent --no-color"'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:formatters_markdown')
|
|
|
|
let g:formatters_markdown = ['remark_markdown']
|
|
|
|
endif
|