Merge branch 'frtmelody-master'

This commit is contained in:
Chiel ten Brinke 2015-12-15 13:17:48 +01:00
commit 5ed4c3cfcb
3 changed files with 35 additions and 9 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

@ -1,8 +1,13 @@
" Function for finding the formatters for this filetype
" Result is stored in b:formatters
if !exists('g:autoformat_autoindent')
let g:autoformat_autoindent = 1
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
@ -60,8 +65,11 @@ 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
" No formatters defined
if g:autoformat_autoindent == 1
" Autoindent code
exe "normal gg=G"
endif
return 0
endif
@ -107,8 +115,11 @@ 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
" Autoindent code
exe "normal gg=G"
endif
return 0
endif
endwhile
@ -123,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
@ -171,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 : "")'