robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
75157d2572
master
1" Vim indent file 2" Language: Liquid 3" Maintainer: Tim Pope <vimNOSPAM@tpope.org> 4" Last Change: 2022 Mar 15 5 6if exists ( 'b:did_indent' ) 7finish 8endif 9 10set indentexpr = 11if exists ( 'b:liquid_subtype' ) 12exe 'runtime! indent/' . b: liquid_subtype . '.vim' 13else 14runtime ! indent/html.vim 15endif 16unlet ! b: did_indent 17 18if & l: indentexpr == '' 19if & l: cindent 20let & l: indentexpr = 'cindent(v:lnum)' 21else 22let & l: indentexpr = 'indent(prevnonblank(v:lnum-1))' 23endif 24endif 25let b: liquid_subtype_indentexpr = & l: indentexpr 26 27let b: did_indent = 1 28 29setlocal indentexpr = GetLiquidIndent () 30setlocal indentkeys = o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=end,=endif,=endunless,=endifchanged,=endcase,=endfor,=endtablerow,=endcapture,=else,=elsif,=when,=empty 31 32let b: undo_indent = "setl inde< indk<" 33 34" Only define the function once. 35if exists ( '*GetLiquidIndent' ) 36finish 37endif 38 39function ! s: count ( string , pattern ) abort 40let string = substitute ( a: string , '\C' . a: pattern , "\n" , 'g' ) 41return strlen ( substitute ( string , "[^\n]" , '' , 'g' )) 42endfunction 43 44function ! GetLiquidIndent (...) abort 45if a: 0 && a: 1 == '.' 46let v: lnum = line ( '.' ) 47elseif a: 0 && a: 1 =~ '^\d' 48let v: lnum = a: 1 49endif 50let vcol = col ( '.' ) 51call cursor ( v: lnum , 1 ) 52exe "let ind = " . b: liquid_subtype_indentexpr 53let lnum = prevnonblank ( v: lnum - 1 ) 54let line = getline ( lnum ) 55let cline = getline ( v: lnum ) 56let line = substitute ( line , '\C^\%(\s*{%-\=\s*end\w*\s*-\=%}\)\+' , '' , '' ) 57let line = substitute ( line , '\C\%(\s*{%-\=\s*if.\+-\=%}.\+{%-\=\s*endif\s*-\=%}\)\+' , '' , 'g' ) 58let line .= matchstr ( cline , '\C^\%(\s*{%-\=\s*end\w*\s*-\=%}\)\+' ) 59let cline = substitute ( cline , '\C^\%(\s*{%-\=\s*end\w*\s*-\=%}\)\+' , '' , '' ) 60let sw = shiftwidth () 61let ind += sw * s: count ( line , '{%-\=\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>' ) 62let ind -= sw * s: count ( line , '{%-\=\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>' ) 63let ind -= sw * s: count ( cline , '{%-\=\s*\%(elsif\|else\|when\|empty\)\>' ) 64let ind -= sw * s: count ( cline , '{%-\=\s*end\w*$' ) 65return ind 66endfunction