@@ -20,6 +20,7 @@ function! elixir#indent#indent(lnum)
20
20
call cursor (lnum, 0 )
21
21
22
22
let handlers = [
23
+ \' inside_embedded_view',
23
24
\' top_of_file',
24
25
\' starts_with_string_continuation',
25
26
\' following_trailing_binary_operator',
@@ -65,6 +66,17 @@ function! s:prev_starts_with(context, expr)
65
66
return s: _starts_with (a: context .prev_nb_text, a: expr , a: context .prev_nb_lnum)
66
67
endfunction
67
68
69
+ function ! s: in_embedded_view ()
70
+ let groups = map (synstack (line (' .' ), col (' .' )), " synIDattr(v:val, 'name')" )
71
+ for group in [' elixirPhoenixESigil' , ' elixirLiveViewSigil' , ' elixirSurfaceSigil' ]
72
+ if index (groups, group) >= 0
73
+ return 1
74
+ endif
75
+ endfor
76
+
77
+ return 0
78
+ endfunction
79
+
68
80
" Returns 0 or 1 based on whether or not the text starts with the given
69
81
" expression and is not a string or comment
70
82
function ! s: _starts_with (text, expr , lnum)
@@ -156,6 +168,95 @@ function! s:find_last_pos(lnum, text, match)
156
168
return -1
157
169
endfunction
158
170
171
+ function ! elixir#indent#handle_inside_embedded_view (context)
172
+ if ! s: in_embedded_view ()
173
+ return -1
174
+ endif
175
+
176
+ " Multi-line Surface data delimiters
177
+ let pair_lnum = searchpair (' {{' , ' ' , ' }}' , ' bW' , " line('.') == " .a: context .lnum." || s:is_string_or_comment(line('.'), col('.'))" , max ([0 , a: context .lnum - g: elixir_indent_max_lookbehind ]))
178
+ if pair_lnum
179
+ if a: context .text = ~ ' }}$'
180
+ return -1
181
+ else
182
+ return indent (pair_lnum) + s: sw ()
183
+ endif
184
+ endif
185
+
186
+ " Multi-line opening tag -- >, />, or %> are on a different line that their opening <
187
+ let pair_lnum = searchpair (' ^\s\+<.*[^>]$' , ' ' , ' ^[^<]*[/%}]\?>$' , ' bW' , " line('.') == " .a: context .lnum." || s:is_string_or_comment(line('.'), col('.'))" , max ([0 , a: context .lnum - g: elixir_indent_max_lookbehind ]))
188
+ if pair_lnum
189
+ if a: context .text = ~ ' ^\s\+\%\(>\|\/>\|%>\|}}>\)$'
190
+ call s: debug (" current line is a lone >, />, or %>" )
191
+ return indent (pair_lnum)
192
+ elseif a: context .text = ~ ' \%\(>\|\/>\|%>\|}}>\)$'
193
+ call s: debug (" current line ends in >, />, or %>" )
194
+ if s: prev_ends_with (a: context , ' ,' )
195
+ return indent (a: context .prev_nb_lnum)
196
+ else
197
+ return -1
198
+ endif
199
+ else
200
+ call s: debug (" in the body of a multi-line opening tag" )
201
+ return indent (pair_lnum) + s: sw ()
202
+ endif
203
+ endif
204
+
205
+ " Special cases
206
+ if s: prev_ends_with (a: context , ' ^[^<]*do\s%>' )
207
+ call s: debug (" prev line closes a multi-line do block" )
208
+ return indent (a: context .prev_nb_lnum)
209
+ elseif a: context .prev_nb_text = ~ ' do\s*%>$'
210
+ call s: debug (" prev line opens a do block" )
211
+ return indent (a: context .prev_nb_lnum) + s: sw ()
212
+ elseif a: context .text = ~ ' ^\s\+<\/[a-zA-Z0-9\.\-_]\+>\|<% end %>'
213
+ call s: debug (" a single closing tag" )
214
+ if a: context .prev_nb_text = ~ ' ^\s\+<[^%\/]*[^/]>.*<\/[a-zA-Z0-9\.\-_]\+>$'
215
+ call s: debug (" opening and closing tags are on the same line" )
216
+ return indent (a: context .prev_nb_lnum) - s: sw ()
217
+ elseif a: context .prev_nb_text = ~ ' ^\s\+<[^%\/]*[^/]>\|\s\+>'
218
+ call s: debug (" prev line is opening html tag or single >" )
219
+ return indent (a: context .prev_nb_lnum)
220
+ elseif s: prev_ends_with (a: context , ' ^[^<]*\%\(do\s\)\@<!%>' )
221
+ call s: debug (" prev line closes a multi-line eex tag" )
222
+ return indent (a: context .prev_nb_lnum) - 2 * s: sw ()
223
+ else
224
+ return indent (a: context .prev_nb_lnum) - s: sw ()
225
+ endif
226
+ elseif a: context .text = ~ ' ^\s*<%\s*\%(end\|else\|catch\|rescue\)\>.*%>'
227
+ call s: debug (" eex middle or closing eex tag" )
228
+ return indent (a: context .prev_nb_lnum) - s: sw ()
229
+ elseif a: context .prev_nb_text = ~ ' \s*<\/\|<% end %>$'
230
+ call s: debug (" prev is closing tag" )
231
+ return indent (a: context .prev_nb_lnum)
232
+ elseif a: context .prev_nb_text = ~ ' ^\s\+<[^%\/]*[^/]>.*<\/[a-zA-Z0-9\.\-_]\+>$'
233
+ call s: debug (" opening and closing tags are on the same line" )
234
+ return indent (a: context .prev_nb_lnum)
235
+ elseif s: prev_ends_with (a: context , ' \s\+\/>' )
236
+ call s: debug (" prev ends with a single \> " )
237
+ return indent (a: context .prev_nb_lnum)
238
+ elseif s: prev_ends_with (a: context , ' ^[^<]*\/>' )
239
+ call s: debug (" prev line is closing a multi-line self-closing tag" )
240
+ return indent (a: context .prev_nb_lnum) - s: sw ()
241
+ elseif a: context .prev_nb_text = ~ ' ^\s\+%\?>$'
242
+ call s: debug (" prev line is a single > or %>" )
243
+ return indent (a: context .prev_nb_lnum) + s: sw ()
244
+ endif
245
+
246
+ " Simple HTML (ie, opening tag is not split across lines)
247
+ let pair_lnum = searchpair (' ^\s\+<[^%\/].*[^\/>]>$' , ' ' , ' ^\s\+<\/\w\+>$' , ' bW' , " line('.') == " .a: context .lnum." || s:is_string_or_comment(line('.'), col('.'))" , max ([0 , a: context .lnum - g: elixir_indent_max_lookbehind ]))
248
+ if pair_lnum
249
+ call s: debug (" simple HTML" )
250
+ if a: context .text = ~ ' ^\s\+<\/\w\+>$'
251
+ return indent (pair_lnum)
252
+ else
253
+ return indent (pair_lnum) + s: sw ()
254
+ endif
255
+ endif
256
+
257
+ return -1
258
+ endfunction
259
+
159
260
function ! elixir#indent#handle_top_of_file (context)
160
261
if a: context .prev_nb_lnum == 0
161
262
return 0
0 commit comments