Skip to content

Instantly share code, notes, and snippets.

@lennart
Created April 21, 2011 14:11
Show Gist options
  • Select an option

  • Save lennart/934593 to your computer and use it in GitHub Desktop.

Select an option

Save lennart/934593 to your computer and use it in GitHub Desktop.
Coffee Script in ERB
autocmd BufNewFile,BufRead *.erb set filetype=eruby-coffee
" Better indent support for ERB by making it possible to indent CoffeeSCript sections
" as well.
if exists("b:did_indent")
finish
endif
" This script pulls in the default indent/coffee.vim with the :runtime command
" which could re-run this script recursively unless we catch that:
if exists('s:doing_indent_inits')
finish
endif
let s:doing_indent_inits = 1
runtime! indent/eruby.vim
unlet b:did_indent
runtime! indent/coffee.vim
unlet s:doing_indent_inits
function! GetERBCoffeeIndent(lnum)
let eruby_ind = GetErubyIndent(a:lnum)
let coffee_ind = GetCoffeeIndent()
if eruby_ind > -1
let coffee = "<%\s*coffee_script.*do\s*%>"
if 0 < searchpair(coffee, '', '<%\s*end\s*%>', 'nWb') || 0 < searchpair(coffee, '', '<%\s*end\s*%>', 'nW'))
let coffee_ind = GetCoffeeIndent()
endif
return eruby_ind
endif
return -1
endfunction
setlocal indentexpr=GetCoffeeIndent(v:lnum)
let b:current_syntax = ''
unlet b:current_syntax
runtime! syntax/eruby.vim
let b:current_syntax = ''
unlet b:current_syntax
syntax include @eRuby syntax/eruby.vim
let b:current_syntax = ''
unlet b:current_syntax
syntax include @Coffee syntax/coffee.vim
syntax region coffeeCode matchgroup=Snip start=/<%\s*coffee_script.*do\s*%>/ end=/<%\s*end\s*%>/ containedin=@eRuby contains=@Coffee
hi link Snip SpecialComment
let b:current_syntax = 'eruby-coffee'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment