vim-polyglot/indent/blade.vim

84 lines
2.8 KiB
VimL
Raw Normal View History

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-07-19 04:09:54 -04:00
" Doesn't include 'foreach' and 'forelse' because these already get matched by 'for'.
let s:directives_start = 'if\|else\|unless\|for\|while\|empty\|push\|section\|can\|hasSection\|verbatim'
let s:directives_end = 'else\|end\|empty\|show\|stop\|append\|overwrite'
if exists('g:blade_custom_directives_pairs')
let s:directives_start .= '\|' . join(keys(g:blade_custom_directives_pairs), '\|')
let s:directives_end .= '\|' . join(values(g:blade_custom_directives_pairs), '\|')
endif
2016-01-22 03:08:00 -05:00
setlocal autoindent
setlocal indentexpr=GetBladeIndent()
2016-07-19 04:09:54 -04:00
exe "setlocal indentkeys=o,O,<>>,!^F,0=}},0=!!},=@" . substitute(s:directives_end, '\\|', ',=@', 'g')
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)
2016-07-19 04:09:54 -04:00
if cline =~# '@\%(' . s:directives_end . '\)' ||
2016-06-26 12:03:28 -04:00
\ cline =~# '\%(<?.*\)\@<!?>\|\%({{.*\)\@<!}}\|\%({!!.*\)\@<!!!}'
2016-05-02 04:42:37 -04:00
let indent = indent - &sw
2016-07-19 04:09:54 -04:00
elseif line =~# '<?\%(.*?>\)\@!\|@php\%(\s*(\)\@!'
2016-07-05 03:53:49 -04:00
let indent = indent + &sw
2016-05-02 04:42:37 -04:00
else
if exists("*GetBladeIndentCustom")
let hindent = GetBladeIndentCustom()
2016-07-19 04:09:54 -04:00
" Don't use PHP indentation if line is a comment
elseif line !~# '^\s*\%(#\|//\)\|\*/\s*$' && (
\ searchpair('@include\%(If\)\?\s*(', '', ')', 'bWr') ||
2016-06-26 12:03:28 -04:00
\ searchpair('{!!', '', '!!}', 'bWr') ||
\ searchpair('{{', '', '}}', 'bWr') ||
2016-07-19 04:09:54 -04:00
\ searchpair('<?', '', '?>', 'bWr') ||
\ searchpair('@php\%(\s*(\)\@!', '', '@endphp', 'bWr') )
2016-06-26 12:03:28 -04:00
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
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-07-19 04:09:54 -04:00
elseif line =~# '@\%(' . s:directives_start . '\)\%(.*@end\|.*@stop\)\@!' ||
2016-06-26 12:03:28 -04:00
\ line =~# '{{\%(.*}}\)\@!' || line =~# '{!!\%(.*!!}\)\@!'
2016-01-22 03:08:00 -05:00
return increase
else
return indent
endif
endfunction
endif