Files
kyn/.vim/indent/kyn.vim

53 lines
1.0 KiB
VimL

" Vim indent file
" Language: Kyn
" Maintainer: Gemini
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal indentexpr=GetKynIndent()
setlocal indentkeys+=={,},0)
let b:undo_indent = "setlocal indentexpr< indentkeys<"
" Only define the function once
if exists("*GetKynIndent")
finish
endif
function GetKynIndent()
" Get the line number of the current line
let lnum = v:lnum
" Get the current line
let cline = getline(lnum)
" If the current line has a '}', decrease indent
if cline =~ '^\s*}'
let lnum = prevnonblank(lnum - 1)
return indent(lnum)
endif
" Find the previous non-blank line
let lnum = prevnonblank(lnum - 1)
" At the start of the file, no indent
if lnum == 0
return 0
endif
" Get the indent of the previous line
let prev_indent = indent(lnum)
let prev_line = getline(lnum)
" If the previous line ends with '{', increase indent
if prev_line =~ '{\s*$'
return prev_indent + &shiftwidth
endif
" Otherwise, keep the same indent
return prev_indent
endfunction