]> git.pld-linux.org Git - packages/vim.git/commitdiff
- up to ver 1.181
authorArkadiusz Miśkiewicz <arekm@maven.pl>
Tue, 20 Sep 2005 20:46:02 +0000 (20:46 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    php.vim -> 1.6

php.vim

diff --git a/php.vim b/php.vim
index 05e5a55be54ded486c2985145b10d061c52f372a..bc7d19d7e02bccdba9b70366a91ef5c1ee3e8c1c 100644 (file)
--- a/php.vim
+++ b/php.vim
@@ -2,8 +2,29 @@
 " Language:    PHP
 " Author:      John Wellesz <John.wellesz (AT) teaser (DOT) fr>
 " 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,*<Return>,=?>,=<?,=*/
 
 
-"This will prevent a bug involving searchpair(), its 'r' flag, utf-8 and vim 6.3
-"from occurring but will forbid you to write other '/*' inside a '/* */' comment.
-if version <= 603 && &encoding == 'utf-8'
-       let s:searchpairflags = 'bW'
-else
-       let s:searchpairflags = 'bWr'
-endif
+
+let s:searchpairflags = 'bWr'
 
 " Clean CR when the file is in Unix format
 if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUnix
@@ -272,8 +288,10 @@ function! GetLastRealCodeLNum(startline) " {{{
                        let lnum = lnum - 1
                elseif lastline =~ '\*/\s*$' " skip multiline comments
                        call cursor(lnum, 1)
-                       call search('\*/\zs', 'W') " positition the cursor after the first */
-                       let lnum = searchpair('/\*', '', '\*/\zs', s:searchpairflags) " find the most outside /*
+                       if lastline !~ '^\*/'
+                               call search('\*/', 'W') " positition the cursor on the first */
+                       endif
+                       let lnum = searchpair('/\*', '', '\*/', s:searchpairflags) " find the most outside /*
                        "echo 'lnum skipnonphp= ' . lnum
                        "call getchar()
 
@@ -425,7 +443,7 @@ endfunction
 " }}}
 
 let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\);'
-let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|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
This page took 0.075412 seconds and 4 git commands to generate.