jade.vim (1704B)
1 " Vim indent file 2 " Language: Jade 3 " Maintainer: Joshua Borton 4 " Credits: Tim Pope (vim-jade) 5 " Last Change: 2010 Sep 22 6 7 if exists("b:did_indent") 8 finish 9 endif 10 11 unlet! b:did_indent 12 let b:did_indent = 1 13 14 setlocal autoindent sw=2 et 15 setlocal indentexpr=GetJadeIndent() 16 setlocal indentkeys=o,O,*<Return>,},],0),!^F 17 18 " Only define the function once. 19 if exists("*GetJadeIndent") 20 finish 21 endif 22 23 let s:attributes = '\%((.\{-\})\)' 24 let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*' 25 26 if !exists('g:jade_self_closing_tags') 27 let g:jade_self_closing_tags = 'meta|link|img|hr|br' 28 endif 29 30 setlocal formatoptions+=r 31 setlocal comments+=n:\| 32 33 function! GetJadeIndent() 34 let lnum = prevnonblank(v:lnum-1) 35 if lnum == 0 36 return 0 37 endif 38 let line = substitute(getline(lnum),'\s\+$','','') 39 let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','') 40 let lastcol = strlen(line) 41 let line = substitute(line,'^\s\+','','') 42 let indent = indent(lnum) 43 let cindent = indent(v:lnum) 44 let increase = indent + &sw 45 if indent == indent(lnum) 46 let indent = cindent <= indent ? -1 : increase 47 endif 48 49 let group = synIDattr(synID(lnum,lastcol,1),'name') 50 51 if line =~ '^!!!' 52 return indent 53 elseif line =~ '^/\%(\[[^]]*\]\)\=$' 54 return increase 55 elseif group == 'jadeFilter' 56 return increase 57 elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$' 58 return increase 59 elseif line == '-#' 60 return increase 61 elseif line =~? '^\v%('.g:jade_self_closing_tags.')>' 62 return indent 63 elseif group =~? '\v^%(jadeTag|jadeAttributesDelimiter|jadeClass|jadeId|htmlTagName|htmlSpecialTagName)$' 64 return increase 65 else 66 return indent 67 endif 68 endfunction 69 70 " vim:set sw=2: