summaryrefslogtreecommitdiffstats
path: root/indent/blade.vim
blob: 4c89ed616446adabd0f4d9cc0f713c0d75603d52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
  
" Vim indent file
" Language:     Blade (Laravel)
" Maintainer:   Jason Walton <jwalton512@gmail.com>

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

setlocal autoindent
setlocal indentexpr=GetBladeIndent()
setlocal indentkeys=o,O,*<Return>,<>>,!^F,=@else,=@end,=@empty,=@show

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

function! GetBladeIndent()
    let lnum = prevnonblank(v:lnum-1)
    if lnum == 0
        return 0
    endif

    let line = substitute(substitute(getline(lnum), '\s\+$', '', ''), '^\s\+', '', '')
    let cline = substitute(substitute(getline(v:lnum), '\s\+$', '', ''), '^\s\+', '', '')
    let indent = indent(lnum)
    let cindent = indent(v:lnum)
    if cline =~# '@\%(else\|elseif\|empty\|end\|show\)'
        let indent = indent - &sw
    else
        if exists("*GetBladeIndentCustom")
            let hindent = GetBladeIndentCustom()
        else
            let hindent = HtmlIndent()
        endif
        if hindent > -1
            let indent = hindent
        endif
    endif
    let increase = indent + &sw
    if indent = indent(lnum)
        let indent = cindent <= indent ? -1 : increase
    endif

    if line =~# '@\%(section\)\%(.*\s*@end\)\@!' && line !~# '@\%(section\)\s*([^,]*)'
        return indent
    elseif line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\|empty\|push\|section\|can\)\%(.*\s*@end\)\@!'
        return increase
    else
        return indent
    endif
endfunction

endif