## closetag-sanity.diff by James Vega <jamessan@debian.org>
##
## Ensure b:unaryTagsStack is defined whenever GetCloseTag is called.

Index: vim-scripts/macros/closetag.vim
===================================================================
--- vim-scripts.orig/macros/closetag.vim
+++ vim-scripts/macros/closetag.vim
@@ -127,16 +127,6 @@
 endif
 let loaded_closetag=1
 
-" if html, don't close certain tags.  Works best if ignorecase is set.
-" otherwise, capitalize these elements according to your html editing style
-if !exists("b:unaryTagsStack") || exists("b:closetag_html_style")
-    if &filetype == "html" || exists("b:closetag_html_style")
-	let b:unaryTagsStack="area base br dd dt hr img input link meta param"
-    else " for xsl and xsl
-	let b:unaryTagsStack=""
-    endif
-endif
-
 " set up mappings for tag closing
 inoremap <C-_> <C-R>=GetCloseTag()<CR>
 map <C-_> a<C-_><ESC>
@@ -226,6 +216,7 @@
 " Returns closing tag for most recent unclosed tag, respecting the
 " current setting of b:unaryTagsStack for tags that should not be closed
 function! GetCloseTag()
+    call s:SanityCheck()
     let tag=GetLastOpenTag("b:unaryTagsStack")
     if tag == ""
 	return ""
@@ -234,6 +225,18 @@
     endif
 endfunction
 
+function! s:SanityCheck()
+    " if html, don't close certain tags.  Works best if ignorecase is set.
+    " otherwise, capitalize these elements according to your html editing style
+    if !exists("b:unaryTagsStack") || exists("b:closetag_html_style")
+	if &filetype == "html" || exists("b:closetag_html_style")
+	    let b:unaryTagsStack="area base br dd dt hr img input link meta param"
+	else " for xsl and xsl
+	    let b:unaryTagsStack=""
+	endif
+    endif
+endfunction
+
 " return 1 if the cursor is in a syntactically identified comment field
 " (fails for empty lines: always returns not-in-comment)
 function! s:InComment()
