Skip to content

Commit

Permalink
Merge pull request #23 from hlissner/master
Browse files Browse the repository at this point in the history
Update indent and phpcomplete.vim
  • Loading branch information
spf13 committed Feb 25, 2014
2 parents 59edadd + db30d6b commit d8af959
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 25 deletions.
8 changes: 8 additions & 0 deletions autoload/phpcomplete.vim
Expand Up @@ -731,6 +731,10 @@ function! phpcomplete#GetClassContents(file, name) " {{{
" this is the most efficient way. The other way " this is the most efficient way. The other way
" is to go through the looong string looking for " is to go through the looong string looking for
" matching {} " matching {}

" remember the window we started at
let phpcomplete_original_window = winnr()

below 1new below 1new
0put =cfile 0put =cfile
call search('class\s\+'.a:name) call search('class\s\+'.a:name)
Expand All @@ -749,6 +753,10 @@ function! phpcomplete#GetClassContents(file, name) " {{{
let classcontent = cfile let classcontent = cfile


bw! % bw! %

" go back to original window
exe phpcomplete_original_window.'wincmd w'

if extends_class != '' if extends_class != ''
let classlocation = phpcomplete#GetClassLocation(extends_class) let classlocation = phpcomplete#GetClassLocation(extends_class)
if filereadable(classlocation) if filereadable(classlocation)
Expand Down
74 changes: 49 additions & 25 deletions indent/php.vim
Expand Up @@ -2,9 +2,20 @@
" Language: PHP " Language: PHP
" Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
" URL: http://www.2072productions.com/vim/indent/php.vim " URL: http://www.2072productions.com/vim/indent/php.vim
" Last Change: 2010 July 26th " Last Change: 2013 February 23rd
" Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php " Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php
" Version: 1.33 " Version: 1.36
"
" Changes: 1.36 - Added support for short array declaration (Thanks to
" Warren Seymour)
"
" Changes: 1.35 - New option: PHP_outdentSLComments to add extra
" indentation to single-line comments.
"
"
" Changes: 1.34 - Fix: string with /* would be treated as comment
" start when using single quote. (Thanks to Manic Chuang
" for the fix)
" "
" "
" Changes: 1.33 - Rewrote Switch(){case:default:} handling from " Changes: 1.33 - Rewrote Switch(){case:default:} handling from
Expand Down Expand Up @@ -247,7 +258,7 @@
" NOTE: This script must be used with PHP syntax ON and with the php syntax " NOTE: This script must be used with PHP syntax ON and with the php syntax
" script by Lutz Eymers (http://www.isp.de/data/php.vim ) or with the " script by Lutz Eymers (http://www.isp.de/data/php.vim ) or with the
" script by Peter Hodge (http://www.vim.org/scripts/script.php?script_id=1571 ) " script by Peter Hodge (http://www.vim.org/scripts/script.php?script_id=1571 )
" the later is bundled by default with Vim 7. " the later is bunbdled by default with Vim 7.
" "
" "
" In the case you have syntax errors in your script such as HereDoc end " In the case you have syntax errors in your script such as HereDoc end
Expand Down Expand Up @@ -303,6 +314,8 @@
" Options: PHP_vintage_case_default_indent = 1 (defaults to 0) to add a meaningless indent " Options: PHP_vintage_case_default_indent = 1 (defaults to 0) to add a meaningless indent
" befaore 'case:' and 'default":' statement in switch blocks. " befaore 'case:' and 'default":' statement in switch blocks.
" "
" Options: PHP_outdentSLComments = # of sw (defaults to 0) to outdent single line PHP
" comments (// and # or /**/).
" "
" Remove all the comments from this file: " Remove all the comments from this file:
" :%s /^\s*".*\({{{\|xxx\)\@<!\n\c//g " :%s /^\s*".*\({{{\|xxx\)\@<!\n\c//g
Expand All @@ -324,13 +337,20 @@ let b:did_indent = 1
let php_sync_method = 0 let php_sync_method = 0




" Apply PHP_default_indenting option " Apply options

if exists("PHP_default_indenting") if exists("PHP_default_indenting")
let b:PHP_default_indenting = PHP_default_indenting * &sw let b:PHP_default_indenting = PHP_default_indenting * &sw
else else
let b:PHP_default_indenting = 0 let b:PHP_default_indenting = 0
endif endif


if exists("PHP_outdentSLComments")
let b:PHP_outdentSLComments = PHP_outdentSLComments * &sw
else
let b:PHP_outdentSLComments = 0
endif

if exists("PHP_BracesAtCodeLevel") if exists("PHP_BracesAtCodeLevel")
let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel
else else
Expand Down Expand Up @@ -500,11 +520,13 @@ function! Skippmatch2()


let line = getline(".") let line = getline(".")


if line =~ '\%(".*\)\@<=/\*\%(.*"\)\@=' || line =~ '\%(\%(//\|#\).*\)\@<=/\*' " Skip opening /* if they are inside a string or preceded by a single
return 1 " line comment starter
else if line =~ "\\([\"']\\).*/\\*.*\\1" || line =~ '\%(//\|#\).*/\*'
return 0 return 1
endif else
return 0
endif
endfun endfun


function! Skippmatch() " {{{ function! Skippmatch() " {{{
Expand Down Expand Up @@ -649,7 +671,7 @@ function! IslinePHP (lnum, tofind) " {{{
endif endif
endfunction " }}} endfunction " }}}


let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|else\)' let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|die\|else\)'
let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\)' let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\)'


" make sure the options needed for this script to work correctly are set here " make sure the options needed for this script to work correctly are set here
Expand Down Expand Up @@ -717,7 +739,7 @@ function! GetPhpIndent()
if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast
if b:PHP_indentbeforelast if b:PHP_indentbeforelast
let b:PHP_indentinghuge = 1 let b:PHP_indentinghuge = 1
echom 'Large indenting detected, speed optimizations engaged (v1.33)' " echom 'Large indenting detected, speed optimizations engaged (v1.34)'
endif endif
let b:PHP_indentbeforelast = b:PHP_lastindented let b:PHP_indentbeforelast = b:PHP_lastindented
endif endif
Expand All @@ -727,7 +749,7 @@ function! GetPhpIndent()
" status variable (we restart from scratch) " status variable (we restart from scratch)
if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented
if b:PHP_indentinghuge if b:PHP_indentinghuge
echom 'Large indenting deactivated' " echom 'Large indenting deactivated'
let b:PHP_indentinghuge = 0 let b:PHP_indentinghuge = 0
let b:PHP_CurrentIndentLevel = b:PHP_default_indenting let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
endif endif
Expand Down Expand Up @@ -793,7 +815,7 @@ function! GetPhpIndent()
let b:InPHPcode = 0 let b:InPHPcode = 0
let b:UserIsTypingComment = 0 let b:UserIsTypingComment = 0
" Then we have to find a php start tag... " Then we have to find a php start tag...
let b:InPHPcode_tofind = '<?\%(.*?>\)\@!\|<script.*>' let b:InPHPcode_tofind = s:PHP_startindenttag
endif endif
endif "!b:InPHPcode_checked }}} endif "!b:InPHPcode_checked }}}


Expand Down Expand Up @@ -884,7 +906,9 @@ function! GetPhpIndent()


" Align correctly multi // or # lines " Align correctly multi // or # lines
" Indent successive // or # comment the same way the first is {{{ " Indent successive // or # comment the same way the first is {{{
let addSpecial = 0
if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)'
let addSpecial = b:PHP_outdentSLComments
if b:PHP_LastIndentedWasComment == 1 if b:PHP_LastIndentedWasComment == 1
return indent(real_PHP_lastindented) return indent(real_PHP_lastindented)
endif endif
Expand Down Expand Up @@ -956,7 +980,7 @@ function! GetPhpIndent()


" Hit the start of the file, use default indent. " Hit the start of the file, use default indent.
if lnum == 0 if lnum == 0
return b:PHP_default_indenting return b:PHP_default_indenting + addSpecial
endif endif




Expand Down Expand Up @@ -995,12 +1019,12 @@ function! GetPhpIndent()
" if optimized mode is active and nor current or previous line are an 'else' " if optimized mode is active and nor current or previous line are an 'else'
" or the end of a possible bracketless thing then indent the same as the previous " or the end of a possible bracketless thing then indent the same as the previous
" line " line
if last_line =~ '[;}]'.endline && last_line !~ '^)' && last_line !~# s:defaultORcase " Added && last_line !~ '^)' on 2007-12-30 if last_line =~ '[;}]'.endline && last_line !~ '^[)\]]' && last_line !~# s:defaultORcase
if ind==b:PHP_default_indenting if ind==b:PHP_default_indenting
" if no indentation for the previous line " if no indentation for the previous line
return b:PHP_default_indenting return b:PHP_default_indenting + addSpecial
elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)' && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)' && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline
return b:PHP_CurrentIndentLevel return b:PHP_CurrentIndentLevel + addSpecial
endif endif
endif endif


Expand Down Expand Up @@ -1056,7 +1080,7 @@ function! GetPhpIndent()
let ind = ind + &sw " we indent one level further when the preceding line is not stated let ind = ind + &sw " we indent one level further when the preceding line is not stated
"echo "42" "echo "42"
"call getchar() "call getchar()
return ind return ind + addSpecial


" If the last line is terminated by ';' or if it's a closing '}' " If the last line is terminated by ';' or if it's a closing '}'
" We need to check if this isn't the end of a multilevel non '{}' " We need to check if this isn't the end of a multilevel non '{}'
Expand All @@ -1077,7 +1101,7 @@ function! GetPhpIndent()
" "
" $thing = " $thing =
" "something"; " "something";
elseif (ind != b:PHP_default_indenting || last_line =~ '^)' ) && last_line =~ terminated " Added || last_line =~ '^)' on 2007-12-30 (array indenting problem broke other things) elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated " Added || last_line =~ '^)' on 2007-12-30 (array indenting problem broke other things)
" If we are here it means that the previous line is: " If we are here it means that the previous line is:
" - a *;$ line " - a *;$ line
" - a [beginning-blanck] } followed by anything but a { $ " - a [beginning-blanck] } followed by anything but a { $
Expand Down Expand Up @@ -1169,7 +1193,7 @@ function! GetPhpIndent()
" from acting in some special cases " from acting in some special cases
let b:PHP_CurrentIndentLevel = b:PHP_default_indenting let b:PHP_CurrentIndentLevel = b:PHP_default_indenting


return ind return ind + addSpecial
endif endif
" if nothing was done lets the old script continue " if nothing was done lets the old script continue
endif endif
Expand Down Expand Up @@ -1200,9 +1224,9 @@ function! GetPhpIndent()
" the last line isn't a .*; or a }$ line " the last line isn't a .*; or a }$ line
" Indent correctly multilevel and multiline '(.*)' things " Indent correctly multilevel and multiline '(.*)' things


" if the last line is a [{(]$ or a multiline function call (or array " if the last line is a [{(\[]$ or a multiline function call (or array
" declaration) with already one parameter on the opening ( line " declaration) with already one parameter on the opening ( line
if last_line =~# '[{(]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(]'.endline if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(]'.endline


if !b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{' if !b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{'
let ind = ind + &sw let ind = ind + &sw
Expand All @@ -1214,7 +1238,7 @@ function! GetPhpIndent()
" case and default are not indented inside blocks " case and default are not indented inside blocks
let b:PHP_CurrentIndentLevel = ind let b:PHP_CurrentIndentLevel = ind


return ind return ind + addSpecial
endif endif


" If the last line isn't empty and ends with a '),' then check if the " If the last line isn't empty and ends with a '),' then check if the
Expand Down Expand Up @@ -1258,12 +1282,12 @@ function! GetPhpIndent()
"echo "end" "echo "end"
"call getchar() "call getchar()
" If the current line closes a multiline function call or array def " If the current line closes a multiline function call or array def
if cline =~ '^\s*);\=' if cline =~ '^\s*[)\]];\='
let ind = ind - &sw let ind = ind - &sw
endif endif


let b:PHP_CurrentIndentLevel = ind let b:PHP_CurrentIndentLevel = ind
return ind return ind + addSpecial
endfunction endfunction


" vim: set ts=8 sw=4 sts=4: " vim: set ts=8 sw=4 sts=4:

0 comments on commit d8af959

Please sign in to comment.