mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-08 11:33:52 -05:00
Update twig source
This commit is contained in:
@@ -111,7 +111,7 @@ If you need full functionality of any plugin, please use it directly with your p
|
||||
- [tmux](https://github.com/keith/tmux.vim) (syntax, ftplugin, ftdetect)
|
||||
- [tomdoc](https://github.com/wellbredgrapefruit/tomdoc.vim) (syntax)
|
||||
- [toml](https://github.com/cespare/vim-toml) (syntax, ftplugin, ftdetect)
|
||||
- [twig](https://github.com/evidens/vim-twig) (syntax, ftplugin)
|
||||
- [twig](https://github.com/lumiliet/vim-twig) (syntax, indent, ftplugin)
|
||||
- [typescript](https://github.com/leafgarland/typescript-vim) (syntax, indent, compiler, ftplugin, ftdetect)
|
||||
- [vala](https://github.com/tkztmk/vim-vala) (syntax, indent, ftdetect)
|
||||
- [vbnet](https://github.com/vim-scripts/vbnet.vim) (syntax)
|
||||
|
||||
2
build
2
build
@@ -184,7 +184,7 @@ PACKS="
|
||||
tmux:keith/tmux.vim
|
||||
tomdoc:wellbredgrapefruit/tomdoc.vim
|
||||
toml:cespare/vim-toml
|
||||
twig:evidens/vim-twig
|
||||
twig:lumiliet/vim-twig
|
||||
typescript:leafgarland/typescript-vim
|
||||
vala:tkztmk/vim-vala
|
||||
vbnet:vim-scripts/vbnet.vim
|
||||
|
||||
80
indent/twig.vim
Normal file
80
indent/twig.vim
Normal file
@@ -0,0 +1,80 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'twig') == -1
|
||||
|
||||
if exists("b:ran_once")
|
||||
finish
|
||||
endif
|
||||
|
||||
let b:ran_once = 1
|
||||
|
||||
let s:baseIndentExpr=&indentexpr
|
||||
setlocal indentexpr=GetTwigIndent(v:lnum)
|
||||
|
||||
fun! GetTwigIndent(currentLineNumber)
|
||||
let currentLine = getline(a:currentLineNumber)
|
||||
let previousLineNumber = prevnonblank(a:currentLineNumber - 1)
|
||||
let previousLine = getline(previousLineNumber)
|
||||
|
||||
if (previousLine =~ s:startStructures || previousLine =~ s:middleStructures) && (currentLine !~ s:endStructures && currentLine !~ s:middleStructures)
|
||||
return indent(previousLineNumber) + &shiftwidth
|
||||
elseif currentLine =~ s:endStructures || currentLine =~ s:middleStructures
|
||||
let previousOpenStructureNumber = s:FindPreviousOpenStructure(a:currentLineNumber)
|
||||
let previousOpenStructureLine = getline(previousOpenStructureNumber)
|
||||
return indent(previousOpenStructureNumber)
|
||||
endif
|
||||
|
||||
return s:CallBaseIndent()
|
||||
endf
|
||||
|
||||
function! s:CallBaseIndent()
|
||||
exe 'redir => s:outputOfBaseIndent'
|
||||
exe 'silent echo ' . s:baseIndentExpr
|
||||
exe 'redir END'
|
||||
return split(s:outputOfBaseIndent)[0]
|
||||
endf
|
||||
|
||||
|
||||
function! s:FindPreviousOpenStructure(lineNumber)
|
||||
let countOpen = 0
|
||||
let countClosed = 0
|
||||
let lineNumber = a:lineNumber
|
||||
while lineNumber != 1 && countOpen <= countClosed
|
||||
let lineNumber -= 1
|
||||
let currentLine = getline(lineNumber)
|
||||
|
||||
if currentLine =~ s:startStructures
|
||||
let countOpen += 1
|
||||
elseif currentLine =~ s:endStructures
|
||||
let countClosed += 1
|
||||
endif
|
||||
endwhile
|
||||
|
||||
return lineNumber
|
||||
endfunction
|
||||
|
||||
function! s:StartStructure(name)
|
||||
return '^\s*{%\s*' . a:name . '.*%}'
|
||||
endfunction
|
||||
|
||||
function! s:EndStructure(name)
|
||||
return '^\s*{%\s*end' . a:name . '.*%}'
|
||||
endfunction
|
||||
|
||||
function! s:Map(Fun, list)
|
||||
if len(a:list) == 0
|
||||
return []
|
||||
else
|
||||
return [a:Fun(a:list[0])] + s:Map(a:Fun, a:list[1:])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
fun! s:BuildStructures()
|
||||
let structures = ['if','for','block']
|
||||
let mStructures = ['elseif','else']
|
||||
let s:startStructures = join(s:Map(function('s:StartStructure'), structures), '\|')
|
||||
let s:endStructures = join(s:Map(function('s:EndStructure'), structures), '\|')
|
||||
let s:middleStructures = join(s:Map(function('s:StartStructure'), mStructures), '\|')
|
||||
endfun
|
||||
|
||||
call s:BuildStructures()
|
||||
|
||||
endif
|
||||
Reference in New Issue
Block a user