Mercurial > vim
annotate runtime/indent/php.vim @ 28730:de8df542fb53
Added tag v8.2.4889 for changeset 1bd1bfc64a47064c8f511ab1f7243fc55cc9bbdf
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 06 May 2022 17:15:04 +0200 |
parents | 847a300aa244 |
children | d46f974fd69e |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: PHP | |
17571 | 3 " Author: John Wellesz <John.wellesz (AT) gmail (DOT) com> |
4 " URL: https://www.2072productions.com/vim/indent/php.vim | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
5 " Home: https://github.com/2072/PHP-Indenting-for-VIm |
19646 | 6 " Last Change: 2020 Mar 05 |
17571 | 7 " Version: 1.70 |
557 | 8 " |
856 | 9 " |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
10 " Type :help php-indent for available options |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
11 " |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
12 " A fully commented version of this file is available on github |
409 | 13 " |
14 " | |
13950
741b1feeac9f
patch 8.0.1845: various comment updates needed, missing white space
Christian Brabandt <cb@256bit.org>
parents:
11518
diff
changeset
|
15 " If you find a bug, please open a ticket on github.com |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
16 " ( https://github.com/2072/PHP-Indenting-for-VIm/issues ) with an example of |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
17 " code that breaks the algorithm. |
409 | 18 " |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
19 |
409 | 20 " NOTE: This script must be used with PHP syntax ON and with the php syntax |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
21 " script by Lutz Eymers (http://www.isp.de/data/php.vim ) or with the |
17571 | 22 " script by Peter Hodge (https://www.vim.org/scripts/script.php?script_id=1571 ) |
2034 | 23 " the later is bunbdled by default with Vim 7. |
409 | 24 " |
25 " | |
1668 | 26 " In the case you have syntax errors in your script such as HereDoc end |
27 " identifiers not at col 1 you'll have to indent your file 2 times (This | |
28 " script will automatically put HereDoc end identifiers at col 1 if | |
29 " they are followed by a ';'). | |
856 | 30 " |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
31 |
2034 | 32 " NOTE: If you are editing files in Unix file format and that (by accident) |
33 " there are '\r' before new lines, this script won't be able to proceed | |
34 " correctly and will make many mistakes because it won't be able to match | |
35 " '\s*$' correctly. | |
36 " So you have to remove those useless characters first with a command like: | |
409 | 37 " |
2034 | 38 " :%s /\r$//g |
7 | 39 " |
2034 | 40 " or simply 'let' the option PHP_removeCRwhenUnix to 1 and the script will |
41 " silently remove them when VIM load this script (at each bufread). | |
5862 | 42 |
43 | |
7 | 44 if exists("b:did_indent") |
532 | 45 finish |
7 | 46 endif |
47 let b:did_indent = 1 | |
48 | |
409 | 49 |
6421 | 50 let g:php_sync_method = 0 |
409 | 51 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
52 |
409 | 53 if exists("PHP_default_indenting") |
11518 | 54 let b:PHP_default_indenting = PHP_default_indenting * shiftwidth() |
409 | 55 else |
532 | 56 let b:PHP_default_indenting = 0 |
409 | 57 endif |
58 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
59 if exists("PHP_outdentSLComments") |
11518 | 60 let b:PHP_outdentSLComments = PHP_outdentSLComments * shiftwidth() |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
61 else |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
62 let b:PHP_outdentSLComments = 0 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
63 endif |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
64 |
409 | 65 if exists("PHP_BracesAtCodeLevel") |
532 | 66 let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel |
409 | 67 else |
532 | 68 let b:PHP_BracesAtCodeLevel = 0 |
409 | 69 endif |
70 | |
1668 | 71 |
557 | 72 if exists("PHP_autoformatcomment") |
73 let b:PHP_autoformatcomment = PHP_autoformatcomment | |
74 else | |
75 let b:PHP_autoformatcomment = 1 | |
76 endif | |
7 | 77 |
2442 | 78 if exists("PHP_outdentphpescape") |
79 let b:PHP_outdentphpescape = PHP_outdentphpescape | |
80 else | |
81 let b:PHP_outdentphpescape = 1 | |
82 endif | |
83 | |
14006 | 84 if exists("PHP_noArrowMatching") |
85 let b:PHP_noArrowMatching = PHP_noArrowMatching | |
86 else | |
87 let b:PHP_noArrowMatching = 0 | |
88 endif | |
89 | |
2442 | 90 |
91 if exists("PHP_vintage_case_default_indent") && PHP_vintage_case_default_indent | |
92 let b:PHP_vintage_case_default_indent = 1 | |
1668 | 93 else |
94 let b:PHP_vintage_case_default_indent = 0 | |
95 endif | |
96 | |
17571 | 97 if exists("PHP_IndentFunctionCallParameters") |
98 let b:PHP_IndentFunctionCallParameters = PHP_IndentFunctionCallParameters | |
99 else | |
100 let b:PHP_IndentFunctionCallParameters = 0 | |
101 endif | |
1668 | 102 |
17571 | 103 if exists("PHP_IndentFunctionDeclarationParameters") |
104 let b:PHP_IndentFunctionDeclarationParameters = PHP_IndentFunctionDeclarationParameters | |
105 else | |
106 let b:PHP_IndentFunctionDeclarationParameters = 0 | |
107 endif | |
1668 | 108 |
409 | 109 let b:PHP_lastindented = 0 |
110 let b:PHP_indentbeforelast = 0 | |
111 let b:PHP_indentinghuge = 0 | |
112 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
113 let b:PHP_LastIndentedWasComment = 0 | |
114 let b:PHP_InsideMultilineComment = 0 | |
115 let b:InPHPcode = 0 | |
116 let b:InPHPcode_checked = 0 | |
117 let b:InPHPcode_and_script = 0 | |
118 let b:InPHPcode_tofind = "" | |
119 let b:PHP_oldchangetick = b:changedtick | |
120 let b:UserIsTypingComment = 0 | |
121 let b:optionsset = 0 | |
122 | |
123 setlocal nosmartindent | |
856 | 124 setlocal noautoindent |
409 | 125 setlocal nocindent |
532 | 126 setlocal nolisp |
409 | 127 |
128 setlocal indentexpr=GetPhpIndent() | |
6421 | 129 setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e,*<Return>,=?>,=<?,=*/ |
409 | 130 |
131 | |
532 | 132 |
133 let s:searchpairflags = 'bWr' | |
409 | 134 |
135 if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUnix | |
532 | 136 silent! %s/\r$//g |
409 | 137 endif |
138 | |
7 | 139 if exists("*GetPhpIndent") |
2034 | 140 call ResetPhpOptions() |
17571 | 141 finish " XXX -- comment this line for easy dev |
7 | 142 endif |
143 | |
5862 | 144 |
17571 | 145 let s:endline = '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' |
6421 | 146 let s:PHP_validVariable = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' |
17571 | 147 let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|die\|else\|end\%(if\|while\|for\|foreach\|switch\)\)' |
148 let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|\%(}\s*\)\?else\>\|do\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|trait\>\|\%()\s*\)\=use\>\|interface\>\|abstract\>\|final\>\|try\>\|\%(}\s*\)\=catch\>\|\%(}\s*\)\=finally\>\)' | |
149 let s:functionDeclPrefix = '\<function\>\%(\s\+&\='.s:PHP_validVariable.'\)\=\s*(' | |
150 let s:functionDecl = s:functionDeclPrefix.'.*' | |
151 let s:multilineFunctionDecl = s:functionDeclPrefix.s:endline | |
152 let s:arrayDecl = '\<array\>\s*(.*' | |
153 let s:multilineFunctionCall = s:PHP_validVariable.'\s*('.s:endline | |
11262 | 154 let s:unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.s:endline |
6421 | 155 |
156 | |
11262 | 157 let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<\s*[''"]\=\a\w*[''"]\=$\|^\s*}\|^\s*'.s:PHP_validVariable.':\)'.s:endline.'\)' |
409 | 158 let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!' |
11262 | 159 let s:structureHead = '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline . '\|\<new\s\+class\>' |
409 | 160 |
161 | |
5862 | 162 let s:escapeDebugStops = 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
163 function! DebugPrintReturn(scriptLine) |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
164 |
6421 | 165 if ! s:escapeDebugStops |
5862 | 166 echo "debug:" . a:scriptLine |
167 let c = getchar() | |
168 if c == "\<Del>" | |
169 let s:escapeDebugStops = 1 | |
170 end | |
171 endif | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
172 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
173 endfunction |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
174 |
409 | 175 function! GetLastRealCodeLNum(startline) " {{{ |
856 | 176 |
532 | 177 let lnum = a:startline |
856 | 178 |
631 | 179 if b:GetLastRealCodeLNum_ADD && b:GetLastRealCodeLNum_ADD == lnum + 1 |
180 let lnum = b:GetLastRealCodeLNum_ADD | |
181 endif | |
856 | 182 |
532 | 183 while lnum > 1 |
184 let lnum = prevnonblank(lnum) | |
185 let lastline = getline(lnum) | |
409 | 186 |
532 | 187 if b:InPHPcode_and_script && lastline =~ '?>\s*$' |
188 let lnum = lnum - 1 | |
189 elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$' | |
190 let lnum = lnum - 1 | |
191 elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' | |
192 let lnum = lnum - 1 | |
193 elseif lastline =~ '\*/\s*$' | |
194 call cursor(lnum, 1) | |
195 if lastline !~ '^\*/' | |
196 call search('\*/', 'W') | |
197 endif | |
557 | 198 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 199 |
532 | 200 let lastline = getline(lnum) |
201 if lastline =~ '^\s*/\*' | |
202 let lnum = lnum - 1 | |
203 else | |
204 break | |
205 endif | |
409 | 206 |
207 | |
532 | 208 elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>' |
209 | |
210 while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1 | |
211 let lnum = lnum - 1 | |
212 let lastline = getline(lnum) | |
213 endwhile | |
214 if lastline =~ '^\s*?>' | |
215 let lnum = lnum - 1 | |
216 else | |
217 break | |
218 endif | |
219 | |
409 | 220 |
2442 | 221 elseif lastline =~? '^\a\w*;\=$' && lastline !~? s:notPhpHereDoc |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
222 let tofind=substitute( lastline, '\(\a\w*\);\=', '<<<\\s*[''"]\\=\1[''"]\\=$', '') |
532 | 223 while getline(lnum) !~? tofind && lnum > 1 |
224 let lnum = lnum - 1 | |
225 endwhile | |
17571 | 226 elseif lastline =~ '^\s*[''"`][;,]' || (lastline =~ '^[^''"`]*[''"`][;,]'.s:endline && IslinePHP(lnum, "") == "SpecStringEntrails") |
11262 | 227 |
228 let tofind=substitute( lastline, '^.*\([''"`]\)[;,].*$', '^[^\1]\\+[\1]$\\|^[^\1]\\+[=([]\\s*[\1]', '') | |
229 let trylnum = lnum | |
230 while getline(trylnum) !~? tofind && trylnum > 1 | |
231 let trylnum = trylnum - 1 | |
5862 | 232 endwhile |
11262 | 233 |
234 if trylnum == 1 | |
235 break | |
236 else | |
237 if lastline =~ ';'.s:endline | |
238 while getline(trylnum) !~? s:terminated && getline(trylnum) !~? '{'.s:endline && trylnum > 1 | |
239 let trylnum = prevnonblank(trylnum - 1) | |
240 endwhile | |
241 | |
242 | |
243 if trylnum == 1 | |
244 break | |
245 end | |
246 end | |
247 let lnum = trylnum | |
248 end | |
532 | 249 else |
856 | 250 break |
409 | 251 endif |
532 | 252 endwhile |
253 | |
2442 | 254 if lnum==1 && getline(lnum) !~ '<?' |
532 | 255 let lnum=0 |
256 endif | |
257 | |
6421 | 258 if b:InPHPcode_and_script && 1 > b:InPHPcode |
532 | 259 let b:InPHPcode_and_script = 0 |
260 endif | |
1120 | 261 |
532 | 262 return lnum |
263 endfunction " }}} | |
409 | 264 |
557 | 265 function! Skippmatch2() |
266 | |
267 let line = getline(".") | |
268 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
269 if line =~ "\\([\"']\\).*/\\*.*\\1" || line =~ '\%(//\|#\).*/\*' |
5862 | 270 return 1 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
271 else |
5862 | 272 return 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
273 endif |
557 | 274 endfun |
275 | |
2442 | 276 function! Skippmatch() " {{{ |
532 | 277 let synname = synIDattr(synID(line("."), col("."), 0), "name") |
14006 | 278 if synname ==? "Delimiter" || synname ==? "phpRegionDelimiter" || synname =~? "^phpParent" || synname ==? "phpArrayParens" || synname =~? '^php\%(Block\|Brace\)' || synname ==? "javaScriptBraces" || synname =~? '^php\%(Doc\)\?Comment' && b:UserIsTypingComment |
532 | 279 return 0 |
280 else | |
281 return 1 | |
282 endif | |
283 endfun " }}} | |
409 | 284 |
5862 | 285 function! FindOpenBracket(lnum, blockStarter) " {{{ |
532 | 286 call cursor(a:lnum, 1) |
5862 | 287 let line = searchpair('{', '', '}', 'bW', 'Skippmatch()') |
288 | |
289 if a:blockStarter == 1 | |
6421 | 290 while line > 1 |
5862 | 291 let linec = getline(line) |
292 | |
11262 | 293 if linec =~ s:terminated || linec =~ s:structureHead |
5862 | 294 break |
295 endif | |
296 | |
297 let line = GetLastRealCodeLNum(line - 1) | |
298 endwhile | |
299 endif | |
300 | |
301 return line | |
532 | 302 endfun " }}} |
409 | 303 |
11262 | 304 let s:blockChars = {'{':1, '[': 1, '(': 1, ')':-1, ']':-1, '}':-1} |
17571 | 305 let s:blockCharsLUT = {'{':'{', '}':'{', '[':'[', ']':'[', '(':'(', ')':'('} |
11262 | 306 function! BalanceDirection (str) |
307 | |
17571 | 308 let balance = {'{':0, '[': 0, '(': 0, 'none':0} |
309 let director = 'none' | |
11262 | 310 |
311 for c in split(a:str, '\zs') | |
312 if has_key(s:blockChars, c) | |
17571 | 313 let balance[s:blockCharsLUT[c]] += s:blockChars[c] |
314 | |
315 if balance[s:blockCharsLUT[c]] | |
316 let director = s:blockCharsLUT[c] | |
317 endif | |
11262 | 318 endif |
319 endfor | |
320 | |
17571 | 321 return balance[director] |
11262 | 322 endfun |
323 | |
14006 | 324 function! StripEndlineComments (line) |
325 return substitute(a:line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') | |
326 endfun | |
327 | |
328 function! FindArrowIndent (lnum) " {{{ | |
329 | |
17571 | 330 let parrentArrowPos = -1 |
331 let cursorPos = -1 | |
14006 | 332 let lnum = a:lnum |
333 while lnum > 1 | |
334 let last_line = getline(lnum) | |
335 if last_line =~ '^\s*->' | |
336 let parrentArrowPos = indent(a:lnum) | |
337 break | |
338 else | |
17571 | 339 |
340 if b:PHP_noArrowMatching | |
14006 | 341 break |
17571 | 342 endif |
343 | |
344 let cleanedLnum = StripEndlineComments(last_line) | |
345 | |
346 if cleanedLnum =~ ')'.s:endline | |
347 if BalanceDirection(cleanedLnum) <= 0 | |
348 call cursor(lnum, 1) | |
349 call searchpos(')'.s:endline, 'cW', lnum) | |
350 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') | |
351 let cursorPos = col(".") | |
352 if openedparent != lnum | |
353 let lnum = openedparent | |
354 continue | |
355 else | |
356 endif | |
14006 | 357 else |
17571 | 358 let parrentArrowPos = -1 |
359 break | |
360 end | |
361 endif | |
14006 | 362 |
17571 | 363 if cleanedLnum =~ '->' |
364 call cursor(lnum, cursorPos == -1 ? strwidth(cleanedLnum) : cursorPos) | |
365 let parrentArrowPos = searchpos('->', 'cWb', lnum)[1] - 1 | |
366 | |
367 break | |
14006 | 368 else |
17571 | 369 let parrentArrowPos = -1 |
14006 | 370 break |
371 endif | |
372 endif | |
373 endwhile | |
374 | |
17571 | 375 if parrentArrowPos == -1 |
376 let parrentArrowPos = indent(lnum) + shiftwidth() | |
377 end | |
378 | |
14006 | 379 return parrentArrowPos |
380 endfun "}}} | |
381 | |
409 | 382 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{ |
532 | 383 |
384 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>' | |
385 let beforeelse = a:lnum | |
386 else | |
387 let beforeelse = GetLastRealCodeLNum(a:lnum - 1) | |
388 endif | |
409 | 389 |
532 | 390 if !s:level |
391 let s:iftoskip = 0 | |
392 endif | |
393 | |
394 if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>' | |
395 let s:iftoskip = s:iftoskip + 1 | |
396 endif | |
397 | |
398 if getline(beforeelse) =~ '^\s*}' | |
5862 | 399 let beforeelse = FindOpenBracket(beforeelse, 0) |
532 | 400 |
401 if getline(beforeelse) =~ '^\s*{' | |
402 let beforeelse = GetLastRealCodeLNum(beforeelse - 1) | |
409 | 403 endif |
532 | 404 endif |
409 | 405 |
406 | |
532 | 407 if !s:iftoskip && a:StopAfterFirstPrevElse && getline(beforeelse) =~# '^\s*\%([}]\s*\)\=else\%(if\)\=\>' |
408 return beforeelse | |
409 endif | |
410 | |
411 if getline(beforeelse) !~# '^\s*if\>' && beforeelse>1 || s:iftoskip && beforeelse>1 | |
412 | |
2442 | 413 if s:iftoskip && getline(beforeelse) =~# '^\s*if\>' |
532 | 414 let s:iftoskip = s:iftoskip - 1 |
409 | 415 endif |
416 | |
532 | 417 let s:level = s:level + 1 |
418 let beforeelse = FindTheIfOfAnElse(beforeelse, a:StopAfterFirstPrevElse) | |
419 endif | |
409 | 420 |
532 | 421 return beforeelse |
409 | 422 |
532 | 423 endfunction " }}} |
409 | 424 |
2442 | 425 let s:defaultORcase = '^\s*\%(default\|case\).*:' |
426 | |
427 function! FindTheSwitchIndent (lnum) " {{{ | |
428 | |
429 let test = GetLastRealCodeLNum(a:lnum - 1) | |
430 | |
431 if test <= 1 | |
11518 | 432 return indent(1) - shiftwidth() * b:PHP_vintage_case_default_indent |
2442 | 433 end |
434 | |
5862 | 435 while getline(test) =~ '^\s*}' && test > 1 |
436 let test = GetLastRealCodeLNum(FindOpenBracket(test, 0) - 1) | |
2442 | 437 |
5862 | 438 if getline(test) =~ '^\s*switch\>' |
439 let test = GetLastRealCodeLNum(test - 1) | |
2442 | 440 endif |
5862 | 441 endwhile |
2442 | 442 |
443 if getline(test) =~# '^\s*switch\>' | |
444 return indent(test) | |
445 elseif getline(test) =~# s:defaultORcase | |
11518 | 446 return indent(test) - shiftwidth() * b:PHP_vintage_case_default_indent |
2442 | 447 else |
448 return FindTheSwitchIndent(test) | |
449 endif | |
450 | |
451 endfunction "}}} | |
452 | |
14006 | 453 let s:SynPHPMatchGroups = {'phpparent':1, 'delimiter':1, 'define':1, 'storageclass':1, 'structure':1, 'exception':1} |
409 | 454 function! IslinePHP (lnum, tofind) " {{{ |
532 | 455 let cline = getline(a:lnum) |
409 | 456 |
532 | 457 if a:tofind=="" |
5862 | 458 let tofind = "^\\s*[\"'`]*\\s*\\zs\\S" |
532 | 459 else |
460 let tofind = a:tofind | |
461 endif | |
409 | 462 |
532 | 463 let tofind = tofind . '\c' |
409 | 464 |
532 | 465 let coltotest = match (cline, tofind) + 1 |
466 | |
467 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") | |
409 | 468 |
14006 | 469 if synname ==? 'phpStringSingle' || synname ==? 'phpStringDouble' || synname ==? 'phpBacktick' |
17571 | 470 if cline !~ '^\s*[''"`]' " ??? XXX |
6421 | 471 return "SpecStringEntrails" |
5862 | 472 else |
473 return synname | |
474 end | |
475 end | |
476 | |
14006 | 477 if get(s:SynPHPMatchGroups, tolower(synname)) || synname =~ '^php' || synname =~? '^javaScript' |
532 | 478 return synname |
479 else | |
480 return "" | |
481 endif | |
482 endfunction " }}} | |
409 | 483 |
2034 | 484 let s:autoresetoptions = 0 |
485 if ! s:autoresetoptions | |
486 let s:autoresetoptions = 1 | |
7 | 487 endif |
488 | |
2034 | 489 function! ResetPhpOptions() |
6421 | 490 if ! b:optionsset && &filetype =~ "php" |
557 | 491 if b:PHP_autoformatcomment |
492 | |
493 setlocal comments=s1:/*,mb:*,ex:*/,://,:# | |
856 | 494 |
1668 | 495 setlocal formatoptions-=t |
557 | 496 setlocal formatoptions+=q |
497 setlocal formatoptions+=r | |
498 setlocal formatoptions+=o | |
499 setlocal formatoptions+=c | |
500 setlocal formatoptions+=b | |
501 endif | |
532 | 502 let b:optionsset = 1 |
503 endif | |
409 | 504 endfunc |
505 | |
2034 | 506 call ResetPhpOptions() |
507 | |
14006 | 508 function! GetPhpIndentVersion() |
17571 | 509 return "1.70-bundle" |
14006 | 510 endfun |
511 | |
409 | 512 function! GetPhpIndent() |
513 | |
631 | 514 let b:GetLastRealCodeLNum_ADD = 0 |
515 | |
532 | 516 let UserIsEditing=0 |
517 if b:PHP_oldchangetick != b:changedtick | |
518 let b:PHP_oldchangetick = b:changedtick | |
519 let UserIsEditing=1 | |
520 endif | |
409 | 521 |
532 | 522 if b:PHP_default_indenting |
11518 | 523 let b:PHP_default_indenting = g:PHP_default_indenting * shiftwidth() |
532 | 524 endif |
525 | |
526 let cline = getline(v:lnum) | |
409 | 527 |
856 | 528 if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast |
532 | 529 if b:PHP_indentbeforelast |
530 let b:PHP_indentinghuge = 1 | |
531 endif | |
532 let b:PHP_indentbeforelast = b:PHP_lastindented | |
533 endif | |
409 | 534 |
532 | 535 if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented |
536 if b:PHP_indentinghuge | |
537 let b:PHP_indentinghuge = 0 | |
538 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 539 endif |
6421 | 540 let real_PHP_lastindented = v:lnum |
532 | 541 let b:PHP_LastIndentedWasComment=0 |
542 let b:PHP_InsideMultilineComment=0 | |
543 let b:PHP_indentbeforelast = 0 | |
409 | 544 |
532 | 545 let b:InPHPcode = 0 |
546 let b:InPHPcode_checked = 0 | |
547 let b:InPHPcode_and_script = 0 | |
548 let b:InPHPcode_tofind = "" | |
409 | 549 |
532 | 550 elseif v:lnum > b:PHP_lastindented |
551 let real_PHP_lastindented = b:PHP_lastindented | |
6421 | 552 else |
553 let real_PHP_lastindented = v:lnum | |
532 | 554 endif |
409 | 555 |
6421 | 556 let b:PHP_lastindented = v:lnum |
557 | |
409 | 558 |
532 | 559 if !b:InPHPcode_checked " {{{ One time check |
560 let b:InPHPcode_checked = 1 | |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
561 let b:UserIsTypingComment = 0 |
409 | 562 |
631 | 563 let synname = "" |
564 if cline !~ '<?.*?>' | |
565 let synname = IslinePHP (prevnonblank(v:lnum), "") | |
566 endif | |
409 | 567 |
532 | 568 if synname!="" |
14006 | 569 if synname ==? "SpecStringEntrails" |
11262 | 570 let b:InPHPcode = -1 " thumb down |
6421 | 571 let b:InPHPcode_tofind = "" |
14006 | 572 elseif synname !=? "phpHereDoc" && synname !=? "phpHereDocDelimiter" |
532 | 573 let b:InPHPcode = 1 |
574 let b:InPHPcode_tofind = "" | |
409 | 575 |
14006 | 576 if synname =~? '^php\%(Doc\)\?Comment' |
532 | 577 let b:UserIsTypingComment = 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
578 let b:InPHPcode_checked = 0 |
409 | 579 endif |
580 | |
532 | 581 if synname =~? '^javaScript' |
582 let b:InPHPcode_and_script = 1 | |
583 endif | |
409 | 584 |
532 | 585 else |
586 let b:InPHPcode = 0 | |
409 | 587 |
532 | 588 let lnum = v:lnum - 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
589 while getline(lnum) !~? '<<<\s*[''"]\=\a\w*[''"]\=$' && lnum > 1 |
532 | 590 let lnum = lnum - 1 |
591 endwhile | |
409 | 592 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
593 let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<\s*[''"]\=\(\a\w*\)[''"]\=$', '^\\s*\1;\\=$', '') |
532 | 594 endif |
595 else | |
596 let b:InPHPcode = 0 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
597 let b:InPHPcode_tofind = s:PHP_startindenttag |
409 | 598 endif |
532 | 599 endif "!b:InPHPcode_checked }}} |
409 | 600 |
601 | |
532 | 602 " Test if we are indenting PHP code {{{ |
603 let lnum = prevnonblank(v:lnum - 1) | |
604 let last_line = getline(lnum) | |
5862 | 605 let endline= s:endline |
409 | 606 |
532 | 607 if b:InPHPcode_tofind!="" |
608 if cline =~? b:InPHPcode_tofind | |
609 let b:InPHPcode_tofind = "" | |
610 let b:UserIsTypingComment = 0 | |
6421 | 611 |
612 if b:InPHPcode == -1 | |
613 let b:InPHPcode = 1 | |
614 return -1 | |
615 end | |
616 | |
617 let b:InPHPcode = 1 | |
618 | |
532 | 619 if cline =~ '\*/' |
409 | 620 call cursor(v:lnum, 1) |
532 | 621 if cline !~ '^\*/' |
622 call search('\*/', 'W') | |
623 endif | |
557 | 624 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 625 |
626 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
627 | |
532 | 628 let b:PHP_LastIndentedWasComment = 0 |
409 | 629 |
532 | 630 if cline =~ '^\s*\*/' |
631 return indent(lnum) + 1 | |
632 else | |
633 return indent(lnum) | |
7 | 634 endif |
532 | 635 |
636 elseif cline =~? '<script\>' | |
637 let b:InPHPcode_and_script = 1 | |
631 | 638 let b:GetLastRealCodeLNum_ADD = v:lnum |
532 | 639 endif |
7 | 640 endif |
532 | 641 endif |
409 | 642 |
6421 | 643 if 1 == b:InPHPcode |
409 | 644 |
14006 | 645 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~?"Delimiter" |
532 | 646 if cline !~? s:PHP_startindenttag |
647 let b:InPHPcode = 0 | |
648 let b:InPHPcode_tofind = s:PHP_startindenttag | |
649 elseif cline =~? '<script\>' | |
650 let b:InPHPcode_and_script = 1 | |
651 endif | |
409 | 652 |
17571 | 653 elseif last_line =~ '^[^''"`]\+[''"`]$' && last_line !~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' " a string identifier with nothing after it and no other string identifier before |
6421 | 654 let b:InPHPcode = -1 |
5862 | 655 let b:InPHPcode_tofind = substitute( last_line, '^.*\([''"`]\).*$', '^[^\1]*\1[;,]$', '') |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
656 elseif last_line =~? '<<<\s*[''"]\=\a\w*[''"]\=$' |
532 | 657 let b:InPHPcode = 0 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
658 let b:InPHPcode_tofind = substitute( last_line, '^.*<<<\s*[''"]\=\(\a\w*\)[''"]\=$', '^\\s*\1;\\=$', '') |
532 | 659 |
660 elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*' | |
661 let b:InPHPcode = 0 | |
662 let b:InPHPcode_tofind = '\*/' | |
409 | 663 |
532 | 664 elseif cline =~? '^\s*</script>' |
665 let b:InPHPcode = 0 | |
666 let b:InPHPcode_tofind = s:PHP_startindenttag | |
667 endif | |
668 endif " }}} | |
669 | |
856 | 670 |
6421 | 671 if 1 > b:InPHPcode && !b:InPHPcode_and_script |
532 | 672 return -1 |
673 endif | |
409 | 674 |
532 | 675 " Indent successive // or # comment the same way the first is {{{ |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
676 let addSpecial = 0 |
532 | 677 if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
678 let addSpecial = b:PHP_outdentSLComments |
532 | 679 if b:PHP_LastIndentedWasComment == 1 |
680 return indent(real_PHP_lastindented) | |
681 endif | |
682 let b:PHP_LastIndentedWasComment = 1 | |
683 else | |
684 let b:PHP_LastIndentedWasComment = 0 | |
685 endif " }}} | |
686 | |
687 " Indent multiline /* comments correctly {{{ | |
688 | |
689 if b:PHP_InsideMultilineComment || b:UserIsTypingComment | |
690 if cline =~ '^\s*\*\%(\/\)\@!' | |
691 if last_line =~ '^\s*/\*' | |
692 return indent(lnum) + 1 | |
693 else | |
694 return indent(lnum) | |
695 endif | |
696 else | |
697 let b:PHP_InsideMultilineComment = 0 | |
698 endif | |
699 endif | |
700 | |
6421 | 701 if !b:PHP_InsideMultilineComment && cline =~ '^\s*/\*\%(.*\*/\)\@!' |
631 | 702 if getline(v:lnum + 1) !~ '^\s*\*' |
703 return -1 | |
704 endif | |
532 | 705 let b:PHP_InsideMultilineComment = 1 |
706 endif " }}} | |
409 | 707 |
708 | |
532 | 709 " Things always indented at col 1 (PHP delimiter: <?, ?>, Heredoc end) {{{ |
2442 | 710 if cline =~# '^\s*<?' && cline !~ '?>' && b:PHP_outdentphpescape |
532 | 711 return 0 |
712 endif | |
409 | 713 |
2442 | 714 if cline =~ '^\s*?>' && cline !~# '<?' && b:PHP_outdentphpescape |
532 | 715 return 0 |
716 endif | |
409 | 717 |
5862 | 718 if cline =~? '^\s*\a\w*;$\|^\a\w*$\|^\s*[''"`][;,]' && cline !~? s:notPhpHereDoc |
532 | 719 return 0 |
720 endif " }}} | |
409 | 721 |
532 | 722 let s:level = 0 |
409 | 723 |
532 | 724 let lnum = GetLastRealCodeLNum(v:lnum - 1) |
631 | 725 |
532 | 726 let last_line = getline(lnum) |
727 let ind = indent(lnum) | |
409 | 728 |
532 | 729 if ind==0 && b:PHP_default_indenting |
730 let ind = b:PHP_default_indenting | |
731 endif | |
409 | 732 |
532 | 733 if lnum == 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
734 return b:PHP_default_indenting + addSpecial |
532 | 735 endif |
409 | 736 |
737 | |
532 | 738 if cline =~ '^\s*}\%(}}\)\@!' |
5862 | 739 let ind = indent(FindOpenBracket(v:lnum, 1)) |
532 | 740 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting |
741 return ind | |
742 endif | |
409 | 743 |
532 | 744 if cline =~ '^\s*\*/' |
745 call cursor(v:lnum, 1) | |
746 if cline !~ '^\*/' | |
747 call search('\*/', 'W') | |
748 endif | |
557 | 749 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
532 | 750 |
751 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 752 |
532 | 753 if cline =~ '^\s*\*/' |
754 return indent(lnum) + 1 | |
755 else | |
756 return indent(lnum) | |
757 endif | |
758 endif | |
759 | |
760 | |
17571 | 761 if last_line =~ '[;}]'.endline && last_line !~ '^[)\]]' && last_line !~# s:defaultORcase && last_line !~ '^\s*[''"`][;,]' |
532 | 762 if ind==b:PHP_default_indenting |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
763 return b:PHP_default_indenting + addSpecial |
532 | 764 elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)' && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
765 return b:PHP_CurrentIndentLevel + addSpecial |
532 | 766 endif |
767 endif | |
768 | |
769 let LastLineClosed = 0 | |
770 | |
5862 | 771 let terminated = s:terminated |
532 | 772 |
11262 | 773 let unstated = s:unstated |
774 | |
409 | 775 |
532 | 776 if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>' |
777 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
778 return indent(FindTheIfOfAnElse(v:lnum, 1)) | |
2442 | 779 elseif cline =~# s:defaultORcase |
11518 | 780 return FindTheSwitchIndent(v:lnum) + shiftwidth() * b:PHP_vintage_case_default_indent |
1668 | 781 elseif cline =~ '^\s*)\=\s*{' |
532 | 782 let previous_line = last_line |
783 let last_line_num = lnum | |
784 | |
785 while last_line_num > 1 | |
786 | |
11262 | 787 if previous_line =~ terminated || previous_line =~ s:structureHead |
532 | 788 |
789 let ind = indent(last_line_num) | |
790 | |
791 if b:PHP_BracesAtCodeLevel | |
11518 | 792 let ind = ind + shiftwidth() |
532 | 793 endif |
794 | |
856 | 795 return ind |
532 | 796 endif |
797 | |
5862 | 798 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
532 | 799 let previous_line = getline(last_line_num) |
800 endwhile | |
14006 | 801 elseif cline =~ '^\s*->' |
802 return FindArrowIndent(lnum) | |
1668 | 803 elseif last_line =~# unstated && cline !~ '^\s*);\='.endline |
11518 | 804 let ind = ind + shiftwidth() " we indent one level further when the preceding line is not stated |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
805 return ind + addSpecial |
532 | 806 |
6421 | 807 elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated |
532 | 808 let previous_line = last_line |
809 let last_line_num = lnum | |
810 let LastLineClosed = 1 | |
811 | |
5862 | 812 let isSingleLineBlock = 0 |
532 | 813 while 1 |
14006 | 814 if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline |
532 | 815 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
816 call cursor(last_line_num, 1) |
5862 | 817 if previous_line !~ '^}' |
818 call search('}\|;\s*}'.endline, 'W') | |
819 end | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
820 let oldLastLine = last_line_num |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
821 let last_line_num = searchpair('{', '', '}', 'bW', 'Skippmatch()') |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
822 |
5862 | 823 if getline(last_line_num) =~ '^\s*{' |
532 | 824 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
5862 | 825 elseif oldLastLine == last_line_num |
826 let isSingleLineBlock = 1 | |
827 continue | |
409 | 828 endif |
532 | 829 |
830 let previous_line = getline(last_line_num) | |
7 | 831 |
532 | 832 continue |
833 else | |
5862 | 834 let isSingleLineBlock = 0 |
409 | 835 |
532 | 836 if getline(last_line_num) =~# '^\s*else\%(if\)\=\>' |
837 let last_line_num = FindTheIfOfAnElse(last_line_num, 0) | |
838 continue | |
839 endif | |
409 | 840 |
841 | |
532 | 842 let last_match = last_line_num |
409 | 843 |
532 | 844 let one_ahead_indent = indent(last_line_num) |
845 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) | |
846 let two_ahead_indent = indent(last_line_num) | |
847 let after_previous_line = previous_line | |
848 let previous_line = getline(last_line_num) | |
409 | 849 |
850 | |
2442 | 851 if previous_line =~# s:defaultORcase.'\|{'.endline |
532 | 852 break |
853 endif | |
409 | 854 |
532 | 855 if after_previous_line=~# '^\s*'.s:blockstart.'.*)'.endline && previous_line =~# '[;}]'.endline |
856 break | |
7 | 857 endif |
409 | 858 |
856 | 859 if one_ahead_indent == two_ahead_indent || last_line_num < 1 |
1668 | 860 if previous_line =~# '\%(;\|^\s*}\)'.endline || last_line_num < 1 |
532 | 861 break |
862 endif | |
863 endif | |
864 endif | |
865 endwhile | |
866 | |
867 if indent(last_match) != ind | |
868 let ind = indent(last_match) | |
869 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
870 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
871 return ind + addSpecial |
532 | 872 endif |
873 endif | |
874 | |
6421 | 875 if (last_line !~ '^\s*}\%(}}\)\@!') |
876 let plinnum = GetLastRealCodeLNum(lnum - 1) | |
877 else | |
878 let plinnum = GetLastRealCodeLNum(FindOpenBracket(lnum, 1) - 1) | |
879 endif | |
880 | |
2442 | 881 let AntepenultimateLine = getline(plinnum) |
532 | 882 |
14006 | 883 let last_line = StripEndlineComments(last_line) |
532 | 884 |
885 if ind == b:PHP_default_indenting | |
6421 | 886 if last_line =~ terminated && last_line !~# s:defaultORcase |
532 | 887 let LastLineClosed = 1 |
888 endif | |
889 endif | |
890 | |
891 if !LastLineClosed | |
892 | |
14006 | 893 let openedparent = -1 |
894 | |
2034 | 895 |
11262 | 896 if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline && BalanceDirection(last_line) > 0 |
532 | 897 |
5862 | 898 let dontIndent = 0 |
14006 | 899 if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\(\s*:\s*'.s:PHP_validVariable.'\)\=\s*{'.endline && last_line !~ s:structureHead |
5862 | 900 let dontIndent = 1 |
901 endif | |
902 | |
903 if !dontIndent && (!b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{') | |
11518 | 904 let ind = ind + shiftwidth() |
532 | 905 endif |
906 | |
17571 | 907 if b:PHP_IndentFunctionCallParameters && last_line =~ s:multilineFunctionCall && last_line !~ s:structureHead && last_line !~ s:arrayDecl |
908 let ind = ind + b:PHP_IndentFunctionCallParameters * shiftwidth() | |
909 endif | |
910 | |
911 if b:PHP_IndentFunctionDeclarationParameters && last_line =~ s:multilineFunctionDecl | |
912 let ind = ind + b:PHP_IndentFunctionDeclarationParameters * shiftwidth() | |
913 endif | |
914 | |
2442 | 915 if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 |
532 | 916 let b:PHP_CurrentIndentLevel = ind |
1668 | 917 |
532 | 918 endif |
919 | |
14006 | 920 elseif last_line =~ '),'.endline && BalanceDirection(last_line) < 0 |
532 | 921 call cursor(lnum, 1) |
14006 | 922 call searchpos('),'.endline, 'cW') |
532 | 923 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') |
924 if openedparent != lnum | |
925 let ind = indent(openedparent) | |
926 endif | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
927 |
14006 | 928 elseif last_line =~ s:structureHead |
11518 | 929 let ind = ind + shiftwidth() |
1668 | 930 |
532 | 931 |
11262 | 932 elseif AntepenultimateLine =~ '{'.endline && AntepenultimateLine !~? '^\s*use\>' || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase |
11518 | 933 let ind = ind + shiftwidth() |
409 | 934 endif |
7 | 935 |
14006 | 936 |
937 if openedparent >= 0 | |
938 let last_line = StripEndlineComments(getline(openedparent)) | |
939 endif | |
532 | 940 endif |
409 | 941 |
14006 | 942 if cline =~ '^\s*[)\]];\=' |
17571 | 943 call cursor(v:lnum, 1) |
944 call searchpos('[)\]]', 'cW') | |
945 let matchedBlockChar = cline[col('.')-1] | |
946 let openedparent = searchpair('\M'.s:blockCharsLUT[matchedBlockChar], '', '\M'.matchedBlockChar, 'bW', 'Skippmatch()') | |
947 if openedparent != v:lnum | |
948 let ind = indent(openedparent) | |
949 endif | |
14006 | 950 |
17571 | 951 elseif last_line =~ '^\s*->' && last_line !~? s:structureHead && BalanceDirection(last_line) <= 0 |
11518 | 952 let ind = ind - shiftwidth() |
532 | 953 endif |
954 | |
955 let b:PHP_CurrentIndentLevel = ind | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
956 return ind + addSpecial |
7 | 957 endfunction |