Merge branch 'master' into dev

This commit is contained in:
Chiel ten Brinke 2015-12-23 17:01:37 +01:00
commit f9cc5ff1b3
3 changed files with 52 additions and 11 deletions

View File

@ -65,9 +65,14 @@ Or to have your code be formatted upon saving your file, you could use something
au BufWrite * :Autoformat au BufWrite * :Autoformat
``` ```
To disable the fallback to vim's indent file, set the following variable to be 0.
```vim
let g:autoformat_autoindent = 0
```
For each filetype, vim-autoformat has a list of applicable formatters. For each filetype, vim-autoformat has a list of applicable formatters.
If you have multiple formatters installed that are supported for some filetype, vim-autoformat just uses the first that occurs in this list of applicable formatters. If you have multiple formatters installed that are supported for some filetype, vim-autoformat tries all formatters in this list of applicable formatters, until one succeeds.
You can either set this list manually in your vimrc (see section *How can I change the behaviour of formatters, or add one myself?*, You can set this list manually in your vimrc (see section *How can I change the behaviour of formatters, or add one myself?*,
or change the formatter with the highest priority by the commands `:NextFormatter` and `:PreviousFormatter`. or change the formatter with the highest priority by the commands `:NextFormatter` and `:PreviousFormatter`.
To print the currently selected formatter use `:CurrentFormatter`. To print the currently selected formatter use `:CurrentFormatter`.
If you have a composite filetype with dots (like `django.python` or `php.wordpress`), vim-autoformat first tries to detect and use formatters for the exact original filetype, and then tries the same for all supertypes occuring from left to right in the original filetype separated by dots (`.`). If you have a composite filetype with dots (like `django.python` or `php.wordpress`), vim-autoformat first tries to detect and use formatters for the exact original filetype, and then tries the same for all supertypes occuring from left to right in the original filetype separated by dots (`.`).
@ -146,6 +151,9 @@ Part of the Dart SDK (make sure it is on your PATH). See https://www.dartlang.or
* `perltidy` for __Perl__. * `perltidy` for __Perl__.
It can be installed from CPAN `cpanm Perl::Tidy` . See https://metacpan.org/pod/Perl::Tidy and http://perltidy.sourceforge.net/ for more info. It can be installed from CPAN `cpanm Perl::Tidy` . See https://metacpan.org/pod/Perl::Tidy and http://perltidy.sourceforge.net/ for more info.
* `stylish-haskell` for __Haskell__
It can be installed using [`cabal`](https://www.haskell.org/cabal/) build tool. Installation instructions are available at https://github.com/jaspervdj/stylish-haskell#installation
How can I change the behaviour of formatters, or add one myself? How can I change the behaviour of formatters, or add one myself?
---------------------------------------------------------------- ----------------------------------------------------------------
If you need a formatter that is not among the defaults, or if you are not satisfied with the default formatting behaviour that is provided by vim-autoformat, you can define it yourself. If you need a formatter that is not among the defaults, or if you are not satisfied with the default formatting behaviour that is provided by vim-autoformat, you can define it yourself.

View File

@ -1,8 +1,13 @@
" Function for finding the formatters for this filetype " Function for finding the formatters for this filetype
" Result is stored in b:formatters " Result is stored in b:formatters
if !exists('g:autoformat_autoindent')
let g:autoformat_autoindent = 1
endif
function! s:find_formatters(...) function! s:find_formatters(...)
" Detect verbosity " Detect verbosity
let verbose = &verbose || exists("g:autoformat_verbosemode") let verbose = &verbose || g:autoformat_verbosemode == 1
" Extract filetype to be used " Extract filetype to be used
let ftype = a:0 ? a:1 : &filetype let ftype = a:0 ? a:1 : &filetype
@ -63,8 +68,11 @@ function! s:TryAllFormatters(...) range
" Make sure formatters are defined and detected " Make sure formatters are defined and detected
if !call('<SID>find_formatters', a:000) if !call('<SID>find_formatters', a:000)
" No formatters defined, so autoindent code " No formatters defined
exe "normal gg=G" if g:autoformat_autoindent == 1
" Autoindent code
exe "normal gg=G"
endif
return 0 return 0
endif endif
@ -116,11 +124,17 @@ function! s:TryAllFormatters(...) range
endif endif
if s:index == b:current_formatter_index if s:index == b:current_formatter_index
" Tried all formatters, none worked so autoindent code
if verbose if verbose
echo "No format definitions were successful. Trying to autoindent code." echo "No format definitions were successful."
endif
" Tried all formatters, none worked
if g:autoformat_autoindent == 1
if verbose
echo "Trying to autoindent code."
endif
" Autoindent code
exe "normal gg=G"
endif endif
exe "normal gg=G"
return 0 return 0
endif endif
endwhile endwhile
@ -135,7 +149,7 @@ endfunction
" +python version " +python version
function! s:TryFormatterPython() function! s:TryFormatterPython()
" Detect verbosity " Detect verbosity
let verbose = &verbose || exists("g:autoformat_verbosemode") let verbose = &verbose || g:autoformat_verbosemode == 1
python << EOF python << EOF
import vim, subprocess, os import vim, subprocess, os
@ -183,7 +197,7 @@ endfunction
" +python3 version " +python3 version
function! s:TryFormatterPython3() function! s:TryFormatterPython3()
" Detect verbosity " Detect verbosity
let verbose = &verbose || exists("g:autoformat_verbosemode") let verbose = &verbose || g:autoformat_verbosemode == 1
python3 << EOF python3 << EOF
import vim, subprocess, os import vim, subprocess, os

View File

@ -1,8 +1,18 @@
" "
" This file contains all default format program definitions and links them to filetypes " This file contains default settings and all format program definitions and links these to filetypes
" "
" Vim-autoformat configuration variables
if !exists('g:autoformat_autoindent')
let g:autoformat_verbosemode = 0
endif
if !exists('g:autoformat_verbosemode')
let g:autoformat_verbosemode = 0
endif
" Python " Python
if !exists('g:formatdef_autopep8') if !exists('g:formatdef_autopep8')
let g:formatdef_autopep8 = '"autopep8 - --range ".a:firstline." ".a:lastline." ".(&textwidth ? "--max-line-length=".&textwidth : "")' let g:formatdef_autopep8 = '"autopep8 - --range ".a:firstline." ".a:lastline." ".(&textwidth ? "--max-line-length=".&textwidth : "")'
@ -232,3 +242,12 @@ endif
if !exists('g:formatters_perl') if !exists('g:formatters_perl')
let g:formatters_perl = ['perltidy'] let g:formatters_perl = ['perltidy']
endif endif
" 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