diff --git a/.vim/ftdetect/slim.vim b/.vim/ftdetect/slim.vim new file mode 100644 index 0000000..17723d8 --- /dev/null +++ b/.vim/ftdetect/slim.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.slim set filetype=slim diff --git a/.vim/indent/slim.vim b/.vim/indent/slim.vim new file mode 100644 index 0000000..5b843bf --- /dev/null +++ b/.vim/indent/slim.vim @@ -0,0 +1,75 @@ +" Vim indent file +" Language: Slim + +if exists("b:did_indent") + finish +endif +runtime! indent/ruby.vim +unlet! b:did_indent +let b:did_indent = 1 + +setlocal autoindent sw=2 et +setlocal indentexpr=GetSlimIndent() +setlocal indentkeys=o,O,*,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when + +" Only define the function once. +if exists("*GetSlimIndent") + finish +endif + +let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)' +let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*' + +if !exists('g:haml_self_closing_tags') + let g:haml_self_closing_tags = 'meta|link|img|hr|br' +endif + +function! GetSlimIndent() + let lnum = prevnonblank(v:lnum-1) + if lnum == 0 + return 0 + endif + let line = substitute(getline(lnum),'\s\+$','','') + let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','') + let lastcol = strlen(line) + let line = substitute(line,'^\s\+','','') + let indent = indent(lnum) + let cindent = indent(v:lnum) + if cline =~# '\v^-\s*%(elsif|else|when)>' + let indent = cindent < indent ? cindent : indent - &sw + endif + let increase = indent + &sw + if indent == indent(lnum) + let indent = cindent <= indent ? -1 : increase + endif + + let group = synIDattr(synID(lnum,lastcol,1),'name') + + if line =~ '^doctype' + return indent + elseif line =~ '^/\%(\[[^]]*\]\)\=$' + return increase + elseif line =~ '^[\.#]' + return increase + elseif line =~? '^div' + return increase + elseif group == 'hamlFilter' + return increase + elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)' + return increase + elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$' + return increase + elseif line == '-#' + return increase + elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^\v('.g:haml_self_closing_tags.')>' + return indent + elseif group =~? '\v^(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$' + return increase + elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter' + return GetRubyIndent() + else + return indent + endif +endfunction + +" vim:set sw=2: diff --git a/.vim/syntax/slim.vim b/.vim/syntax/slim.vim new file mode 100644 index 0000000..b8d7b6a --- /dev/null +++ b/.vim/syntax/slim.vim @@ -0,0 +1,102 @@ +" Vim syntax file +" Language: Slim +" Maintainer: Andrew Stone +" Version: 1 +" Last Change: 2010 Sep 25 +" TODO: Feedback is welcomed. + +" Quit when a syntax file is already loaded. +if exists("b:current_syntax") + finish +endif + +if !exists("main_syntax") + let main_syntax = 'slim' +endif + +" Allows a per line syntax evaluation. +let b:ruby_no_expensive = 1 + +" Include Ruby syntax highlighting +syn include @slimRubyTop syntax/ruby.vim +unlet! b:current_syntax +" Include Haml syntax highlighting +syn include @slimHaml syntax/haml.vim +unlet! b:current_syntax + +syn match slimBegin "^\s*\(&[^= ]\)\@!" nextgroup=slimTag,slimClassChar,slimIdChar,slimRuby + +syn region rubyCurlyBlock start="{" end="}" contains=@slimRubyTop contained +syn cluster slimRubyTop add=rubyCurlyBlock + +syn cluster slimComponent contains=slimClassChar,slimIdChar,slimWrappedAttrs,slimRuby,slimAttr,slimInlineTagChar + +syn keyword slimDocType contained html 5 1.1 strict frameset mobile basic transitional +syn match slimDocTypeKeyword "^\s*\(doctype\)\s\+" nextgroup=slimDocType + +syn keyword slimTodo FIXME TODO NOTE OPTIMIZE XXX contained +syn keyword htmlTagName contained script + +syn match slimTag "\w\+[><]*" contained contains=htmlTagName nextgroup=@slimComponent +syn match slimIdChar "#{\@!" contained nextgroup=slimId +syn match slimId "\%(\w\|-\)\+" contained nextgroup=@slimComponent +syn match slimClassChar "\." contained nextgroup=slimClass +syn match slimClass "\%(\w\|-\)\+" contained nextgroup=@slimComponent +syn match slimInlineTagChar "\s*:\s*" contained nextgroup=slimTag,slimClassChar,slimIdChar + +syn region slimWrappedAttrs matchgroup=slimWrappedAttrsDelimiter start="\s*{\s*" skip="}\s*\"" end="\s*}\s*" contained contains=slimAttr nextgroup=slimRuby +syn region slimWrappedAttrs matchgroup=slimWrappedAttrsDelimiter start="\s*\[\s*" end="\s*\]\s*" contained contains=slimAttr nextgroup=slimRuby +syn region slimWrappedAttrs matchgroup=slimWrappedAttrsDelimiter start="\s*(\s*" end="\s*)\s*" contained contains=slimAttr nextgroup=slimRuby + +syn match slimAttr /\s*\%(\w\|-\)\+\s*=/me=e-1 contained contains=htmlArg nextgroup=slimAttrAssignment +syn match slimAttrAssignment "\s*=\s*" contained nextgroup=slimWrappedAttrValue,slimAttrString + +syn region slimWrappedAttrValue start="[^"']" end="\s\|$" contained contains=slimAttrString,@slimRubyTop nextgroup=slimAttr,slimRuby,slimInlineTagChar +syn region slimWrappedAttrValue matchgroup=slimWrappedAttrValueDelimiter start="{" end="}" contained contains=slimAttrString,@slimRubyTop nextgroup=slimAttr,slimRuby,slimInlineTagChar +syn region slimWrappedAttrValue matchgroup=slimWrappedAttrValueDelimiter start="\[" end="\]" contained contains=slimAttrString,@slimRubyTop nextgroup=slimAttr,slimRuby,slimInlineTagChar +syn region slimWrappedAttrValue matchgroup=slimWrappedAttrValueDelimiter start="(" end=")" contained contains=slimAttrString,@slimRubyTop nextgroup=slimAttr,slimRuby,slimInlineTagChar + +syn region slimAttrString start=+\s*"+ skip=+\%(\\\\\)*\\"+ end=+"\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr,slimRuby,slimInlineTagChar +syn region slimAttrString start=+\s*'+ skip=+\%(\\\\\)*\\"+ end=+'\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr,slimRuby,slimInlineTagChar + +syn region slimInnerAttrString start=+\s*"+ skip=+\%(\\\\\)*\\"+ end=+"\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr +syn region slimInnerAttrString start=+\s*'+ skip=+\%(\\\\\)*\\"+ end=+'\s*+ contained contains=slimInterpolation,slimInterpolationEscape nextgroup=slimAttr + +syn region slimInterpolation matchgroup=slimInterpolationDelimiter start="#{" end="}" contains=@hamlRubyTop containedin=javascriptStringS,javascriptStringD,slimWrappedAttrs +syn region slimInterpolation matchgroup=slimInterpolationDelimiter start="#{{" end="}}" contains=@hamlRubyTop containedin=javascriptStringS,javascriptStringD,slimWrappedAttrs +syn match slimInterpolationEscape "\\\@.*\(\n\1\s.*\)*/ contains=@slimHaml,slimFilter + +syn match slimIEConditional "\%(^\s*/\)\@<=\[\s*if\>[^]]*]" contained containedin=slimComment + +hi def link slimAttrString String +hi def link slimBegin String +hi def link slimClass Type +hi def link slimAttr Type +hi def link slimClassChar Type +hi def link slimComment Comment +hi def link slimDocType Identifier +hi def link slimDocTypeKeyword Keyword +hi def link slimFilter Keyword +hi def link slimIEConditional SpecialComment +hi def link slimId Identifier +hi def link slimIdChar Identifier +hi def link slimInnerAttrString String +hi def link slimInterpolationDelimiter Delimiter +hi def link slimRubyChar Special +hi def link slimRubyOutputChar Special +hi def link slimText String +hi def link slimTodo Todo +hi def link slimWrappedAttrValueDelimiter Delimiter +hi def link slimWrappedAttrsDelimiter Delimiter +hi def link slimInlineTagChar Delimiter + +let b:current_syntax = "slim"