robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0c2a7aa5f7
master
1" Vim indent file 2" Language: CSS 3" Maintainer: Doug Kearns <dougkearns@gmail.com> 4" Previous Maintainer: Nikolai Weibull <now@bitwi.se> 5" Last Change: 24 Sep 2021 6 7" Use of shiftwidth() added by Oleg Zubchenko. 8 9if exists ( "b:did_indent" ) 10finish 11endif 12let b: did_indent = 1 13 14setlocal indentexpr = GetCSSIndent () 15setlocal indentkeys = 0{,0},!^F,o,O 16setlocal nosmartindent 17 18let b: undo_indent = "setl inde< indk< si<" 19 20if exists ( "*GetCSSIndent" ) 21finish 22endif 23let s: keepcpo = & cpo 24set cpo & vim 25 26function s: prevnonblanknoncomment ( lnum ) 27let lnum = a: lnum 28while lnum > 1 29let lnum = prevnonblank ( lnum ) 30let line = getline ( lnum ) 31if line =~ '\*/' 32while lnum > 1 && line !~ '/\*' 33let lnum -= 1 34endwhile 35if line =~ '^\s*/\*' 36let lnum -= 1 37else 38break 39endif 40else 41break 42endif 43endwhile 44return lnum 45endfunction 46 47function s: count_braces ( lnum , count_open ) 48let n_open = 0 49let n_close = 0 50let line = getline ( a: lnum ) 51let pattern = '[{}]' 52let i = match ( line , pattern ) 53while i != -1 54if synIDattr ( synID ( a: lnum , i + 1 , 0 ), 'name' ) !~ 'css\%(Comment\|StringQ\{1,2}\)' 55if line [ i ] == '{' 56let n_open += 1 57elseif line [ i ] == '}' 58if n_open > 0 59let n_open -= 1 60else 61let n_close += 1 62endif 63endif 64endif 65let i = match ( line , pattern , i + 1 ) 66endwhile 67return a: count_open ? n_open : n_close 68endfunction 69 70function GetCSSIndent () 71let line = getline ( v: lnum ) 72if line =~ '^\s*\*' 73return cindent ( v: lnum ) 74endif 75 76let pnum = s: prevnonblanknoncomment ( v: lnum - 1 ) 77if pnum == 0 78return 0 79endif 80 81return indent ( pnum ) + s: count_braces ( pnum , 1 ) * shiftwidth () 82 \- s: count_braces ( v: lnum , 0 ) * shiftwidth () 83endfunction 84 85let & cpo = s: keepcpo 86unlet s: keepcpo