Skip to content

Commit

Permalink
Merge pull request #7 from blueyed/fix-endblocks-etc
Browse files Browse the repository at this point in the history
Fix matching of endblocks, use `:norm!`
  • Loading branch information
mjbrownie committed Sep 8, 2014
2 parents 875197e + c2ed67f commit b97989a
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions after/ftplugin/htmldjango/template_textobjects.vim
Expand Up @@ -53,57 +53,58 @@ if exists("loaded_matchit")
let b:match_words = '<:>,' .
\ '<\@<=[ou]l\>[^>]*\%(>\|$\):<\@<=li\>:<\@<=/[ou]l>,' .
\ '<\@<=dl\>[^>]*\%(>\|$\):<\@<=d[td]\>:<\@<=/dl>,' .
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>,' .
\ '{% *if .*%}:{% *else *%}:{% *elif .*%}:{% *endif *%},' .
\ '{% *ifequal .*%}:{% *else *%}:{% *endifequal *%},' .
\ '{% *ifnotequal .*%}:{% *else *%}:{% *endifnotequal *%},' .
\ '{% *ifchanged .*%}:{% *else *%}:{% *endifchanged *%},' .
\ '{% *for .*%}:{% *endfor *%},' .
\ '{% *with .*%}:{% *endwith *%},' .
\ '{% *comment .*%}:{% *endcomment *%},' .
\ '{% *block .*%}:{% *endblock *%},' .
\ '{% *filter .*%}:{% *endfilter *%},' .
\ '{% *spaceless .*%}:{% *endspaceless *%},' .
\ '{% *cache .*%}:{% *endcache *%}' .
\ '{% *blocktrans .*%}:{% *endblocktrans *%}'
\ '<\@<=\([^/][^ \t>]*\)[^>]*\%(>\|$\):<\@<=/\1>,' .
\ '{% *block\>.\{-}%}:{% *endblock\>.\{-}%},' .
\ '{% *blocktrans\>.\{-}%}:{% *endblocktrans\>.\{-}%},' .
\ '{% *cache\>.\{-}%}:{% *endcache\>.\{-}%},' .
\ '{% *comment\>.\{-}%}:{% *endcomment\>.\{-}%},' .
\ '{% *filter\>.\{-}%}:{% *endfilter\>.\{-}%},' .
\ '{% *for\>.\{-}%}:{% *empty\>.\{-}%}:{% *endfor\>.\{-}%},' .
\ '{% *if\>.\{-}%}:{% *else\>.\{-}%}:{% *elif\>.\{-}%}:{% *endif\>.\{-}%},' .
\ '{% *ifchanged\>.\{-}%}:{% *else\>.\{-}%}:{% *endifchanged\>.\{-}%},' .
\ '{% *ifequal\>.\{-}%}:{% *else\>.\{-}%}:{% *endifequal\>.\{-}%},' .
\ '{% *ifnotequal\>.\{-}%}:{% *else\>.\{-}%}:{% *endifnotequal\>.\{-}%},' .
\ '{% *spaceless\>.\{-}%}:{% *endspaceless\>.\{-}%},' .
\ '{% *verbatim\>.\{-}%}:{% *endverbatim\>.\{-}%},' .
\ '{% *with\>.\{-}%}:{% *endwith\>.\{-}%}'
endif

if !exists('*s:select_a')

fun s:select_a(type)
let initpos = getpos(".")

let e =searchpairpos('{% *'.a:type.' .*%}','','{% *end'.a:type. ' *%}','b')
if ( e == [0,0])
let e = searchpairpos('{% *'.a:type.'\>.\{-}%}','','{% *end'.a:type. '\>.\{-}%}','b')
if e == [0,0]
return 0
endif

let e = [bufnr("%")] + e + [0]

call setpos(".",initpos)

call searchpair('{% *'.a:type.' .*%}','','{% *end'.a:type. ' *%}','')
call searchpair('{% *'.a:type.'\>.\{-}%}','','{% *end'.a:type. '\>.\{-}%}','')

norm f}
normal! f}
let b = getpos(".")

return ['v',b,e]
endfun

fun s:select_i(type)
let initpos = getpos(".")
if (searchpair('{% *'.a:type.' .*%}','','{% *end'.a:type. ' *%}','b') == 0)
if (searchpair('{% *'.a:type.'\>.\{-}%}','','{% *end'.a:type. '\>.\{-}%}','b') == 0)
return 0
endif

normal f}
normal! f}
"move one pesky char
call search('.')
let e =getpos('.')

call setpos(".",initpos)

call searchpair('{% *'.a:type.' .*%}','','{% *end'.a:type. ' *%}','')
call searchpair('{% *'.a:type.'\>.\{-}%}','','{% *end'.a:type. '\>.\{-}%}','')
" call search(".", 'b')
let b = getpos(".")

Expand Down

0 comments on commit b97989a

Please sign in to comment.