Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a016bc

Browse files
committedMar 4, 2021
WIP
1 parent 768e5e9 commit 1a016bc

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed
 

Diff for: ‎autoload/elixir/indent.vim

+32-23
Original file line numberDiff line numberDiff line change
@@ -372,36 +372,45 @@ function! elixir#indent#handle_inside_embedded_view(context)
372372
return -1
373373
endif
374374

375-
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]))
375+
" Multi-line opening tag -- >, />, or %> are on a different line that their opening <
376+
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]))
376377
if pair_lnum
377-
if a:context.text =~ '<[^\/%].*>.*<\/.*[^\/%]>$'
378-
call s:debug("open and close tags are on the same line")
378+
if a:context.text =~ '^\s\+\%\(>\|\/>\|%>\)$'
379+
call s:debug("current line is alone >, />, or %>")
379380
return indent(pair_lnum)
380-
elseif a:context.text =~ '<\/.*[^%\/]>'
381-
call s:debug("a close tag")
382-
return indent(pair_lnum)
383-
elseif a:context.text =~ '^\s\+\/\?>$'
384-
call s:debug("a lone >")
385-
return indent(pair_lnum)
386-
elseif a:context.prev_nb_text =~ '\s\+<[^%\/].*>$'
387-
call s:debug("single open tag")
388-
return indent(pair_lnum) + s:sw()
389-
elseif a:context.prev_nb_text =~ '\s\+<[^%\/].*[^>]$'
390-
call s:debug("multiline opening tag")
381+
elseif a:context.text =~ '\%\(>\|\/>\|%>\)$'
382+
call s:debug("current line ends in >, />, or %>")
383+
return -1
384+
else
385+
call s:debug("in the body of a multi-line opening tag")
391386
return indent(pair_lnum) + s:sw()
392-
elseif s:prev_ends_with(a:context, ',')
393-
call s:debug("multiline opening eex")
394-
return indent(pair_lnum)
395-
elseif a:context.text =~ '<\/.\+ \/>'
396-
call s:debug("self-closing tag")
387+
endif
388+
endif
389+
390+
" Special cases
391+
" if s:prev_ends_with(a:context, '^\s\+\/>\|<\/.*>')
392+
if s:prev_ends_with(a:context, '^[^<]*\/>')
393+
call s:debug("prev line is closing a multi-line self-closing tag")
394+
return indent(a:context.prev_nb_lnum) - s:sw()
395+
elseif s:prev_ends_with(a:context, '\/>\|<\/\w\+>')
396+
call s:debug("prev line is any other kind of closing tag")
397+
return indent(a:context.prev_nb_lnum)
398+
elseif s:prev_ends_with(a:context, '^\s\+>')
399+
call s:debug("prev line is a single >")
400+
return indent(a:context.prev_nb_lnum) + s:sw()
401+
endif
402+
403+
" Regular old HTML
404+
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]))
405+
if pair_lnum
406+
if a:context.text =~ '^\s\+<\/\w\+>$'
397407
return indent(pair_lnum)
398408
else
399-
call debug("normal")
400-
return -2
409+
return indent(pair_lnum) + s:sw()
401410
endif
402-
else
403-
return -1
404411
endif
412+
413+
return -1
405414
endfunction
406415

407416
function! elixir#indent#handle_inside_generic_block(context)

0 commit comments

Comments
 (0)
Please sign in to comment.