75336684bc6c27ccf4b3e3f4467348bdc64f5471

Author: AD7six

Date: 2009-11-19 18:37:02 +0100

adding a load of autocorrections for cleaning up dirtily formatted php code

diff --git a/vendors/vim/plugins/cakephp.vim b/vendors/vim/plugins/cakephp.vim index 7f47b36..cc6cf59 100644 --- a/vendors/vim/plugins/cakephp.vim +++ b/vendors/vim/plugins/cakephp.vim @@ -165,12 +165,10 @@ endfunction " Function: BufferWritePre() " EOL markers are not desired, change to binary mode before saving so one isn't added function s:BufferWritePre() - " clear trailing whitespace - ":%s/\(\*\)\@<!\s\+$//ge - :%s/\s\s*$//ge - " put a blank line before comment blocks - :%s/\([\{\}\/;]\)\n\zs\/\*/\r\/\*/ge - "exe "norm :silent %s/\\s\\s*$//e\<CR>" + "TODO configure this? + if (&ft == 'php') + call s:FormatPhp() + endif " set to binary and remove eol let b:save_bin = &bin let &l:bin = 1 @@ -451,7 +449,7 @@ function s:SetupCommands() " command -nargs=0 F %call s:CleanBuffer() "endif if !exists(":R") - command -nargs=0 R call s:ReprocessComments() + command -nargs=0 R call s:FormatPhp() endif if !exists(":L") command -bar -narg=0 L call DocDebug() @@ -523,6 +521,31 @@ function s:ReprocessComments() %:call DocRange() endfunction +function s:FormatPhp() + " put a blank line before comment blocks + :silent %s/\([\{\}\/;]\)\n\zs\/\*/\r\/\*/e + " correct doc block headers + :silent %s/^\s*\/\*\*/\/\*\*/e + " correct doc block contents/tail that is indented ( * or */) + :silent %s/^\s*\*/ \*/e + + "remove trailing whitespace + :silent %s/\s\s*$//e + + " auto correct lines which start with a { + :silent %s/\n\s*{/ {/e + " auto correct lines which start with 'else' + :silent %s/\n\s*else/ else/e + " add parenthesese to a trailing else or if + :silent %s/\(else|if)\s*\n/\1 {\n/e + " add parenthesese to what looks like an else with no parenthesese + :silent %s/^\(\s*\)\zselse\s*\([^{]\)/else {\n\t\1\2/e + + " correct whitespace around comas (parameters) + :silent %s/,\(\S\)\@=/, /e + " correct whitespace around assignments/comparisons + :silent %s/=\([^=&> ]\)\@=/= /e +endfunction " Function: FormatComments() " Correct whitespace around doc blocks function s:FormatComments()