robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
37596fcd29
master
1" Vim indent file 2" Language: Stylus 3" Maintainer: Marc Harter 4" Last Change: 2010 May 21 5" 2026 May 04 by Vim Project: fix typo 6" Based On: sass.vim from Tim Pope 7" 8if exists ( "b:did_indent" ) 9finish 10endif 11let b: did_indent = 1 12 13setlocal indentexpr = GetStylusIndent () 14setlocal indentkeys = o,O,*<Return>,},],0),!^F 15let b: undo_indent = "setl indentexpr< indentkeys<" 16 17if exists ( "*GetStylusIndent" ) " only define once 18finish 19endif 20 21function s: prevnonblanknoncomment ( lnum ) 22let lnum = a: lnum 23while lnum > 1 24let lnum = prevnonblank ( lnum ) 25let line = getline ( lnum ) 26if line =~ '\*/' 27while lnum > 1 && line !~ '/\*' 28let lnum -= 1 29endwhile 30if line =~ '^\s*/\*' 31let lnum -= 1 32else 33break 34endif 35else 36break 37endif 38endwhile 39return lnum 40endfunction 41 42function s: count_braces ( lnum , count_open ) 43let n_open = 0 44let n_close = 0 45let line = getline ( a: lnum ) 46let pattern = '[{}]' 47let i = match ( line , pattern ) 48while i != -1 49if synIDattr ( synID ( a: lnum , i + 1 , 0 ), 'name' ) !~ 'css\%(Comment\|StringQ\{1,2}\)' 50if line [ i ] == '{' 51let n_open += 1 52elseif line [ i ] == '}' 53if n_open > 0 54let n_open -= 1 55else 56let n_close += 1 57endif 58endif 59endif 60let i = match ( line , pattern , i + 1 ) 61endwhile 62return a: count_open ? n_open : n_close 63endfunction 64 65" function CheckCSSIndent() 66" let line = getline(v:lnum) 67" if line =~ '^\s*\*' 68" return cindent(v:lnum) 69" endif 70" 71" let pnum = s:prevnonblanknoncomment(v:lnum - 1) 72" if pnum == 0 73" return 0 74" endif 75 76function ! GetStylusIndent () 77let line = getline ( v: lnum ) 78if line =~ '^\s*\*' 79return cindent ( v: lnum ) 80endif 81 82let pnum = s: prevnonblanknoncomment ( v: lnum - 1 ) 83if pnum == 0 84return 0 85endif 86 87let lnum = prevnonblank ( v: lnum - 1 ) 88if lnum == 0 89return 0 90endif 91 92let pline = getline ( pnum ) 93 94if pline =~ '[}{]' 95return indent ( pnum ) + s: count_braces ( pnum , 1 ) * & sw - s: count_braces ( v: lnum , 0 ) * & sw 96endif 97 98let line = substitute ( getline ( lnum ), '[\s()]\+$' , '' , '' ) " get last line strip ending whitespace 99let cline = substitute ( substitute ( getline ( v: lnum ), '\s\+$' , '' , '' ), '^\s\+' , '' , '' ) " get current line, trimmed 100let lastcol = strlen ( line ) " get last col in prev line 101let line = substitute ( line , '^\s\+' , '' , '' ) " then remove preceding whitespace 102let indent = indent ( lnum ) " get indent on prev line 103let cindent = indent ( v: lnum ) " get indent on current line 104let increase = indent + & sw " increase indent by the shift width 105if indent == indent ( lnum ) 106let indent = cindent <= indent ? indent : increase 107endif 108 109let group = synIDattr ( synID ( lnum , lastcol , 1 ), 'name' ) 110 111" if group !~? 'css.*' && line =~? ')\s*$' " match user functions 112" return increase 113if group =~? '\v^%(cssTagName|cssClassName|cssIdentifier|cssSelectorOp|cssSelectorOp2|cssBraces|cssAttributeSelector|cssPseudo|stylusId|stylusClass)$' 114return increase 115elseif ( group == 'stylusUserFunction' ) && ( indent ( lnum ) == '0' ) " mixin definition 116return increase 117else 118return indent 119endif 120endfunction 121 122" vim:set sw=2;