From 81f5e989c2f82e61db9f55228cd65d292ff10e73 Mon Sep 17 00:00:00 2001 From: Chiel ten Brinke Date: Wed, 30 Mar 2016 10:01:56 +0200 Subject: [PATCH] Add bufferlocal variants for all options. --- README.md | 3 +++ plugin/autoformat.vim | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 55a51bf..ba21b3e 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,8 @@ let g:autoformat_retab = 0 let g:autoformat_remove_trailing_spaces = 0 ``` +To disable or re-enable these option for specific buffers, use the buffer local variants: +`b:autoformat_autoindent`, `b:autoformat_retab` and `b:autoformat_remove_trailing_spaces`. You can manually autoindent, retab or remove trailing whitespace with the following respective commands. @@ -95,6 +97,7 @@ tries all formatters in this list of applicable formatters, until one succeeds. 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`. To print the currently selected formatter use `:CurrentFormatter`. +These latter commands are mostly useful for debugging purposes. 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 diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index df19909..699b305 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -138,26 +138,28 @@ function! s:Fallback() " Detect verbosity let verbose = &verbose || g:autoformat_verbosemode == 1 - if g:autoformat_remove_trailing_spaces == 1 + if exists('b:autoformat_remove_trailing_spaces') ? b:autoformat_remove_trailing_spaces == 1 : g:autoformat_remove_trailing_spaces == 1 if verbose echomsg "Removing trailing whitespace..." endif call s:RemoveTrailingSpaces() endif - if g:autoformat_retab == 1 + + if exists('b:autoformat_retab') ? b:autoformat_retab == 1 : g:autoformat_retab == 1 if verbose echomsg "Retabbing..." endif retab endif - if g:autoformat_autoindent == 1 + + if exists('b:autoformat_autoindent') ? b:autoformat_autoindent == 1 : g:autoformat_autoindent == 1 if verbose echomsg "Autoindenting..." endif " Autoindent code exe "normal gg=G" endif - return 0 + endfunction