Mercurial > vim
annotate runtime/indent/php.vim @ 4793:66e849c4558a v7.3.1143
updated for version 7.3.1143
Problem: When mapping NUL it is displayed as an X.
Solution: Check for KS_ZERO instead of K_ZERO. (Yasuhiro Matsumoto)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Fri, 07 Jun 2013 19:53:10 +0200 |
parents | 605c9ce57ec3 |
children | 42bf9264e64e |
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 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
6 " Last Change: 2013 May 10th |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
7 " Version: 1.37 |
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). | |
409 | 42 " |
557 | 43 |
7 | 44 if exists("b:did_indent") |
532 | 45 finish |
7 | 46 endif |
47 let b:did_indent = 1 | |
48 | |
409 | 49 |
50 let php_sync_method = 0 | |
51 | |
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") |
532 | 55 let b:PHP_default_indenting = PHP_default_indenting * &sw |
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") |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
61 let b:PHP_outdentSLComments = PHP_outdentSLComments * &sw |
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() | |
114 setlocal indentkeys=0{,0},0),:,!^F,o,O,e,*<Return>,=?>,=<?,=*/ | |
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() |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
126 finish " XXX -- comment this line for easy dev |
7 | 127 endif |
128 | |
409 | 129 let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$' |
130 let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!' | |
131 | |
132 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
133 function! DebugPrintReturn(scriptLine) |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
134 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
135 echo "debug:" . a:scriptLine |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
136 call getchar() |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
137 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
138 endfunction |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
139 |
409 | 140 function! GetLastRealCodeLNum(startline) " {{{ |
856 | 141 |
532 | 142 let lnum = a:startline |
856 | 143 |
631 | 144 if b:GetLastRealCodeLNum_ADD && b:GetLastRealCodeLNum_ADD == lnum + 1 |
145 let lnum = b:GetLastRealCodeLNum_ADD | |
146 endif | |
856 | 147 |
532 | 148 let old_lnum = lnum |
409 | 149 |
532 | 150 while lnum > 1 |
151 let lnum = prevnonblank(lnum) | |
152 let lastline = getline(lnum) | |
409 | 153 |
532 | 154 if b:InPHPcode_and_script && lastline =~ '?>\s*$' |
155 let lnum = lnum - 1 | |
156 elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$' | |
157 let lnum = lnum - 1 | |
158 elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' | |
159 let lnum = lnum - 1 | |
160 elseif lastline =~ '\*/\s*$' | |
161 call cursor(lnum, 1) | |
162 if lastline !~ '^\*/' | |
163 call search('\*/', 'W') | |
164 endif | |
557 | 165 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 166 |
532 | 167 let lastline = getline(lnum) |
168 if lastline =~ '^\s*/\*' | |
169 let lnum = lnum - 1 | |
170 else | |
171 break | |
172 endif | |
409 | 173 |
174 | |
532 | 175 elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>' |
176 | |
177 while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1 | |
178 let lnum = lnum - 1 | |
179 let lastline = getline(lnum) | |
180 endwhile | |
181 if lastline =~ '^\s*?>' | |
182 let lnum = lnum - 1 | |
183 else | |
184 break | |
185 endif | |
186 | |
409 | 187 |
2442 | 188 elseif lastline =~? '^\a\w*;\=$' && lastline !~? s:notPhpHereDoc |
189 let tofind=substitute( lastline, '\(\a\w*\);\=', '<<<''\\=\1''\\=$', '') | |
532 | 190 while getline(lnum) !~? tofind && lnum > 1 |
191 let lnum = lnum - 1 | |
192 endwhile | |
193 else | |
856 | 194 break |
409 | 195 endif |
532 | 196 endwhile |
197 | |
2442 | 198 if lnum==1 && getline(lnum) !~ '<?' |
532 | 199 let lnum=0 |
200 endif | |
201 | |
202 if b:InPHPcode_and_script && !b:InPHPcode | |
203 let b:InPHPcode_and_script = 0 | |
204 endif | |
1120 | 205 |
532 | 206 return lnum |
207 endfunction " }}} | |
409 | 208 |
557 | 209 function! Skippmatch2() |
210 | |
211 let line = getline(".") | |
212 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
213 if line =~ "\\([\"']\\).*/\\*.*\\1" || line =~ '\%(//\|#\).*/\*' |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
214 return 1 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
215 else |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
216 return 0 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
217 endif |
557 | 218 endfun |
219 | |
2442 | 220 function! Skippmatch() " {{{ |
532 | 221 let synname = synIDattr(synID(line("."), col("."), 0), "name") |
1668 | 222 if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# "^phpComment" && b:UserIsTypingComment |
532 | 223 return 0 |
224 else | |
225 return 1 | |
226 endif | |
227 endfun " }}} | |
409 | 228 |
229 function! FindOpenBracket(lnum) " {{{ | |
532 | 230 call cursor(a:lnum, 1) |
231 return searchpair('{', '', '}', 'bW', 'Skippmatch()') | |
232 endfun " }}} | |
409 | 233 |
234 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{ | |
532 | 235 |
236 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>' | |
237 let beforeelse = a:lnum | |
238 else | |
239 let beforeelse = GetLastRealCodeLNum(a:lnum - 1) | |
240 endif | |
409 | 241 |
532 | 242 if !s:level |
243 let s:iftoskip = 0 | |
244 endif | |
245 | |
246 if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>' | |
247 let s:iftoskip = s:iftoskip + 1 | |
248 endif | |
249 | |
250 if getline(beforeelse) =~ '^\s*}' | |
251 let beforeelse = FindOpenBracket(beforeelse) | |
252 | |
253 if getline(beforeelse) =~ '^\s*{' | |
254 let beforeelse = GetLastRealCodeLNum(beforeelse - 1) | |
409 | 255 endif |
532 | 256 endif |
409 | 257 |
258 | |
532 | 259 if !s:iftoskip && a:StopAfterFirstPrevElse && getline(beforeelse) =~# '^\s*\%([}]\s*\)\=else\%(if\)\=\>' |
260 return beforeelse | |
261 endif | |
262 | |
263 if getline(beforeelse) !~# '^\s*if\>' && beforeelse>1 || s:iftoskip && beforeelse>1 | |
264 | |
2442 | 265 if s:iftoskip && getline(beforeelse) =~# '^\s*if\>' |
532 | 266 let s:iftoskip = s:iftoskip - 1 |
409 | 267 endif |
268 | |
532 | 269 let s:level = s:level + 1 |
270 let beforeelse = FindTheIfOfAnElse(beforeelse, a:StopAfterFirstPrevElse) | |
271 endif | |
409 | 272 |
532 | 273 return beforeelse |
409 | 274 |
532 | 275 endfunction " }}} |
409 | 276 |
2442 | 277 let s:defaultORcase = '^\s*\%(default\|case\).*:' |
278 | |
279 function! FindTheSwitchIndent (lnum) " {{{ | |
280 | |
281 | |
282 let test = GetLastRealCodeLNum(a:lnum - 1) | |
283 | |
284 if test <= 1 | |
285 return indent(1) - &sw * b:PHP_vintage_case_default_indent | |
286 end | |
287 | |
288 if getline(test) =~ '^\s*}' | |
289 let test = FindOpenBracket(test) | |
290 | |
291 if getline(test) =~ '^\s*{' | |
292 let test = GetLastRealCodeLNum(GetLastRealCodeLNum(test - 1) - 1) | |
293 endif | |
294 endif | |
295 | |
296 if getline(test) =~# '^\s*switch\>' | |
297 return indent(test) | |
298 elseif getline(test) =~# s:defaultORcase | |
299 return indent(test) - &sw * b:PHP_vintage_case_default_indent | |
300 else | |
301 return FindTheSwitchIndent(test) | |
302 endif | |
303 | |
304 endfunction "}}} | |
305 | |
306 | |
409 | 307 function! IslinePHP (lnum, tofind) " {{{ |
532 | 308 let cline = getline(a:lnum) |
409 | 309 |
532 | 310 if a:tofind=="" |
557 | 311 let tofind = "^\\s*[\"']*\\s*\\zs\\S" |
532 | 312 else |
313 let tofind = a:tofind | |
314 endif | |
409 | 315 |
532 | 316 let tofind = tofind . '\c' |
409 | 317 |
532 | 318 let coltotest = match (cline, tofind) + 1 |
319 | |
320 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") | |
409 | 321 |
532 | 322 if synname =~ '^php' || synname=="Delimiter" || synname =~? '^javaScript' |
323 return synname | |
324 else | |
325 return "" | |
326 endif | |
327 endfunction " }}} | |
409 | 328 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
329 let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|die\|else\)' |
2442 | 330 let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\)' |
409 | 331 |
2034 | 332 let s:autoresetoptions = 0 |
333 if ! s:autoresetoptions | |
334 let s:autoresetoptions = 1 | |
7 | 335 endif |
336 | |
2034 | 337 function! ResetPhpOptions() |
2442 | 338 if ! b:optionsset && &filetype == "php" |
557 | 339 if b:PHP_autoformatcomment |
340 | |
341 setlocal comments=s1:/*,mb:*,ex:*/,://,:# | |
856 | 342 |
1668 | 343 setlocal formatoptions-=t |
557 | 344 setlocal formatoptions+=q |
345 setlocal formatoptions+=r | |
346 setlocal formatoptions+=o | |
1668 | 347 setlocal formatoptions+=w |
557 | 348 setlocal formatoptions+=c |
349 setlocal formatoptions+=b | |
350 endif | |
532 | 351 let b:optionsset = 1 |
352 endif | |
409 | 353 endfunc |
354 | |
2034 | 355 call ResetPhpOptions() |
356 | |
409 | 357 function! GetPhpIndent() |
358 | |
631 | 359 let b:GetLastRealCodeLNum_ADD = 0 |
360 | |
532 | 361 let UserIsEditing=0 |
362 if b:PHP_oldchangetick != b:changedtick | |
363 let b:PHP_oldchangetick = b:changedtick | |
364 let UserIsEditing=1 | |
365 endif | |
409 | 366 |
532 | 367 if b:PHP_default_indenting |
368 let b:PHP_default_indenting = g:PHP_default_indenting * &sw | |
369 endif | |
370 | |
371 let cline = getline(v:lnum) | |
409 | 372 |
856 | 373 if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast |
532 | 374 if b:PHP_indentbeforelast |
375 let b:PHP_indentinghuge = 1 | |
376 endif | |
377 let b:PHP_indentbeforelast = b:PHP_lastindented | |
378 endif | |
409 | 379 |
532 | 380 if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented |
381 if b:PHP_indentinghuge | |
382 let b:PHP_indentinghuge = 0 | |
383 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 384 endif |
532 | 385 let b:PHP_lastindented = v:lnum |
386 let b:PHP_LastIndentedWasComment=0 | |
387 let b:PHP_InsideMultilineComment=0 | |
388 let b:PHP_indentbeforelast = 0 | |
409 | 389 |
532 | 390 let b:InPHPcode = 0 |
391 let b:InPHPcode_checked = 0 | |
392 let b:InPHPcode_and_script = 0 | |
393 let b:InPHPcode_tofind = "" | |
409 | 394 |
532 | 395 elseif v:lnum > b:PHP_lastindented |
396 let real_PHP_lastindented = b:PHP_lastindented | |
397 let b:PHP_lastindented = v:lnum | |
398 endif | |
409 | 399 |
400 | |
532 | 401 if !b:InPHPcode_checked " {{{ One time check |
402 let b:InPHPcode_checked = 1 | |
409 | 403 |
631 | 404 let synname = "" |
405 if cline !~ '<?.*?>' | |
406 let synname = IslinePHP (prevnonblank(v:lnum), "") | |
407 endif | |
409 | 408 |
532 | 409 if synname!="" |
1120 | 410 if synname != "phpHereDoc" && synname != "phpHereDocDelimiter" |
532 | 411 let b:InPHPcode = 1 |
412 let b:InPHPcode_tofind = "" | |
409 | 413 |
1668 | 414 if synname =~# "^phpComment" |
532 | 415 let b:UserIsTypingComment = 1 |
416 else | |
417 let b:UserIsTypingComment = 0 | |
409 | 418 endif |
419 | |
532 | 420 if synname =~? '^javaScript' |
421 let b:InPHPcode_and_script = 1 | |
422 endif | |
409 | 423 |
532 | 424 else |
425 let b:InPHPcode = 0 | |
426 let b:UserIsTypingComment = 0 | |
409 | 427 |
532 | 428 let lnum = v:lnum - 1 |
1668 | 429 while getline(lnum) !~? '<<<''\=\a\w*''\=$' && lnum > 1 |
532 | 430 let lnum = lnum - 1 |
431 endwhile | |
409 | 432 |
2442 | 433 let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<''\=\(\a\w*\)''\=$', '^\\s*\1;\\=$', '') |
532 | 434 endif |
435 else | |
436 let b:InPHPcode = 0 | |
437 let b:UserIsTypingComment = 0 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
438 let b:InPHPcode_tofind = s:PHP_startindenttag |
409 | 439 endif |
532 | 440 endif "!b:InPHPcode_checked }}} |
409 | 441 |
442 | |
532 | 443 " Test if we are indenting PHP code {{{ |
444 let lnum = prevnonblank(v:lnum - 1) | |
445 let last_line = getline(lnum) | |
409 | 446 |
532 | 447 if b:InPHPcode_tofind!="" |
448 if cline =~? b:InPHPcode_tofind | |
2442 | 449 let b:InPHPcode = 1 |
532 | 450 let b:InPHPcode_tofind = "" |
451 let b:UserIsTypingComment = 0 | |
452 if cline =~ '\*/' | |
409 | 453 call cursor(v:lnum, 1) |
532 | 454 if cline !~ '^\*/' |
455 call search('\*/', 'W') | |
456 endif | |
557 | 457 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 458 |
459 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
460 | |
532 | 461 let b:PHP_LastIndentedWasComment = 0 |
409 | 462 |
532 | 463 if cline =~ '^\s*\*/' |
464 return indent(lnum) + 1 | |
465 else | |
466 return indent(lnum) | |
7 | 467 endif |
532 | 468 |
469 elseif cline =~? '<script\>' | |
470 let b:InPHPcode_and_script = 1 | |
631 | 471 let b:GetLastRealCodeLNum_ADD = v:lnum |
532 | 472 endif |
7 | 473 endif |
532 | 474 endif |
409 | 475 |
532 | 476 if b:InPHPcode |
409 | 477 |
1120 | 478 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~"Delimiter" |
532 | 479 if cline !~? s:PHP_startindenttag |
480 let b:InPHPcode = 0 | |
481 let b:InPHPcode_tofind = s:PHP_startindenttag | |
482 elseif cline =~? '<script\>' | |
483 let b:InPHPcode_and_script = 1 | |
484 endif | |
409 | 485 |
2442 | 486 elseif last_line =~? '<<<''\=\a\w*''\=$' |
532 | 487 let b:InPHPcode = 0 |
2442 | 488 let b:InPHPcode_tofind = substitute( last_line, '^.*<<<''\=\(\a\w*\)''\=$', '^\\s*\1;\\=$', '') |
532 | 489 |
490 elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*' | |
491 let b:InPHPcode = 0 | |
492 let b:InPHPcode_tofind = '\*/' | |
409 | 493 |
532 | 494 elseif cline =~? '^\s*</script>' |
495 let b:InPHPcode = 0 | |
496 let b:InPHPcode_tofind = s:PHP_startindenttag | |
497 endif | |
498 endif " }}} | |
499 | |
856 | 500 |
532 | 501 if !b:InPHPcode && !b:InPHPcode_and_script |
502 return -1 | |
503 endif | |
409 | 504 |
532 | 505 " 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
|
506 let addSpecial = 0 |
532 | 507 if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
508 let addSpecial = b:PHP_outdentSLComments |
532 | 509 if b:PHP_LastIndentedWasComment == 1 |
510 return indent(real_PHP_lastindented) | |
511 endif | |
512 let b:PHP_LastIndentedWasComment = 1 | |
513 else | |
514 let b:PHP_LastIndentedWasComment = 0 | |
515 endif " }}} | |
516 | |
517 " Indent multiline /* comments correctly {{{ | |
518 | |
519 if b:PHP_InsideMultilineComment || b:UserIsTypingComment | |
520 if cline =~ '^\s*\*\%(\/\)\@!' | |
521 if last_line =~ '^\s*/\*' | |
522 return indent(lnum) + 1 | |
523 else | |
524 return indent(lnum) | |
525 endif | |
526 else | |
527 let b:PHP_InsideMultilineComment = 0 | |
528 endif | |
529 endif | |
530 | |
631 | 531 if !b:PHP_InsideMultilineComment && cline =~ '^\s*/\*' && cline !~ '\*/\s*$' |
532 if getline(v:lnum + 1) !~ '^\s*\*' | |
533 return -1 | |
534 endif | |
532 | 535 let b:PHP_InsideMultilineComment = 1 |
536 endif " }}} | |
409 | 537 |
538 | |
532 | 539 " Things always indented at col 1 (PHP delimiter: <?, ?>, Heredoc end) {{{ |
2442 | 540 if cline =~# '^\s*<?' && cline !~ '?>' && b:PHP_outdentphpescape |
532 | 541 return 0 |
542 endif | |
409 | 543 |
2442 | 544 if cline =~ '^\s*?>' && cline !~# '<?' && b:PHP_outdentphpescape |
532 | 545 return 0 |
546 endif | |
409 | 547 |
2442 | 548 if cline =~? '^\s*\a\w*;$\|^\a\w*$' && cline !~? s:notPhpHereDoc |
532 | 549 return 0 |
550 endif " }}} | |
409 | 551 |
532 | 552 let s:level = 0 |
409 | 553 |
532 | 554 let lnum = GetLastRealCodeLNum(v:lnum - 1) |
631 | 555 |
532 | 556 let last_line = getline(lnum) |
557 let ind = indent(lnum) | |
558 let endline= s:endline | |
409 | 559 |
532 | 560 if ind==0 && b:PHP_default_indenting |
561 let ind = b:PHP_default_indenting | |
562 endif | |
409 | 563 |
532 | 564 if lnum == 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
565 return b:PHP_default_indenting + addSpecial |
532 | 566 endif |
409 | 567 |
568 | |
532 | 569 if cline =~ '^\s*}\%(}}\)\@!' |
570 let ind = indent(FindOpenBracket(v:lnum)) | |
571 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
572 return ind | |
573 endif | |
409 | 574 |
532 | 575 if cline =~ '^\s*\*/' |
576 call cursor(v:lnum, 1) | |
577 if cline !~ '^\*/' | |
578 call search('\*/', 'W') | |
579 endif | |
557 | 580 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
532 | 581 |
582 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 583 |
532 | 584 if cline =~ '^\s*\*/' |
585 return indent(lnum) + 1 | |
586 else | |
587 return indent(lnum) | |
588 endif | |
589 endif | |
590 | |
591 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
592 if last_line =~ '[;}]'.endline && last_line !~ '^[)\]]' && last_line !~# s:defaultORcase |
532 | 593 if ind==b:PHP_default_indenting |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
594 return b:PHP_default_indenting + addSpecial |
532 | 595 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
|
596 return b:PHP_CurrentIndentLevel + addSpecial |
532 | 597 endif |
598 endif | |
599 | |
600 let LastLineClosed = 0 | |
601 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
602 let terminated = '\%(;\%(\s*\%(?>\|}\)\)\=\|<<<''\=\a\w*''\=$\|^\s*}\)'.endline |
532 | 603 |
604 let unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.endline | |
409 | 605 |
532 | 606 if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>' |
607 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
608 return indent(FindTheIfOfAnElse(v:lnum, 1)) | |
2442 | 609 elseif cline =~# s:defaultORcase |
610 return FindTheSwitchIndent(v:lnum) + &sw * b:PHP_vintage_case_default_indent | |
1668 | 611 elseif cline =~ '^\s*)\=\s*{' |
532 | 612 let previous_line = last_line |
613 let last_line_num = lnum | |
614 | |
615 while last_line_num > 1 | |
616 | |
1668 | 617 if previous_line =~ '^\s*\%(' . s:blockstart . '\|\%([a-zA-Z]\s*\)*function\)' |
532 | 618 |
619 let ind = indent(last_line_num) | |
620 | |
621 if b:PHP_BracesAtCodeLevel | |
622 let ind = ind + &sw | |
623 endif | |
624 | |
856 | 625 return ind |
532 | 626 endif |
627 | |
628 let last_line_num = last_line_num - 1 | |
629 let previous_line = getline(last_line_num) | |
630 endwhile | |
409 | 631 |
1668 | 632 elseif last_line =~# unstated && cline !~ '^\s*);\='.endline |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
633 let ind = ind + &sw " we indent one level further when the preceding line is not stated |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
634 return ind + addSpecial |
532 | 635 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
636 elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated " Added || last_line =~ '^)' on 2007-12-30 (array indenting problem broke other things) |
532 | 637 let previous_line = last_line |
638 let last_line_num = lnum | |
639 let LastLineClosed = 1 | |
640 | |
641 while 1 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
642 if previous_line =~ '^\s*}\|;\s*}'.endline " XXX |
532 | 643 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
644 call cursor(last_line_num, 1) |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
645 call search('}\|;\s*}'.endline, 'W') |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
646 let oldLastLine = last_line_num |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
647 let last_line_num = searchpair('{', '', '}', 'bW', 'Skippmatch()') |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
648 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
649 if oldLastLine == last_line_num || getline(last_line_num) =~ '^\s*{' |
532 | 650 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
409 | 651 endif |
532 | 652 |
653 let previous_line = getline(last_line_num) | |
7 | 654 |
532 | 655 continue |
656 else | |
409 | 657 |
532 | 658 if getline(last_line_num) =~# '^\s*else\%(if\)\=\>' |
659 let last_line_num = FindTheIfOfAnElse(last_line_num, 0) | |
660 continue | |
661 endif | |
409 | 662 |
663 | |
532 | 664 let last_match = last_line_num |
409 | 665 |
532 | 666 let one_ahead_indent = indent(last_line_num) |
667 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) | |
668 let two_ahead_indent = indent(last_line_num) | |
669 let after_previous_line = previous_line | |
670 let previous_line = getline(last_line_num) | |
409 | 671 |
672 | |
2442 | 673 if previous_line =~# s:defaultORcase.'\|{'.endline |
532 | 674 break |
675 endif | |
409 | 676 |
532 | 677 if after_previous_line=~# '^\s*'.s:blockstart.'.*)'.endline && previous_line =~# '[;}]'.endline |
678 break | |
7 | 679 endif |
409 | 680 |
856 | 681 if one_ahead_indent == two_ahead_indent || last_line_num < 1 |
1668 | 682 if previous_line =~# '\%(;\|^\s*}\)'.endline || last_line_num < 1 |
532 | 683 break |
684 endif | |
685 endif | |
686 endif | |
687 endwhile | |
688 | |
689 if indent(last_match) != ind | |
690 let ind = indent(last_match) | |
691 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
692 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
693 return ind + addSpecial |
532 | 694 endif |
695 endif | |
696 | |
697 let plinnum = GetLastRealCodeLNum(lnum - 1) | |
2442 | 698 let AntepenultimateLine = getline(plinnum) |
532 | 699 |
700 let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','') | |
701 | |
702 | |
703 if ind == b:PHP_default_indenting | |
704 if last_line =~ terminated | |
705 let LastLineClosed = 1 | |
706 endif | |
707 endif | |
708 | |
709 if !LastLineClosed | |
710 | |
2034 | 711 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
712 if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(]'.endline |
532 | 713 |
714 if !b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{' | |
409 | 715 let ind = ind + &sw |
532 | 716 endif |
717 | |
2442 | 718 if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 |
532 | 719 let b:PHP_CurrentIndentLevel = ind |
1668 | 720 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
721 return ind + addSpecial |
532 | 722 endif |
723 | |
724 elseif last_line =~ '\S\+\s*),'.endline | |
725 call cursor(lnum, 1) | |
726 call search('),'.endline, 'W') | |
727 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') | |
728 if openedparent != lnum | |
729 let ind = indent(openedparent) | |
730 endif | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
731 |
1668 | 732 elseif last_line =~ '^\s*'.s:blockstart |
733 let ind = ind + &sw | |
734 | |
532 | 735 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
736 elseif AntepenultimateLine =~ '\%(;\%(\s*\%(?>\|}\)\)\=\|<<<''\=\a\w*''\=$\|^\s*}\|{\)'.endline . '\|' . s:defaultORcase |
532 | 737 let ind = ind + &sw |
409 | 738 endif |
7 | 739 |
532 | 740 endif |
409 | 741 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
742 if cline =~ '^\s*[)\]];\=' |
532 | 743 let ind = ind - &sw |
744 endif | |
745 | |
746 let b:PHP_CurrentIndentLevel = ind | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
747 return ind + addSpecial |
7 | 748 endfunction |