2015-07-18 17:05:45 -04:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1
|
|
|
|
|
2016-01-22 03:08:00 -05:00
|
|
|
" Vim indent file
|
|
|
|
" Language: Blade (Laravel)
|
|
|
|
" Maintainer: Jason Walton <jwalton512@gmail.com>
|
2015-05-11 09:05:13 -04:00
|
|
|
|
|
|
|
if exists("b:did_indent")
|
2016-01-22 03:08:00 -05:00
|
|
|
finish
|
2015-05-11 09:05:13 -04:00
|
|
|
endif
|
2016-06-26 12:03:28 -04:00
|
|
|
|
2015-05-11 09:05:13 -04:00
|
|
|
runtime! indent/html.vim
|
2016-06-26 12:03:28 -04:00
|
|
|
let s:htmlindent = &indentexpr
|
|
|
|
unlet! b:did_indent
|
|
|
|
|
|
|
|
runtime! indent/php.vim
|
|
|
|
let s:phpindent = &indentexpr
|
2016-01-22 03:08:00 -05:00
|
|
|
unlet! b:did_indent
|
2016-06-26 12:03:28 -04:00
|
|
|
|
2016-01-22 03:08:00 -05:00
|
|
|
let b:did_indent = 1
|
2015-05-11 09:05:13 -04:00
|
|
|
|
2016-01-22 03:08:00 -05:00
|
|
|
setlocal autoindent
|
|
|
|
setlocal indentexpr=GetBladeIndent()
|
2016-06-26 12:03:28 -04:00
|
|
|
setlocal indentkeys=o,O,*<Return>,<>>,!^F,=@else,=@end,=@empty,=@show,=@stop
|
2015-05-11 09:05:13 -04:00
|
|
|
|
2016-01-22 03:08:00 -05:00
|
|
|
" Only define the function once.
|
|
|
|
if exists("*GetBladeIndent")
|
|
|
|
finish
|
|
|
|
endif
|
2015-05-11 09:05:13 -04:00
|
|
|
|
2016-01-22 03:08:00 -05:00
|
|
|
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)
|
2016-06-26 12:03:28 -04:00
|
|
|
if cline =~# '@\%(else\|elseif\|empty\|end\|show\|stop\)' ||
|
|
|
|
\ cline =~# '\%(<?.*\)\@<!?>\|\%({{.*\)\@<!}}\|\%({!!.*\)\@<!!!}'
|
2016-05-02 04:42:37 -04:00
|
|
|
let indent = indent - &sw
|
|
|
|
else
|
|
|
|
if exists("*GetBladeIndentCustom")
|
|
|
|
let hindent = GetBladeIndentCustom()
|
2016-06-26 12:03:28 -04:00
|
|
|
elseif searchpair('@include\s*(', '', ')', 'bWr') ||
|
|
|
|
\ searchpair('{!!', '', '!!}', 'bWr') ||
|
|
|
|
\ searchpair('{{', '', '}}', 'bWr') ||
|
|
|
|
\ searchpair('<?', '', '?>', 'bWr')
|
|
|
|
execute 'let hindent = ' . s:phpindent
|
2016-05-02 04:42:37 -04:00
|
|
|
else
|
2016-06-26 12:03:28 -04:00
|
|
|
execute 'let hindent = ' . s:htmlindent
|
2016-05-02 04:42:37 -04:00
|
|
|
endif
|
|
|
|
if hindent > -1
|
|
|
|
let indent = hindent
|
|
|
|
endif
|
2016-01-22 03:08:00 -05:00
|
|
|
endif
|
|
|
|
let increase = indent + &sw
|
|
|
|
if indent = indent(lnum)
|
|
|
|
let indent = cindent <= indent ? -1 : increase
|
|
|
|
endif
|
|
|
|
|
2016-06-26 12:03:28 -04:00
|
|
|
if line =~# '@\%(section\)\%(.*@end\)\@!' && line !~# '@\%(section\)\s*([^,]*)'
|
2016-05-02 04:42:37 -04:00
|
|
|
return indent
|
2016-06-26 12:03:28 -04:00
|
|
|
elseif line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\|empty\|push\|section\|can\|hasSection\)\%(.*@end\|.*@stop\)\@!' ||
|
|
|
|
\ line =~# '{{\%(.*}}\)\@!' || line =~# '{!!\%(.*!!}\)\@!'
|
2016-01-22 03:08:00 -05:00
|
|
|
return increase
|
2016-06-26 12:03:28 -04:00
|
|
|
elseif line =~# '<?\%(.*?>\)\@!'
|
|
|
|
return indent(lnum-1) == -1 ? increase : indent(lnum) + increase
|
2016-01-22 03:08:00 -05:00
|
|
|
else
|
|
|
|
return indent
|
|
|
|
endif
|
|
|
|
endfunction
|
2015-07-18 17:05:45 -04:00
|
|
|
|
|
|
|
endif
|