annotate runtime/indent/php.vim @ 1362:2f70b8f1f1e3 v7.1.076

updated for version 7.1-076
author vimboss
date Tue, 14 Aug 2007 20:54:49 +0000
parents e6db096b07a1
children b9740fb41986
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: PHP
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
3 " Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
4 " URL: http://www.2072productions.com/vim/indent/php.vim
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
5 " Last Change: 2007 February 25th
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
6 " Newsletter: http://www.2072productions.com/?to=php-indent-for-vim-newsletter.php
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
7 " Version: 1.24
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
8 "
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
9 " The change log and all the comments have been removed from this file.
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
10 "
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
11 " For a complete change log and fully commented code, download the script on
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
12 " 2072productions.com at the URI provided above.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
13 "
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
14 " If you find a bug, please e-mail me at John.wellesz (AT) teaser (DOT) fr
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
15 " with an example of code that breaks the algorithm.
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
16 "
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
17 "
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
18 " Thanks a lot for using this script.
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
19 "
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
20 "
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
21 " NOTE: This script must be used with PHP syntax ON and with the php syntax
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
22 " script by Lutz Eymers ( http://www.isp.de/data/php.vim ) that's the script bundled with Vim.
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
23 "
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
24 "
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
25 " In the case you have syntax errors in your script such as end of HereDoc
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
26 " tags not at col 1 you'll have to indent your file 2 times (This script
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
27 " will automatically put HereDoc end tags at col 1).
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
28 "
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
29 "
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
30 " NOTE: If you are editing file in Unix file format and that (by accident)
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
31 " there are '\r' before new lines, this script won't be able to proceed
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
32 " correctly and will make many mistakes because it won't be able to match
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
33 " '\s*$' correctly.
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
34 " So you have to remove those useless characters first with a command like:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 "
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
36 " :%s /\r$//g
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
37 "
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
38 " or simply 'let' the option PHP_removeCRwhenUnix to 1 and the script will
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
39 " silently remove them when VIM load this script (at each bufread).
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
40
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
41
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
42 " Options: PHP_autoformatcomment = 0 to not enable autoformating of comment by
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
43 " default, if set to 0, this script will let the 'formatoptions' setting intact.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
44 "
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
45 " Options: PHP_default_indenting = # of sw (default is 0), # of sw will be
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
46 " added to the indent of each line of PHP code.
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
47 "
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
48 " Options: PHP_removeCRwhenUnix = 1 to make the script automatically remove CR
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
49 " at end of lines (by default this option is unset), NOTE that you
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
50 " MUST remove CR when the fileformat is UNIX else the indentation
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
51 " won't be correct...
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 "
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
53 " Options: PHP_BracesAtCodeLevel = 1 to indent the '{' and '}' at the same
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
54 " level than the code they contain.
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
55 " Exemple:
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
56 " Instead of:
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
57 " if ($foo)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
58 " {
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
59 " foo();
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
60 " }
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
61 "
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
62 " You will write:
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
63 " if ($foo)
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
64 " {
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
65 " foo();
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
66 " }
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
67 "
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
68 " NOTE: The script will be a bit slower if you use this option because
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
69 " some optimizations won't be available.
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
70
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 if exists("b:did_indent")
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
72 finish
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
76
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
77 let php_sync_method = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
78
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
79
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
80 if exists("PHP_default_indenting")
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
81 let b:PHP_default_indenting = PHP_default_indenting * &sw
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
82 else
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
83 let b:PHP_default_indenting = 0
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
84 endif
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
85
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
86 if exists("PHP_BracesAtCodeLevel")
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
87 let b:PHP_BracesAtCodeLevel = PHP_BracesAtCodeLevel
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
88 else
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
89 let b:PHP_BracesAtCodeLevel = 0
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
90 endif
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
91
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
92 if exists("PHP_autoformatcomment")
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
93 let b:PHP_autoformatcomment = PHP_autoformatcomment
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
94 else
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
95 let b:PHP_autoformatcomment = 1
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
96 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
98 let b:PHP_lastindented = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
99 let b:PHP_indentbeforelast = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
100 let b:PHP_indentinghuge = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
101 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
102 let b:PHP_LastIndentedWasComment = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
103 let b:PHP_InsideMultilineComment = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
104 let b:InPHPcode = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
105 let b:InPHPcode_checked = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
106 let b:InPHPcode_and_script = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
107 let b:InPHPcode_tofind = ""
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
108 let b:PHP_oldchangetick = b:changedtick
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
109 let b:UserIsTypingComment = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
110 let b:optionsset = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
111
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
112 setlocal nosmartindent
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
113 setlocal noautoindent
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
114 setlocal nocindent
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
115 setlocal nolisp
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
116
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
117 setlocal indentexpr=GetPhpIndent()
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
118 setlocal indentkeys=0{,0},0),:,!^F,o,O,e,*<Return>,=?>,=<?,=*/
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
119
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
120
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
121
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
122 let s:searchpairflags = 'bWr'
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
123
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
124 if &fileformat == "unix" && exists("PHP_removeCRwhenUnix") && PHP_removeCRwhenUnix
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
125 silent! %s/\r$//g
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
126 endif
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
127
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 if exists("*GetPhpIndent")
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
129 finish " XXX
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
132 let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$'
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
133 let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!'
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
134 "setlocal debug=msg " XXX
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
135
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
136
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
137 function! GetLastRealCodeLNum(startline) " {{{
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
138
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
139 let lnum = a:startline
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
140
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
141 if b:GetLastRealCodeLNum_ADD && b:GetLastRealCodeLNum_ADD == lnum + 1
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
142 let lnum = b:GetLastRealCodeLNum_ADD
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
143 endif
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
144
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
145 let old_lnum = lnum
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
146
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
147 while lnum > 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
148 let lnum = prevnonblank(lnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
149 let lastline = getline(lnum)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
150
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
151 if b:InPHPcode_and_script && lastline =~ '?>\s*$'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
152 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
153 elseif lastline =~ '^\s*?>.*<?\%(php\)\=\s*$'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
154 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
155 elseif lastline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
156 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
157 elseif lastline =~ '\*/\s*$'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
158 call cursor(lnum, 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
159 if lastline !~ '^\*/'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
160 call search('\*/', 'W')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
161 endif
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
162 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()')
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
163
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
164 let lastline = getline(lnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
165 if lastline =~ '^\s*/\*'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
166 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
167 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
168 break
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
169 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
170
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
171
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
172 elseif lastline =~? '\%(//\s*\|?>.*\)\@<!<?\%(php\)\=\s*$\|^\s*<script\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
173
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
174 while lastline !~ '\(<?.*\)\@<!?>' && lnum > 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
175 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
176 let lastline = getline(lnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
177 endwhile
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
178 if lastline =~ '^\s*?>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
179 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
180 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
181 break
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
182 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
183
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
184
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
185 elseif lastline =~? '^\a\w*;$' && lastline !~? s:notPhpHereDoc
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
186 let tofind=substitute( lastline, '\([^;]\+\);', '<<<\1$', '')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
187 while getline(lnum) !~? tofind && lnum > 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
188 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
189 endwhile
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
190 else
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
191 break
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
192 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
193 endwhile
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
194
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
195 if lnum==1 && getline(lnum)!~ '<?'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
196 let lnum=0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
197 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
198
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
199 if b:InPHPcode_and_script && !b:InPHPcode
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
200 let b:InPHPcode_and_script = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
201 endif
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
202
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
203
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
204
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
205 return lnum
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
206 endfunction " }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
207
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
208 function! Skippmatch2()
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
209
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
210 let line = getline(".")
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
211
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
212 if line =~ '\%(".*\)\@<=/\*\%(.*"\)\@=' || line =~ '\%(//.*\)\@<=/\*'
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
213 return 1
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
214 else
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
215 return 0
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
216 endif
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
217 endfun
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
218
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
219 function! Skippmatch() " {{{
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
220 let synname = synIDattr(synID(line("."), col("."), 0), "name")
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
221 if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname == "phpComment" && b:UserIsTypingComment
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
222 return 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
223 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
224 return 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
225 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
226 endfun " }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
227
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
228 function! FindOpenBracket(lnum) " {{{
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
229 call cursor(a:lnum, 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
230 return searchpair('{', '', '}', 'bW', 'Skippmatch()')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
231 endfun " }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
232
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
233 function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
234
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
235 if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
236 let beforeelse = a:lnum
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
237 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
238 let beforeelse = GetLastRealCodeLNum(a:lnum - 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
239 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
240
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
241 if !s:level
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
242 let s:iftoskip = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
243 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
244
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
245 if getline(beforeelse) =~# '^\s*\%(}\s*\)\=else\%(\s*if\)\@!\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
246 let s:iftoskip = s:iftoskip + 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
247 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
248
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
249 if getline(beforeelse) =~ '^\s*}'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
250 let beforeelse = FindOpenBracket(beforeelse)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
251
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
252 if getline(beforeelse) =~ '^\s*{'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
253 let beforeelse = GetLastRealCodeLNum(beforeelse - 1)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
254 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
255 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
256
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
257
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
258 if !s:iftoskip && a:StopAfterFirstPrevElse && getline(beforeelse) =~# '^\s*\%([}]\s*\)\=else\%(if\)\=\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
259 return beforeelse
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
260 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
261
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
262 if getline(beforeelse) !~# '^\s*if\>' && beforeelse>1 || s:iftoskip && beforeelse>1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
263
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
264 if s:iftoskip && getline(beforeelse) =~# '^\s*if\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
265 let s:iftoskip = s:iftoskip - 1
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
266 endif
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
267
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
268 let s:level = s:level + 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
269 let beforeelse = FindTheIfOfAnElse(beforeelse, a:StopAfterFirstPrevElse)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
270 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
271
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
272 return beforeelse
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
273
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
274 endfunction " }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
275
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
276 function! IslinePHP (lnum, tofind) " {{{
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
277 let cline = getline(a:lnum)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
278
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
279 if a:tofind==""
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
280 let tofind = "^\\s*[\"']*\\s*\\zs\\S"
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
281 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
282 let tofind = a:tofind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
283 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
284
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
285 let tofind = tofind . '\c'
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
286
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
287 let coltotest = match (cline, tofind) + 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
288
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
289 let synname = synIDattr(synID(a:lnum, coltotest, 0), "name")
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
290
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
291 if synname =~ '^php' || synname=="Delimiter" || synname =~? '^javaScript'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
292 return synname
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
293 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
294 return ""
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
295 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
296 endfunction " }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
297
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
298 let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\);'
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
299 let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|else\>\|while\>\|switch\>\|for\%(each\)\=\>\|declare\>\|class\>\|interface\>\|abstract\>\|try\>\|catch\>\|[|&]\)'
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
300
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
301 let s:autorestoptions = 0
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
302 if ! s:autorestoptions
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
303 au BufWinEnter,Syntax *.php,*.php3,*.php4,*.php5 call ResetOptions()
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
304 let s:autorestoptions = 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
307 function! ResetOptions()
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
308 if ! b:optionsset
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
309 if b:PHP_autoformatcomment
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
310
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
311 setlocal comments=s1:/*,mb:*,ex:*/,://,:#
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
312
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
313 setlocal formatoptions-=t
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
314 setlocal formatoptions+=q
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
315 setlocal formatoptions+=r
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
316 setlocal formatoptions+=o
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
317 setlocal formatoptions+=w
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
318 setlocal formatoptions+=c
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
319 setlocal formatoptions+=b
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
320 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
321 let b:optionsset = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
322 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
323 endfunc
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
324
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
325 function! GetPhpIndent()
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
326
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
327 let b:GetLastRealCodeLNum_ADD = 0
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
328
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
329 let UserIsEditing=0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
330 if b:PHP_oldchangetick != b:changedtick
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
331 let b:PHP_oldchangetick = b:changedtick
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
332 let UserIsEditing=1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
333 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
334
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
335 if b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
336 let b:PHP_default_indenting = g:PHP_default_indenting * &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
337 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
338
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
339 let cline = getline(v:lnum)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
340
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
341 if !b:PHP_indentinghuge && b:PHP_lastindented > b:PHP_indentbeforelast
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
342 if b:PHP_indentbeforelast
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
343 let b:PHP_indentinghuge = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
344 echom 'Large indenting detected, speed optimizations engaged'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
345 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
346 let b:PHP_indentbeforelast = b:PHP_lastindented
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
347 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
348
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
349 if b:InPHPcode_checked && prevnonblank(v:lnum - 1) != b:PHP_lastindented
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
350 if b:PHP_indentinghuge
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
351 echom 'Large indenting deactivated'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
352 let b:PHP_indentinghuge = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
353 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
354 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
355 let b:PHP_lastindented = v:lnum
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
356 let b:PHP_LastIndentedWasComment=0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
357 let b:PHP_InsideMultilineComment=0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
358 let b:PHP_indentbeforelast = 0
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
359
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
360 let b:InPHPcode = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
361 let b:InPHPcode_checked = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
362 let b:InPHPcode_and_script = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
363 let b:InPHPcode_tofind = ""
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
364
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
365 elseif v:lnum > b:PHP_lastindented
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
366 let real_PHP_lastindented = b:PHP_lastindented
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
367 let b:PHP_lastindented = v:lnum
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
368 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
369
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
370
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
371 if !b:InPHPcode_checked " {{{ One time check
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
372 let b:InPHPcode_checked = 1
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
373
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
374 let synname = ""
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
375 if cline !~ '<?.*?>'
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
376 let synname = IslinePHP (prevnonblank(v:lnum), "")
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
377 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
378
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
379 if synname!=""
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
380 if synname != "phpHereDoc" && synname != "phpHereDocDelimiter"
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
381 let b:InPHPcode = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
382 let b:InPHPcode_tofind = ""
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
383
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
384 if synname == "phpComment"
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
385 let b:UserIsTypingComment = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
386 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
387 let b:UserIsTypingComment = 0
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
388 endif
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
389
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
390 if synname =~? '^javaScript'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
391 let b:InPHPcode_and_script = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
392 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
393
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
394 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
395 let b:InPHPcode = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
396 let b:UserIsTypingComment = 0
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
397
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
398 let lnum = v:lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
399 while getline(lnum) !~? '<<<\a\w*$' && lnum > 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
400 let lnum = lnum - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
401 endwhile
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
402
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
403 let b:InPHPcode_tofind = substitute( getline(lnum), '^.*<<<\(\a\w*\)\c', '^\\s*\1;$', '')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
404 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
405 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
406 let b:InPHPcode = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
407 let b:UserIsTypingComment = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
408 let b:InPHPcode_tofind = '<?\%(.*?>\)\@!\|<script.*>'
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
409 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
410 endif "!b:InPHPcode_checked }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
411
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
412
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
413 " Test if we are indenting PHP code {{{
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
414 let lnum = prevnonblank(v:lnum - 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
415 let last_line = getline(lnum)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
416
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
417 if b:InPHPcode_tofind!=""
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
418 if cline =~? b:InPHPcode_tofind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
419 let b:InPHPcode = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
420 let b:InPHPcode_tofind = ""
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
421 let b:UserIsTypingComment = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
422 if cline =~ '\*/'
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
423 call cursor(v:lnum, 1)
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
424 if cline !~ '^\*/'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
425 call search('\*/', 'W')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
426 endif
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
427 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()')
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
428
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
429 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
430
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
431 let b:PHP_LastIndentedWasComment = 0
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
432
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
433 if cline =~ '^\s*\*/'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
434 return indent(lnum) + 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
435 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
436 return indent(lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
438
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
439 elseif cline =~? '<script\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
440 let b:InPHPcode_and_script = 1
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
441 let b:GetLastRealCodeLNum_ADD = v:lnum
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
442 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
444 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
445
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
446 if b:InPHPcode
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
447
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
448 if !b:InPHPcode_and_script && last_line =~ '\%(<?.*\)\@<!?>\%(.*<?\)\@!' && IslinePHP(lnum, '?>')=~"Delimiter"
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
449 if cline !~? s:PHP_startindenttag
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
450 let b:InPHPcode = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
451 let b:InPHPcode_tofind = s:PHP_startindenttag
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
452 elseif cline =~? '<script\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
453 let b:InPHPcode_and_script = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
454 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
455
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
456 elseif last_line =~? '<<<\a\w*$'
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
457 let b:InPHPcode = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
458 let b:InPHPcode_tofind = substitute( last_line, '^.*<<<\(\a\w*\)\c', '^\\s*\1;$', '')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
459
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
460 elseif !UserIsEditing && cline =~ '^\s*/\*\%(.*\*/\)\@!' && getline(v:lnum + 1) !~ '^\s*\*'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
461 let b:InPHPcode = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
462 let b:InPHPcode_tofind = '\*/'
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
463
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
464 elseif cline =~? '^\s*</script>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
465 let b:InPHPcode = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
466 let b:InPHPcode_tofind = s:PHP_startindenttag
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
467 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
468 endif " }}}
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
469
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
470
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
471 if !b:InPHPcode && !b:InPHPcode_and_script
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
472 return -1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
473 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
474
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
475 " Indent successive // or # comment the same way the first is {{{
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
476 if cline =~ '^\s*\%(//\|#\|/\*.*\*/\s*$\)'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
477 if b:PHP_LastIndentedWasComment == 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
478 return indent(real_PHP_lastindented)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
479 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
480 let b:PHP_LastIndentedWasComment = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
481 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
482 let b:PHP_LastIndentedWasComment = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
483 endif " }}}
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
484
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
485 " Indent multiline /* comments correctly {{{
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
486
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
487 if b:PHP_InsideMultilineComment || b:UserIsTypingComment
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
488 if cline =~ '^\s*\*\%(\/\)\@!'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
489 if last_line =~ '^\s*/\*'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
490 return indent(lnum) + 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
491 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
492 return indent(lnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
493 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
494 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
495 let b:PHP_InsideMultilineComment = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
496 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
497 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
498
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
499 if !b:PHP_InsideMultilineComment && cline =~ '^\s*/\*' && cline !~ '\*/\s*$'
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
500 if getline(v:lnum + 1) !~ '^\s*\*'
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
501 return -1
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
502 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
503 let b:PHP_InsideMultilineComment = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
504 endif " }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
505
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
506
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
507 " Things always indented at col 1 (PHP delimiter: <?, ?>, Heredoc end) {{{
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
508 if cline =~# '^\s*<?' && cline !~ '?>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
509 return 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
510 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
511
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
512 if cline =~ '^\s*?>' && cline !~# '<?'
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
513 return 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
514 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
515
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
516 if cline =~? '^\s*\a\w*;$' && cline !~? s:notPhpHereDoc
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
517 return 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
518 endif " }}}
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
519
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
520 let s:level = 0
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
521
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
522 let lnum = GetLastRealCodeLNum(v:lnum - 1)
631
68a196b7504d updated for version 7.0182
vimboss
parents: 557
diff changeset
523
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
524 let last_line = getline(lnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
525 let ind = indent(lnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
526 let endline= s:endline
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
527
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
528 if ind==0 && b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
529 let ind = b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
530 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
531
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
532 if lnum == 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
533 return b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
534 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
535
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
536
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
537 if cline =~ '^\s*}\%(}}\)\@!'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
538 let ind = indent(FindOpenBracket(v:lnum))
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
539 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
540 return ind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
541 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
542
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
543 if cline =~ '^\s*\*/'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
544 call cursor(v:lnum, 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
545 if cline !~ '^\*/'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
546 call search('\*/', 'W')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
547 endif
557
862863033fdd updated for version 7.0158
vimboss
parents: 532
diff changeset
548 let lnum = searchpair('/\*', '', '\*/', s:searchpairflags, 'Skippmatch2()')
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
549
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
550 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
551
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
552 if cline =~ '^\s*\*/'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
553 return indent(lnum) + 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
554 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
555 return indent(lnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
556 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
557 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
558
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
559 let defaultORcase = '^\s*\%(default\|case\).*:'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
560
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
561 if last_line =~ '[;}]'.endline && last_line !~# defaultORcase
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
562 if ind==b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
563 return b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
564 elseif b:PHP_indentinghuge && ind==b:PHP_CurrentIndentLevel && cline !~# '^\s*\%(else\|\%(case\|default\).*:\|[})];\=\)' && last_line !~# '^\s*\%(\%(}\s*\)\=else\)' && getline(GetLastRealCodeLNum(lnum - 1))=~';'.endline
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
565 return b:PHP_CurrentIndentLevel
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
566 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
567 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
568
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
569 let LastLineClosed = 0
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
570
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
571 let terminated = '\%(;\%(\s*?>\)\=\|<<<\a\w*\|}\)'.endline
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
572
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
573 let unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.endline
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
574
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
575 if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
576 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
577 return indent(FindTheIfOfAnElse(v:lnum, 1))
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
578 elseif cline =~ '^\s*{'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
579 let previous_line = last_line
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
580 let last_line_num = lnum
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
581
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
582 while last_line_num > 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
583
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
584 if previous_line =~ '^\s*\%(' . s:blockstart . '\|\%([a-zA-Z]\s*\)*function\)' && previous_line !~ '^\s*[|&]'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
585
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
586 let ind = indent(last_line_num)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
587
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
588 if b:PHP_BracesAtCodeLevel
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
589 let ind = ind + &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
590 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
591
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
592 return ind
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
593 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
594
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
595 let last_line_num = last_line_num - 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
596 let previous_line = getline(last_line_num)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
597 endwhile
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
598
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
599 elseif last_line =~# unstated && cline !~ '^\s*{\|^\s*);\='.endline
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
600 let ind = ind + &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
601 return ind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
602
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
603 elseif ind != b:PHP_default_indenting && last_line =~ terminated
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
604 let previous_line = last_line
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
605 let last_line_num = lnum
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
606 let LastLineClosed = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
607
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
608 while 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
609 if previous_line =~ '^\s*}'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
610 let last_line_num = FindOpenBracket(last_line_num)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
611
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
612 if getline(last_line_num) =~ '^\s*{'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
613 let last_line_num = GetLastRealCodeLNum(last_line_num - 1)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
614 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
615
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
616 let previous_line = getline(last_line_num)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
618 continue
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
619 else
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
620
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
621 if getline(last_line_num) =~# '^\s*else\%(if\)\=\>'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
622 let last_line_num = FindTheIfOfAnElse(last_line_num, 0)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
623 continue
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
624 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
625
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
626
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
627 let last_match = last_line_num
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
628
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
629 let one_ahead_indent = indent(last_line_num)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
630 let last_line_num = GetLastRealCodeLNum(last_line_num - 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
631 let two_ahead_indent = indent(last_line_num)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
632 let after_previous_line = previous_line
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
633 let previous_line = getline(last_line_num)
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
634
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
635
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
636 if previous_line =~# defaultORcase.'\|{'.endline
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
637 break
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
638 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
639
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
640 if after_previous_line=~# '^\s*'.s:blockstart.'.*)'.endline && previous_line =~# '[;}]'.endline
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
641 break
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
643
856
8cd729851562 updated for version 7.0g
vimboss
parents: 631
diff changeset
644 if one_ahead_indent == two_ahead_indent || last_line_num < 1
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
645 if previous_line =~# '[;}]'.endline || last_line_num < 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
646 break
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
647 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
648 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
649 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
650 endwhile
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
651
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
652 if indent(last_match) != ind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
653 let ind = indent(last_match)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
654 let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
655
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
656 if cline =~# defaultORcase
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
657 let ind = ind - &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
658 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
659 return ind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
660 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
661 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
662
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
663 let plinnum = GetLastRealCodeLNum(lnum - 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
664 let pline = getline(plinnum)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
665
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
666 let last_line = substitute(last_line,"\\(//\\|#\\)\\(\\(\\([^\"']*\\([\"']\\)[^\"']*\\5\\)\\+[^\"']*$\\)\\|\\([^\"']*$\\)\\)",'','')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
667
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
668
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
669 if ind == b:PHP_default_indenting
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
670 if last_line =~ terminated
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
671 let LastLineClosed = 1
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
672 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
673 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
674
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
675 if !LastLineClosed
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
676
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
677 if last_line =~# '[{(]'.endline || last_line =~? '\h\w*\s*(.*,$' && pline !~ '[,(]'.endline
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
678
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
679 if !b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{'
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
680 let ind = ind + &sw
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
681 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
682
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
683 if b:PHP_BracesAtCodeLevel || cline !~# defaultORcase
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
684 let b:PHP_CurrentIndentLevel = ind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
685 return ind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
686 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
687
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
688 elseif last_line =~ '\S\+\s*),'.endline
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
689 call cursor(lnum, 1)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
690 call search('),'.endline, 'W')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
691 let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
692 if openedparent != lnum
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
693 let ind = indent(openedparent)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
694 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
695
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
696
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
697 elseif cline !~ '^\s*{' && pline =~ '\%(;\%(\s*?>\)\=\|<<<\a\w*\|{\|^\s*'.s:blockstart.'\s*(.*)\)'.endline.'\|^\s*}\|'.defaultORcase
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
698
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
699 let ind = ind + &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
700
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
701 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
703 elseif last_line =~# defaultORcase
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
704 let ind = ind + &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
705 endif
409
e6fd82f42ba0 updated for version 7.0107
vimboss
parents: 227
diff changeset
706
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
707 if cline =~ '^\s*);\='
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
708 let ind = ind - &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
709 elseif cline =~# defaultORcase
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
710 let ind = ind - &sw
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
711
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
712 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
713
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
714 let b:PHP_CurrentIndentLevel = ind
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 481
diff changeset
715 return ind
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 endfunction