From ed32d9424d12f93dcdb96f2a5c512f7ad9945bee Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 6 Dec 2014 23:33:00 +0100 Subject: Update runtime files. --- runtime/indent/php.vim | 87 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 34 deletions(-) (limited to 'runtime/indent/php.vim') diff --git a/runtime/indent/php.vim b/runtime/indent/php.vim index b83a1923e..1bffa7f19 100644 --- a/runtime/indent/php.vim +++ b/runtime/indent/php.vim @@ -3,8 +3,8 @@ " Author: John Wellesz " URL: http://www.2072productions.com/vim/indent/php.vim " Home: https://github.com/2072/PHP-Indenting-for-VIm -" Last Change: 2014 April 3rd -" Version: 1.49 +" Last Change: 2014 November 26th +" Version: 1.57 " " " Type :help php-indent for available options @@ -48,7 +48,7 @@ endif let b:did_indent = 1 -let php_sync_method = 0 +let g:php_sync_method = 0 @@ -112,7 +112,7 @@ setlocal nocindent setlocal nolisp setlocal indentexpr=GetPhpIndent() -setlocal indentkeys=0{,0},0),:,!^F,o,O,e,*,=?>,=,=?>,=\|\%(}\s*\)\?else\>\|do\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|trait\>\|use\>\|interface\>\|abstract\>\|final\>\|try\>\|\%(}\s*\)\=catch\>\|\%(}\s*\)\=finally\>\)' -let s:functionDecl = '\\%(\s\+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\)\=\s*(.*' +let s:functionDecl = '\\%(\s\+'.s:PHP_validVariable.'\)\=\s*(.*' let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' -let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<''\=\a\w*''\=$\|^\s*}\)'.s:endline.'\)\|^[^''"`]*[''"`]$' + + +let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|^\s*'.s:PHP_validVariable.':\)'.s:endline.'\)\|^[^''"`]*[''"`]$' let s:PHP_startindenttag = '\)\@!\|]*>\%(.*<\/script>\)\@!' @@ -140,7 +143,7 @@ let s:PHP_startindenttag = '\)\@!\|]*>\%(.*<\/script>\)\@!' let s:escapeDebugStops = 0 function! DebugPrintReturn(scriptLine) - if ! s:escapeDebugStops + if ! s:escapeDebugStops echo "debug:" . a:scriptLine let c = getchar() if c == "\" @@ -158,8 +161,6 @@ function! GetLastRealCodeLNum(startline) " {{{ let lnum = b:GetLastRealCodeLNum_ADD endif - let old_lnum = lnum - while lnum > 1 let lnum = prevnonblank(lnum) let lastline = getline(lnum) @@ -217,7 +218,7 @@ function! GetLastRealCodeLNum(startline) " {{{ let lnum=0 endif - if b:InPHPcode_and_script && !b:InPHPcode + if b:InPHPcode_and_script && 1 > b:InPHPcode let b:InPHPcode_and_script = 0 endif @@ -237,7 +238,7 @@ endfun function! Skippmatch() " {{{ let synname = synIDattr(synID(line("."), col("."), 0), "name") - if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# "^phpComment" && b:UserIsTypingComment + if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# '^php\%(Doc\)\?Comment' && b:UserIsTypingComment return 0 else return 1 @@ -249,7 +250,7 @@ function! FindOpenBracket(lnum, blockStarter) " {{{ let line = searchpair('{', '', '}', 'bW', 'Skippmatch()') if a:blockStarter == 1 - while line > 1 + while line > 1 let linec = getline(line) if linec =~ s:terminated || linec =~ '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline @@ -310,7 +311,6 @@ let s:defaultORcase = '^\s*\%(default\|case\).*:' function! FindTheSwitchIndent (lnum) " {{{ - let test = GetLastRealCodeLNum(a:lnum - 1) if test <= 1 @@ -353,7 +353,7 @@ function! IslinePHP (lnum, tofind) " {{{ if synname == 'phpStringSingle' || synname == 'phpStringDouble' || synname == 'phpBacktick' if cline !~ '^\s*[''"`]' - return "" + return "SpecStringEntrails" else return synname end @@ -372,7 +372,7 @@ if ! s:autoresetoptions endif function! ResetPhpOptions() - if ! b:optionsset && &filetype == "php" + if ! b:optionsset && &filetype =~ "php" if b:PHP_autoformatcomment setlocal comments=s1:/*,mb:*,ex:*/,://,:# @@ -418,7 +418,7 @@ function! GetPhpIndent() let b:PHP_indentinghuge = 0 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting endif - let b:PHP_lastindented = v:lnum + let real_PHP_lastindented = v:lnum let b:PHP_LastIndentedWasComment=0 let b:PHP_InsideMultilineComment=0 let b:PHP_indentbeforelast = 0 @@ -430,9 +430,12 @@ function! GetPhpIndent() elseif v:lnum > b:PHP_lastindented let real_PHP_lastindented = b:PHP_lastindented - let b:PHP_lastindented = v:lnum + else + let real_PHP_lastindented = v:lnum endif + let b:PHP_lastindented = v:lnum + if !b:InPHPcode_checked " {{{ One time check let b:InPHPcode_checked = 1 @@ -443,11 +446,15 @@ function! GetPhpIndent() endif if synname!="" - if synname != "phpHereDoc" && synname != "phpHereDocDelimiter" + if synname == "SpecStringEntrails" + let b:InPHPcode = -1 " thumb down + let b:UserIsTypingComment = 0 + let b:InPHPcode_tofind = "" + elseif synname != "phpHereDoc" && synname != "phpHereDocDelimiter" let b:InPHPcode = 1 let b:InPHPcode_tofind = "" - if synname =~# "^phpComment" + if synname =~# '^php\%(Doc\)\?Comment' let b:UserIsTypingComment = 1 else let b:UserIsTypingComment = 0 @@ -483,9 +490,16 @@ function! GetPhpIndent() if b:InPHPcode_tofind!="" if cline =~? b:InPHPcode_tofind - let b:InPHPcode = 1 let b:InPHPcode_tofind = "" let b:UserIsTypingComment = 0 + + if b:InPHPcode == -1 + let b:InPHPcode = 1 + return -1 + end + + let b:InPHPcode = 1 + if cline =~ '\*/' call cursor(v:lnum, 1) if cline !~ '^\*/' @@ -510,7 +524,7 @@ function! GetPhpIndent() endif endif - if b:InPHPcode + if 1 == b:InPHPcode if !b:InPHPcode_and_script && last_line =~ '\%(\%(.*')=~"Delimiter" if cline !~? s:PHP_startindenttag @@ -520,8 +534,8 @@ function! GetPhpIndent() let b:InPHPcode_and_script = 1 endif - elseif last_line =~ '^[^''"`]\+[''"`]$' " a string identifier with nothing after it and no other string identifier before - let b:InPHPcode = 0 + elseif last_line =~ '^[^''"`]\+[''"`]$' + let b:InPHPcode = -1 let b:InPHPcode_tofind = substitute( last_line, '^.*\([''"`]\).*$', '^[^\1]*\1[;,]$', '') elseif last_line =~? '<<<''\=\a\w*''\=$' let b:InPHPcode = 0 @@ -538,7 +552,7 @@ function! GetPhpIndent() endif " }}} - if !b:InPHPcode && !b:InPHPcode_and_script + if 1 > b:InPHPcode && !b:InPHPcode_and_script return -1 endif @@ -568,7 +582,7 @@ function! GetPhpIndent() endif endif - if !b:PHP_InsideMultilineComment && cline =~ '^\s*/\*' && cline !~ '\*/\s*$' + if !b:PHP_InsideMultilineComment && cline =~ '^\s*/\*\%(.*\*/\)\@!' if getline(v:lnum + 1) !~ '^\s*\*' return -1 endif @@ -669,17 +683,17 @@ function! GetPhpIndent() endwhile elseif last_line =~# unstated && cline !~ '^\s*);\='.endline - let ind = ind + &sw " we indent one level further when the preceding line is not stated + let ind = ind + &sw return ind + addSpecial - 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 let previous_line = last_line let last_line_num = lnum let LastLineClosed = 1 let isSingleLineBlock = 0 while 1 - if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline " XXX + if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline call cursor(last_line_num, 1) if previous_line !~ '^}' @@ -740,14 +754,19 @@ function! GetPhpIndent() endif endif - let plinnum = GetLastRealCodeLNum(lnum - 1) + if (last_line !~ '^\s*}\%(}}\)\@!') + let plinnum = GetLastRealCodeLNum(lnum - 1) + else + let plinnum = GetLastRealCodeLNum(FindOpenBracket(lnum, 1) - 1) + endif + let AntepenultimateLine = getline(plinnum) let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') if ind == b:PHP_default_indenting - if last_line =~ terminated + if last_line =~ terminated && last_line !~# s:defaultORcase let LastLineClosed = 1 endif endif @@ -755,10 +774,10 @@ function! GetPhpIndent() if !LastLineClosed - if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(]'.endline + if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline let dontIndent = 0 - if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline + if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*)\s*{'.endline && last_line !~ '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline let dontIndent = 1 endif @@ -774,7 +793,7 @@ function! GetPhpIndent() elseif last_line =~ '\S\+\s*),'.endline call cursor(lnum, 1) - call search('),'.endline, 'W') " line never begins with ) so no need for 'c' flag + call search('),'.endline, 'W') let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') if openedparent != lnum let ind = indent(openedparent) @@ -784,7 +803,7 @@ function! GetPhpIndent() let ind = ind + &sw - elseif AntepenultimateLine =~ '\%(;\%(\s*\%(?>\|}\)\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . s:defaultORcase + elseif AntepenultimateLine =~ '{'.endline || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase let ind = ind + &sw endif -- cgit v1.2.3