mirror of
https://github.com/lepture/vim-jinja.git
synced 2025-11-11 12:53:50 -05:00
indent
This commit is contained in:
@@ -10,7 +10,7 @@ Jinja bundle for vim.
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
- Install with [Vundle](https://github.com/gmarik/vundle)
|
### Install with [Vundle](https://github.com/gmarik/vundle)
|
||||||
|
|
||||||
If you are not using vundle, you really should have a try.
|
If you are not using vundle, you really should have a try.
|
||||||
Edit your vimrc:
|
Edit your vimrc:
|
||||||
@@ -23,7 +23,7 @@ And install it:
|
|||||||
:BundleInstall
|
:BundleInstall
|
||||||
|
|
||||||
|
|
||||||
- Install with [pathogen](https://github.com/tpope/vim-pathogen)
|
### Install with [pathogen](https://github.com/tpope/vim-pathogen)
|
||||||
|
|
||||||
If you prefer tpope's pathogen, that's ok. Just clone it:
|
If you prefer tpope's pathogen, that's ok. Just clone it:
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,22 @@ if exists("*GetJinjaIndent")
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
function! GetHtmlIndent()
|
||||||
|
exe "let ind = ".b:html_indentexpr
|
||||||
|
return ind
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
if !exists("s:indent_tags")
|
||||||
|
let s:indent_tags = {}
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! AddBlockTags(taglist)
|
||||||
|
for itag in a:taglist
|
||||||
|
let s:indent_tags[itag] = 1
|
||||||
|
let s:indent_tags['/'.itag] = -1
|
||||||
|
endfor
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! GetJinjaIndent(...)
|
function! GetJinjaIndent(...)
|
||||||
if a:0 && a:1 == '.'
|
if a:0 && a:1 == '.'
|
||||||
let v:lnum = line('.')
|
let v:lnum = line('.')
|
||||||
@@ -41,35 +57,30 @@ function! GetJinjaIndent(...)
|
|||||||
|
|
||||||
call cursor(v:lnum,vcol)
|
call cursor(v:lnum,vcol)
|
||||||
|
|
||||||
exe "let ind = ".b:html_indentexpr
|
let ind = GetHtmlIndent()
|
||||||
|
|
||||||
let lnum = prevnonblank(v:lnum-1)
|
let lnum = prevnonblank(v:lnum-1)
|
||||||
let pnb = getline(lnum)
|
let line = getline(lnum)
|
||||||
let cur = getline(v:lnum)
|
let cline = getline(v:lnum)
|
||||||
|
|
||||||
let tagstart = '.*' . '{%\s*'
|
|
||||||
let tagend = '.*%}' . '.*'
|
|
||||||
|
|
||||||
let blocktags = '\(block\|for\|if\|with\|autoescape\|filter\|macro\|raw\|call\)'
|
let blocktags = '\(block\|for\|if\|with\|autoescape\|filter\|macro\|raw\|call\)'
|
||||||
let midtags = '\(elif\|else\)'
|
let midtags = '\(elif\|else\)'
|
||||||
|
|
||||||
let pnb_blockstart = pnb =~# tagstart . blocktags . tagend
|
if line =~# '^\s*{%-\?\s*'.blocktags.'\s*-\?%}$'
|
||||||
let pnb_blockend = pnb =~# tagstart . 'end' . blocktags . tagend
|
echomsg "line start"
|
||||||
let pnb_blockmid = pnb =~# tagstart . midtags . tagend
|
|
||||||
|
|
||||||
let cur_blockstart = cur =~# tagstart . blocktags . tagend
|
|
||||||
let cur_blockend = cur =~# tagstart . 'end' . blocktags . tagend
|
|
||||||
let cur_blockmid = cur =~# tagstart . midtags . tagend
|
|
||||||
|
|
||||||
if pnb_blockstart && !pnb_blockend
|
|
||||||
let ind = ind + &sw
|
let ind = ind + &sw
|
||||||
elseif pnb_blockmid && !pnb_blockend
|
if line =~# '^\s*{%-\?\s*'.midtags.'\s*-\?%}$'
|
||||||
|
echomsg "line mid"
|
||||||
let ind = ind + &sw
|
let ind = ind + &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if cur_blockend && !cur_blockstart
|
if cline =~# '^\s*{%-\?\s*end'.blocktags.'\s*-\?%}$'
|
||||||
|
echomsg = 'cline end'
|
||||||
let ind = ind - &sw
|
let ind = ind - &sw
|
||||||
elseif cur_blockmid
|
endif
|
||||||
|
|
||||||
|
if cline =~# '^\s*{%-\?\s*'.midtags.'\s*-\?%}$'
|
||||||
|
echomsg "mid end"
|
||||||
let ind = ind - &sw
|
let ind = ind - &sw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user