Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if exists("b:did_indent")
- finish
- endif
- function! s:CountMatches(line, pats)
- let matches = 0
- for p in a:pats
- let idx = 0
- while idx >= 0
- let idx = match(a:line, p, idx)
- if idx > 0
- let matches = matches + 1
- let idx = idx + strlen(p)
- endif
- endwhile
- endfor
- return matches
- endfunction
- function! GetMyrIndent(ln)
- let ln = a:ln
- if ln == 1
- let ind = 0
- else
- let prevln = getline(ln - 1)
- let curln = getline(ln)
- let inpat = ['if','while','for',
- \ 'pkg','trait',
- \ 'struct', 'union',
- \ '{', ':\s*$']
- let outpat = ['}',';;']
- let outalone = '^\(\s*}\s*\|\s*;;\s*\)$'
- let ind = indent(ln - 1)
- let width = &tabstop
- let n_in = s:CountMatches(prevln, inpat)
- let n_out = s:CountMatches(prevln, outpat)
- if curln =~ outalone
- let ind = ind - &tabstop
- elseif prevln !~ outalone
- let ind = ind + (n_in - n_out) * &tabstop
- endif
- endif
- return ind
- endfunction
- set indentkeys+=0},;
- set indentexpr=GetMyrIndent(v:lnum)
- let b:did_indent = 1
Add Comment
Please, Sign In to add comment