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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
1 " Vim indent file
2202
f7579a31705c Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
2 " Language: Haml
f7579a31705c Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
18818
5c40013d45ee Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
4 " Last Change: 2019 Dec 05
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
5
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
7 finish
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
8 endif
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
9 runtime! indent/ruby.vim
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
10 unlet! b:did_indent
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
11 let b:did_indent = 1
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
12
18818
5c40013d45ee Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 11518
diff changeset
13 setlocal autoindent
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
14 setlocal indentexpr=GetHamlIndent()
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
15 setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
16
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
17 " Only define the function once.
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
18 if exists("*GetHamlIndent")
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
19 finish
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
20 endif
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
21
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
22 let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
23 let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
24
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
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
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
27 endif
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
28
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
29 function! GetHamlIndent()
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
30 let lnum = prevnonblank(v:lnum-1)
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
31 if lnum == 0
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
32 return 0
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
33 endif
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
34 let line = substitute(getline(lnum),'\s\+$','','')
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
35 let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
36 let lastcol = strlen(line)
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
37 let line = substitute(line,'^\s\+','','')
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
38 let indent = indent(lnum)
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
39 let cindent = indent(v:lnum)
11518
63b0b7b79b25 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 10048
diff changeset
40 let sw = shiftwidth()
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
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
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
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
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
45 if indent == indent(lnum)
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
46 let indent = cindent <= indent ? -1 : increase
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
47 endif
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
48
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
49 let group = synIDattr(synID(lnum,lastcol,1),'name')
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
50
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
51 if line =~ '^!!!'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
52 return indent
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
53 elseif line =~ '^/\%(\[[^]]*\]\)\=$'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
54 return increase
2202
f7579a31705c Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
55 elseif group == 'hamlFilter'
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
56 return increase
2202
f7579a31705c Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
57 elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)'
f7579a31705c Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
58 return increase
f7579a31705c Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1668
diff changeset
59 elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$'
1668
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
60 return increase
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
61 elseif line == '-#'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
62 return increase
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
63 elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^%\v%('.g:haml_self_closing_tags.')>'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
64 return indent
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
65 elseif group =~? '\v^%(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
66 return increase
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
67 elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter'
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
68 return GetRubyIndent()
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
69 else
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
70 return indent
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
71 endif
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
72 endfunction
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
73
0b796e045c42 updated for version 7.2b-000
vimboss
parents:
diff changeset
74 " vim:set sw=2: