summaryrefslogtreecommitdiffstats
path: root/indent/odin.vim
blob: b00b538771708a4b9ebf9965a0c92f83bba0936e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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