From 61390f58850c34b27d2a28dc14ebd760de152cc9 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Fri, 22 Jan 2016 09:08:00 +0100 Subject: Update --- indent/blade.vim | 94 +++++++++++++++++++++++--------------------------------- 1 file changed, 39 insertions(+), 55 deletions(-) (limited to 'indent/blade.vim') diff --git a/indent/blade.vim b/indent/blade.vim index 8327f451..78a8a78c 100644 --- a/indent/blade.vim +++ b/indent/blade.vim @@ -1,66 +1,50 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'blade') == -1 -" Language: Blade -" Author: Barry Deeney -" Version: 0.1 -" Description: BLADE indent file based on HTML indentation... +" Vim indent file +" Language: Blade (Laravel) +" Maintainer: Jason Walton -" Check if this file has already been loaded if exists("b:did_indent") - finish + finish endif - -" Include HTML runtime! indent/html.vim -runtime! indent/php.vim -silent! unlet b:did_indent - -" What function do we need to use to detect indentation? -setlocal indentexpr=BladeIndent() - -" What keys would trigger indentation? -setlocal indentkeys=o,O,,<>>,{,},!^F,0{,0},0),:,!^F,o,O,e,*,=?>,=,<>>,!^F,=@else,=@end,=@empty - " Give the indent back! - return indent -endfunc +" Only define the function once. +if exists("*GetBladeIndent") + finish +endif -" Make sure we store that flag! -let b:did_indent = 1 +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\)' + let indent = cindent < indent ? cindent : indent - &sw + elseif HtmlIndent() > -1 + let indent = HtmlIndent() + endif + let increase = indent + &sw + if indent = indent(lnum) + let indent = cindent <= indent ? -1 : increase + endif + + if line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\)\%(.*\s*@end\)\@!' + return increase + else + return indent + endif +endfunction endif -- cgit v1.2.3