Mercurial > vim
annotate runtime/indent/haml.vim @ 23914:b56544307168
Added tag v8.2.2499 for changeset dfdd973cf0c995ddf3f304b7a9739eccd199be64
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 11 Feb 2021 19:15:04 +0100 |
parents | 5c40013d45ee |
children | dce918af0c00 |
rev | line source |
---|---|
1668 | 1 " Vim indent file |
2202 | 2 " Language: Haml |
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org> | |
18818 | 4 " Last Change: 2019 Dec 05 |
1668 | 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 | |
18818 | 13 setlocal autoindent |
1668 | 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') | |
4681
2eb30f341e8d
Updated runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
2420
diff
changeset
|
26 let g:haml_self_closing_tags = 'base|link|meta|br|hr|img|input' |
1668 | 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) | |
11518 | 40 let sw = shiftwidth() |
1668 | 41 if cline =~# '\v^-\s*%(elsif|else|when)>' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
42 let indent = cindent < indent ? cindent : indent - sw |
1668 | 43 endif |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4681
diff
changeset
|
44 let increase = indent + sw |
1668 | 45 if indent == indent(lnum) |
46 let indent = cindent <= indent ? -1 : increase | |
47 endif | |
48 | |
49 let group = synIDattr(synID(lnum,lastcol,1),'name') | |
50 | |
51 if line =~ '^!!!' | |
52 return indent | |
53 elseif line =~ '^/\%(\[[^]]*\]\)\=$' | |
54 return increase | |
2202 | 55 elseif group == 'hamlFilter' |
1668 | 56 return increase |
2202 | 57 elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)' |
58 return increase | |
59 elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$' | |
1668 | 60 return increase |
61 elseif line == '-#' | |
62 return increase | |
63 elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^%\v%('.g:haml_self_closing_tags.')>' | |
64 return indent | |
65 elseif group =~? '\v^%(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$' | |
66 return increase | |
67 elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter' | |
68 return GetRubyIndent() | |
69 else | |
70 return indent | |
71 endif | |
72 endfunction | |
73 | |
74 " vim:set sw=2: |