dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 55bc65ad56cfc2a619464de94e8cecd82b3f793c
parent 881bd25be28f5b5a57482d28b68a61d9990901f9
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 15 Jan 2022 13:03:34 +0000

.c/n/i/rcshell.vim: add rc indent file

Diffstat:
A.config/nvim/indent/rcshell.vim | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+), 0 deletions(-)

diff --git a/.config/nvim/indent/rcshell.vim b/.config/nvim/indent/rcshell.vim @@ -0,0 +1,59 @@ +" Vim indent file +" Language: rc +" Maintainer: hhvn <dev@hhvn.uk> +" License: This file is placed in the public domain. +" +" Written by hhvn. + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetRcIndent() + +if exists("GetRcIndent") + finish +endif + +function! GetRcIndent() + let lnum = prevnonblank(v:lnum - 1) + let pnum = prevnonblank(lnum - 1) + + if lnum == 0 + return 0 + endif + + let prevline = getline(pnum) + let line = getline(lnum) + let indent = indent(lnum) + let origindent = indent + + let braces = s:Get_brace_balance(line, '{', '}') + let indent += braces * &sw + + let braces = s:Get_brace_balance(line, '(', ')') + let indent += braces * &sw + + if line =~ '[|\\]\s*$' + if prevline =~ '[|\\]\s*$' + let indent += 0 + elseif origindent == indent + let indent += &sw + endif + endif + + " Todo: have ending braces automatically + " unindented like cindent + + return indent +endfunction + +" Taken from awk indenter +function! s:Get_brace_balance( line, b_open, b_close ) + let line2 = substitute( a:line, a:b_open, "", "g" ) + let openb = strlen( a:line ) - strlen( line2 ) + let line3 = substitute( line2, a:b_close, "", "g" ) + let closeb = strlen( line2 ) - strlen( line3 ) + return openb - closeb +endfunction