Skip to content

Commit 5a50c28

Browse files
author
lepture
committed
indent
1 parent 03a4f90 commit 5a50c28

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Jinja bundle for vim.
1010

1111
## Installation
1212

13-
- Install with [Vundle](https://github.com/gmarik/vundle)
13+
### Install with [Vundle](https://github.com/gmarik/vundle)
1414

1515
If you are not using vundle, you really should have a try.
1616
Edit your vimrc:
@@ -23,7 +23,7 @@ And install it:
2323
:BundleInstall
2424

2525

26-
- Install with [pathogen](https://github.com/tpope/vim-pathogen)
26+
### Install with [pathogen](https://github.com/tpope/vim-pathogen)
2727

2828
If you prefer tpope's pathogen, that's ok. Just clone it:
2929

indent/jinja.vim

+29-18
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ if exists("*GetJinjaIndent")
3131
finish
3232
endif
3333

34+
function! GetHtmlIndent()
35+
exe "let ind = ".b:html_indentexpr
36+
return ind
37+
endfunction
38+
39+
if !exists("s:indent_tags")
40+
let s:indent_tags = {}
41+
endif
42+
43+
function! AddBlockTags(taglist)
44+
for itag in a:taglist
45+
let s:indent_tags[itag] = 1
46+
let s:indent_tags['/'.itag] = -1
47+
endfor
48+
endfunction
49+
3450
function! GetJinjaIndent(...)
3551
if a:0 && a:1 == '.'
3652
let v:lnum = line('.')
@@ -41,35 +57,30 @@ function! GetJinjaIndent(...)
4157

4258
call cursor(v:lnum,vcol)
4359

44-
exe "let ind = ".b:html_indentexpr
60+
let ind = GetHtmlIndent()
4561

4662
let lnum = prevnonblank(v:lnum-1)
47-
let pnb = getline(lnum)
48-
let cur = getline(v:lnum)
49-
50-
let tagstart = '.*' . '{%\s*'
51-
let tagend = '.*%}' . '.*'
63+
let line = getline(lnum)
64+
let cline = getline(v:lnum)
5265

5366
let blocktags = '\(block\|for\|if\|with\|autoescape\|filter\|macro\|raw\|call\)'
5467
let midtags = '\(elif\|else\)'
5568

56-
let pnb_blockstart = pnb =~# tagstart . blocktags . tagend
57-
let pnb_blockend = pnb =~# tagstart . 'end' . blocktags . tagend
58-
let pnb_blockmid = pnb =~# tagstart . midtags . tagend
59-
60-
let cur_blockstart = cur =~# tagstart . blocktags . tagend
61-
let cur_blockend = cur =~# tagstart . 'end' . blocktags . tagend
62-
let cur_blockmid = cur =~# tagstart . midtags . tagend
63-
64-
if pnb_blockstart && !pnb_blockend
69+
if line =~# '^\s*{%-\?\s*'.blocktags.'\s*-\?%}$'
70+
echomsg "line start"
6571
let ind = ind + &sw
66-
elseif pnb_blockmid && !pnb_blockend
72+
if line =~# '^\s*{%-\?\s*'.midtags.'\s*-\?%}$'
73+
echomsg "line mid"
6774
let ind = ind + &sw
6875
endif
6976

70-
if cur_blockend && !cur_blockstart
77+
if cline =~# '^\s*{%-\?\s*end'.blocktags.'\s*-\?%}$'
78+
echomsg = 'cline end'
7179
let ind = ind - &sw
72-
elseif cur_blockmid
80+
endif
81+
82+
if cline =~# '^\s*{%-\?\s*'.midtags.'\s*-\?%}$'
83+
echomsg "mid end"
7384
let ind = ind - &sw
7485
endif
7586

0 commit comments

Comments
 (0)