SOURCES: php.vim - updated to 1.20 (20051121)
adamg
adamg at pld-linux.org
Wed Nov 30 16:24:56 CET 2005
Author: adamg Date: Wed Nov 30 15:24:55 2005 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- updated to 1.20 (20051121)
---- Files affected:
SOURCES:
php.vim (1.6 -> 1.7)
---- Diffs:
================================================================
Index: SOURCES/php.vim
diff -u SOURCES/php.vim:1.6 SOURCES/php.vim:1.7
--- SOURCES/php.vim:1.6 Tue Sep 20 22:46:02 2005
+++ SOURCES/php.vim Wed Nov 30 16:24:50 2005
@@ -2,144 +2,166 @@
" Language: PHP
" Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
" URL: http://www.2072productions.com/vim/indent/php.vim
-" Last Change: 2005 September 17th
-" Version: 1.181
+" Last Change: 2005 Nobember 21st
+" Version: 1.20
"
+" Changes: 1.20 - Line beginning by a single or double quote followed
+" by a space would cause problems... this was related
+" to the bug correction of version 1.10 - Thanks to
+" David F. for finding this (he was lucky).
+" - Changed the way this script set the 'formatoptions'
+" setting, now it uses '-=' and '+='
+" - New option: PHP_autoformatcomment (defaults to 1),
+" if set to 0 the 'formatoptions' setting will not be
+" altered.
+" - When PHP_autoformatcomment is not 0, the 'comments'
+" setting is set to the type of comments that PHP
+" supports.
"
-" Changes: 1.181 - I Forgot to register 'class' as a block starter so the '{'
+"
+" Changes: 1.19 - Indentation of '*/' delimiter of '/**/' won't be broken by
+" strings or '//' comments containing the "/*" character sequence.
+"
+" Changes: 1.182 - I Forgot to register 'interface' and 'abstract' as block starters so the '{'
+" after them could be wrongly indented...
+"
+" 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.
+" - Opening braces "{" are always indented according to their block starter.
"
" Instead of:
"
" if( $test
-" && $test2 )
-" {
-" }
+" && $test2 )
+" {
+" }
"
" You have:
"
" if( $test
-" && $test2 )
+" && $test2 )
" {
-" }
+" }
"
"
" Changes: 1.17 - Now following parts of split lines are indented:
-" Instead of:
-" $foo=
-" "foo"
-" ."foo";
-"
-" You have:
-" $foo=
-" "foo"
-" ."foo";
+"
+" Instead of:
+"
+" $foo=
+" "foo"
+" ."foo";
+"
+" You have:
+"
+" $foo=
+" "foo"
+" ."foo";
"
-" - If a "case : break;" was declared on a single line, the
-" following "case" was not indented correctly.
-" - If a </script> html tag was preceded by a "?>" it wasn't indented.
-" - Some other minor corrections and improvements.
+" - If a "case : break;" was declared on a single line, the
+" following "case" was not indented correctly.
+" - If a </script> html tag was preceded by a "?>" it wasn't indented.
+" - Some other minor corrections and improvements.
"
"
" Changes: 1.16 - Now starting and ending '*' of multiline '/* */' comments are aligned
-" on the '*' of the '/*' comment starter.
-" - Some code improvements that make indentation faster.
+" on the '*' of the '/*' comment starter.
+" - Some code improvements that make indentation faster.
"
" Changes: 1.15 - Corrected some problems with the indentation of
-" multiline "array()" declarations.
+" multiline "array()" declarations.
"
" Changes: 1.14 - Added auto-formatting for comments (using the Vim option formatoptions=qroc).
-" - Added the script option PHP_BracesAtCodeLevel to
-" indent the '{' and '}' at the same level than the
-" code they contain.
+" - Added the script option PHP_BracesAtCodeLevel to
+" indent the '{' and '}' at the same level than the
+" code they contain.
"
" Changes: 1.13 - Some code cleaning and typo corrections (Thanks to
-" Emanuele Giaquinta for his patches)
+" Emanuele Giaquinta for his patches)
"
" Changes: 1.12 - The bug involving searchpair() and utf-8 encoding in Vim 6.3 will
-" not make this script to hang but you'll have to be
-" careful to not write '/* */' comments with other '/*'
-" inside the comments else the indentation won't be correct.
-" NOTE: This is true only if you are using utf-8 and vim 6.3.
+" not make this script to hang but you'll have to be
+" careful to not write '/* */' comments with other '/*'
+" inside the comments else the indentation won't be correct.
+" NOTE: This is true only if you are using utf-8 and vim 6.3.
"
" Changes: 1.11 - If the "case" of a "switch" wasn't alone on its line
-" and if the "switch" was at col 0 (or at default indenting)
-" the lines following the "case" were not indented.
+" and if the "switch" was at col 0 (or at default indenting)
+" the lines following the "case" were not indented.
"
" Changes: 1.10 - Lines beginning by a single or double quote were
-" not indented in some cases.
+" not indented in some cases.
"
" Changes: 1.09 - JavaScript code was not always directly indented.
"
" Changes: 1.08 - End comment tags '*/' are indented like start tags '/*'.
-" - When typing a multiline comment, '}' are indented
-" according to other commented '{'.
-" - Added a new option 'PHP_removeCRwhenUnix' to
-" automatically remove CR at end of lines when the file
-" format is Unix.
-" - Changed the file format of this very file to Unix.
-" - This version seems to correct several issues some people
-" had with 1.07.
+" - When typing a multiline comment, '}' are indented
+" according to other commented '{'.
+" - Added a new option 'PHP_removeCRwhenUnix' to
+" automatically remove CR at end of lines when the file
+" format is Unix.
+" - Changed the file format of this very file to Unix.
+" - This version seems to correct several issues some people
+" had with 1.07.
"
" Changes: 1.07 - Added support for "Here document" tags:
-" - HereDoc end tags are indented properly.
-" - HereDoc content remains unchanged.
-" - All the code that is outside PHP delimiters remains
-" unchanged.
-" - New feature: The content of <script.*> html tags is considered as PHP
-" and indented according to the surrounding PHP code.
-" - "else if" are detected as "elseif".
-" - Multiline /**/ are indented when the user types it but
-" remain unchanged when indenting from their beginning.
-" - Fixed indenting of // and # comments.
-" - php_sync_method option is set to 0 (fromstart).
-" This is required for complex PHP scripts else the indent
-" may fail.
-" - Files with non PHP code at the beginning could alter the indent
-" of the following PHP code.
-" - Other minor improvements and corrections.
+" - HereDoc end tags are indented properly.
+" - HereDoc content remains unchanged.
+" - All the code that is outside PHP delimiters remains
+" unchanged.
+" - New feature: The content of <script.*> html tags is considered as PHP
+" and indented according to the surrounding PHP code.
+" - "else if" are detected as "elseif".
+" - Multiline /**/ are indented when the user types it but
+" remain unchanged when indenting from their beginning.
+" - Fixed indenting of // and # comments.
+" - php_sync_method option is set to 0 (fromstart).
+" This is required for complex PHP scripts else the indent
+" may fail.
+" - Files with non PHP code at the beginning could alter the indent
+" of the following PHP code.
+" - Other minor improvements and corrections.
"
" Changes: 1.06: - Switch block were no longer indented correctly...
-" - Added an option to use a default indenting instead of 0.
-" (whereas I still can't find any good reason to use it!)
-" - A problem with ^\s*);\= lines where ending a non '{}'
-" structure.
-" - Changed script local variable to be buffer local
-" variable instead.
+" - Added an option to use a default indenting instead of 0.
+" (whereas I still can't find any good reason to use it!)
+" - A problem with ^\s*);\= lines where ending a non '{}'
+" structure.
+" - Changed script local variable to be buffer local
+" variable instead.
"
" Changes: 1.05: - Lines containing "<?php ?>" and "?> <?php"
-" (start and end tag on the same line) are no
-" longer indented at col 1 but as normal code.
+" (start and end tag on the same line) are no
+" longer indented at col 1 but as normal code.
"
-" Changes: 1.04: - Strings containing "//" could break the indenting
-" algorithm.
-" - When a '{}' block was at col 1, the second line of the
-" block was not indented at all (because of a stupid
-" optimization coupled with a bug).
-"
-" Changes: 1.03: - Some indenting problems corrected: end of non '{}'
-" structures was not detected in some cases. The part of
-" code concerned have been re-written
-" - PHP start tags were not indented at col 1
-" - Wrong comment in the code have been corrected
-"
-" Changes: 1.02: - The bug I was talking about in version 1.01 (right below) has
-" been corrected :)
-" - Also corrected another bug that could occur in
-" some special cases.
-" - I removed the debug mode left in 1.01 that could
-" cause some Vim messages at loading if other script were
-" bugged.
-"
-" Changes: 1.01: - Some little bug corrections reguarding automatic optimized
-" mode that missed some tests and could break the indenting.
-" - There is also a problem with complex non bracked structures, when several
-" else are following each other, the algorithm do not indent the way it
-" should.
-" That will be corrected in the next version.
+" Changes: 1.04: - Strings containing "//" could break the indenting
+" algorithm.
+" - When a '{}' block was at col 1, the second line of the
+" block was not indented at all (because of a stupid
+" optimization coupled with a bug).
+"
+" Changes: 1.03: - Some indenting problems corrected: end of non '{}'
+" structures was not detected in some cases. The part of
+" code concerned have been re-written
+" - PHP start tags were not indented at col 1
+" - Wrong comment in the code have been corrected
+"
+" Changes: 1.02: - The bug I was talking about in version 1.01 (right below) has
+" been corrected :)
+" - Also corrected another bug that could occur in
+" some special cases.
+" - I removed the debug mode left in 1.01 that could
+" cause some Vim messages at loading if other script were
+" bugged.
+"
+" Changes: 1.01: - Some little bug corrections reguarding automatic optimized
+" mode that missed some tests and could break the indenting.
+" - There is also a problem with complex non bracked structures, when several
+" else are following each other, the algorithm do not indent the way it
+" should.
+" That will be corrected in the next version.
"
" If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr
" with an example of code that break the algorithm.
@@ -149,7 +171,7 @@
"
" 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 ) that's the script bundled with Gvim.
+" script by Lutz Eymers (http://www.isp.de/data/php.vim ) that's the script bundled with Gvim.
"
"
" In the case you have syntax errors in your script such as end of HereDoc
@@ -168,6 +190,10 @@
" or simply 'let' the option PHP_removeCRwhenUnix to 1 and the script will
" silently remove them when VIM load this script (at each bufread).
+
+" Options: PHP_autoformatcomment = 0 to not enable autoformating of comment by
+" default, if set to 0, this script will let the 'formatoptions' setting intact.
+"
" Options: PHP_default_indenting = # of sw (default is 0), # of sw will be
" added to the indent of each line of PHP code.
"
@@ -195,10 +221,14 @@
" some optimizations won't be available.
+" Remove all the comments from this file:
+" :%s /^\s*".*\({{{\|xxx\)\@<!\n\c//g
+" }}}
+
" The 4 following lines prevent this script from being loaded several times per buffer.
" They also prevent the load of different indent scripts for PHP at the same time.
if exists("b:did_indent")
- finish
+ finish
endif
let b:did_indent = 1
@@ -213,17 +243,22 @@
" Apply PHP_default_indenting option
if exists("PHP_default_indenting")
- let b:PHP_default_indenting = PHP_default_indenting * &sw
+ let b:PHP_default_indenting = PHP_default_indenting * &sw
else
- let b:PHP_default_indenting = 0
+ let b:PHP_default_indenting = 0
endif
if exists("PHP_BracesAtCodeLevel")
- let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel
+ let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel
else
- let b:PHP_BracesAtCodeLevel = 0
+ let b:PHP_BracesAtCodeLevel = 0
endif
+if exists("PHP_autoformatcomment")
+ let b:PHP_autoformatcomment = PHP_autoformatcomment
+else
+ let b:PHP_autoformatcomment = 1
+endif
let b:PHP_lastindented = 0
let b:PHP_indentbeforelast = 0
@@ -245,7 +280,8 @@
setlocal nosmartindent
setlocal noautoindent
setlocal nocindent
-setlocal nolisp " autoindent must be on, so this line is also useless...
+" autoindent must be on, so the line below is also useless...
+setlocal nolisp
setlocal indentexpr=GetPhpIndent()
setlocal indentkeys=0{,0},0),:,!^F,o,O,e,*<Return>,=?>,=<?,=*/
@@ -256,738 +292,784 @@
" Clean CR when the file is in Unix format
if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUnix
- silent! %s/\r$//g
+ silent! %s/\r$//g
endif
" Only define the functions once per Vim session.
if exists("*GetPhpIndent")
- finish " XXX
+ finish " XXX
endif
let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$'
let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!'
-"setlocal debug=msg " XXX
+" setlocal debug=msg " XXX
function! GetLastRealCodeLNum(startline) " {{{
- "Inspired from the function SkipJavaBlanksAndComments by Toby Allsopp for indent/java.vim
- let lnum = a:startline
- let old_lnum = lnum
+ "Inspired from the function SkipJavaBlanksAndComments by Toby Allsopp for indent/java.vim
+ let lnum = a:startline
+ let old_lnum = lnum
+
+ while lnum > 1
+ let lnum = prevnonblank(lnum)
+ let lastline = getline(lnum)
+
+ " if we are inside an html <script> we must skip ?> tags to indent
+ " everything as php
+ if b:InPHPcode_and_script && lastline =~ '?>\s*$'
+ let lnum = lnum - 1
+ elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$'
+ let lnum = lnum - 1
+ elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)'
+ " if line is under comment
+ let lnum = lnum - 1
+ elseif lastline =~ '\*/\s*$'
+ " skip multiline comments
+ call cursor(lnum, 1)
+ if lastline !~ '^\*/'
+ call search('\*/', 'W')
+ " positition the cursor on the first */
+ endif
+ let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()')
+ " find the most outside /*
+
+ let lastline = getline(lnum)
+ if lastline =~ '^\s*/\*'
+ " if line contains nothing but comment
+ " do the job again on the line before (a comment can hide another...)
+ let lnum = lnum - 1
+ else
+ break
+ endif
- while lnum > 1
- let lnum = prevnonblank(lnum)
- let lastline = getline(lnum)
- " if we are inside an html <script> we must skip ?> tags to indent
- " everything as php
- if b:InPHPcode_and_script && lastline =~ '?>\s*$'
- let lnum = lnum - 1
- elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$'
- let lnum = lnum - 1
- elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' " if line is under comment
- let lnum = lnum - 1
- elseif lastline =~ '\*/\s*$' " skip multiline comments
- call cursor(lnum, 1)
- 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()
-
- let lastline = getline(lnum)
- if lastline =~ '^\s*/\*' " if line contains nothing but comment
- let lnum = lnum - 1 " do the job again on the line before (a comment can hide another...)
- else
- break
- endif
-
-
- elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>' " skip non php code
- " call cursor(lnum, 1)
- " call search('<?', 'W')
- " let lnum = searchpair('?>', '', '<?\zs', 'bW', 'getline(".") =~ "<?.*?>"')
-
- " let lastline = getline(lnum)
- while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1
- let lnum = lnum - 1
- let lastline = getline(lnum)
- endwhile
- if lastline =~ '^\s*?>' " if line contains nothing but end tag
- let lnum = lnum - 1
- else
- break " else there is something important before the ?>
- endif
-
-
- " Manage "here document" tags
- elseif lastline =~? '^\a\w*;$' && lastline !~? s:notPhpHereDoc " match the end of a heredoc
- let tofind=substitute( lastline, '\([^;]\+\);', '<<<\1$', '')
- while getline(lnum) !~? tofind && lnum > 1
- let lnum = lnum - 1
- endwhile
- else
- break " if none of these were true then we are done
- endif
- endwhile
-
- if lnum==1 && getline(lnum)!~ '<?'
- let lnum=0
- endif
-
- " This is to handle correctly end of script tags; to return the real last php
- " code line else a '?>' could be returned has last_line
- if b:InPHPcode_and_script && !b:InPHPcode
- let b:InPHPcode_and_script = 0
- endif
- return lnum
-endfunction
-" }}}
+ elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>'
+ " skip non php code
-function! Skippmatch() " {{{
- " the slowest instruction of this script, remove it and the script is 3
- " times faster but you may have troubles with '{' inside comments or strings
- " that will break the indent algorithm...
- let synname = synIDattr(synID(line("."), col("."), 0), "name")
- if synname == "Delimiter" || synname == "phpParent" || synname == "javaScriptBraces" || synname == "phpComment" && b:UserIsTypingComment
- return 0
+ while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1
+ let lnum = lnum - 1
+ let lastline = getline(lnum)
+ endwhile
+ if lastline =~ '^\s*?>'
+ " if line contains nothing but end tag
+ let lnum = lnum - 1
+ else
+ break
+ " else there is something important before the ?>
+ endif
+
+
+ " Manage "here document" tags
+ elseif lastline =~? '^\a\w*;$' && lastline !~? s:notPhpHereDoc
+ " match the end of a heredoc
+ let tofind=substitute( lastline, '\([^;]\+\);', '<<<\1$', '')
+ while getline(lnum) !~? tofind && lnum > 1
+ let lnum = lnum - 1
+ endwhile
else
- return 1
+ " if none of these were true then we are done
+ break
endif
+ endwhile
+
+ if lnum==1 && getline(lnum)!~ '<?'
+ let lnum=0
+ endif
+
+ " This is to handle correctly end of script tags; to return the real last php
+ " code line else a '?>' could be returned has last_line
+ if b:InPHPcode_and_script && !b:InPHPcode
+ let b:InPHPcode_and_script = 0
+ endif
+ return lnum
+endfunction " }}}
+
+function! Skippmatch2()
+
+ let line = getline(".")
+
+ if line =~ '\%(".*\)\@<=/\*\%(.*"\)\@=' || line =~ '\%(//.*\)\@<=/\*'
+ return 1
+ else
+ return 0
+ endif
endfun
-" }}}
+
+function! Skippmatch() " {{{
+ " the slowest instruction of this script, remove it and the script is 3
+ " times faster but you may have troubles with '{' inside comments or strings
+ " that will break the indent algorithm...
+ let synname = synIDattr(synID(line("."), col("."), 0), "name")
+ if synname == "Delimiter" || synname == "phpParent" || synname == "javaScriptBraces" || synname == "phpComment" && b:UserIsTypingComment
+ return 0
+ else
+ return 1
+ endif
+endfun " }}}
function! FindOpenBracket(lnum) " {{{
- call cursor(a:lnum, 1) " set the cursor to the start of the lnum line
- return searchpair('{', '', '}', 'bW', 'Skippmatch()')
-endfun
-" }}}
+ " set the cursor to the start of the lnum line
+ call cursor(a:lnum, 1)
+ return searchpair('{', '', '}', 'bW', 'Skippmatch()')
+endfun " }}}
function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{
-" A very clever recoursive function created by me (John Wellesz) that find the "if" corresponding to an
-" "else". This function can easily be adapted for other languages :)
-
- if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>'
- let beforeelse = a:lnum " we do this so we can find the opened bracket to speed up the process
- else
- let beforeelse = GetLastRealCodeLNum(a:lnum - 1)
- endif
+ " A very clever recoursive function created by me (John Wellesz) that find the "if" corresponding to an
+ " "else". This function can easily be adapted for other languages :)
- if !s:level
- let s:iftoskip = 0
+ if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>'
+ " we do this so we can find the opened bracket to speed up the process
+ let beforeelse = a:lnum
+ else
+ let beforeelse = GetLastRealCodeLNum(a:lnum - 1)
+ endif
+
+ if !s:level
+ let s:iftoskip = 0
+ endif
+
+ " If we found another "else" then it means we need to skip the next "if"
+ " we'll found. (since version 1.02)
+ if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>'
+ let s:iftoskip = s:iftoskip + 1
+ endif
+
+ " A closing bracket? let skip the whole block to save some recursive calls
+ if getline(beforeelse) =~ '^\s*}'
+ let beforeelse = FindOpenBracket(beforeelse)
+
+ " Put us on the block starter
+ if getline(beforeelse) =~ '^\s*{'
+ let beforeelse = GetLastRealCodeLNum(beforeelse - 1)
endif
+ endif
- " If we found another "else" then it means we need to skip the next "if"
- " we'll found. (since version 1.02)
- if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>'
- let s:iftoskip = s:iftoskip + 1
- endif
<<Diff was trimmed, longer than 597 lines>>
---- CVS-web:
http://cvs.pld-linux.org/SOURCES/php.vim?r1=1.6&r2=1.7&f=u
More information about the pld-cvs-commit
mailing list