Mercurial > vim
comparison runtime/indent/php.vim @ 14006:665fe1f419b0
Update runtime files.
commit https://github.com/vim/vim/commit/0b0f0992d46ef02fdfc1240744bef91d4299c1df
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 22 21:41:30 2018 +0200
Update runtime files.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 22 May 2018 21:45:06 +0200 |
parents | 741b1feeac9f |
children | 2704c4e3e20a |
comparison
equal
deleted
inserted
replaced
14005:ca2dc95f2417 | 14006:665fe1f419b0 |
---|---|
1 " Vim indent file | 1 " Vim indent file |
2 " Language: PHP | 2 " Language: PHP |
3 " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> | 3 " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> |
4 " URL: http://www.2072productions.com/vim/indent/php.vim | 4 " URL: http://www.2072productions.com/vim/indent/php.vim |
5 " Home: https://github.com/2072/PHP-Indenting-for-VIm | 5 " Home: https://github.com/2072/PHP-Indenting-for-VIm |
6 " Last Change: 2018 May 14 | 6 " Last Change: 2018 May 18th |
7 " Version: 1.62 | 7 " Version: 1.66 |
8 " | 8 " |
9 " | 9 " |
10 " Type :help php-indent for available options | 10 " Type :help php-indent for available options |
11 " | 11 " |
12 " A fully commented version of this file is available on github | 12 " A fully commented version of this file is available on github |
78 | 78 |
79 if exists("PHP_outdentphpescape") | 79 if exists("PHP_outdentphpescape") |
80 let b:PHP_outdentphpescape = PHP_outdentphpescape | 80 let b:PHP_outdentphpescape = PHP_outdentphpescape |
81 else | 81 else |
82 let b:PHP_outdentphpescape = 1 | 82 let b:PHP_outdentphpescape = 1 |
83 endif | |
84 | |
85 if exists("PHP_noArrowMatching") | |
86 let b:PHP_noArrowMatching = PHP_noArrowMatching | |
87 else | |
88 let b:PHP_noArrowMatching = 0 | |
83 endif | 89 endif |
84 | 90 |
85 | 91 |
86 if exists("PHP_vintage_case_default_indent") && PHP_vintage_case_default_indent | 92 if exists("PHP_vintage_case_default_indent") && PHP_vintage_case_default_indent |
87 let b:PHP_vintage_case_default_indent = 1 | 93 let b:PHP_vintage_case_default_indent = 1 |
128 | 134 |
129 | 135 |
130 let s:PHP_validVariable = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' | 136 let s:PHP_validVariable = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' |
131 let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|die\|else\)' | 137 let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|die\|else\)' |
132 let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|\%(}\s*\)\?else\>\|do\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|trait\>\|use\>\|interface\>\|abstract\>\|final\>\|try\>\|\%(}\s*\)\=catch\>\|\%(}\s*\)\=finally\>\)' | 138 let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|\%(}\s*\)\?else\>\|do\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|trait\>\|use\>\|interface\>\|abstract\>\|final\>\|try\>\|\%(}\s*\)\=catch\>\|\%(}\s*\)\=finally\>\)' |
133 let s:functionDecl = '\<function\>\%(\s\+'.s:PHP_validVariable.'\)\=\s*(.*' | 139 let s:functionDecl = '\<function\>\%(\s\+&\='.s:PHP_validVariable.'\)\=\s*(.*' |
134 let s:endline = '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' | 140 let s:endline = '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' |
135 let s:unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.s:endline | 141 let s:unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.s:endline |
136 | 142 |
137 | 143 |
138 let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<\s*[''"]\=\a\w*[''"]\=$\|^\s*}\|^\s*'.s:PHP_validVariable.':\)'.s:endline.'\)' | 144 let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<\s*[''"]\=\a\w*[''"]\=$\|^\s*}\|^\s*'.s:PHP_validVariable.':\)'.s:endline.'\)' |
139 let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!' | 145 let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!' |
140 let s:structureHead = '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline . '\|\<new\s\+class\>' | 146 let s:structureHead = '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline . '\|\<new\s\+class\>' |
141 | |
142 | 147 |
143 | 148 |
144 let s:escapeDebugStops = 0 | 149 let s:escapeDebugStops = 0 |
145 function! DebugPrintReturn(scriptLine) | 150 function! DebugPrintReturn(scriptLine) |
146 | 151 |
255 endif | 260 endif |
256 endfun | 261 endfun |
257 | 262 |
258 function! Skippmatch() " {{{ | 263 function! Skippmatch() " {{{ |
259 let synname = synIDattr(synID(line("."), col("."), 0), "name") | 264 let synname = synIDattr(synID(line("."), col("."), 0), "name") |
260 if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# '^php\%(Doc\)\?Comment' && b:UserIsTypingComment | 265 if synname ==? "Delimiter" || synname ==? "phpRegionDelimiter" || synname =~? "^phpParent" || synname ==? "phpArrayParens" || synname =~? '^php\%(Block\|Brace\)' || synname ==? "javaScriptBraces" || synname =~? '^php\%(Doc\)\?Comment' && b:UserIsTypingComment |
261 return 0 | 266 return 0 |
262 else | 267 else |
263 return 1 | 268 return 1 |
264 endif | 269 endif |
265 endfun " }}} | 270 endfun " }}} |
294 endif | 299 endif |
295 endfor | 300 endfor |
296 | 301 |
297 return balance | 302 return balance |
298 endfun | 303 endfun |
304 | |
305 function! StripEndlineComments (line) | |
306 return substitute(a:line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') | |
307 endfun | |
308 | |
309 function! FindArrowIndent (lnum) " {{{ | |
310 | |
311 let parrentArrowPos = 0 | |
312 let lnum = a:lnum | |
313 while lnum > 1 | |
314 let last_line = getline(lnum) | |
315 if last_line =~ '^\s*->' | |
316 let parrentArrowPos = indent(a:lnum) | |
317 break | |
318 else | |
319 call cursor(lnum, 1) | |
320 let cleanedLnum = StripEndlineComments(last_line) | |
321 if cleanedLnum =~ '->' | |
322 if ! b:PHP_noArrowMatching | |
323 let parrentArrowPos = searchpos('->', 'W', lnum)[1] - 1 | |
324 else | |
325 let parrentArrowPos = indent(lnum) + shiftwidth() | |
326 endif | |
327 break | |
328 elseif cleanedLnum =~ ')'.s:endline && BalanceDirection(last_line) < 0 | |
329 call searchpos(')'.s:endline, 'cW', lnum) | |
330 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') | |
331 if openedparent != lnum | |
332 let lnum = openedparent | |
333 else | |
334 let openedparent = -1 | |
335 endif | |
336 | |
337 else | |
338 let parrentArrowPos = indent(lnum) + shiftwidth() | |
339 break | |
340 endif | |
341 endif | |
342 endwhile | |
343 | |
344 return parrentArrowPos | |
345 endfun "}}} | |
299 | 346 |
300 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{ | 347 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{ |
301 | 348 |
302 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>' | 349 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>' |
303 let beforeelse = a:lnum | 350 let beforeelse = a:lnum |
366 return FindTheSwitchIndent(test) | 413 return FindTheSwitchIndent(test) |
367 endif | 414 endif |
368 | 415 |
369 endfunction "}}} | 416 endfunction "}}} |
370 | 417 |
371 let s:SynPHPMatchGroups = {'phpParent':1, 'Delimiter':1, 'Define':1, 'Storageclass':1, 'StorageClass':1, 'Structure':1, 'Exception':1} | 418 let s:SynPHPMatchGroups = {'phpparent':1, 'delimiter':1, 'define':1, 'storageclass':1, 'structure':1, 'exception':1} |
372 function! IslinePHP (lnum, tofind) " {{{ | 419 function! IslinePHP (lnum, tofind) " {{{ |
373 let cline = getline(a:lnum) | 420 let cline = getline(a:lnum) |
374 | 421 |
375 if a:tofind=="" | 422 if a:tofind=="" |
376 let tofind = "^\\s*[\"'`]*\\s*\\zs\\S" | 423 let tofind = "^\\s*[\"'`]*\\s*\\zs\\S" |
382 | 429 |
383 let coltotest = match (cline, tofind) + 1 | 430 let coltotest = match (cline, tofind) + 1 |
384 | 431 |
385 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") | 432 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") |
386 | 433 |
387 if synname == 'phpStringSingle' || synname == 'phpStringDouble' || synname == 'phpBacktick' | 434 if synname ==? 'phpStringSingle' || synname ==? 'phpStringDouble' || synname ==? 'phpBacktick' |
388 if cline !~ '^\s*[''"`]' | 435 if cline !~ '^\s*[''"`]' |
389 return "SpecStringEntrails" | 436 return "SpecStringEntrails" |
390 else | 437 else |
391 return synname | 438 return synname |
392 end | 439 end |
393 end | 440 end |
394 | 441 |
395 if get(s:SynPHPMatchGroups, synname) || synname =~ '^php' || synname =~? '^javaScript' | 442 if get(s:SynPHPMatchGroups, tolower(synname)) || synname =~ '^php' || synname =~? '^javaScript' |
396 return synname | 443 return synname |
397 else | 444 else |
398 return "" | 445 return "" |
399 endif | 446 endif |
400 endfunction " }}} | 447 endfunction " }}} |
421 endif | 468 endif |
422 endfunc | 469 endfunc |
423 | 470 |
424 call ResetPhpOptions() | 471 call ResetPhpOptions() |
425 | 472 |
473 function! GetPhpIndentVersion() | |
474 return "1.66-bundle" | |
475 endfun | |
476 | |
426 function! GetPhpIndent() | 477 function! GetPhpIndent() |
427 | 478 |
428 let b:GetLastRealCodeLNum_ADD = 0 | 479 let b:GetLastRealCodeLNum_ADD = 0 |
429 | 480 |
430 let UserIsEditing=0 | 481 let UserIsEditing=0 |
478 if cline !~ '<?.*?>' | 529 if cline !~ '<?.*?>' |
479 let synname = IslinePHP (prevnonblank(v:lnum), "") | 530 let synname = IslinePHP (prevnonblank(v:lnum), "") |
480 endif | 531 endif |
481 | 532 |
482 if synname!="" | 533 if synname!="" |
483 if synname == "SpecStringEntrails" | 534 if synname ==? "SpecStringEntrails" |
484 let b:InPHPcode = -1 " thumb down | 535 let b:InPHPcode = -1 " thumb down |
485 let b:InPHPcode_tofind = "" | 536 let b:InPHPcode_tofind = "" |
486 elseif synname != "phpHereDoc" && synname != "phpHereDocDelimiter" | 537 elseif synname !=? "phpHereDoc" && synname !=? "phpHereDocDelimiter" |
487 let b:InPHPcode = 1 | 538 let b:InPHPcode = 1 |
488 let b:InPHPcode_tofind = "" | 539 let b:InPHPcode_tofind = "" |
489 | 540 |
490 if synname =~# '^php\%(Doc\)\?Comment' | 541 if synname =~? '^php\%(Doc\)\?Comment' |
491 let b:UserIsTypingComment = 1 | 542 let b:UserIsTypingComment = 1 |
492 let b:InPHPcode_checked = 0 | 543 let b:InPHPcode_checked = 0 |
493 endif | 544 endif |
494 | 545 |
495 if synname =~? '^javaScript' | 546 if synname =~? '^javaScript' |
554 endif | 605 endif |
555 endif | 606 endif |
556 | 607 |
557 if 1 == b:InPHPcode | 608 if 1 == b:InPHPcode |
558 | 609 |
559 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~"Delimiter" | 610 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~?"Delimiter" |
560 if cline !~? s:PHP_startindenttag | 611 if cline !~? s:PHP_startindenttag |
561 let b:InPHPcode = 0 | 612 let b:InPHPcode = 0 |
562 let b:InPHPcode_tofind = s:PHP_startindenttag | 613 let b:InPHPcode_tofind = s:PHP_startindenttag |
563 elseif cline =~? '<script\>' | 614 elseif cline =~? '<script\>' |
564 let b:InPHPcode_and_script = 1 | 615 let b:InPHPcode_and_script = 1 |
710 endif | 761 endif |
711 | 762 |
712 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) | 763 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
713 let previous_line = getline(last_line_num) | 764 let previous_line = getline(last_line_num) |
714 endwhile | 765 endwhile |
715 | 766 elseif cline =~ '^\s*->' |
767 return FindArrowIndent(lnum) | |
716 elseif last_line =~# unstated && cline !~ '^\s*);\='.endline | 768 elseif last_line =~# unstated && cline !~ '^\s*);\='.endline |
717 let ind = ind + shiftwidth() " we indent one level further when the preceding line is not stated | 769 let ind = ind + shiftwidth() " we indent one level further when the preceding line is not stated |
718 return ind + addSpecial | 770 return ind + addSpecial |
719 | 771 |
720 elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated | 772 elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated |
722 let last_line_num = lnum | 774 let last_line_num = lnum |
723 let LastLineClosed = 1 | 775 let LastLineClosed = 1 |
724 | 776 |
725 let isSingleLineBlock = 0 | 777 let isSingleLineBlock = 0 |
726 while 1 | 778 while 1 |
727 if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline " XXX | 779 if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline |
728 | 780 |
729 call cursor(last_line_num, 1) | 781 call cursor(last_line_num, 1) |
730 if previous_line !~ '^}' | 782 if previous_line !~ '^}' |
731 call search('}\|;\s*}'.endline, 'W') | 783 call search('}\|;\s*}'.endline, 'W') |
732 end | 784 end |
791 let plinnum = GetLastRealCodeLNum(FindOpenBracket(lnum, 1) - 1) | 843 let plinnum = GetLastRealCodeLNum(FindOpenBracket(lnum, 1) - 1) |
792 endif | 844 endif |
793 | 845 |
794 let AntepenultimateLine = getline(plinnum) | 846 let AntepenultimateLine = getline(plinnum) |
795 | 847 |
796 let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') | 848 let last_line = StripEndlineComments(last_line) |
797 | |
798 | 849 |
799 if ind == b:PHP_default_indenting | 850 if ind == b:PHP_default_indenting |
800 if last_line =~ terminated && last_line !~# s:defaultORcase | 851 if last_line =~ terminated && last_line !~# s:defaultORcase |
801 let LastLineClosed = 1 | 852 let LastLineClosed = 1 |
802 endif | 853 endif |
803 endif | 854 endif |
804 | 855 |
805 if !LastLineClosed | 856 if !LastLineClosed |
806 | 857 |
858 let openedparent = -1 | |
859 | |
807 | 860 |
808 if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline && BalanceDirection(last_line) > 0 | 861 if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline && BalanceDirection(last_line) > 0 |
809 | 862 |
810 let dontIndent = 0 | 863 let dontIndent = 0 |
811 if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\s*{'.endline && last_line !~ s:structureHead | 864 if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\(\s*:\s*'.s:PHP_validVariable.'\)\=\s*{'.endline && last_line !~ s:structureHead |
812 let dontIndent = 1 | 865 let dontIndent = 1 |
813 endif | 866 endif |
814 | 867 |
815 if !dontIndent && (!b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{') | 868 if !dontIndent && (!b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{') |
816 let ind = ind + shiftwidth() | 869 let ind = ind + shiftwidth() |
817 endif | 870 endif |
818 | 871 |
819 if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 | 872 if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 |
820 let b:PHP_CurrentIndentLevel = ind | 873 let b:PHP_CurrentIndentLevel = ind |
821 | 874 |
822 return ind + addSpecial | 875 endif |
823 endif | 876 |
824 | 877 elseif last_line =~ '),'.endline && BalanceDirection(last_line) < 0 |
825 elseif last_line =~ '\S\+\s*),'.endline && BalanceDirection(last_line) < 0 | |
826 call cursor(lnum, 1) | 878 call cursor(lnum, 1) |
827 call search('),'.endline, 'W') " line never begins with ) so no need for 'c' flag | 879 call searchpos('),'.endline, 'cW') |
828 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') | 880 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') |
829 if openedparent != lnum | 881 if openedparent != lnum |
830 let ind = indent(openedparent) | 882 let ind = indent(openedparent) |
831 endif | 883 endif |
832 | 884 |
833 elseif last_line =~ '^\s*'.s:blockstart | 885 elseif last_line =~ s:structureHead |
834 let ind = ind + shiftwidth() | 886 let ind = ind + shiftwidth() |
835 | 887 |
836 | 888 |
837 elseif AntepenultimateLine =~ '{'.endline && AntepenultimateLine !~? '^\s*use\>' || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase | 889 elseif AntepenultimateLine =~ '{'.endline && AntepenultimateLine !~? '^\s*use\>' || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase |
838 let ind = ind + shiftwidth() | 890 let ind = ind + shiftwidth() |
839 endif | 891 endif |
840 | 892 |
841 endif | 893 |
842 | 894 if openedparent >= 0 |
843 if cline =~ '^\s*[)\]];\=' | 895 let last_line = StripEndlineComments(getline(openedparent)) |
896 endif | |
897 endif | |
898 | |
899 if cline =~ '^\s*[)\]];\=' | |
900 let ind = ind - shiftwidth() | |
901 endif | |
902 | |
903 if last_line =~ '^\s*->' && last_line !~? s:structureHead && BalanceDirection(last_line) <= 0 | |
844 let ind = ind - shiftwidth() | 904 let ind = ind - shiftwidth() |
845 endif | 905 endif |
846 | 906 |
847 let b:PHP_CurrentIndentLevel = ind | 907 let b:PHP_CurrentIndentLevel = ind |
848 return ind + addSpecial | 908 return ind + addSpecial |