Skip to content

Commit

Permalink
add play2-html indent
Browse files Browse the repository at this point in the history
  • Loading branch information
alswl committed Jul 25, 2012
1 parent 170d8ee commit 5461c36
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions indent/play2-html.vim
@@ -0,0 +1,57 @@
" Vim indent file
" Language: play2-html
" Maintainer: alswl <alswlx@gmail.com>
" Last Change: 2012/07/25

if exists("b:did_indent")
finish
endif
let b:did_indent = 1
runtime! indent/html.vim
runtime! indent/html5.vim

setlocal autoindent sw=4 noet
setlocal indentexpr=GetPlay2HtmlIndent()
setlocal indentkeys=*,},<Return>

let s:tags = ['if', 'list', 'else', 'elseif', 'cache', 'form', 'ifError', 'ifErros', 'ifnot', 'errors']

" Only define the function once.
if exists("*GetPlay2HtmlIndent")
finish
endif

function! GetPlay2HtmlIndent()
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)

let increase_tags_re = ''
let increase_tags = []
let decrease_tags_re = ''
let decrease_tags = []
for i in s:tags
call add(increase_tags, '^\s*#{\s*' . i)
call add(decrease_tags, '^\s*#{\s*/' . i)
endfor
let increase_tags_re = join(increase_tags, '\|')
let decrease_tags_re = join(increase_tags, '\|')

if line =~ increase_tags_re
return indent + &sw
elseif cline =~ s:property_close
return indent - &sw
else
return HtmlIndentGet(v:lnum)
endif
endfunction


" vim:set sw=2:

0 comments on commit 5461c36

Please sign in to comment.