summaryrefslogblamecommitdiffstats
path: root/indent/odin.vim
blob: 6cd93a9acacde33936b34a3e454fb28692be4c6e (plain) (tree)
1
2
3
4
5




                                                                                                                                








































                                                                             
let files = filter(globpath(&rtp, 'indent/odin.vim', 1, 1), { _, v -> v !~ "vim-polyglot" && v !~ $VIMRUNTIME && v !~ "after" })
if len(files) > 0
  exec 'source ' . files[0]
  finish
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'odin') == -1

if exists("b:did_indent")
  finish
endif
let b:did_indent = 1

setlocal nosmartindent
setlocal nolisp
setlocal autoindent

setlocal indentexpr=GetOdinIndent(v:lnum)

if exists("*GetOdinIndent")
  finish
endif

function! GetOdinIndent(lnum)
  let prev = prevnonblank(a:lnum-1)

  if prev == 0
    return 0
  endif

  let prevline = getline(prev)
  let line = getline(a:lnum)

  let ind = indent(prev)

  if prevline =~ '[({]\s*$'
    let ind += &sw
  endif

  if line =~ '^\s*[)}]'
    let ind -= &sw
  endif

  return ind
endfunction

endif