Cleanup and update README.

This commit is contained in:
Chiel ten Brinke 2015-12-15 13:15:05 +01:00
parent 37a6b7f979
commit 7902a12391
3 changed files with 26 additions and 16 deletions

View File

@ -65,8 +65,13 @@ Or to have your code be formatted upon saving your file, you could use something
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.
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?*, or change the formatter with the highest priority by the commands `:NextFormatter` and `:PreviousFormatter`.
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 (`.`).

View File

@ -7,7 +7,7 @@ endif
function! s:find_formatters(...)
" Detect verbosity
let verbose = &verbose || exists("g:autoformat_verbosemode")
let verbose = &verbose || g:autoformat_verbosemode == 1
" Extract filetype to be used
let ftype = a:0 ? a:1 : &filetype
@ -65,15 +65,12 @@ endfunction
function! s:TryAllFormatters(...) range
" Make sure formatters are defined and detected
if !call('<SID>find_formatters', a:000)
" No formatters defined, so autoindent code
" exe "normal gg=G"
" No formatters defined
if g:autoformat_autoindent == 1
" No formatters defined, so autoindent code
" Autoindent code
exe "normal gg=G"
return 0
else
return 0
endif
return 0
endif
" Make sure index exist and is valid
@ -118,14 +115,12 @@ function! s:TryAllFormatters(...) range
endif
if s:index == b:current_formatter_index
" Tried all formatters, none worked so autoindent code
" Tried all formatters, none worked
if g:autoformat_autoindent == 1
" No formatters defined, so autoindent code
" Autoindent code
exe "normal gg=G"
return 0
else
return 0
endif
return 0
endif
endwhile
@ -139,7 +134,7 @@ endfunction
" +python version
function! s:TryFormatterPython()
" Detect verbosity
let verbose = &verbose || exists("g:autoformat_verbosemode")
let verbose = &verbose || g:autoformat_verbosemode == 1
python << EOF
import vim, subprocess, os
@ -187,7 +182,7 @@ endfunction
" +python3 version
function! s:TryFormatterPython3()
" Detect verbosity
let verbose = &verbose || exists("g:autoformat_verbosemode")
let verbose = &verbose || g:autoformat_verbosemode == 1
python3 << EOF
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
if !exists('g:formatdef_autopep8')
let g:formatdef_autopep8 = '"autopep8 - --range ".a:firstline." ".a:lastline." ".(&textwidth ? "--max-line-length=".&textwidth : "")'