Skip to content

Commit

Permalink
Almost, mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
sodapopcan committed Mar 6, 2021
1 parent 768e5e9 commit d08477a
Showing 1 changed file with 52 additions and 23 deletions.
75 changes: 52 additions & 23 deletions autoload/elixir/indent.vim
Original file line number Diff line number Diff line change
Expand Up @@ -372,36 +372,65 @@ function! elixir#indent#handle_inside_embedded_view(context)
return -1
endif

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]))
" Multi-line Surface data delimiters
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]))
if pair_lnum
if a:context.text =~ '<[^\/%].*>.*<\/.*[^\/%]>$'
call s:debug("open and close tags are on the same line")
return indent(pair_lnum)
elseif a:context.text =~ '<\/.*[^%\/]>'
call s:debug("a close tag")
return indent(pair_lnum)
elseif a:context.text =~ '^\s\+\/\?>$'
call s:debug("a lone >")
return indent(pair_lnum)
elseif a:context.prev_nb_text =~ '\s\+<[^%\/].*>$'
call s:debug("single open tag")
return indent(pair_lnum) + s:sw()
elseif a:context.prev_nb_text =~ '\s\+<[^%\/].*[^>]$'
call s:debug("multiline opening tag")
if a:context.text =~ '}}$'
return -1
else
return indent(pair_lnum) + s:sw()
elseif s:prev_ends_with(a:context, ',')
call s:debug("multiline opening eex")
endif
endif

" Multi-line opening tag -- >, />, or %> are on a different line that their opening <
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]))
if pair_lnum
if a:context.text =~ '^\s\+\%\(>\|\/>\|%>\|}}>\)$'
call s:debug("current line is alone >, />, or %>")
return indent(pair_lnum)
elseif a:context.text =~ '<\/.\+ \/>'
call s:debug("self-closing tag")
elseif a:context.text =~ '\%\(>\|\/>\|%>\|}}>\)$'
call s:debug("current line ends in >, />, or %>")
return -1
else
call s:debug("in the body of a multi-line opening tag")
return indent(pair_lnum) + s:sw()
endif
endif

" Special cases
if a:context.prev_nb_text =~ '^\s\+<[^%\/]*[^/]>.*<\/[a-zA-Z0-9\.\-_]\+>$'
call s:debug("opening and closing tags are on the same line")
return indent(a:context.prev_nb_lnum)
elseif s:prev_ends_with(a:context, '^\s\+\/>')
call s:debug("prev line is a single \>")
return indent(a:context.prev_nb_lnum)
elseif s:prev_ends_with(a:context, '^[^<]*\/>')
call s:debug("prev line is closing a multi-line self-closing tag")
return indent(a:context.prev_nb_lnum) - s:sw()
elseif a:context.prev_nb_text =~ '^\s\+>$'
call s:debug("prev line is a single >")
return indent(a:context.prev_nb_lnum) + s:sw()
elseif a:context.text =~ '^\s\+<\/[a-zA-Z0-9\.\-_]\+>'
call s:debug("a single closing tag")
if a:context.prev_nb_text =~ '^\s\+<[^%\/]*[^/]>\|\s\+>'
return indent(a:context.prev_nb_lnum)
else
return indent(a:context.prev_nb_lnum) - s:sw()
endif
endif

" Regular old HTML
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]))
if pair_lnum
call s:debug("regular old html")
if a:context.text =~ '^\s\+<\/\w\+>$'
return indent(pair_lnum)
else
call debug("normal")
return -2
return indent(pair_lnum) + s:sw()
endif
else
return -1
endif

return -1
endfunction

function! elixir#indent#handle_inside_generic_block(context)
Expand Down

0 comments on commit d08477a

Please sign in to comment.