summaryrefslogtreecommitdiffstats
path: root/indent/eelixir.vim
diff options
context:
space:
mode:
Diffstat (limited to 'indent/eelixir.vim')
-rw-r--r--indent/eelixir.vim72
1 files changed, 72 insertions, 0 deletions
diff --git a/indent/eelixir.vim b/indent/eelixir.vim
new file mode 100644
index 00000000..7b17c104
--- /dev/null
+++ b/indent/eelixir.vim
@@ -0,0 +1,72 @@
+" Vim indent file
+" Language: Embedded Elixir
+" URL: https://github.com/elixir-lang/vim-elixir
+
+
+if exists("b:did_indent")
+ finish
+endif
+
+runtime! indent/elixir.vim
+unlet! b:did_indent
+setlocal indentexpr=
+
+if exists("b:eelixir_subtype")
+ exe "runtime! indent/".b:eelixir_subtype.".vim"
+else
+ runtime! indent/html.vim
+endif
+unlet! b:did_indent
+
+if &l:indentexpr == ''
+ if &l:cindent
+ let &l:indentexpr = 'cindent(v:lnum)'
+ else
+ let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'
+ endif
+endif
+let b:eelixir_subtype_indentexpr = &l:indentexpr
+
+let b:did_indent = 1
+
+setlocal indentexpr=GetEelixirIndent()
+setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=else,=elsif,=catch,=after,=rescue
+
+" Only define the function once.
+if exists("*GetEelixirIndent")
+ finish
+endif
+
+function! GetEelixirIndent(...)
+ if a:0 && a:1 == '.'
+ let v:lnum = line('.')
+ elseif a:0 && a:1 =~ '^\d'
+ let v:lnum = a:1
+ endif
+ let vcol = col('.')
+ call cursor(v:lnum,1)
+ let inelixir = searchpair('<%','','%>','W')
+ call cursor(v:lnum,vcol)
+ if inelixir && getline(v:lnum) !~ '^<%\|^\s*%>'
+ let ind = GetElixirIndent()
+ else
+ exe "let ind = ".b:eelixir_subtype_indentexpr
+ endif
+ let lnum = prevnonblank(v:lnum-1)
+ let line = getline(lnum)
+ let cline = getline(v:lnum)
+ if cline =~# '^\s*<%\s*\%(end\|else\|elsif\|catch\|after\|rescue\)\>.*%>'
+ let ind = ind - &sw
+ elseif line =~# '\S\s*<%\s*end\s*%>'
+ let ind = ind - &sw
+ endif
+ if line =~# '<%[=%]\=\s*.*\<do\s*%>'
+ let ind = ind + &sw
+ elseif line =~# '<%\s*\%(else\|elsif\|catch\|after\|rescue\)\>.*%>'
+ let ind = ind + &sw
+ endif
+ if cline =~# '^\s*%>\s*$'
+ let ind = ind - &sw
+ endif
+ return ind
+endfunction