Skip to content

Commit

Permalink
Add support for indenting coffeescript in html
Browse files Browse the repository at this point in the history
  • Loading branch information
kchmck committed Aug 25, 2013
1 parent 114dd93 commit d42f504
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions after/indent/html.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
" Language: CoffeeScript
" Maintainer: Mick Koch <kchmck@gmail.com>
" URL: http://github.com/kchmck/vim-coffee-script
" License: WTFPL

" Load the coffee and html indent functions.
unlet b:did_indent
runtime indent/coffee.vim
let s:coffeeIndentExpr = &l:indentexpr

" Load html last so it can overwrite coffee settings.
unlet b:did_indent
runtime indent/html.vim
let s:htmlIndentExpr = &l:indentexpr

" Inject our wrapper indent function.
setlocal indentexpr=GetCoffeeHtmlIndent(v:lnum)

function! GetCoffeeHtmlIndent(curlinenum)
" See if we're inside a coffeescript block.
let scriptlnum = searchpair('<script [^>]*type="text/coffeescript"[^>]*>', '',
\ '</script>','bWn')
let prevlnum = prevnonblank(a:curlinenum)

" If we're in the script block and the previous line isn't the script tag
" itself, use coffee indenting.
if scriptlnum && scriptlnum != prevlnum
exec "return " s:coffeeIndentExpr
endif

" Otherwise use html indenting.
exec "return " s:htmlIndentExpr
endfunction

0 comments on commit d42f504

Please sign in to comment.