3 " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
4 " URL: http://www.2072productions.com/vim/indent/php.vim
5 " Last Change: 2005 February 10th
8 " Changes: 1.10 - Lines beginning by a single or double quote were
9 " not indented in some cases.
11 " Changes: 1.09 - JavaScript code was not always directly indented.
13 " Changes: 1.08 - End comment tags '*/' are indented like start tags '/*'.
14 " - When typing a multiline comment, '}' are indented
15 " according to other commented '{'.
16 " - Added a new option 'PHP_removeCRwhenUnix' to
17 " automatically remove CR at end of lines when the file
19 " - Changed the file format of this very file to Unix.
20 " - This version seems to correct several issues some people
23 " Changes: 1.07 - Added support for "Here document" tags:
24 " - HereDoc end tags are indented properly.
25 " - HereDoc content remains unchanged.
26 " - All the code that is outside PHP delimiters remains
28 " - New feature: The content of <script.*> html tags is considered as PHP
29 " and indented according to the surrounding PHP code.
30 " - "else if" are detected as "elseif".
31 " - Multiline /**/ are indented when the user types it but
32 " remain unchanged when indenting from their beginning.
33 " - Fixed indenting of // and # comments.
34 " - php_sync_method option is set to 0 (fromstart).
35 " This is required for complex PHP scripts else the indent
37 " - Files with non PHP code at the beginning could alter the indent
38 " of the following PHP code.
39 " - Other minor improvements and corrections.
41 " Changes: 1.06: - Switch block were no longer indented correctly...
42 " - Added an option to use a default indenting instead of 0.
43 " (whereas I still can't find any good reason to use it!)
44 " - A problem with ^\s*);\= lines where ending a non '{}'
46 " - Changed script local variable to be buffer local
49 " Changes: 1.05: - Lines containing "<?php ?>" and "?> <?php"
50 " (start and end tag on the same line) are no
51 " longer indented at col 1 but as normal code.
53 " Changes: 1.04: - Strings containing "//" could break the indenting
55 " - When a '{}' block was at col 1, the second line of the
56 " block was not indented at all (because of a stupid
57 " optimization coupled with a bug).
59 " Changes: 1.03: - Some indenting problems corrected: end of non '{}'
60 " structures was not detected in some cases. The part of
61 " code concerned have been re-written
62 " - PHP start tags were not indented at col 1
63 " - Wrong comment in the code have been corrected
65 " Changes: 1.02: - The bug I was talking about in version 1.01 (right below) has
67 " - Also corrected another bug that could occur in
69 " - I removed the debug mode left in 1.01 that could
70 " cause some Vim messages at loading if other script were
73 " Changes: 1.01: - Some little bug corrections reguarding automatic optimized
74 " mode that missed some tests and could break the indenting.
75 " - There is also a problem with complex non bracked structures, when several
76 " else are following each other, the algorithm do not indent the way it
78 " That will be corrected in the next version.
80 " Changes: improvements with regard to the original version (0.5) by Miles Lott (whose this script was inspired):
81 " - Commented part of code or non PHP code no longer break the
82 " indent algorithm, the content of those parts are indented
84 " - corrected a strange thing (a part of code was duplicated) ->
85 " the last version couldn't work.
86 " - Folds can be used without problem
87 " - multilevel non bracked structures are indented (like
90 " if (!isset($History_lst_sel))
91 " if (!isset($blabla))
92 " if (!isset($bloum)) {
97 " $command_hist = TRUE;
99 " - "array( 'blabla'," lines no longer break the indent of the
101 " - the options php_noindent_switch and php_indent_shortopentags have been removed
102 " (couldn't find any reason why one would want to use them)
103 " - PHP open and close tags are always set to col 1 as for the
104 " immediate following php code
106 " If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr
107 " with an example of code that break the algorithm.
110 " Thanks a lot for using this script.
113 " NOTE: This script must be used with PHP syntax ON and with the php syntax
114 " script by Lutz Eymers (http://www.isp.de/data/php.vim ) that's the script bundled with Gvim.
116 " This script set the option php_sync_method of PHP syntax script to 0
117 " (fromstart indenting method) in order to have an accurate syntax.
118 " If you are using very big PHP files (which is a bad idea) you will
119 " experience slowings down while editing, if your code contains only PHP
120 " code you can comment the line below.
122 let php_sync_method = 0
125 " In the case you have syntax errors in your script such as end of HereDoc
126 " tags not at col 1 you'll have to indent your file 2 times (This script
127 " will automatically put HereDoc end tags at col 1).
130 " NOTE: If you are editing file in Unix file format and that (by accident)
131 " there are '\r' before new lines, this script won't be able to proceed
132 " correctly and will make many mistakes because it won't be able to match
134 " So you have to remove those useless characters first with a command like:
138 " or simply 'let' the option PHP_removeCRwhenUnix to 1 and the script will
139 " silently remove them when VIM load this script (at each bufread).
141 " Options: PHP_default_indenting = # of sw (default is 0), # of sw will be
142 " added to the indent of each line of PHP code.
144 " Options: PHP_removeCRwhenUnix = 1 to make the script automatically remove CR
145 " at end of lines (by default this option is unset), NOTE that you
146 " MUST remove CR when the fileformat is UNIX else the indentation
147 " won't be correct...
149 if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUnix
154 if exists("PHP_default_indenting")
155 let b:PHP_default_indenting = PHP_default_indenting * &sw
157 let b:PHP_default_indenting = 0
159 " Only load this indent file when no other was loaded. But reset those state
162 let b:PHP_lastindented = 0
163 let b:PHP_indentbeforelast = 0
164 let b:PHP_indentinghuge = 0
165 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
166 let b:PHP_LastIndentedWasComment = 0
167 " PHP code detect variables
169 let b:InPHPcode_checked = 0
170 let b:InPHPcode_and_script = 0
171 let b:InPHPcode_tofind = ""
172 let b:PHP_oldchangetick = b:changedtick
173 let b:UserIsTypingComment = 0
175 if exists("b:did_indent")
180 setlocal nosmartindent
183 setlocal indentexpr=GetPhpIndent()
184 setlocal indentkeys=0{,0},0),:,!^F,o,O,e,*<Return>,=?>,=<?,=*/
186 " Only define the function once.
187 if exists("*GetPhpIndent")
191 let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$'
192 let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!'
196 function! GetLastRealCodeLNum(startline) " {{{
197 "Inspired from the function SkipJavaBlanksAndComments by Toby Allsopp for indent/java.vim
198 let lnum = a:startline
202 let lnum = prevnonblank(lnum)
203 let lastline = getline(lnum)
205 " if we are inside an html <script> we must skip ?> tags to indent
207 if b:InPHPcode_and_script && lastline =~ '?>\s*$'
211 elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' " if line is under comment
213 elseif lastline =~ '\*/\s*$' " skip multiline comments
215 call search('\*/\zs', 'W')
216 let lnum = searchpair('/\*\zs', '', '\*/\zs', 'bWr', '') " find the most outside /*
218 let lastline = getline(lnum)
219 if lastline =~ '^\s*/\*' " if line contains nothing but comment
220 let lnum = lnum - 1 " do the job again on the line before (a comment can hide another...)
226 elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>' " skip non php code
227 " call cursor(lnum, 1)
228 " call search('<?\zs', 'W')
229 " let lnum = searchpair('?>\zs', '', '<?\zs', 'bW', 'getline(".") =~ "<?.*?>"') " find the most outside /*
231 " let lastline = getline(lnum)
232 while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1
234 let lastline = getline(lnum)
236 if lastline =~ '^\s*?>' " if line contains nothing but end tag
239 break " else there is something important before the ?>
243 " Manage "here document" tags
244 elseif lastline =~? '^\a\w*;$' && lastline !~? s:notPhpHereDoc " match the end of a heredoc
245 let tofind=substitute( lastline, '\([^;]\+\);', '<<<\1$', '')
246 while getline(lnum) !~? tofind && lnum > 1
250 break " if none of these were true then we are done
254 if lnum==1 && getline(lnum)!~ '<?'
261 function! Skippmatch() " {{{
262 " the slowest instruction of this script, remove it and the script is 3
263 " times faster but you may have troubles with '{' inside comments or strings
264 " that will break the indent algorithm...
265 let synname = synIDattr(synID(line("."), col("."), 0), "name")
266 if synname == "phpParent" || synname == "javaScriptBraces" || synname == "phpComment" && b:UserIsTypingComment
274 function! FindOpenBracket(lnum) " {{{
275 call cursor(a:lnum, 1) " set the cursor to the start of the lnum line
276 return searchpair('{', '', '}', 'bW', 'Skippmatch()')
280 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{
281 " A very clever recoursive function created by me (John Wellesz) that find the "if" corresponding to an
282 " "else". This function can easily be adapted for other languages :)
284 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>'
285 let beforeelse = a:lnum " we do this so we can find the opened bracket to speed up the process
287 let beforeelse = GetLastRealCodeLNum(a:lnum - 1)
294 " If we found another "else" then it means we need to skip the next "if"
295 " we'll found. (since version 1.02)
296 if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>'
297 let s:iftoskip = s:iftoskip + 1
300 " A closing bracket? let skip the whole block to save some recursive calls
301 if getline(beforeelse) =~ '^\s*}' " .s:endline
302 let beforeelse = FindOpenBracket(beforeelse)
304 " Put us on the block starter
305 if getline(beforeelse) =~ '^\s*{'
306 let beforeelse = GetLastRealCodeLNum(beforeelse - 1)
311 if !s:iftoskip && a:StopAfterFirstPrevElse && getline(beforeelse) =~# '^\s*\%([}]\s*\)\=else\%(if\)\=\>'
315 " if there was an else, then there is a if...
316 if getline(beforeelse) !~# '^\s*if\>' && beforeelse>1 || s:iftoskip && beforeelse>1
318 if s:iftoskip && getline(beforeelse) =~# '^\s*if\>'
319 let s:iftoskip = s:iftoskip - 1
322 let s:level = s:level + 1
323 let beforeelse = FindTheIfOfAnElse(beforeelse, a:StopAfterFirstPrevElse)
331 function! IslinePHP (lnum, tofind) " {{{
332 " This function asks to the syntax if the pattern 'tofind' on the line
333 " number 'lnum' is PHP code (very slow...).
334 let cline = getline(a:lnum)
337 let tofind = "^\\s*[\"']*\s*\\zs\\S" " This correct the issue where lines beginning by a
338 " single or double quote were not indented in some cases.
340 let tofind = a:tofind
343 let tofind = tofind . '\c' " ignorecase
345 let coltotest = match (cline, tofind) + 1 "find the first non blank char in the current line
347 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") " ask to syntax what is its name
350 " if matchstr(synname, '^...') == "php" || synname=="Delimiter" || synname =~? '^javaScript'
351 if synname =~ '^php' || synname=="Delimiter" || synname =~? '^javaScript'
359 let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\);'
360 let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|while\>\|for\%(each\)\=\>\|declare\|||\|&&\>\)'
362 function! GetPhpIndent()
363 "##############################################
364 "########### MAIN INDENT FUNCTION #############
365 "##############################################
367 " This detect if the user is currently typing text between each call
369 if b:PHP_oldchangetick != b:changedtick
370 let b:PHP_oldchangetick = b:changedtick
374 if b:PHP_default_indenting
375 let b:PHP_default_indenting = g:PHP_default_indenting * &sw
378 let cline = getline(v:lnum) " current line
380 " Let's detect if we are indenting just one line or more than 3 lines
381 " in the last case we can slightly optimize our algorithm
382 if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast
383 if b:PHP_indentbeforelast
384 let b:PHP_indentinghuge = 1
385 echom 'Large indenting detected, speed optimizations engaged'
387 let b:PHP_indentbeforelast = b:PHP_lastindented
390 " If the line we are indenting isn't directly under the previous non-blank
391 " line of the file then deactivate the optimization procedures and reset
392 " status variable (we restart for scratch)
393 if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented
394 if b:PHP_indentinghuge
395 echom 'Large indenting deactivated'
396 let b:PHP_indentinghuge = 0
397 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
399 let b:PHP_lastindented = v:lnum
400 let b:PHP_LastIndentedWasComment=0
401 let b:PHP_indentbeforelast = 0
404 let b:InPHPcode_checked = 0
405 let b:InPHPcode_and_script = 0
406 let b:InPHPcode_tofind = ""
408 elseif v:lnum > b:PHP_lastindented " we are indenting line in > order (we can rely on the line before)
409 let real_PHP_lastindented = b:PHP_lastindented
410 let b:PHP_lastindented = v:lnum
413 " We must detect if we are in PHPCODE or not, but one time only, then
414 " we will detect php end and start tags, comments /**/ and HereDoc
417 if !b:InPHPcode_checked " {{{ One time check
418 let b:InPHPcode_checked = 1
420 let synname = IslinePHP (prevnonblank(v:lnum), "") " the line could be blank (if the user presses 'return')
423 if synname != "phpHereDoc"
425 let b:InPHPcode_tofind = ""
427 if synname == "phpComment"
428 let b:UserIsTypingComment = 1
430 let b:UserIsTypingComment = 0
433 if synname =~? '^javaScript'
434 let b:InPHPcode_and_script = 1
439 let b:UserIsTypingComment = 0
441 let lnum = v:lnum - 1
442 while getline(lnum) !~? '<<<\a\w*$' && lnum > 1
446 let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<\(\a\w*\)\c', '^\\s*\1;$', '')
448 else " IslinePHP returned "" => we are not in PHP or Javascript
450 let b:UserIsTypingComment = 0
451 " Then we have to find a php start tag...
452 let b:InPHPcode_tofind = '<?\%(.*?>\)\@!\|<script.*>'
454 endif "!b:InPHPcode_checked }}}
456 " Now we know where we are so we can verify the line right above the
457 " current one to see if we have to stop or restart php indenting
459 " Test if we are indenting PHP code {{{
460 " Find an executable php code line above the current line.
461 let lnum = prevnonblank(v:lnum - 1)
462 let last_line = getline(lnum)
464 " If we aren't in php code, then there is something we have to find
465 if b:InPHPcode_tofind!=""
466 if cline =~? b:InPHPcode_tofind
468 let b:InPHPcode_tofind = ""
469 let b:UserIsTypingComment = 0
470 if cline =~ '\*/' " End comment tags must be indented like start comment tags
471 call cursor(v:lnum, 1)
472 call search('\*/\zs', 'W')
473 let lnum = searchpair('/\*\zs', '', '\*/\zs', 'bWr', '') " find the most outside /*
475 elseif cline =~? '<script\>' " a more accurate test is useless since there isn't any other possibility
476 let b:InPHPcode_and_script = 1
481 " ### If we are in PHP code, we test the line before to see if we have to stop indenting
485 " Was last line containing a PHP end tag ?
486 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=="Delimiter"
487 if cline !~? s:PHP_startindenttag
489 let b:InPHPcode_tofind = s:PHP_startindenttag
490 elseif cline =~? '<script\>'
491 let b:InPHPcode_and_script = 1
494 " Was last line the start of a HereDoc ?
495 elseif last_line =~? '<<<\a\w*$'
496 " \&& IslinePHP(lnum, '\a\w*$')=="Delimiter"
498 let b:InPHPcode_tofind = substitute( last_line, '^.*<<<\(\a\w*\)\c', '^\\s*\1;$', '')
500 " Skip /* \n+ */ comments execept when the user is currently
502 elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!'
503 " \ && IslinePHP(v:lnum, '/\*')=="phpComment"
505 let b:InPHPcode_tofind = '\*/'
507 " is current line the end of a HTML script ? (we indent script the
509 elseif cline =~? '^\s*</script>'
511 " let b:InPHPcode_and_script = 0
512 let b:InPHPcode_tofind = s:PHP_startindenttag
516 " Non PHP code is let as it is
517 if !b:InPHPcode && !b:InPHPcode_and_script
520 let b:InPHPcode_and_script = 0
523 " Align correctly multi // or # lines
525 " Indent successive // or # comment the same way the first is {{{
526 if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)'
527 if b:PHP_LastIndentedWasComment == 1
528 return indent(real_PHP_lastindented) " line replaced in 1.02
530 let b:PHP_LastIndentedWasComment = 1
532 let b:PHP_LastIndentedWasComment = 0
536 " Some tags are always indented to col 1
538 " Things always indented at col 1 (PHP delimiter: <?, ?>, Heredoc end) {{{
539 " PHP start tags are always at col 1, useless to indent unless the end tag
540 " is on the same line
541 if cline =~# '^\s*<?' && cline !~ '?>' " Added the ^\s* part in version 1.03
545 " PHP end tags are always at col 1, useless to indent unless if it's
546 " followed by a start tag on the same line
547 if cline =~ '^\s*?>' && cline !~# '<?'
551 " put HereDoc end tags at start of lines
552 if cline =~? '^\s*\a\w*;$' && cline !~? s:notPhpHereDoc
559 " Find an executable php code line above the current line.
560 let lnum = GetLastRealCodeLNum(v:lnum - 1)
561 let last_line = getline(lnum) " last line
562 let ind = indent(lnum) " by default
563 let endline= s:endline
565 if ind==0 && b:PHP_default_indenting
566 let ind = b:PHP_default_indenting
569 " Hit the start of the file, use default indent.
571 return b:PHP_default_indenting
574 " if the last line is a stated line and it's not indented then why should
575 " we indent this one??
576 " if optimized mode is active and nor current or previous line are an 'else'
577 " or the end of a possible bracketless thing then indent the same as the previous
579 if last_line =~ '[;}]'.endline
580 if ind==b:PHP_default_indenting
581 return b:PHP_default_indenting
582 elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)' && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline
583 return b:PHP_CurrentIndentLevel
587 " Search the matching open bracket (with searchpair()) and set the indent of cline
588 " to the indent of the matching line.
589 if cline =~ '^\s*}\%(}}\)\@!'
590 let ind = indent(FindOpenBracket(v:lnum))
591 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
595 " While editing check for end of comment and indent it like its beginning
596 if UserIsEditing && cline =~ '\*/' " End comment tags must be indented like start comment tags
597 call cursor(v:lnum, 1)
598 call search('\*/\zs', 'W')
599 let lnum = searchpair('/\*\zs', '', '\*/\zs', 'bWr', '') " find the most outside /*
603 let LastLineClosed = 0 " used to prevent redundant tests in the last part of the script
605 let unstated='\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.endline
606 " What is an unstated line?
607 " - an "else" at the end of line
608 " - a s:blockstart (if while etc...) followed by anything and a ")" at
611 " if the current line is an 'else' starting line
612 " (to match an 'else' preceded by a '}' is irrelevant and futile - see
614 if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>'
615 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting " prevent optimized to work at next call
616 return indent(FindTheIfOfAnElse(v:lnum, 1))
617 elseif last_line =~# unstated && cline !~ '^\s*{\|^\s*);\='.endline
621 " If the last line is terminated by ';' or if it's a closing '}'
622 " We need to check if this isn't the end of a multilevel non '{}'
633 " echo 'infinite loop\n';
635 elseif ind != b:PHP_default_indenting && last_line =~ ';'.endline.'\|^\s*}\%(.*{'. endline.'\)\@!'
636 " If we are here it means that the previous line is:
638 " - a [beginning-blanck] } followed by anything but a { $
639 let previous_line = last_line
640 let last_line_num = lnum
641 let LastLineClosed = 1
642 " The idea here is to check if the current line is after a non '{}'
643 " structure so we can indent it like the top of that structure.
644 " The top of that structure is caracterized by a if (ff)$ style line
645 " preceded by a stated line. If there is no such structure then we
646 " just have to find two 'normal' lines following each other with the
647 " same indentation and with the first of these two lines terminated by
651 " let's skip '{}' blocks
652 if previous_line =~ '^\s*}'
653 " find the openning '{'
654 let last_line_num = FindOpenBracket(last_line_num)
656 " if the '{' is alone on the line get the line before
657 if getline(last_line_num) =~ '^\s*{'
658 let last_line_num = GetLastRealCodeLNum(last_line_num - 1)
661 let previous_line = getline(last_line_num)
665 " At this point we know that the previous_line isn't a closing
666 " '}' so we can check if we really are in such a structure.
668 " it's not a '}' but it could be an else alone...
669 if getline(last_line_num) =~# '^\s*else\%(if\)\=\>'
670 let last_line_num = FindTheIfOfAnElse(last_line_num, 0)
671 continue " re-run the loop (we could find a '}' again)
674 " So now it's ok we can check :-)
675 " A good quality is to have confidence in oneself so to know
676 " if yes or no we are in that struct lets test the indent of
677 " last_line_num and of last_line_num - 1!
678 " If those are == then we are almost done.
680 " That isn't sufficient, we need to test how the first of the
681 " 2 lines is ended...
683 " Note the indenting of the line we are checking
685 let last_match = last_line_num " remember the 'topest' line we found so far
687 let one_ahead_indent = indent(last_line_num)
688 let last_line_num = GetLastRealCodeLNum(last_line_num - 1)
689 let two_ahead_indent = indent(last_line_num)
690 let after_previous_line = previous_line
691 let previous_line = getline(last_line_num)
694 " If we find a '{' or a case/default then we are inside that block so lets
695 " indent properly... Like the line following that block starter
696 if previous_line =~# '^\s*\%(case\|default\).*:\|{'.endline
700 " The 3 lines below are not necessary for the script to work
701 " but it makes it work a little more faster in some (rare) cases.
702 " We verify if we are at the top of a non '{}' struct.
703 if after_previous_line=~# '^\s*'.s:blockstart.'.*)'.endline && previous_line =~# '[;}]'.endline
707 if one_ahead_indent == two_ahead_indent || last_line_num < 1
708 " So the previous line and the line before are at the same
709 " col. Now we just have to check if the line before is a ;$ or [}]$ ended line
710 " we always check the most ahead line of the 2 lines so
711 " it's useless to match ')$' since the lines couldn't have
713 if previous_line =~# '[;}]'.endline || last_line_num < 1
720 if indent(last_match) != ind " if nothing was done lets the old script continue
721 let ind = indent(last_match) " let's use the indent of the last line matched by the alhorithm above
722 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting "line added in version 1.02 to prevent optimized mode
723 " from acting in some special cases
729 let plinnum = GetLastRealCodeLNum(lnum - 1)
730 let pline = getline(plinnum) " previous to last line
732 " REMOVE comments at end of line before treatment
733 " the first par of the regex removes // from the end of line when they are
734 " followed by a number of '"' which is a multiple of 2. The second part
735 " removes // that are not followed by any '"'
736 " Sorry for this unreadable thing...
737 let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','')
739 " Indent blocks enclosed by {} or () (default indenting)
740 if !LastLineClosed " the last line isn't a .*; or a }$ line
741 " if the last line is a [{(]$ or a multiline function call (or array
742 " declaration) with already one parameter on the opening ( line
743 if last_line =~# '[{(]'.endline || last_line =~? '\h\w*\s*(.*,$' && pline !~ '[,(]'.endline
745 if cline !~# '^\s*\%(default\|case\).*:' " case and default are not indented inside blocks
746 let b:PHP_CurrentIndentLevel = ind
752 " If the current line closes a multiline function call or array def
753 if cline =~ '^\s*);\='
755 elseif cline =~# '^\s*\%(default\|case\).*:'
759 if last_line =~# '^\s*\%(default\|case\).*:'
763 let b:PHP_CurrentIndentLevel = ind
767 " vim: set ts=4 sw=4: