From: Arkadiusz Miƛkiewicz Date: Tue, 20 Sep 2005 20:46:02 +0000 (+0000) Subject: - up to ver 1.181 X-Git-Tag: auto/ac/vim-6_3_086-4~1 X-Git-Url: https://git.pld-linux.org/?a=commitdiff_plain;h=b2707e991f0781bc426f1ef932af2eda47e7d291;p=packages%2Fvim.git - up to ver 1.181 Changed files: php.vim -> 1.6 --- diff --git a/php.vim b/php.vim index 05e5a55..bc7d19d 100644 --- a/php.vim +++ b/php.vim @@ -2,8 +2,29 @@ " Language: PHP " Author: John Wellesz " URL: http://www.2072productions.com/vim/indent/php.vim -" Last Change: 2005 June 30th -" Version: 1.17 +" Last Change: 2005 September 17th +" Version: 1.181 +" +" +" Changes: 1.181 - I Forgot to register 'class' as a block starter so the '{' +" after a 'class' could be wrongly indented... +" +" Changes: 1.18 - No more problems with Vim 6.3 and UTF-8. +" - Opening braces "{" are always indented according to their block starter. +" +" Instead of: +" +" if( $test +" && $test2 ) +" { +" } +" +" You have: +" +" if( $test +" && $test2 ) +" { +" } " " " Changes: 1.17 - Now following parts of split lines are indented: @@ -230,13 +251,8 @@ setlocal indentexpr=GetPhpIndent() setlocal indentkeys=0{,0},0),:,!^F,o,O,e,*,=?>,=\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|[|&]\)' +let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|class\>\|[|&]\)' " make sure the options needed for this script to work correctly are set here " for the last time. They could have been overriden by any 'onevent' @@ -554,8 +572,10 @@ function! GetPhpIndent() let b:UserIsTypingComment = 0 if cline =~ '\*/' " End comment tags must be indented like start comment tags call cursor(v:lnum, 1) - call search('\*/\zs', 'W') - let lnum = searchpair('/\*', '', '\*/\zs', s:searchpairflags) " find the most outside /* + if cline !~ '^\*/' + call search('\*/', 'W') + endif + let lnum = searchpair('/\*', '', '\*/', s:searchpairflags) " find the most outside /* let b:PHP_CurrentIndentLevel = b:PHP_default_indenting let b:PHP_LastIndentedWasComment = 0 " prevent a problem if multiline /**/ comment are surounded by @@ -594,7 +614,7 @@ function! GetPhpIndent() " Skip /* \n+ */ comments execept when the user is currently " writting them - elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*' " XXX indent comments + elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*' let b:InPHPcode = 0 let b:InPHPcode_tofind = '\*/' @@ -699,8 +719,12 @@ function! GetPhpIndent() " Check for end of comment and indent it like its beginning if cline =~ '^\s*\*/' " End comment tags must be indented like start comment tags call cursor(v:lnum, 1) - call search('\*/\zs', 'W') - let lnum = searchpair('/\*', '', '\*/\zs', s:searchpairflags) " find the most outside /* + if cline !~ '^\*/' + call search('\*/', 'W') + endif + let lnum = searchpair('/\*', '', '\*/', s:searchpairflags) " find the most outside /* + "echo 'Searchpair returned: ' . lnum + "call getchar() let b:PHP_CurrentIndentLevel = b:PHP_default_indenting @@ -728,7 +752,6 @@ function! GetPhpIndent() let LastLineClosed = 0 " used to prevent redundant tests in the last part of the script - "let terminated = '\%(;\%(\s*?>\)\=\|<<<\a\w*\)'.endline.'\|}\%(.*{'. endline.'\)\@!' let terminated = '\%(;\%(\s*?>\)\=\|<<<\a\w*\|}\)'.endline " What is a terminated line? " - a line terminated by a ";" optionaly followed by a "?>" @@ -747,6 +770,30 @@ function! GetPhpIndent() if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>' let b:PHP_CurrentIndentLevel = b:PHP_default_indenting " prevent optimized to work at next call return indent(FindTheIfOfAnElse(v:lnum, 1)) + elseif cline =~ '^\s*{' + let previous_line = last_line + let last_line_num = lnum + + while last_line_num > 1 + + if previous_line =~ '^\s*\%(' . s:blockstart . '\|\%([a-zA-Z]\s*\)*function\)' && previous_line !~ '^\s*[|&]' + "echo '{ detected and aligned to ' . last_line_num . ' ('.previous_line.')' + "call getchar() + + let ind = indent(last_line_num) + + " If the PHP_BracesAtCodeLevel is set then indent the '{' + if b:PHP_BracesAtCodeLevel " XXX mod { + let ind = ind + &sw + endif + + return ind + endif + + let last_line_num = last_line_num - 1 + let previous_line = getline(last_line_num) + endwhile + elseif last_line =~# unstated && cline !~ '^\s*{\|^\s*);\='.endline let ind = ind + &sw return ind @@ -924,10 +971,6 @@ function! GetPhpIndent() let ind = ind + &sw endif - " If the PHP_BracesAtCodeLevel is set then indent the '{' - if b:PHP_BracesAtCodeLevel && cline =~# '^\s*{' " XXX mod { - let ind = ind + &sw - endif elseif last_line =~# defaultORcase let ind = ind + &sw