Mercurial > vim
annotate runtime/indent/php.vim @ 12572:31737ff54115 v8.0.1164
patch 8.0.1164: changing StatusLine highlight does not always work
commit https://github.com/vim/vim/commit/65ed136844fbaffdd473903ed841c944600234dc
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 30 16:00:14 2017 +0200
patch 8.0.1164: changing StatusLine highlight does not always work
Problem: Changing StatusLine highlight while evaluating 'statusline' may
not change the status line color.
Solution: When changing highlighting while redrawing don't cause another
redraw. (suggested by Ozaki Kiichi, closes #2171, closes #2120)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Sep 2017 16:15:04 +0200 |
parents | 63b0b7b79b25 |
children | 741b1feeac9f |
rev | line source |
---|---|
7 | 1 " Vim indent file |
2 " Language: PHP | |
409 | 3 " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr> |
4 " URL: http://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 |
11518 | 6 " Last Change: 2017 Jun 13 |
11262 | 7 " Version: 1.62 |
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 " | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
15 " If you find a bug, please open a ticket on github.org |
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 |
1668 | 22 " script by Peter Hodge (http://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 | |
557 | 44 |
7 | 45 if exists("b:did_indent") |
532 | 46 finish |
7 | 47 endif |
48 let b:did_indent = 1 | |
49 | |
409 | 50 |
6421 | 51 let g:php_sync_method = 0 |
409 | 52 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
53 |
409 | 54 if exists("PHP_default_indenting") |
11518 | 55 let b:PHP_default_indenting = PHP_default_indenting * shiftwidth() |
409 | 56 else |
532 | 57 let b:PHP_default_indenting = 0 |
409 | 58 endif |
59 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
60 if exists("PHP_outdentSLComments") |
11518 | 61 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
|
62 else |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
63 let b:PHP_outdentSLComments = 0 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
64 endif |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
65 |
409 | 66 if exists("PHP_BracesAtCodeLevel") |
532 | 67 let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel |
409 | 68 else |
532 | 69 let b:PHP_BracesAtCodeLevel = 0 |
409 | 70 endif |
71 | |
1668 | 72 |
557 | 73 if exists("PHP_autoformatcomment") |
74 let b:PHP_autoformatcomment = PHP_autoformatcomment | |
75 else | |
76 let b:PHP_autoformatcomment = 1 | |
77 endif | |
7 | 78 |
2442 | 79 if exists("PHP_outdentphpescape") |
80 let b:PHP_outdentphpescape = PHP_outdentphpescape | |
81 else | |
82 let b:PHP_outdentphpescape = 1 | |
83 endif | |
84 | |
85 | |
86 if exists("PHP_vintage_case_default_indent") && PHP_vintage_case_default_indent | |
87 let b:PHP_vintage_case_default_indent = 1 | |
1668 | 88 else |
89 let b:PHP_vintage_case_default_indent = 0 | |
90 endif | |
91 | |
92 | |
93 | |
409 | 94 let b:PHP_lastindented = 0 |
95 let b:PHP_indentbeforelast = 0 | |
96 let b:PHP_indentinghuge = 0 | |
97 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
98 let b:PHP_LastIndentedWasComment = 0 | |
99 let b:PHP_InsideMultilineComment = 0 | |
100 let b:InPHPcode = 0 | |
101 let b:InPHPcode_checked = 0 | |
102 let b:InPHPcode_and_script = 0 | |
103 let b:InPHPcode_tofind = "" | |
104 let b:PHP_oldchangetick = b:changedtick | |
105 let b:UserIsTypingComment = 0 | |
106 let b:optionsset = 0 | |
107 | |
108 setlocal nosmartindent | |
856 | 109 setlocal noautoindent |
409 | 110 setlocal nocindent |
532 | 111 setlocal nolisp |
409 | 112 |
113 setlocal indentexpr=GetPhpIndent() | |
6421 | 114 setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e,*<Return>,=?>,=<?,=*/ |
409 | 115 |
116 | |
532 | 117 |
118 let s:searchpairflags = 'bWr' | |
409 | 119 |
120 if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUnix | |
532 | 121 silent! %s/\r$//g |
409 | 122 endif |
123 | |
7 | 124 if exists("*GetPhpIndent") |
2034 | 125 call ResetPhpOptions() |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
126 finish |
7 | 127 endif |
128 | |
5862 | 129 |
6421 | 130 let s:PHP_validVariable = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' |
5862 | 131 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\>\)' | |
6421 | 133 let s:functionDecl = '\<function\>\%(\s\+'.s:PHP_validVariable.'\)\=\s*(.*' |
11262 | 134 let s:endline = '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' |
135 let s:unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.s:endline | |
6421 | 136 |
137 | |
11262 | 138 let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<\s*[''"]\=\a\w*[''"]\=$\|^\s*}\|^\s*'.s:PHP_validVariable.':\)'.s:endline.'\)' |
409 | 139 let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!' |
11262 | 140 let s:structureHead = '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline . '\|\<new\s\+class\>' |
409 | 141 |
142 | |
5862 | 143 |
144 let s:escapeDebugStops = 0 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
145 function! DebugPrintReturn(scriptLine) |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
146 |
6421 | 147 if ! s:escapeDebugStops |
5862 | 148 echo "debug:" . a:scriptLine |
149 let c = getchar() | |
150 if c == "\<Del>" | |
151 let s:escapeDebugStops = 1 | |
152 end | |
153 endif | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
154 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
155 endfunction |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
156 |
409 | 157 function! GetLastRealCodeLNum(startline) " {{{ |
856 | 158 |
532 | 159 let lnum = a:startline |
856 | 160 |
631 | 161 if b:GetLastRealCodeLNum_ADD && b:GetLastRealCodeLNum_ADD == lnum + 1 |
162 let lnum = b:GetLastRealCodeLNum_ADD | |
163 endif | |
856 | 164 |
532 | 165 while lnum > 1 |
166 let lnum = prevnonblank(lnum) | |
167 let lastline = getline(lnum) | |
409 | 168 |
532 | 169 if b:InPHPcode_and_script && lastline =~ '?>\s*$' |
170 let lnum = lnum - 1 | |
171 elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$' | |
172 let lnum = lnum - 1 | |
173 elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' | |
174 let lnum = lnum - 1 | |
175 elseif lastline =~ '\*/\s*$' | |
176 call cursor(lnum, 1) | |
177 if lastline !~ '^\*/' | |
178 call search('\*/', 'W') | |
179 endif | |
557 | 180 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 181 |
532 | 182 let lastline = getline(lnum) |
183 if lastline =~ '^\s*/\*' | |
184 let lnum = lnum - 1 | |
185 else | |
186 break | |
187 endif | |
409 | 188 |
189 | |
532 | 190 elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>' |
191 | |
192 while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1 | |
193 let lnum = lnum - 1 | |
194 let lastline = getline(lnum) | |
195 endwhile | |
196 if lastline =~ '^\s*?>' | |
197 let lnum = lnum - 1 | |
198 else | |
199 break | |
200 endif | |
201 | |
409 | 202 |
2442 | 203 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
|
204 let tofind=substitute( lastline, '\(\a\w*\);\=', '<<<\\s*[''"]\\=\1[''"]\\=$', '') |
532 | 205 while getline(lnum) !~? tofind && lnum > 1 |
206 let lnum = lnum - 1 | |
207 endwhile | |
5862 | 208 elseif lastline =~ '^[^''"`]*[''"`][;,]'.s:endline |
11262 | 209 |
210 let tofind=substitute( lastline, '^.*\([''"`]\)[;,].*$', '^[^\1]\\+[\1]$\\|^[^\1]\\+[=([]\\s*[\1]', '') | |
211 let trylnum = lnum | |
212 while getline(trylnum) !~? tofind && trylnum > 1 | |
213 let trylnum = trylnum - 1 | |
5862 | 214 endwhile |
11262 | 215 |
216 if trylnum == 1 | |
217 break | |
218 else | |
219 if lastline =~ ';'.s:endline | |
220 while getline(trylnum) !~? s:terminated && getline(trylnum) !~? '{'.s:endline && trylnum > 1 | |
221 let trylnum = prevnonblank(trylnum - 1) | |
222 endwhile | |
223 | |
224 | |
225 if trylnum == 1 | |
226 break | |
227 end | |
228 end | |
229 let lnum = trylnum | |
230 end | |
532 | 231 else |
856 | 232 break |
409 | 233 endif |
532 | 234 endwhile |
235 | |
2442 | 236 if lnum==1 && getline(lnum) !~ '<?' |
532 | 237 let lnum=0 |
238 endif | |
239 | |
6421 | 240 if b:InPHPcode_and_script && 1 > b:InPHPcode |
532 | 241 let b:InPHPcode_and_script = 0 |
242 endif | |
1120 | 243 |
532 | 244 return lnum |
245 endfunction " }}} | |
409 | 246 |
557 | 247 function! Skippmatch2() |
248 | |
249 let line = getline(".") | |
250 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
251 if line =~ "\\([\"']\\).*/\\*.*\\1" || line =~ '\%(//\|#\).*/\*' |
5862 | 252 return 1 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
253 else |
5862 | 254 return 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
255 endif |
557 | 256 endfun |
257 | |
2442 | 258 function! Skippmatch() " {{{ |
532 | 259 let synname = synIDattr(synID(line("."), col("."), 0), "name") |
6421 | 260 if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# '^php\%(Doc\)\?Comment' && b:UserIsTypingComment |
532 | 261 return 0 |
262 else | |
263 return 1 | |
264 endif | |
265 endfun " }}} | |
409 | 266 |
5862 | 267 function! FindOpenBracket(lnum, blockStarter) " {{{ |
532 | 268 call cursor(a:lnum, 1) |
5862 | 269 let line = searchpair('{', '', '}', 'bW', 'Skippmatch()') |
270 | |
271 if a:blockStarter == 1 | |
6421 | 272 while line > 1 |
5862 | 273 let linec = getline(line) |
274 | |
11262 | 275 if linec =~ s:terminated || linec =~ s:structureHead |
5862 | 276 break |
277 endif | |
278 | |
279 let line = GetLastRealCodeLNum(line - 1) | |
280 endwhile | |
281 endif | |
282 | |
283 return line | |
532 | 284 endfun " }}} |
409 | 285 |
11262 | 286 let s:blockChars = {'{':1, '[': 1, '(': 1, ')':-1, ']':-1, '}':-1} |
287 function! BalanceDirection (str) | |
288 | |
289 let balance = 0 | |
290 | |
291 for c in split(a:str, '\zs') | |
292 if has_key(s:blockChars, c) | |
293 let balance += s:blockChars[c] | |
294 endif | |
295 endfor | |
296 | |
297 return balance | |
298 endfun | |
299 | |
409 | 300 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{ |
532 | 301 |
302 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>' | |
303 let beforeelse = a:lnum | |
304 else | |
305 let beforeelse = GetLastRealCodeLNum(a:lnum - 1) | |
306 endif | |
409 | 307 |
532 | 308 if !s:level |
309 let s:iftoskip = 0 | |
310 endif | |
311 | |
312 if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>' | |
313 let s:iftoskip = s:iftoskip + 1 | |
314 endif | |
315 | |
316 if getline(beforeelse) =~ '^\s*}' | |
5862 | 317 let beforeelse = FindOpenBracket(beforeelse, 0) |
532 | 318 |
319 if getline(beforeelse) =~ '^\s*{' | |
320 let beforeelse = GetLastRealCodeLNum(beforeelse - 1) | |
409 | 321 endif |
532 | 322 endif |
409 | 323 |
324 | |
532 | 325 if !s:iftoskip && a:StopAfterFirstPrevElse && getline(beforeelse) =~# '^\s*\%([}]\s*\)\=else\%(if\)\=\>' |
326 return beforeelse | |
327 endif | |
328 | |
329 if getline(beforeelse) !~# '^\s*if\>' && beforeelse>1 || s:iftoskip && beforeelse>1 | |
330 | |
2442 | 331 if s:iftoskip && getline(beforeelse) =~# '^\s*if\>' |
532 | 332 let s:iftoskip = s:iftoskip - 1 |
409 | 333 endif |
334 | |
532 | 335 let s:level = s:level + 1 |
336 let beforeelse = FindTheIfOfAnElse(beforeelse, a:StopAfterFirstPrevElse) | |
337 endif | |
409 | 338 |
532 | 339 return beforeelse |
409 | 340 |
532 | 341 endfunction " }}} |
409 | 342 |
2442 | 343 let s:defaultORcase = '^\s*\%(default\|case\).*:' |
344 | |
345 function! FindTheSwitchIndent (lnum) " {{{ | |
346 | |
347 let test = GetLastRealCodeLNum(a:lnum - 1) | |
348 | |
349 if test <= 1 | |
11518 | 350 return indent(1) - shiftwidth() * b:PHP_vintage_case_default_indent |
2442 | 351 end |
352 | |
5862 | 353 while getline(test) =~ '^\s*}' && test > 1 |
354 let test = GetLastRealCodeLNum(FindOpenBracket(test, 0) - 1) | |
2442 | 355 |
5862 | 356 if getline(test) =~ '^\s*switch\>' |
357 let test = GetLastRealCodeLNum(test - 1) | |
2442 | 358 endif |
5862 | 359 endwhile |
2442 | 360 |
361 if getline(test) =~# '^\s*switch\>' | |
362 return indent(test) | |
363 elseif getline(test) =~# s:defaultORcase | |
11518 | 364 return indent(test) - shiftwidth() * b:PHP_vintage_case_default_indent |
2442 | 365 else |
366 return FindTheSwitchIndent(test) | |
367 endif | |
368 | |
369 endfunction "}}} | |
370 | |
5294 | 371 let s:SynPHPMatchGroups = {'phpParent':1, 'Delimiter':1, 'Define':1, 'Storageclass':1, 'StorageClass':1, 'Structure':1, 'Exception':1} |
409 | 372 function! IslinePHP (lnum, tofind) " {{{ |
532 | 373 let cline = getline(a:lnum) |
409 | 374 |
532 | 375 if a:tofind=="" |
5862 | 376 let tofind = "^\\s*[\"'`]*\\s*\\zs\\S" |
532 | 377 else |
378 let tofind = a:tofind | |
379 endif | |
409 | 380 |
532 | 381 let tofind = tofind . '\c' |
409 | 382 |
532 | 383 let coltotest = match (cline, tofind) + 1 |
384 | |
385 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") | |
409 | 386 |
5862 | 387 if synname == 'phpStringSingle' || synname == 'phpStringDouble' || synname == 'phpBacktick' |
388 if cline !~ '^\s*[''"`]' | |
6421 | 389 return "SpecStringEntrails" |
5862 | 390 else |
391 return synname | |
392 end | |
393 end | |
394 | |
5277 | 395 if get(s:SynPHPMatchGroups, synname) || synname =~ '^php' || synname =~? '^javaScript' |
532 | 396 return synname |
397 else | |
398 return "" | |
399 endif | |
400 endfunction " }}} | |
409 | 401 |
2034 | 402 let s:autoresetoptions = 0 |
403 if ! s:autoresetoptions | |
404 let s:autoresetoptions = 1 | |
7 | 405 endif |
406 | |
2034 | 407 function! ResetPhpOptions() |
6421 | 408 if ! b:optionsset && &filetype =~ "php" |
557 | 409 if b:PHP_autoformatcomment |
410 | |
411 setlocal comments=s1:/*,mb:*,ex:*/,://,:# | |
856 | 412 |
1668 | 413 setlocal formatoptions-=t |
557 | 414 setlocal formatoptions+=q |
415 setlocal formatoptions+=r | |
416 setlocal formatoptions+=o | |
417 setlocal formatoptions+=c | |
418 setlocal formatoptions+=b | |
419 endif | |
532 | 420 let b:optionsset = 1 |
421 endif | |
409 | 422 endfunc |
423 | |
2034 | 424 call ResetPhpOptions() |
425 | |
409 | 426 function! GetPhpIndent() |
427 | |
631 | 428 let b:GetLastRealCodeLNum_ADD = 0 |
429 | |
532 | 430 let UserIsEditing=0 |
431 if b:PHP_oldchangetick != b:changedtick | |
432 let b:PHP_oldchangetick = b:changedtick | |
433 let UserIsEditing=1 | |
434 endif | |
409 | 435 |
532 | 436 if b:PHP_default_indenting |
11518 | 437 let b:PHP_default_indenting = g:PHP_default_indenting * shiftwidth() |
532 | 438 endif |
439 | |
440 let cline = getline(v:lnum) | |
409 | 441 |
856 | 442 if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast |
532 | 443 if b:PHP_indentbeforelast |
444 let b:PHP_indentinghuge = 1 | |
445 endif | |
446 let b:PHP_indentbeforelast = b:PHP_lastindented | |
447 endif | |
409 | 448 |
532 | 449 if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented |
450 if b:PHP_indentinghuge | |
451 let b:PHP_indentinghuge = 0 | |
452 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 453 endif |
6421 | 454 let real_PHP_lastindented = v:lnum |
532 | 455 let b:PHP_LastIndentedWasComment=0 |
456 let b:PHP_InsideMultilineComment=0 | |
457 let b:PHP_indentbeforelast = 0 | |
409 | 458 |
532 | 459 let b:InPHPcode = 0 |
460 let b:InPHPcode_checked = 0 | |
461 let b:InPHPcode_and_script = 0 | |
462 let b:InPHPcode_tofind = "" | |
409 | 463 |
532 | 464 elseif v:lnum > b:PHP_lastindented |
465 let real_PHP_lastindented = b:PHP_lastindented | |
6421 | 466 else |
467 let real_PHP_lastindented = v:lnum | |
532 | 468 endif |
409 | 469 |
6421 | 470 let b:PHP_lastindented = v:lnum |
471 | |
409 | 472 |
532 | 473 if !b:InPHPcode_checked " {{{ One time check |
474 let b:InPHPcode_checked = 1 | |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
475 let b:UserIsTypingComment = 0 |
409 | 476 |
631 | 477 let synname = "" |
478 if cline !~ '<?.*?>' | |
479 let synname = IslinePHP (prevnonblank(v:lnum), "") | |
480 endif | |
409 | 481 |
532 | 482 if synname!="" |
6421 | 483 if synname == "SpecStringEntrails" |
11262 | 484 let b:InPHPcode = -1 " thumb down |
6421 | 485 let b:InPHPcode_tofind = "" |
486 elseif synname != "phpHereDoc" && synname != "phpHereDocDelimiter" | |
532 | 487 let b:InPHPcode = 1 |
488 let b:InPHPcode_tofind = "" | |
409 | 489 |
6421 | 490 if synname =~# '^php\%(Doc\)\?Comment' |
532 | 491 let b:UserIsTypingComment = 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
492 let b:InPHPcode_checked = 0 |
409 | 493 endif |
494 | |
532 | 495 if synname =~? '^javaScript' |
496 let b:InPHPcode_and_script = 1 | |
497 endif | |
409 | 498 |
532 | 499 else |
500 let b:InPHPcode = 0 | |
409 | 501 |
532 | 502 let lnum = v:lnum - 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
503 while getline(lnum) !~? '<<<\s*[''"]\=\a\w*[''"]\=$' && lnum > 1 |
532 | 504 let lnum = lnum - 1 |
505 endwhile | |
409 | 506 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
507 let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<\s*[''"]\=\(\a\w*\)[''"]\=$', '^\\s*\1;\\=$', '') |
532 | 508 endif |
509 else | |
510 let b:InPHPcode = 0 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
511 let b:InPHPcode_tofind = s:PHP_startindenttag |
409 | 512 endif |
532 | 513 endif "!b:InPHPcode_checked }}} |
409 | 514 |
515 | |
532 | 516 " Test if we are indenting PHP code {{{ |
517 let lnum = prevnonblank(v:lnum - 1) | |
518 let last_line = getline(lnum) | |
5862 | 519 let endline= s:endline |
409 | 520 |
532 | 521 if b:InPHPcode_tofind!="" |
522 if cline =~? b:InPHPcode_tofind | |
523 let b:InPHPcode_tofind = "" | |
524 let b:UserIsTypingComment = 0 | |
6421 | 525 |
526 if b:InPHPcode == -1 | |
527 let b:InPHPcode = 1 | |
528 return -1 | |
529 end | |
530 | |
531 let b:InPHPcode = 1 | |
532 | |
532 | 533 if cline =~ '\*/' |
409 | 534 call cursor(v:lnum, 1) |
532 | 535 if cline !~ '^\*/' |
536 call search('\*/', 'W') | |
537 endif | |
557 | 538 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 539 |
540 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
541 | |
532 | 542 let b:PHP_LastIndentedWasComment = 0 |
409 | 543 |
532 | 544 if cline =~ '^\s*\*/' |
545 return indent(lnum) + 1 | |
546 else | |
547 return indent(lnum) | |
7 | 548 endif |
532 | 549 |
550 elseif cline =~? '<script\>' | |
551 let b:InPHPcode_and_script = 1 | |
631 | 552 let b:GetLastRealCodeLNum_ADD = v:lnum |
532 | 553 endif |
7 | 554 endif |
532 | 555 endif |
409 | 556 |
6421 | 557 if 1 == b:InPHPcode |
409 | 558 |
1120 | 559 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~"Delimiter" |
532 | 560 if cline !~? s:PHP_startindenttag |
561 let b:InPHPcode = 0 | |
562 let b:InPHPcode_tofind = s:PHP_startindenttag | |
563 elseif cline =~? '<script\>' | |
564 let b:InPHPcode_and_script = 1 | |
565 endif | |
409 | 566 |
11262 | 567 elseif last_line =~ '^[^''"`]\+[''"`]$' " a string identifier with nothing after it and no other string identifier before |
6421 | 568 let b:InPHPcode = -1 |
5862 | 569 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
|
570 elseif last_line =~? '<<<\s*[''"]\=\a\w*[''"]\=$' |
532 | 571 let b:InPHPcode = 0 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
572 let b:InPHPcode_tofind = substitute( last_line, '^.*<<<\s*[''"]\=\(\a\w*\)[''"]\=$', '^\\s*\1;\\=$', '') |
532 | 573 |
574 elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*' | |
575 let b:InPHPcode = 0 | |
576 let b:InPHPcode_tofind = '\*/' | |
409 | 577 |
532 | 578 elseif cline =~? '^\s*</script>' |
579 let b:InPHPcode = 0 | |
580 let b:InPHPcode_tofind = s:PHP_startindenttag | |
581 endif | |
582 endif " }}} | |
583 | |
856 | 584 |
6421 | 585 if 1 > b:InPHPcode && !b:InPHPcode_and_script |
532 | 586 return -1 |
587 endif | |
409 | 588 |
532 | 589 " 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
|
590 let addSpecial = 0 |
532 | 591 if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
592 let addSpecial = b:PHP_outdentSLComments |
532 | 593 if b:PHP_LastIndentedWasComment == 1 |
594 return indent(real_PHP_lastindented) | |
595 endif | |
596 let b:PHP_LastIndentedWasComment = 1 | |
597 else | |
598 let b:PHP_LastIndentedWasComment = 0 | |
599 endif " }}} | |
600 | |
601 " Indent multiline /* comments correctly {{{ | |
602 | |
603 if b:PHP_InsideMultilineComment || b:UserIsTypingComment | |
604 if cline =~ '^\s*\*\%(\/\)\@!' | |
605 if last_line =~ '^\s*/\*' | |
606 return indent(lnum) + 1 | |
607 else | |
608 return indent(lnum) | |
609 endif | |
610 else | |
611 let b:PHP_InsideMultilineComment = 0 | |
612 endif | |
613 endif | |
614 | |
6421 | 615 if !b:PHP_InsideMultilineComment && cline =~ '^\s*/\*\%(.*\*/\)\@!' |
631 | 616 if getline(v:lnum + 1) !~ '^\s*\*' |
617 return -1 | |
618 endif | |
532 | 619 let b:PHP_InsideMultilineComment = 1 |
620 endif " }}} | |
409 | 621 |
622 | |
532 | 623 " Things always indented at col 1 (PHP delimiter: <?, ?>, Heredoc end) {{{ |
2442 | 624 if cline =~# '^\s*<?' && cline !~ '?>' && b:PHP_outdentphpescape |
532 | 625 return 0 |
626 endif | |
409 | 627 |
2442 | 628 if cline =~ '^\s*?>' && cline !~# '<?' && b:PHP_outdentphpescape |
532 | 629 return 0 |
630 endif | |
409 | 631 |
5862 | 632 if cline =~? '^\s*\a\w*;$\|^\a\w*$\|^\s*[''"`][;,]' && cline !~? s:notPhpHereDoc |
532 | 633 return 0 |
634 endif " }}} | |
409 | 635 |
532 | 636 let s:level = 0 |
409 | 637 |
532 | 638 let lnum = GetLastRealCodeLNum(v:lnum - 1) |
631 | 639 |
532 | 640 let last_line = getline(lnum) |
641 let ind = indent(lnum) | |
409 | 642 |
532 | 643 if ind==0 && b:PHP_default_indenting |
644 let ind = b:PHP_default_indenting | |
645 endif | |
409 | 646 |
532 | 647 if lnum == 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
648 return b:PHP_default_indenting + addSpecial |
532 | 649 endif |
409 | 650 |
651 | |
532 | 652 if cline =~ '^\s*}\%(}}\)\@!' |
5862 | 653 let ind = indent(FindOpenBracket(v:lnum, 1)) |
532 | 654 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting |
655 return ind | |
656 endif | |
409 | 657 |
532 | 658 if cline =~ '^\s*\*/' |
659 call cursor(v:lnum, 1) | |
660 if cline !~ '^\*/' | |
661 call search('\*/', 'W') | |
662 endif | |
557 | 663 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
532 | 664 |
665 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 666 |
532 | 667 if cline =~ '^\s*\*/' |
668 return indent(lnum) + 1 | |
669 else | |
670 return indent(lnum) | |
671 endif | |
672 endif | |
673 | |
674 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
675 if last_line =~ '[;}]'.endline && last_line !~ '^[)\]]' && last_line !~# s:defaultORcase |
532 | 676 if ind==b:PHP_default_indenting |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
677 return b:PHP_default_indenting + addSpecial |
532 | 678 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
|
679 return b:PHP_CurrentIndentLevel + addSpecial |
532 | 680 endif |
681 endif | |
682 | |
683 let LastLineClosed = 0 | |
684 | |
5862 | 685 let terminated = s:terminated |
532 | 686 |
11262 | 687 let unstated = s:unstated |
688 | |
409 | 689 |
532 | 690 if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>' |
691 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
692 return indent(FindTheIfOfAnElse(v:lnum, 1)) | |
2442 | 693 elseif cline =~# s:defaultORcase |
11518 | 694 return FindTheSwitchIndent(v:lnum) + shiftwidth() * b:PHP_vintage_case_default_indent |
1668 | 695 elseif cline =~ '^\s*)\=\s*{' |
532 | 696 let previous_line = last_line |
697 let last_line_num = lnum | |
698 | |
699 while last_line_num > 1 | |
700 | |
11262 | 701 if previous_line =~ terminated || previous_line =~ s:structureHead |
532 | 702 |
703 let ind = indent(last_line_num) | |
704 | |
705 if b:PHP_BracesAtCodeLevel | |
11518 | 706 let ind = ind + shiftwidth() |
532 | 707 endif |
708 | |
856 | 709 return ind |
532 | 710 endif |
711 | |
5862 | 712 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
532 | 713 let previous_line = getline(last_line_num) |
714 endwhile | |
409 | 715 |
1668 | 716 elseif last_line =~# unstated && cline !~ '^\s*);\='.endline |
11518 | 717 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
|
718 return ind + addSpecial |
532 | 719 |
6421 | 720 elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated |
532 | 721 let previous_line = last_line |
722 let last_line_num = lnum | |
723 let LastLineClosed = 1 | |
724 | |
5862 | 725 let isSingleLineBlock = 0 |
532 | 726 while 1 |
11262 | 727 if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline " XXX |
532 | 728 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
729 call cursor(last_line_num, 1) |
5862 | 730 if previous_line !~ '^}' |
731 call search('}\|;\s*}'.endline, 'W') | |
732 end | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
733 let oldLastLine = last_line_num |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
734 let last_line_num = searchpair('{', '', '}', 'bW', 'Skippmatch()') |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
735 |
5862 | 736 if getline(last_line_num) =~ '^\s*{' |
532 | 737 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
5862 | 738 elseif oldLastLine == last_line_num |
739 let isSingleLineBlock = 1 | |
740 continue | |
409 | 741 endif |
532 | 742 |
743 let previous_line = getline(last_line_num) | |
7 | 744 |
532 | 745 continue |
746 else | |
5862 | 747 let isSingleLineBlock = 0 |
409 | 748 |
532 | 749 if getline(last_line_num) =~# '^\s*else\%(if\)\=\>' |
750 let last_line_num = FindTheIfOfAnElse(last_line_num, 0) | |
751 continue | |
752 endif | |
409 | 753 |
754 | |
532 | 755 let last_match = last_line_num |
409 | 756 |
532 | 757 let one_ahead_indent = indent(last_line_num) |
758 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) | |
759 let two_ahead_indent = indent(last_line_num) | |
760 let after_previous_line = previous_line | |
761 let previous_line = getline(last_line_num) | |
409 | 762 |
763 | |
2442 | 764 if previous_line =~# s:defaultORcase.'\|{'.endline |
532 | 765 break |
766 endif | |
409 | 767 |
532 | 768 if after_previous_line=~# '^\s*'.s:blockstart.'.*)'.endline && previous_line =~# '[;}]'.endline |
769 break | |
7 | 770 endif |
409 | 771 |
856 | 772 if one_ahead_indent == two_ahead_indent || last_line_num < 1 |
1668 | 773 if previous_line =~# '\%(;\|^\s*}\)'.endline || last_line_num < 1 |
532 | 774 break |
775 endif | |
776 endif | |
777 endif | |
778 endwhile | |
779 | |
780 if indent(last_match) != ind | |
781 let ind = indent(last_match) | |
782 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
783 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
784 return ind + addSpecial |
532 | 785 endif |
786 endif | |
787 | |
6421 | 788 if (last_line !~ '^\s*}\%(}}\)\@!') |
789 let plinnum = GetLastRealCodeLNum(lnum - 1) | |
790 else | |
791 let plinnum = GetLastRealCodeLNum(FindOpenBracket(lnum, 1) - 1) | |
792 endif | |
793 | |
2442 | 794 let AntepenultimateLine = getline(plinnum) |
532 | 795 |
796 let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') | |
797 | |
798 | |
799 if ind == b:PHP_default_indenting | |
6421 | 800 if last_line =~ terminated && last_line !~# s:defaultORcase |
532 | 801 let LastLineClosed = 1 |
802 endif | |
803 endif | |
804 | |
805 if !LastLineClosed | |
806 | |
2034 | 807 |
11262 | 808 if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline && BalanceDirection(last_line) > 0 |
532 | 809 |
5862 | 810 let dontIndent = 0 |
11262 | 811 if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\s*{'.endline && last_line !~ s:structureHead |
5862 | 812 let dontIndent = 1 |
813 endif | |
814 | |
815 if !dontIndent && (!b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{') | |
11518 | 816 let ind = ind + shiftwidth() |
532 | 817 endif |
818 | |
2442 | 819 if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 |
532 | 820 let b:PHP_CurrentIndentLevel = ind |
1668 | 821 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
822 return ind + addSpecial |
532 | 823 endif |
824 | |
11262 | 825 elseif last_line =~ '\S\+\s*),'.endline && BalanceDirection(last_line) < 0 |
532 | 826 call cursor(lnum, 1) |
11262 | 827 call search('),'.endline, 'W') " line never begins with ) so no need for 'c' flag |
532 | 828 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') |
829 if openedparent != lnum | |
830 let ind = indent(openedparent) | |
831 endif | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
832 |
1668 | 833 elseif last_line =~ '^\s*'.s:blockstart |
11518 | 834 let ind = ind + shiftwidth() |
1668 | 835 |
532 | 836 |
11262 | 837 elseif AntepenultimateLine =~ '{'.endline && AntepenultimateLine !~? '^\s*use\>' || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase |
11518 | 838 let ind = ind + shiftwidth() |
409 | 839 endif |
7 | 840 |
532 | 841 endif |
409 | 842 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
843 if cline =~ '^\s*[)\]];\=' |
11518 | 844 let ind = ind - shiftwidth() |
532 | 845 endif |
846 | |
847 let b:PHP_CurrentIndentLevel = ind | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
848 return ind + addSpecial |
7 | 849 endfunction |