Skip to content

Commit d08477a

Browse files
committed
Almost, mostly working
1 parent 768e5e9 commit d08477a

File tree

1 file changed

+52
-23
lines changed

1 file changed

+52
-23
lines changed

autoload/elixir/indent.vim

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -372,36 +372,65 @@ 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 Surface data delimiters
376+
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]))
376377
if pair_lnum
377-
if a:context.text =~ '<[^\/%].*>.*<\/.*[^\/%]>$'
378-
call s:debug("open and close tags are on the same line")
379-
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")
378+
if a:context.text =~ '}}$'
379+
return -1
380+
else
391381
return indent(pair_lnum) + s:sw()
392-
elseif s:prev_ends_with(a:context, ',')
393-
call s:debug("multiline opening eex")
382+
endif
383+
endif
384+
385+
" Multi-line opening tag -- >, />, or %> are on a different line that their opening <
386+
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]))
387+
if pair_lnum
388+
if a:context.text =~ '^\s\+\%\(>\|\/>\|%>\|}}>\)$'
389+
call s:debug("current line is alone >, />, or %>")
394390
return indent(pair_lnum)
395-
elseif a:context.text =~ '<\/.\+ \/>'
396-
call s:debug("self-closing tag")
391+
elseif a:context.text =~ '\%\(>\|\/>\|%>\|}}>\)$'
392+
call s:debug("current line ends in >, />, or %>")
393+
return -1
394+
else
395+
call s:debug("in the body of a multi-line opening tag")
396+
return indent(pair_lnum) + s:sw()
397+
endif
398+
endif
399+
400+
" Special cases
401+
if a:context.prev_nb_text =~ '^\s\+<[^%\/]*[^/]>.*<\/[a-zA-Z0-9\.\-_]\+>$'
402+
call s:debug("opening and closing tags are on the same line")
403+
return indent(a:context.prev_nb_lnum)
404+
elseif s:prev_ends_with(a:context, '^\s\+\/>')
405+
call s:debug("prev line is a single \>")
406+
return indent(a:context.prev_nb_lnum)
407+
elseif s:prev_ends_with(a:context, '^[^<]*\/>')
408+
call s:debug("prev line is closing a multi-line self-closing tag")
409+
return indent(a:context.prev_nb_lnum) - s:sw()
410+
elseif a:context.prev_nb_text =~ '^\s\+>$'
411+
call s:debug("prev line is a single >")
412+
return indent(a:context.prev_nb_lnum) + s:sw()
413+
elseif a:context.text =~ '^\s\+<\/[a-zA-Z0-9\.\-_]\+>'
414+
call s:debug("a single closing tag")
415+
if a:context.prev_nb_text =~ '^\s\+<[^%\/]*[^/]>\|\s\+>'
416+
return indent(a:context.prev_nb_lnum)
417+
else
418+
return indent(a:context.prev_nb_lnum) - s:sw()
419+
endif
420+
endif
421+
422+
" Regular old HTML
423+
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]))
424+
if pair_lnum
425+
call s:debug("regular old html")
426+
if a:context.text =~ '^\s\+<\/\w\+>$'
397427
return indent(pair_lnum)
398428
else
399-
call debug("normal")
400-
return -2
429+
return indent(pair_lnum) + s:sw()
401430
endif
402-
else
403-
return -1
404431
endif
432+
433+
return -1
405434
endfunction
406435

407436
function! elixir#indent#handle_inside_generic_block(context)

0 commit comments

Comments
 (0)