Support python cli-version of js-beautify by default

This commit is contained in:
Chiel92 2015-05-30 16:11:37 +02:00
parent 5d90bb9241
commit 495dc9651d
3 changed files with 8 additions and 14 deletions

View File

@ -69,8 +69,10 @@ To to load style configuration from a .clang-format file, add to your .vimrc: `l
Details: http://clang.llvm.org/docs/ClangFormat.html.
* `astyle` for __C#__, __C++__, __C__ and __Java__.
*Important*: version `2.0.4` or higher is required, since only those versions correctly support piping.
Download it here: http://astyle.sourceforge.net/.
*Important*:
- version `2.0.4` or higher is required, since only those versions correctly support piping.
- Astyle is currently bugged: https://sourceforge.net/p/astyle/bugs/368/
* `autopep8` for __Python__ (supports formatting ranges).
@ -82,11 +84,7 @@ And here the link to its page on the python website: http://pypi.python.org/pypi
* `js-beautify` for __Javascript__ and __JSON__.
It can be installed by running `npm install -g js-beautify`.
Note that `nodejs` is needed for this to work.
The *python version is not supported by default* because it needs different arguments.
If you want (or need) to use the python version, you manually have to specify a formatter definition that is valid for the python version in your `.vimrc`. Example:
```vim
let g:formatdef_jsbeautify_javascript = '"-".(&expandtab ? "s ".&shiftwidth : "t").(&textwidth ? " -w ".&textwidth : "")." -"'
```
The python version version is also supported by default, which does not need `nodejs` to run.
Here is the link to the repository: https://github.com/einars/js-beautify.
* `typescript-formatter` for __Typescript__.

View File

@ -1,7 +1,3 @@
" TODO:
" - Make :Autoformat accept ranges
" Function for finding the formatters for this filetype
" Result is stored in b:formatters
function! s:find_formatters(...)
@ -41,10 +37,11 @@ endfunction
" Try all formatters, starting with the currently selected one, until one
" works. If none works, autoindent the buffer.
function! s:TryAllFormatters(...) range
echom a:firstline.", ".a:lastline
"echom a:firstline.", ".a:lastline
"echom line('.')", ".line('v')
"echom line("'<")", ".line("'>")
"echom mode()
" Make sure formatters are defined and detected
if !call('<SID>find_formatters', a:000)
return 0
@ -108,7 +105,6 @@ text = '\n'.join(vim.current.buffer[:])
formatprg = vim.eval('&formatprg')
verbose = vim.eval('verbose')
p = subprocess.Popen(formatprg, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
#print(text)
stdoutdata, stderrdata = p.communicate(text)
if stderrdata:
if verbose:
@ -117,8 +113,6 @@ if stderrdata:
print('Failing config: {} '.format(repr(formatprg), stderrdata))
vim.command('return 0')
else:
#print(stdoutdata)
#print('asdf')
vim.current.buffer[:] = stdoutdata.split('\n')
EOF

View File

@ -66,10 +66,12 @@ endif
" Javascript
let g:formatdef_jsbeautify_javascript = '"js-beautify -f - -".(&expandtab ? "s ".&shiftwidth : "t").(&textwidth ? " -w ".&textwidth : "")'
let g:formatdef_pyjsbeautify_javascript = '"-".(&expandtab ? "s ".&shiftwidth : "t").(&textwidth ? " -w ".&textwidth : "")." -"'
let g:formatdef_jscs = '"jscs -x"'
if !exists('g:formatters_javascript')
let g:formatters_javascript = [
\ 'jsbeautify_javascript',
\ 'pyjsbeautify_javascript',
\ 'jscs'
\ ]
endif