Merge branch 'frtmelody-master'
This commit is contained in:
commit
5ed4c3cfcb
@ -65,8 +65,13 @@ 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?*, or change the formatter with the highest priority by the commands `:NextFormatter` and `:PreviousFormatter`.
|
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 (`.`).
|
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 (`.`).
|
||||||
|
|
||||||
|
@ -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
|
||||||
@ -60,8 +65,11 @@ endfunction
|
|||||||
function! s:TryAllFormatters(...) range
|
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
|
||||||
|
|
||||||
@ -107,8 +115,11 @@ 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
|
" Tried all formatters, none worked
|
||||||
exe "normal gg=G"
|
if g:autoformat_autoindent == 1
|
||||||
|
" Autoindent code
|
||||||
|
exe "normal gg=G"
|
||||||
|
endif
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
@ -123,7 +134,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
|
||||||
@ -171,7 +182,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
|
||||||
|
@ -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 : "")'
|
||||||
|
Loading…
Reference in New Issue
Block a user