2024-06-10 23:44:44 -07:00
|
|
|
" Vim indent file
|
|
|
|
" Language: KDL
|
|
|
|
" Author: Aram Drevekenin <aram@poor.dev>
|
|
|
|
" Maintainer: Yinzuo Jiang <jiangyinzuo@foxmail.com>
|
2024-06-16 02:30:17 -07:00
|
|
|
" Last Change: 2024-06-16
|
2024-06-10 23:44:44 -07:00
|
|
|
|
|
|
|
" Only load this indent file when no other was loaded.
|
|
|
|
if exists("b:did_indent")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let b:did_indent = 1
|
|
|
|
|
|
|
|
setlocal indentexpr=KdlIndent()
|
|
|
|
let b:undo_indent = "setlocal indentexpr<"
|
|
|
|
|
|
|
|
function! KdlIndent(...)
|
2024-06-16 02:30:17 -07:00
|
|
|
let line = substitute(getline(v:lnum), '//.*$', '', '')
|
2024-06-10 23:44:44 -07:00
|
|
|
let previousNum = prevnonblank(v:lnum - 1)
|
2024-06-16 02:30:17 -07:00
|
|
|
let previous = substitute(getline(previousNum), '//.*$', '', '')
|
2024-06-10 23:44:44 -07:00
|
|
|
|
2024-06-16 02:30:17 -07:00
|
|
|
let l:indent = indent(previousNum)
|
|
|
|
if previous =~ "{" && previous !~ "}"
|
|
|
|
let l:indent += shiftwidth()
|
2024-06-10 23:44:44 -07:00
|
|
|
endif
|
2024-06-16 02:30:17 -07:00
|
|
|
if line =~ "}" && line !~ "{"
|
|
|
|
let l:indent -= shiftwidth()
|
|
|
|
endif
|
|
|
|
return l:indent
|
2024-06-10 23:44:44 -07:00
|
|
|
endfunction
|
2024-06-16 02:30:17 -07:00
|
|
|
" vim: sw=2 sts=2 et
|