robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0c2a7aa5f7
master
1" Vim indent file 2" Language: Autoconf configure.{ac,in} file 3" Maintainer: Doug Kearns <dougkearns@gmail.com> 4" Previous Maintainer: Nikolai Weibull <now@bitwi.se> 5" Last Change: 24 Sep 2021 6 7" TODO: how about nested [()]'s in one line what's wrong with '\\\@!'? 8 9" Only load this indent file when no other was loaded. 10if exists ( "b:did_indent" ) 11finish 12endif 13 14runtime ! indent/sh.vim " will set b:did_indent 15 16setlocal indentexpr = GetConfigIndent () 17setlocal indentkeys = !^F,o,O,=then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done 18setlocal nosmartindent 19 20let b: undo_indent = "setl inde< indk< si<" 21 22" Only define the function once. 23if exists ( "*GetConfigIndent" ) 24finish 25endif 26 27" get the offset (indent) of the end of the match of 'regexp' in 'line' 28function s: GetOffsetOf ( line , regexp ) 29let end = matchend ( a: line , a: regexp ) 30let width = 0 31let i = 0 32while i < end 33if a: line [ i ] != "\t" 34let width = width + 1 35else 36let width = width + & ts - ( width % & ts ) 37endif 38let i = i + 1 39endwhile 40return width 41endfunction 42 43function GetConfigIndent () 44" Find a non-blank line above the current line. 45let lnum = prevnonblank ( v: lnum - 1 ) 46 47" Hit the start of the file, use zero indent. 48if lnum == 0 49return 0 50endif 51 52" where to put this 53let ind = GetShIndent () 54let line = getline ( lnum ) 55 56" if previous line has unmatched, unescaped opening parentheses, 57" indent to its position. TODO: not failsafe if multiple ('s 58if line =~ '\\\@<!([^)]*$' 59let ind = s: GetOffsetOf ( line , '\\\@!(' ) 60endif 61 62" if previous line has unmatched opening bracket, 63" indent to its position. TODO: same as above 64if line =~ '\[[^]]*$' 65let ind = s: GetOffsetOf ( line , '\[' ) 66endif 67 68" if previous line had an unmatched closing parentheses, 69" indent to the matching opening parentheses 70if line =~ '[^(]\+\\\@<!)$' 71call search ( ')' , 'bW' ) 72let lnum = searchpair ( '\\\@<!(' , '' , ')' , 'bWn' ) 73let ind = indent ( lnum ) 74endif 75 76" if previous line had an unmatched closing bracket, 77" indent to the matching opening bracket 78if line =~ '[^[]\+]$' 79call search ( ']' , 'bW' ) 80let lnum = searchpair ( '\[' , '' , ']' , 'bWn' ) 81let ind = indent ( lnum ) 82endif 83 84return ind 85endfunction