compatibilty with default gq functionality

This commit is contained in:
Chiel92 2013-03-26 23:03:15 +01:00
parent 83c935d35f
commit f5e60b5266
2 changed files with 12 additions and 9 deletions

View File

@ -98,7 +98,7 @@ As you see, this allows us to dynamically define some parameters.
In this example, the indent width that astyle will use, depends on the buffer local value of `&shiftwidth`.
So if you're editing a csharp file and change the `shiftwidth`, the `formatprg_args_expr_<filetype>` will change correspondingly.
For the default formatprogram definitions, the options `expandtab` and `shiftwidth` are taken into account whenever possible.
For the default formatprogram definitions, the options `expandtab`, `shiftwidth` and `textwidth` are taken into account whenever possible.
This means that the formatting style will match your current vim settings as much as possible.
For the exact default definitions, have a look in `vim-autoformat/plugin/defaults.vim`.
@ -108,7 +108,6 @@ Todo list
* Check for windows support.
* Option for on-the-fly code-formatting, like visual studio (If ever. When you have a clever idea about how to do this, i'd be glad to hear.)
* Create a help file.
* Take `textwidth` into account.
* Only use autoindent as fallback when running `:Autoformat`.

View File

@ -42,18 +42,22 @@ function! s:set_formatprg()
return 1
endfunction
"When gq has been pressed:
"1. set right formatprg
"2. if formatprg!="" run regular gq
"3. else run =
noremap <expr> gq <SID>set_formatprg() ? 'gq' : '='
"set right formatprg before formatting
noremap <expr> gq <SID>set_formatprg() ? 'gq' : 'gq'
"Function for formatting the entire buffer
function! s:Autoformat()
"Save window state
let winview=winsaveview()
"Autoformat code
exe "normal gggqG"
if <SID>set_formatprg()
"Autoformat code
exe "1,$!".&formatprg
else
"Autoindent code
exe "normal gg=G"
endif
"Recall window state
call winrestview(winview)
endfunction