robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
75157d2572
master
1" Vim indent file 2" Language: Haml 3" Maintainer: Tim Pope <vimNOSPAM@tpope.org> 4" Last Change: 2022 Mar 15 5 6if exists ( "b:did_indent" ) 7finish 8endif 9runtime ! indent/ruby.vim 10unlet ! b: did_indent 11let b: did_indent = 1 12 13setlocal autoindent 14setlocal indentexpr = GetHamlIndent () 15setlocal indentkeys = o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when 16 17let b: undo_indent = "setl ai< inde< indk<" 18 19" Only define the function once. 20if exists ( "*GetHamlIndent" ) 21finish 22endif 23 24let s: attributes = '\%({.\{-\}}\|\[.\{-\}\]\)' 25let s: tag = '\%([%.#][[:alnum:]_-]\+\|' . s: attributes . '\)*[<>]*' 26 27if ! exists ( 'g:haml_self_closing_tags' ) 28let g: haml_self_closing_tags = 'base|link|meta|br|hr|img|input' 29endif 30 31function ! GetHamlIndent () 32let lnum = prevnonblank ( v: lnum - 1 ) 33if lnum == 0 34return 0 35endif 36let line = substitute ( getline ( lnum ), '\s\+$' , '' , '' ) 37let cline = substitute ( substitute ( getline ( v: lnum ), '\s\+$' , '' , '' ), '^\s\+' , '' , '' ) 38let lastcol = strlen ( line ) 39let line = substitute ( line , '^\s\+' , '' , '' ) 40let indent = indent ( lnum ) 41let cindent = indent ( v: lnum ) 42let sw = shiftwidth () 43if cline =~# '\v^-\s*%(elsif|else|when)>' 44let indent = cindent < indent ? cindent : indent - sw 45endif 46let increase = indent + sw 47if indent == indent ( lnum ) 48let indent = cindent <= indent ? -1 : increase 49endif 50 51let group = synIDattr ( synID ( lnum , lastcol , 1 ), 'name' ) 52 53if line =~ '^!!!' 54return indent 55elseif line =~ '^/\%(\[[^]]*\]\)\=$' 56return increase 57elseif group == 'hamlFilter' 58return increase 59elseif line =~ '^' . s: tag . '[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)' 60return increase 61elseif line =~ '^' . s: tag . '[&!]\=[=~-].*,\s*$' 62return increase 63elseif line == '-#' 64return increase 65elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^%\v%(' . g: haml_self_closing_tags . ')>' 66return indent 67elseif group =~? '\v^%(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$' 68return increase 69elseif synIDattr ( synID ( v: lnum , 1 , 1 ), 'name' ) ==? 'hamlRubyFilter' 70return GetRubyIndent () 71else 72return indent 73endif 74endfunction 75 76" vim:set sw=2: