Mercurial > vim
annotate runtime/indent/php.vim @ 33235:44fa2b82a642 v9.0.1891
patch 9.0.1891: No runtime support for Mojo
Commit: https://github.com/vim/vim/commit/0ce2c594d0704f27a16d2c13fce85d596cc91489
Author: Mahmoud Abduljawad <mahmoud@masaar.com>
Date: Sun Sep 10 18:23:04 2023 +0200
patch 9.0.1891: No runtime support for Mojo
Problem: No runtime support for Mojo
Solution: Add basic filetype and syntax plugins
closes: #13062
closes: #13063
Signed-off-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: Doug Kearns <dougkearns@gmail.com>
Co-authored-by: Mahmoud Abduljawad <mahmoud@masaar.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 10 Sep 2023 18:30:06 +0200 |
parents | 345c8a959d76 |
children |
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 |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
6 " Last Change: 2023 August 18th |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
7 " Version: 1.75 |
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 |
33052
5c220cf30f1f
runtime: Set b:undo_indent where missing (#12944)
Christian Brabandt <cb@256bit.org>
parents:
32984
diff
changeset
|
131 let b:undo_indent = "setl ai< cin< inde< indk< lisp< si<" |
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 |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
145 let s:endline = '\s*\%(//.*\|#\[\@!.*\|/\*.*\*/\s*\)\=$' |
6421 | 146 let s:PHP_validVariable = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
147 let s:notPhpHereDoc = '\<\%(break\|return\|continue\|exit\|die\|true\|false\|elseif\|else\|end\%(if\|while\|for\|foreach\|match\|switch\)\)\>' |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
148 let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|\%(}\s*\)\?else\>\|do\>\|while\>\|match\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|trait\>\|\%()\s*\)\=use\>\|interface\>\|abstract\>\|final\>\|try\>\|\%(}\s*\)\=catch\>\|\%(}\s*\)\=finally\>\)' |
17571 | 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>\)\@!' |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
159 let s:matchStart = 'match\s*(\s*\$\?'.s:PHP_validVariable.'\s*)\s*{'. s:endline |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
160 let s:structureHead = '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline . '\|\<new\s\+class\>\|' . s:matchStart |
409 | 161 |
162 | |
5862 | 163 let s:escapeDebugStops = 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
164 function! DebugPrintReturn(scriptLine) |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
165 |
6421 | 166 if ! s:escapeDebugStops |
5862 | 167 echo "debug:" . a:scriptLine |
168 let c = getchar() | |
169 if c == "\<Del>" | |
170 let s:escapeDebugStops = 1 | |
171 end | |
172 endif | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
173 |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
174 endfunction |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
175 |
409 | 176 function! GetLastRealCodeLNum(startline) " {{{ |
856 | 177 |
532 | 178 let lnum = a:startline |
856 | 179 |
631 | 180 if b:GetLastRealCodeLNum_ADD && b:GetLastRealCodeLNum_ADD == lnum + 1 |
181 let lnum = b:GetLastRealCodeLNum_ADD | |
182 endif | |
856 | 183 |
532 | 184 while lnum > 1 |
185 let lnum = prevnonblank(lnum) | |
186 let lastline = getline(lnum) | |
409 | 187 |
532 | 188 if b:InPHPcode_and_script && lastline =~ '?>\s*$' |
189 let lnum = lnum - 1 | |
190 elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$' | |
191 let lnum = lnum - 1 | |
192 elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)' | |
193 let lnum = lnum - 1 | |
194 elseif lastline =~ '\*/\s*$' | |
195 call cursor(lnum, 1) | |
196 if lastline !~ '^\*/' | |
197 call search('\*/', 'W') | |
198 endif | |
557 | 199 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 200 |
532 | 201 let lastline = getline(lnum) |
202 if lastline =~ '^\s*/\*' | |
203 let lnum = lnum - 1 | |
204 else | |
205 break | |
206 endif | |
409 | 207 |
208 | |
532 | 209 elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>' |
210 | |
211 while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1 | |
212 let lnum = lnum - 1 | |
213 let lastline = getline(lnum) | |
214 endwhile | |
215 if lastline =~ '^\s*?>' | |
216 let lnum = lnum - 1 | |
217 else | |
218 break | |
219 endif | |
220 | |
409 | 221 |
2442 | 222 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
|
223 let tofind=substitute( lastline, '\(\a\w*\);\=', '<<<\\s*[''"]\\=\1[''"]\\=$', '') |
532 | 224 while getline(lnum) !~? tofind && lnum > 1 |
225 let lnum = lnum - 1 | |
226 endwhile | |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
227 elseif lastline =~ '^\s*[''"`][;,]'.s:endline || (lastline =~ '^[^''"`]*[''"`][;,]'.s:endline && IslinePHP(lnum, "") == "SpecStringEntrails") |
11262 | 228 |
229 let tofind=substitute( lastline, '^.*\([''"`]\)[;,].*$', '^[^\1]\\+[\1]$\\|^[^\1]\\+[=([]\\s*[\1]', '') | |
230 let trylnum = lnum | |
231 while getline(trylnum) !~? tofind && trylnum > 1 | |
232 let trylnum = trylnum - 1 | |
5862 | 233 endwhile |
11262 | 234 |
235 if trylnum == 1 | |
236 break | |
237 else | |
238 if lastline =~ ';'.s:endline | |
239 while getline(trylnum) !~? s:terminated && getline(trylnum) !~? '{'.s:endline && trylnum > 1 | |
240 let trylnum = prevnonblank(trylnum - 1) | |
241 endwhile | |
242 | |
243 | |
244 if trylnum == 1 | |
245 break | |
246 end | |
247 end | |
248 let lnum = trylnum | |
249 end | |
532 | 250 else |
856 | 251 break |
409 | 252 endif |
532 | 253 endwhile |
254 | |
2442 | 255 if lnum==1 && getline(lnum) !~ '<?' |
532 | 256 let lnum=0 |
257 endif | |
258 | |
6421 | 259 if b:InPHPcode_and_script && 1 > b:InPHPcode |
532 | 260 let b:InPHPcode_and_script = 0 |
261 endif | |
1120 | 262 |
532 | 263 return lnum |
264 endfunction " }}} | |
409 | 265 |
557 | 266 function! Skippmatch2() |
267 | |
268 let line = getline(".") | |
269 | |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
270 if line =~ "\\([\"']\\).*/\\*.*\\1" || line =~ '\%(//\|#\[\@!\).*/\*' |
5862 | 271 return 1 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
272 else |
5862 | 273 return 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
274 endif |
557 | 275 endfun |
276 | |
2442 | 277 function! Skippmatch() " {{{ |
532 | 278 let synname = synIDattr(synID(line("."), col("."), 0), "name") |
14006 | 279 if synname ==? "Delimiter" || synname ==? "phpRegionDelimiter" || synname =~? "^phpParent" || synname ==? "phpArrayParens" || synname =~? '^php\%(Block\|Brace\)' || synname ==? "javaScriptBraces" || synname =~? '^php\%(Doc\)\?Comment' && b:UserIsTypingComment |
532 | 280 return 0 |
281 else | |
282 return 1 | |
283 endif | |
284 endfun " }}} | |
409 | 285 |
5862 | 286 function! FindOpenBracket(lnum, blockStarter) " {{{ |
532 | 287 call cursor(a:lnum, 1) |
5862 | 288 let line = searchpair('{', '', '}', 'bW', 'Skippmatch()') |
289 | |
290 if a:blockStarter == 1 | |
6421 | 291 while line > 1 |
5862 | 292 let linec = getline(line) |
293 | |
11262 | 294 if linec =~ s:terminated || linec =~ s:structureHead |
5862 | 295 break |
296 endif | |
297 | |
298 let line = GetLastRealCodeLNum(line - 1) | |
299 endwhile | |
300 endif | |
301 | |
302 return line | |
532 | 303 endfun " }}} |
409 | 304 |
11262 | 305 let s:blockChars = {'{':1, '[': 1, '(': 1, ')':-1, ']':-1, '}':-1} |
17571 | 306 let s:blockCharsLUT = {'{':'{', '}':'{', '[':'[', ']':'[', '(':'(', ')':'('} |
11262 | 307 function! BalanceDirection (str) |
308 | |
17571 | 309 let balance = {'{':0, '[': 0, '(': 0, 'none':0} |
310 let director = 'none' | |
11262 | 311 |
312 for c in split(a:str, '\zs') | |
313 if has_key(s:blockChars, c) | |
17571 | 314 let balance[s:blockCharsLUT[c]] += s:blockChars[c] |
315 | |
316 if balance[s:blockCharsLUT[c]] | |
317 let director = s:blockCharsLUT[c] | |
318 endif | |
11262 | 319 endif |
320 endfor | |
321 | |
17571 | 322 return balance[director] |
11262 | 323 endfun |
324 | |
14006 | 325 function! StripEndlineComments (line) |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
326 |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
327 let cleaned = substitute(a:line,'\v(//|#\[\@!)((([^"'']*(["''])[^"'']*\5)+[^"'']*$)|([^"'']*$))','','') |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
328 if cleaned != a:line |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
329 endif |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
330 return cleaned |
14006 | 331 endfun |
332 | |
333 function! FindArrowIndent (lnum) " {{{ | |
334 | |
32984 | 335 let parentArrowPos = -1 |
17571 | 336 let cursorPos = -1 |
14006 | 337 let lnum = a:lnum |
338 while lnum > 1 | |
339 let last_line = getline(lnum) | |
340 if last_line =~ '^\s*->' | |
32984 | 341 let parentArrowPos = indent(a:lnum) |
14006 | 342 break |
343 else | |
17571 | 344 |
345 if b:PHP_noArrowMatching | |
14006 | 346 break |
17571 | 347 endif |
348 | |
349 let cleanedLnum = StripEndlineComments(last_line) | |
350 | |
351 if cleanedLnum =~ ')'.s:endline | |
352 if BalanceDirection(cleanedLnum) <= 0 | |
353 call cursor(lnum, 1) | |
354 call searchpos(')'.s:endline, 'cW', lnum) | |
355 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') | |
356 let cursorPos = col(".") | |
357 if openedparent != lnum | |
358 let lnum = openedparent | |
359 continue | |
360 else | |
361 endif | |
14006 | 362 else |
32984 | 363 let parentArrowPos = -1 |
17571 | 364 break |
365 end | |
366 endif | |
14006 | 367 |
17571 | 368 if cleanedLnum =~ '->' |
369 call cursor(lnum, cursorPos == -1 ? strwidth(cleanedLnum) : cursorPos) | |
32984 | 370 let parentArrowPos = searchpos('->', 'cWb', lnum)[1] - 1 |
17571 | 371 |
372 break | |
14006 | 373 else |
32984 | 374 let parentArrowPos = -1 |
14006 | 375 break |
376 endif | |
377 endif | |
378 endwhile | |
379 | |
32984 | 380 if parentArrowPos == -1 |
381 let parentArrowPos = indent(lnum) + shiftwidth() | |
17571 | 382 end |
383 | |
32984 | 384 return parentArrowPos |
14006 | 385 endfun "}}} |
386 | |
409 | 387 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{ |
532 | 388 |
389 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>' | |
390 let beforeelse = a:lnum | |
391 else | |
392 let beforeelse = GetLastRealCodeLNum(a:lnum - 1) | |
393 endif | |
409 | 394 |
532 | 395 if !s:level |
396 let s:iftoskip = 0 | |
397 endif | |
398 | |
399 if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>' | |
400 let s:iftoskip = s:iftoskip + 1 | |
401 endif | |
402 | |
403 if getline(beforeelse) =~ '^\s*}' | |
5862 | 404 let beforeelse = FindOpenBracket(beforeelse, 0) |
532 | 405 |
406 if getline(beforeelse) =~ '^\s*{' | |
407 let beforeelse = GetLastRealCodeLNum(beforeelse - 1) | |
409 | 408 endif |
532 | 409 endif |
409 | 410 |
411 | |
532 | 412 if !s:iftoskip && a:StopAfterFirstPrevElse && getline(beforeelse) =~# '^\s*\%([}]\s*\)\=else\%(if\)\=\>' |
413 return beforeelse | |
414 endif | |
415 | |
416 if getline(beforeelse) !~# '^\s*if\>' && beforeelse>1 || s:iftoskip && beforeelse>1 | |
417 | |
2442 | 418 if s:iftoskip && getline(beforeelse) =~# '^\s*if\>' |
532 | 419 let s:iftoskip = s:iftoskip - 1 |
409 | 420 endif |
421 | |
532 | 422 let s:level = s:level + 1 |
423 let beforeelse = FindTheIfOfAnElse(beforeelse, a:StopAfterFirstPrevElse) | |
424 endif | |
409 | 425 |
532 | 426 return beforeelse |
409 | 427 |
532 | 428 endfunction " }}} |
409 | 429 |
2442 | 430 let s:defaultORcase = '^\s*\%(default\|case\).*:' |
431 | |
432 function! FindTheSwitchIndent (lnum) " {{{ | |
433 | |
434 let test = GetLastRealCodeLNum(a:lnum - 1) | |
435 | |
436 if test <= 1 | |
11518 | 437 return indent(1) - shiftwidth() * b:PHP_vintage_case_default_indent |
2442 | 438 end |
439 | |
5862 | 440 while getline(test) =~ '^\s*}' && test > 1 |
441 let test = GetLastRealCodeLNum(FindOpenBracket(test, 0) - 1) | |
2442 | 442 |
5862 | 443 if getline(test) =~ '^\s*switch\>' |
444 let test = GetLastRealCodeLNum(test - 1) | |
2442 | 445 endif |
5862 | 446 endwhile |
2442 | 447 |
448 if getline(test) =~# '^\s*switch\>' | |
449 return indent(test) | |
450 elseif getline(test) =~# s:defaultORcase | |
11518 | 451 return indent(test) - shiftwidth() * b:PHP_vintage_case_default_indent |
2442 | 452 else |
453 return FindTheSwitchIndent(test) | |
454 endif | |
455 | |
456 endfunction "}}} | |
457 | |
14006 | 458 let s:SynPHPMatchGroups = {'phpparent':1, 'delimiter':1, 'define':1, 'storageclass':1, 'structure':1, 'exception':1} |
409 | 459 function! IslinePHP (lnum, tofind) " {{{ |
532 | 460 let cline = getline(a:lnum) |
409 | 461 |
532 | 462 if a:tofind=="" |
5862 | 463 let tofind = "^\\s*[\"'`]*\\s*\\zs\\S" |
532 | 464 else |
465 let tofind = a:tofind | |
466 endif | |
409 | 467 |
532 | 468 let tofind = tofind . '\c' |
409 | 469 |
532 | 470 let coltotest = match (cline, tofind) + 1 |
471 | |
472 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name") | |
409 | 473 |
14006 | 474 if synname ==? 'phpStringSingle' || synname ==? 'phpStringDouble' || synname ==? 'phpBacktick' |
17571 | 475 if cline !~ '^\s*[''"`]' " ??? XXX |
6421 | 476 return "SpecStringEntrails" |
5862 | 477 else |
478 return synname | |
479 end | |
480 end | |
481 | |
14006 | 482 if get(s:SynPHPMatchGroups, tolower(synname)) || synname =~ '^php' || synname =~? '^javaScript' |
532 | 483 return synname |
484 else | |
485 return "" | |
486 endif | |
487 endfunction " }}} | |
409 | 488 |
2034 | 489 let s:autoresetoptions = 0 |
490 if ! s:autoresetoptions | |
491 let s:autoresetoptions = 1 | |
7 | 492 endif |
493 | |
2034 | 494 function! ResetPhpOptions() |
6421 | 495 if ! b:optionsset && &filetype =~ "php" |
557 | 496 if b:PHP_autoformatcomment |
497 | |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
498 setlocal comments=s1:/*,mb:*,ex:*/,://,f:#[,:# |
856 | 499 |
1668 | 500 setlocal formatoptions-=t |
557 | 501 setlocal formatoptions+=q |
502 setlocal formatoptions+=r | |
503 setlocal formatoptions+=o | |
504 setlocal formatoptions+=c | |
505 setlocal formatoptions+=b | |
506 endif | |
532 | 507 let b:optionsset = 1 |
508 endif | |
409 | 509 endfunc |
510 | |
2034 | 511 call ResetPhpOptions() |
512 | |
14006 | 513 function! GetPhpIndentVersion() |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
514 return "1.75" |
14006 | 515 endfun |
516 | |
409 | 517 function! GetPhpIndent() |
518 | |
631 | 519 let b:GetLastRealCodeLNum_ADD = 0 |
520 | |
532 | 521 let UserIsEditing=0 |
522 if b:PHP_oldchangetick != b:changedtick | |
523 let b:PHP_oldchangetick = b:changedtick | |
524 let UserIsEditing=1 | |
525 endif | |
409 | 526 |
532 | 527 if b:PHP_default_indenting |
11518 | 528 let b:PHP_default_indenting = g:PHP_default_indenting * shiftwidth() |
532 | 529 endif |
530 | |
531 let cline = getline(v:lnum) | |
409 | 532 |
856 | 533 if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast |
532 | 534 if b:PHP_indentbeforelast |
535 let b:PHP_indentinghuge = 1 | |
536 endif | |
537 let b:PHP_indentbeforelast = b:PHP_lastindented | |
538 endif | |
409 | 539 |
532 | 540 if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented |
541 if b:PHP_indentinghuge | |
542 let b:PHP_indentinghuge = 0 | |
543 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 544 endif |
6421 | 545 let real_PHP_lastindented = v:lnum |
532 | 546 let b:PHP_LastIndentedWasComment=0 |
547 let b:PHP_InsideMultilineComment=0 | |
548 let b:PHP_indentbeforelast = 0 | |
409 | 549 |
532 | 550 let b:InPHPcode = 0 |
551 let b:InPHPcode_checked = 0 | |
552 let b:InPHPcode_and_script = 0 | |
553 let b:InPHPcode_tofind = "" | |
409 | 554 |
532 | 555 elseif v:lnum > b:PHP_lastindented |
556 let real_PHP_lastindented = b:PHP_lastindented | |
6421 | 557 else |
558 let real_PHP_lastindented = v:lnum | |
532 | 559 endif |
409 | 560 |
6421 | 561 let b:PHP_lastindented = v:lnum |
562 | |
409 | 563 |
532 | 564 if !b:InPHPcode_checked " {{{ One time check |
565 let b:InPHPcode_checked = 1 | |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
566 let b:UserIsTypingComment = 0 |
409 | 567 |
631 | 568 let synname = "" |
569 if cline !~ '<?.*?>' | |
570 let synname = IslinePHP (prevnonblank(v:lnum), "") | |
571 endif | |
409 | 572 |
532 | 573 if synname!="" |
14006 | 574 if synname ==? "SpecStringEntrails" |
11262 | 575 let b:InPHPcode = -1 " thumb down |
6421 | 576 let b:InPHPcode_tofind = "" |
14006 | 577 elseif synname !=? "phpHereDoc" && synname !=? "phpHereDocDelimiter" |
532 | 578 let b:InPHPcode = 1 |
579 let b:InPHPcode_tofind = "" | |
409 | 580 |
14006 | 581 if synname =~? '^php\%(Doc\)\?Comment' |
532 | 582 let b:UserIsTypingComment = 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
583 let b:InPHPcode_checked = 0 |
409 | 584 endif |
585 | |
532 | 586 if synname =~? '^javaScript' |
587 let b:InPHPcode_and_script = 1 | |
588 endif | |
409 | 589 |
532 | 590 else |
591 let b:InPHPcode = 0 | |
409 | 592 |
532 | 593 let lnum = v:lnum - 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
594 while getline(lnum) !~? '<<<\s*[''"]\=\a\w*[''"]\=$' && lnum > 1 |
532 | 595 let lnum = lnum - 1 |
596 endwhile | |
409 | 597 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
598 let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<\s*[''"]\=\(\a\w*\)[''"]\=$', '^\\s*\1;\\=$', '') |
532 | 599 endif |
600 else | |
601 let b:InPHPcode = 0 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
602 let b:InPHPcode_tofind = s:PHP_startindenttag |
409 | 603 endif |
532 | 604 endif "!b:InPHPcode_checked }}} |
409 | 605 |
606 | |
532 | 607 " Test if we are indenting PHP code {{{ |
608 let lnum = prevnonblank(v:lnum - 1) | |
609 let last_line = getline(lnum) | |
5862 | 610 let endline= s:endline |
409 | 611 |
532 | 612 if b:InPHPcode_tofind!="" |
613 if cline =~? b:InPHPcode_tofind | |
614 let b:InPHPcode_tofind = "" | |
615 let b:UserIsTypingComment = 0 | |
6421 | 616 |
617 if b:InPHPcode == -1 | |
618 let b:InPHPcode = 1 | |
619 return -1 | |
620 end | |
621 | |
622 let b:InPHPcode = 1 | |
623 | |
532 | 624 if cline =~ '\*/' |
409 | 625 call cursor(v:lnum, 1) |
532 | 626 if cline !~ '^\*/' |
627 call search('\*/', 'W') | |
628 endif | |
557 | 629 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
409 | 630 |
631 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
632 | |
532 | 633 let b:PHP_LastIndentedWasComment = 0 |
409 | 634 |
532 | 635 if cline =~ '^\s*\*/' |
636 return indent(lnum) + 1 | |
637 else | |
638 return indent(lnum) | |
7 | 639 endif |
532 | 640 |
641 elseif cline =~? '<script\>' | |
642 let b:InPHPcode_and_script = 1 | |
631 | 643 let b:GetLastRealCodeLNum_ADD = v:lnum |
532 | 644 endif |
7 | 645 endif |
532 | 646 endif |
409 | 647 |
6421 | 648 if 1 == b:InPHPcode |
409 | 649 |
14006 | 650 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~?"Delimiter" |
532 | 651 if cline !~? s:PHP_startindenttag |
652 let b:InPHPcode = 0 | |
653 let b:InPHPcode_tofind = s:PHP_startindenttag | |
654 elseif cline =~? '<script\>' | |
655 let b:InPHPcode_and_script = 1 | |
656 endif | |
409 | 657 |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
658 elseif last_line =~ '^[^''"`]\+[''"`]$' && last_line !~ '^\s*\%(//\|#\[\@!\|/\*.*\*/\s*$\)' " a string identifier with nothing after it and no other string identifier before |
6421 | 659 let b:InPHPcode = -1 |
5862 | 660 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
|
661 elseif last_line =~? '<<<\s*[''"]\=\a\w*[''"]\=$' |
532 | 662 let b:InPHPcode = 0 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
6421
diff
changeset
|
663 let b:InPHPcode_tofind = substitute( last_line, '^.*<<<\s*[''"]\=\(\a\w*\)[''"]\=$', '^\\s*\1;\\=$', '') |
532 | 664 |
665 elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*' | |
666 let b:InPHPcode = 0 | |
667 let b:InPHPcode_tofind = '\*/' | |
409 | 668 |
532 | 669 elseif cline =~? '^\s*</script>' |
670 let b:InPHPcode = 0 | |
671 let b:InPHPcode_tofind = s:PHP_startindenttag | |
672 endif | |
673 endif " }}} | |
674 | |
856 | 675 |
6421 | 676 if 1 > b:InPHPcode && !b:InPHPcode_and_script |
532 | 677 return -1 |
678 endif | |
409 | 679 |
532 | 680 " 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
|
681 let addSpecial = 0 |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
682 if cline =~ '^\s*\%(//\|#\[\@!\|/\*.*\*/\s*$\)' |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
683 let addSpecial = b:PHP_outdentSLComments |
532 | 684 if b:PHP_LastIndentedWasComment == 1 |
685 return indent(real_PHP_lastindented) | |
686 endif | |
687 let b:PHP_LastIndentedWasComment = 1 | |
688 else | |
689 let b:PHP_LastIndentedWasComment = 0 | |
690 endif " }}} | |
691 | |
692 " Indent multiline /* comments correctly {{{ | |
693 | |
694 if b:PHP_InsideMultilineComment || b:UserIsTypingComment | |
695 if cline =~ '^\s*\*\%(\/\)\@!' | |
696 if last_line =~ '^\s*/\*' | |
697 return indent(lnum) + 1 | |
698 else | |
699 return indent(lnum) | |
700 endif | |
701 else | |
702 let b:PHP_InsideMultilineComment = 0 | |
703 endif | |
704 endif | |
705 | |
6421 | 706 if !b:PHP_InsideMultilineComment && cline =~ '^\s*/\*\%(.*\*/\)\@!' |
631 | 707 if getline(v:lnum + 1) !~ '^\s*\*' |
708 return -1 | |
709 endif | |
532 | 710 let b:PHP_InsideMultilineComment = 1 |
711 endif " }}} | |
409 | 712 |
713 | |
532 | 714 " Things always indented at col 1 (PHP delimiter: <?, ?>, Heredoc end) {{{ |
2442 | 715 if cline =~# '^\s*<?' && cline !~ '?>' && b:PHP_outdentphpescape |
532 | 716 return 0 |
717 endif | |
409 | 718 |
2442 | 719 if cline =~ '^\s*?>' && cline !~# '<?' && b:PHP_outdentphpescape |
532 | 720 return 0 |
721 endif | |
409 | 722 |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
723 if (cline =~? '^\s*\a\w*;$\|^\a\w*$' || (cline =~? '^\s*[''"`][;,]' && IslinePHP(v:lnum, '[;,]') !~? '^\(phpString[SD]\|phpBacktick\)') ) && cline !~? s:notPhpHereDoc |
532 | 724 return 0 |
725 endif " }}} | |
409 | 726 |
532 | 727 let s:level = 0 |
409 | 728 |
532 | 729 let lnum = GetLastRealCodeLNum(v:lnum - 1) |
631 | 730 |
532 | 731 let last_line = getline(lnum) |
732 let ind = indent(lnum) | |
409 | 733 |
532 | 734 if ind==0 && b:PHP_default_indenting |
735 let ind = b:PHP_default_indenting | |
736 endif | |
409 | 737 |
532 | 738 if lnum == 0 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
739 return b:PHP_default_indenting + addSpecial |
532 | 740 endif |
409 | 741 |
742 | |
532 | 743 if cline =~ '^\s*}\%(}}\)\@!' |
5862 | 744 let ind = indent(FindOpenBracket(v:lnum, 1)) |
532 | 745 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
746 if b:PHP_BracesAtCodeLevel |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
747 let ind = ind + shiftwidth() |
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
748 endif |
532 | 749 return ind |
750 endif | |
409 | 751 |
532 | 752 if cline =~ '^\s*\*/' |
753 call cursor(v:lnum, 1) | |
754 if cline !~ '^\*/' | |
755 call search('\*/', 'W') | |
756 endif | |
557 | 757 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()') |
532 | 758 |
759 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
409 | 760 |
532 | 761 if cline =~ '^\s*\*/' |
762 return indent(lnum) + 1 | |
763 else | |
764 return indent(lnum) | |
765 endif | |
766 endif | |
767 | |
768 | |
17571 | 769 if last_line =~ '[;}]'.endline && last_line !~ '^[)\]]' && last_line !~# s:defaultORcase && last_line !~ '^\s*[''"`][;,]' |
532 | 770 if ind==b:PHP_default_indenting |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
771 return b:PHP_default_indenting + addSpecial |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
772 elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)\|^\(\s*\S\+\s*\)\+}'.endline && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
773 return b:PHP_CurrentIndentLevel + addSpecial |
532 | 774 endif |
775 endif | |
776 | |
777 let LastLineClosed = 0 | |
778 | |
5862 | 779 let terminated = s:terminated |
532 | 780 |
11262 | 781 let unstated = s:unstated |
782 | |
409 | 783 |
532 | 784 if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>' |
785 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
786 return indent(FindTheIfOfAnElse(v:lnum, 1)) | |
2442 | 787 elseif cline =~# s:defaultORcase |
11518 | 788 return FindTheSwitchIndent(v:lnum) + shiftwidth() * b:PHP_vintage_case_default_indent |
1668 | 789 elseif cline =~ '^\s*)\=\s*{' |
532 | 790 let previous_line = last_line |
791 let last_line_num = lnum | |
792 | |
793 while last_line_num > 1 | |
794 | |
11262 | 795 if previous_line =~ terminated || previous_line =~ s:structureHead |
532 | 796 |
797 let ind = indent(last_line_num) | |
798 | |
799 if b:PHP_BracesAtCodeLevel | |
11518 | 800 let ind = ind + shiftwidth() |
532 | 801 endif |
802 | |
856 | 803 return ind |
532 | 804 endif |
805 | |
5862 | 806 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
532 | 807 let previous_line = getline(last_line_num) |
808 endwhile | |
14006 | 809 elseif cline =~ '^\s*->' |
810 return FindArrowIndent(lnum) | |
1668 | 811 elseif last_line =~# unstated && cline !~ '^\s*);\='.endline |
11518 | 812 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
|
813 return ind + addSpecial |
532 | 814 |
6421 | 815 elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated |
532 | 816 let previous_line = last_line |
817 let last_line_num = lnum | |
818 let LastLineClosed = 1 | |
819 | |
5862 | 820 let isSingleLineBlock = 0 |
532 | 821 while 1 |
14006 | 822 if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline |
532 | 823 |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
824 call cursor(last_line_num, 1) |
5862 | 825 if previous_line !~ '^}' |
826 call search('}\|;\s*}'.endline, 'W') | |
827 end | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
828 let oldLastLine = last_line_num |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
829 let last_line_num = searchpair('{', '', '}', 'bW', 'Skippmatch()') |
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
830 |
5862 | 831 if getline(last_line_num) =~ '^\s*{' |
532 | 832 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) |
5862 | 833 elseif oldLastLine == last_line_num |
834 let isSingleLineBlock = 1 | |
835 continue | |
409 | 836 endif |
532 | 837 |
838 let previous_line = getline(last_line_num) | |
7 | 839 |
532 | 840 continue |
841 else | |
5862 | 842 let isSingleLineBlock = 0 |
409 | 843 |
532 | 844 if getline(last_line_num) =~# '^\s*else\%(if\)\=\>' |
845 let last_line_num = FindTheIfOfAnElse(last_line_num, 0) | |
846 continue | |
847 endif | |
409 | 848 |
849 | |
532 | 850 let last_match = last_line_num |
409 | 851 |
532 | 852 let one_ahead_indent = indent(last_line_num) |
853 let last_line_num = GetLastRealCodeLNum(last_line_num - 1) | |
854 let two_ahead_indent = indent(last_line_num) | |
855 let after_previous_line = previous_line | |
856 let previous_line = getline(last_line_num) | |
409 | 857 |
858 | |
2442 | 859 if previous_line =~# s:defaultORcase.'\|{'.endline |
532 | 860 break |
861 endif | |
409 | 862 |
532 | 863 if after_previous_line=~# '^\s*'.s:blockstart.'.*)'.endline && previous_line =~# '[;}]'.endline |
864 break | |
7 | 865 endif |
409 | 866 |
856 | 867 if one_ahead_indent == two_ahead_indent || last_line_num < 1 |
1668 | 868 if previous_line =~# '\%(;\|^\s*}\)'.endline || last_line_num < 1 |
532 | 869 break |
870 endif | |
871 endif | |
872 endif | |
873 endwhile | |
874 | |
875 if indent(last_match) != ind | |
876 let ind = indent(last_match) | |
877 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting | |
878 | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
879 return ind + addSpecial |
532 | 880 endif |
881 endif | |
882 | |
6421 | 883 if (last_line !~ '^\s*}\%(}}\)\@!') |
884 let plinnum = GetLastRealCodeLNum(lnum - 1) | |
885 else | |
886 let plinnum = GetLastRealCodeLNum(FindOpenBracket(lnum, 1) - 1) | |
887 endif | |
888 | |
2442 | 889 let AntepenultimateLine = getline(plinnum) |
532 | 890 |
14006 | 891 let last_line = StripEndlineComments(last_line) |
532 | 892 |
893 if ind == b:PHP_default_indenting | |
6421 | 894 if last_line =~ terminated && last_line !~# s:defaultORcase |
532 | 895 let LastLineClosed = 1 |
896 endif | |
897 endif | |
898 | |
899 if !LastLineClosed | |
900 | |
14006 | 901 let openedparent = -1 |
902 | |
2034 | 903 |
11262 | 904 if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline && BalanceDirection(last_line) > 0 |
532 | 905 |
5862 | 906 let dontIndent = 0 |
14006 | 907 if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\(\s*:\s*'.s:PHP_validVariable.'\)\=\s*{'.endline && last_line !~ s:structureHead |
5862 | 908 let dontIndent = 1 |
909 endif | |
910 | |
911 if !dontIndent && (!b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{') | |
11518 | 912 let ind = ind + shiftwidth() |
532 | 913 endif |
914 | |
17571 | 915 if b:PHP_IndentFunctionCallParameters && last_line =~ s:multilineFunctionCall && last_line !~ s:structureHead && last_line !~ s:arrayDecl |
916 let ind = ind + b:PHP_IndentFunctionCallParameters * shiftwidth() | |
917 endif | |
918 | |
919 if b:PHP_IndentFunctionDeclarationParameters && last_line =~ s:multilineFunctionDecl | |
920 let ind = ind + b:PHP_IndentFunctionDeclarationParameters * shiftwidth() | |
921 endif | |
922 | |
2442 | 923 if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1 |
532 | 924 let b:PHP_CurrentIndentLevel = ind |
1668 | 925 |
532 | 926 endif |
927 | |
14006 | 928 elseif last_line =~ '),'.endline && BalanceDirection(last_line) < 0 |
532 | 929 call cursor(lnum, 1) |
14006 | 930 call searchpos('),'.endline, 'cW') |
532 | 931 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()') |
932 if openedparent != lnum | |
933 let ind = indent(openedparent) | |
934 endif | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
935 |
14006 | 936 elseif last_line =~ s:structureHead |
11518 | 937 let ind = ind + shiftwidth() |
1668 | 938 |
532 | 939 |
33170
345c8a959d76
runtime(php): Update the php indent script to the 1.75 (from 1.70) (#13025)
Christian Brabandt <cb@256bit.org>
parents:
33052
diff
changeset
|
940 elseif AntepenultimateLine =~ '{'.endline && AntepenultimateLine !~? '^\s*use\>' && AntepenultimateLine !~? s:matchStart || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase |
11518 | 941 let ind = ind + shiftwidth() |
409 | 942 endif |
7 | 943 |
14006 | 944 |
945 if openedparent >= 0 | |
946 let last_line = StripEndlineComments(getline(openedparent)) | |
947 endif | |
532 | 948 endif |
409 | 949 |
14006 | 950 if cline =~ '^\s*[)\]];\=' |
17571 | 951 call cursor(v:lnum, 1) |
952 call searchpos('[)\]]', 'cW') | |
953 let matchedBlockChar = cline[col('.')-1] | |
954 let openedparent = searchpair('\M'.s:blockCharsLUT[matchedBlockChar], '', '\M'.matchedBlockChar, 'bW', 'Skippmatch()') | |
955 if openedparent != v:lnum | |
956 let ind = indent(openedparent) | |
957 endif | |
14006 | 958 |
17571 | 959 elseif last_line =~ '^\s*->' && last_line !~? s:structureHead && BalanceDirection(last_line) <= 0 |
11518 | 960 let ind = ind - shiftwidth() |
532 | 961 endif |
962 | |
963 let b:PHP_CurrentIndentLevel = ind | |
4502
605c9ce57ec3
Updated runtime files, language files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2442
diff
changeset
|
964 return ind + addSpecial |
7 | 965 endfunction |