8ec14a86b4da3ef2f0bbb3fec86c9b472bfa4b2e
Author: AD7six
Date: 2009-11-24 14:39:00 +0100
diff --git a/vendors/vim/plugins/cakephp.vim b/vendors/vim/plugins/cakephp.vim
index 7c530cc..a5f1f3c 100644
--- a/vendors/vim/plugins/cakephp.vim
+++ b/vendors/vim/plugins/cakephp.vim
@@ -243,50 +243,77 @@ endfunction
" and then indent it. It's a lot easier to read/cleanup code that's been too-exploded
" than code that isn't wrapped/formatted/indented
function ExplodePhp() range
+ let l:line = line('.')
+ :delmarks yz
+ :silent exe 'norm ' . a:firstline . 'G'
+ :ky
+ :silent exe 'norm ' . a:lastline . 'G'
+ :kz
+
"explode on any comma, or ()
- :silent '<,'>s/\([,()]\)\( \?[^, ]\)/\1 \r\2/ge
+ :silent 'y,'zs/\([,()]\)\( \?[^, ]\)/\1 \r\2/ge
"for any closing bracket that isn't on its own line explode that too
- :silent '<,'>s/\([\S]\))\(,?\)$/\1\r)\2/ge
+ :silent 'y,'zs/\([\S]\))\(,?\)$/\1\r)\2/ge
"For a closing bracket, with a semicolon on the following line - clean up
- :silent '<,'>s/)\s\r\s*;/);/e
- "indent the range TODO not working
- '<,'>=
+ :silent 'y,'zs/)\s\r\s*;/);/e
+
+ " indent
+ exe "norm ='y'z"
+ :silent exe 'norm ' . l:line . 'G'
endfunction
" Function: FormatPhp()
" (Attempt to) autoformat php code according to various conventions
function FormatPhp() range
+ let l:line = line('.')
+ :delmarks yz
+ :silent exe 'norm ' . a:firstline . 'G'
+ :ky
+ :silent exe 'norm ' . a:lastline . 'G'
+ :kz
+
""replace any double spaces with a single space
":silent '<,'>s/ \{2,}/ /ge
"remove trailing whitespace
- :silent '<,'>s/\s\s*$//e
+ :silent 'y,'zs/\s\s*$//e
+ " Lower case booleans please
+ :silent 'y,'zs/TRUE/true/e
+ :silent 'y,'zs/FALSE/false/e
" auto correct lines which start with a { so the { is on the end of the
" previous line
- :silent '<,'>s/\n\s*{/ {/e
- " auto correct lines which start with 'else'
- :silent '<,'>s/\n\s*else/ else/e
+ :silent 'y,'zs/\n\s*{/ {/e
+ " auto correct lines which start with 'else' prepending the else to the
+ " previous line
+ :silent 'y,'zs/}\s*\n\s*else/ else/e
+ :silent 'y,'zs/\n\s*else/} else/e
" add parenthesese to a trailing else or if
- :silent '<,'>s/\(else|if\)\s*\n/\1 {\n/e
+ :silent 'y,'zs/\(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
+ :silent 'y,'zs/^\(\s*\)\zselse\s*\([^{]\)/else {\n\t\1\2/e
" correct whitespace around comas (parameters)
- :silent '<,'>s/,\(\S\)\@=/, /ge
+ :silent 'y,'zs/,\(\S\)\@=/, /ge
" correct whitespace around assignments/comparisons x=y becomes x = y
- :silent '<,'>s/\([^=<>& ]\)\([!<]\?==\?[=>&]\?\)\([^=<>& ]\)/\1 \2 \3/ge
+ :silent 'y,'zs/\([^=<>& ]\)\([!<]\?==\?[=>&]\?\)\([^=<>& ]\)/\1 \2 \3/ge
" correct whitespace around assignments/comparisons x= y becomes x = y
- :silent '<,'>s/\([^=<>& ]\)\([!<]\?==\?[=>&]\?\)/\1 \2/ge
+ :silent 'y,'zs/\([^=<>& ]\)\([!<]\?==\?[=>&]\?\)/\1 \2/ge
" correct whitespace around assignments/comparisons x =y becomes x = y
- :silent '<,'>s/\([!<]\?==\?[=>&]\?\)\([^=<>& ]\)/\1 \2/ge
+ :silent 'y,'zs/\([!<]\?==\?[=>&]\?\)\([^=<>& ]\)/\1 \2/ge
" put a blank line before comment blocks
- :silent '<,'>s/\([\{\}\/;]\)\n\zs\/\*/\r\/\*/e
+ :silent 'y,'zs/\([\{\}\/;]\)\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
- '<,'>:call s:FormatComments()
+ :silent 'y,'zs/^\s*\/\*\*/\/\*\*/e
+ " correct doc block contents/tail that is indented ( * or */)
+ :silent 'y,'zs/^\s*\*/ \*/e
+
+ 'y,'z:call s:FormatComments()
+
+ " indent
+ exe "norm ='y'z"
+
+ :silent exe 'norm ' . l:line . 'G'
endfunction
" Function: ImplodePhp()
@@ -294,14 +321,24 @@ endfunction
" and then indent it. It's a lot easier to read/cleanup code that's been too-exploded
" than code that isn't wrapped/formatted/indented
function ImplodePhp() range
+ let l:line = line('.')
+ :delmarks yz
+ :silent exe 'norm ' . a:firstline . 'G'
+ :ky
+ :silent exe 'norm ' . a:lastline . 'G'
+ :kz
+
"explode on any comma, or ()
- :silent '<,'>s/\([,()]\)\( \?[^, ]\)/\1 \r\2/ge
+ :silent 'y,'zs/\([,()]\)\( \?[^, ]\)/\1 \r\2/ge
"for any closing bracket that isn't on its own line explode that too
- :silent '<,'>s/\([\S]\))\(,?\)$/\1\r)\2/ge
+ :silent 'y,'zs/\([\S]\))\(,?\)$/\1\r)\2/ge
"For a closing bracket, with a semicolon on the following line - clean up
- :silent '<,'>s/)\s\r\s*;/);/e
- "indent the range TODO not working
- '<,'>=
+ :silent 'y,'zs/)\s\r\s*;/);/e
+
+ " indent
+ exe "norm ='y'z"
+
+ :silent exe 'norm ' . l:line . 'G'
endfunction
@@ -564,19 +601,27 @@ endfunction
" Function: FormatComments()
" Correct whitespace around doc blocks
function s:FormatComments() range
- '<,'>s/\*\s*@copyright\s*/\* @copyright /ge
- '<,'>s/\*\s*@link\s*/\* @link /ge
- '<,'>s/\*\s*@package\s*/\* @package /ge
- '<,'>s/\*\s*@subpackage\s*/\* @subpackage /ge
- '<,'>s/\*\s*@since\s*/\* @since /ge
- '<,'>s/\*\s*@version\s*/\* @version /ge
- '<,'>s/\*\s*@modifiedBy\s*/\* @modifiedby /ge
- '<,'>s/\*\s*@modifiedby\s*/\* @modifiedby /ge
- '<,'>s/\*\s*@lastModified\s*/\* @lastmodified /ge
- '<,'>s/\*\s*@lastmodified\s*/\* @lastmodified /ge
- '<,'>s/\*\s*@license\s*/\* @license /ge
- '<,'>s/\*\s*@uses\s*/\* @uses /ge
- '<,'>s/\*\s*@author\s*/\* @author /ge
+ let l:line = line('.')
+ :delmarks yz
+ :silent exe 'norm ' . a:firstline . 'G'
+ :ky
+ :silent exe 'norm ' . a:lastline . 'G'
+ :kz
+
+ 'y,'zs/\*\s*@copyright\s*/\* @copyright /ge
+ 'y,'zs/\*\s*@link\s*/\* @link /ge
+ 'y,'zs/\*\s*@package\s*/\* @package /ge
+ 'y,'zs/\*\s*@subpackage\s*/\* @subpackage /ge
+ 'y,'zs/\*\s*@since\s*/\* @since /ge
+ 'y,'zs/\*\s*@version\s*/\* @version /ge
+ 'y,'zs/\*\s*@modifiedBy\s*/\* @modifiedby /ge
+ 'y,'zs/\*\s*@modifiedby\s*/\* @modifiedby /ge
+ 'y,'zs/\*\s*@lastModified\s*/\* @lastmodified /ge
+ 'y,'zs/\*\s*@lastmodified\s*/\* @lastmodified /ge
+ 'y,'zs/\*\s*@license\s*/\* @license /ge
+ 'y,'zs/\*\s*@uses\s*/\* @uses /ge
+ 'y,'zs/\*\s*@author\s*/\* @author /ge
+ :silent exe 'norm ' . l:line . 'G'
endfunction
" Function: DeleteBlankLines()
