]>
Commit | Line | Data |
---|---|---|
0d23b6e5 BB |
1 | " Vim indent file |
2 | " Language: Haml | |
3 | " Maintainer: Tim Pope <vimNOSPAM@tpope.org> | |
4 | " Last Change: 2010 May 21 | |
5 | ||
6 | if exists("b:did_indent") | |
7 | finish | |
8 | endif | |
9 | runtime! indent/ruby.vim | |
10 | unlet! b:did_indent | |
11 | let b:did_indent = 1 | |
12 | ||
13 | setlocal autoindent sw=2 et | |
14 | setlocal indentexpr=GetHamlIndent() | |
15 | setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when | |
16 | ||
17 | " Only define the function once. | |
18 | if exists("*GetHamlIndent") | |
19 | finish | |
20 | endif | |
21 | ||
22 | let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)' | |
23 | let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*' | |
24 | ||
25 | if !exists('g:haml_self_closing_tags') | |
26 | let g:haml_self_closing_tags = 'meta|link|img|hr|br' | |
27 | endif | |
28 | ||
29 | function! GetHamlIndent() | |
30 | let lnum = prevnonblank(v:lnum-1) | |
31 | if lnum == 0 | |
32 | return 0 | |
33 | endif | |
34 | let line = substitute(getline(lnum),'\s\+$','','') | |
35 | let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','') | |
36 | let lastcol = strlen(line) | |
37 | let line = substitute(line,'^\s\+','','') | |
38 | let indent = indent(lnum) | |
39 | let cindent = indent(v:lnum) | |
40 | if cline =~# '\v^-\s*%(elsif|else|when)>' | |
41 | let indent = cindent < indent ? cindent : indent - &sw | |
42 | endif | |
43 | let increase = indent + &sw | |
44 | if indent == indent(lnum) | |
45 | let indent = cindent <= indent ? -1 : increase | |
46 | endif | |
47 | ||
48 | let group = synIDattr(synID(lnum,lastcol,1),'name') | |
49 | ||
50 | if line =~ '^!!!' | |
51 | return indent | |
52 | elseif line =~ '^/\%(\[[^]]*\]\)\=$' | |
53 | return increase | |
54 | elseif group == 'hamlFilter' | |
55 | return increase | |
56 | elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)' | |
57 | return increase | |
58 | elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$' | |
59 | return increase | |
60 | elseif line == '-#' | |
61 | return increase | |
62 | elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^%\v%('.g:haml_self_closing_tags.')>' | |
63 | return indent | |
64 | elseif group =~? '\v^%(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$' | |
65 | return increase | |
66 | elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter' | |
67 | return GetRubyIndent() | |
68 | else | |
69 | return indent | |
70 | endif | |
71 | endfunction | |
72 | ||
73 | " vim:set sw=2: |