Skip to content

Commit

Permalink
improvements to django template end tag completion
Browse files Browse the repository at this point in the history
git-svn-id: https://eclim.svn.sourceforge.net/svnroot/eclim/trunk@1801 b5bd0a2e-1a23-0410-8567-9814cbbba304
  • Loading branch information
ervandew committed Mar 25, 2008
1 parent 861c038 commit 8be577c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/forrest/content/xdocs/vim/python/django.xml
Expand Up @@ -139,7 +139,7 @@
</a>
setting along with the pre-configured default list of body elements,
eclim includes support for auto completion of ending template tags when
you type a '%' preceded by a '{':
you type an '{%e' or '{% e':
</p>

<anchor id="DjangoFind"/>
Expand Down
16 changes: 10 additions & 6 deletions src/vim/eclim/autoload/eclim/python/django/template.vim
Expand Up @@ -28,7 +28,7 @@ let s:endtag = '{%\s*end\w\+\s*%}'

let s:body_tags = {}
for elements in g:HtmlDjangoBodyElements
let s:body_tags[elements[0]] = elements[-1]
let s:body_tags[elements[0]] = elements[1:]
endfor
" }}}

Expand All @@ -37,13 +37,17 @@ endfor
" Ex. imap <silent> % <c-r>=eclim#python#django#template#CompleteEndTag()<cr>
function eclim#python#django#template#CompleteEndTag ()
let line = getline('.')
if line[col('.') - 2] == '{' && line !~ '\%' . col('.') . 'c\s*\w\+\s*%}'
if line =~ '.*{%\s*\%' . col('.') . 'c\(\s\|$\)'
let tag = s:GetStartTag(line('.'))
if tag != ''
return '% ' . tag . ' %}'
echom 'result = ' . string(tag)
if len(tag) == 1
return tag[0] . ' %}'
elseif len(tag) > 1
call complete(col('.'), tag)
return ''
endif
endif
return '%'
return 'e'
endfunction " }}}

" s:GetStartTag(line) {{{
Expand All @@ -65,7 +69,7 @@ function s:GetStartTag (line)
" see if the tag has a matching close tag
let pos = searchpairpos(
\ '{%\s*' . tag[0] . '\s*\([^}]\+\)\?\s*%}', '',
\ '{%\s*' . tag[1], 'nW')
\ '{%\s*' . tag[1][-1], 'nW')
"\ '{%\s*' . tag[1] . '\s*%}', 'nW')
if !pos[0] || pos[0] > a:line
return tag[1]
Expand Down
2 changes: 1 addition & 1 deletion src/vim/eclim/ftplugin/htmldjango/eclim.vim
Expand Up @@ -36,7 +36,7 @@ endif

" Mappings {{{
if g:HtmlDjangoCompleteEndTag
imap <buffer> <silent> % <c-r>=eclim#python#django#template#CompleteEndTag()<cr>
imap <buffer> <silent> e <c-r>=eclim#python#django#template#CompleteEndTag()<cr>
endif
" }}}

Expand Down

0 comments on commit 8be577c

Please sign in to comment.