From 85eb3b5caf4057d02cd9d3097b3bfb743667f54c Mon Sep 17 00:00:00 2001 From: Tyler Brazier Date: Mon, 28 Sep 2015 22:04:48 -0400 Subject: [PATCH 1/4] Fix

| issue, | issue The getCurrentTag() function previously didn't account for tags with numbers in them such as h1, h2, etc. Also it didn't account for special characters such as # anywhere within < and >. --- ftplugin/html_autoclosetag.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ftplugin/html_autoclosetag.vim b/ftplugin/html_autoclosetag.vim index bff4dc1..43821d3 100644 --- a/ftplugin/html_autoclosetag.vim +++ b/ftplugin/html_autoclosetag.vim @@ -16,8 +16,7 @@ let s:did_auto_closetag = 1 " Gets the current HTML tag by the cursor. fun s:GetCurrentTag() - return matchstr(matchstr(getline('.'), - \ '<\zs\(\w\|=\| \|''\|"\)*>\%'.col('.').'c'), '^\a*') + return matchstr(matchstr(getline('.'), '<\zs.\+>\%'.col('.').'c'), '^\w*') endf " Cleanly return after autocompleting an html/xml tag. From b17a36962bc98812f54daf61bf0e967699599a4a Mon Sep 17 00:00:00 2001 From: Tyler Brazier Date: Mon, 28 Sep 2015 22:13:55 -0400 Subject: [PATCH 2/4] Update list of void elements for html 5 --- ftplugin/html_autoclosetag.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftplugin/html_autoclosetag.vim b/ftplugin/html_autoclosetag.vim index 43821d3..b0264f8 100644 --- a/ftplugin/html_autoclosetag.vim +++ b/ftplugin/html_autoclosetag.vim @@ -58,8 +58,8 @@ fun s:CloseTag() if line[col] !~ '\w\|<\|>' && !s:InComment() let tag = s:GetCurrentTag() " Insert closing tag if tag is not self-closing and has not already - " been closed - if tag != '' && tag !~ '\vimg|input|link|meta|br|hr|area|base|param|dd|dt' + " been closed. http://www.w3.org/TR/html5/syntax.html#void-elements + if tag != '' && tag !~ '\varea|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr' \ && !s:ClosingTag(tag) let line = substitute(line, '\%'.col.'c', '', '') call setline('.', line) From bd7bd7f2340c4dfd8e1880f73061822ca3e061fc Mon Sep 17 00:00:00 2001 From: Tyler Brazier Date: Mon, 28 Sep 2015 23:28:16 -0400 Subject: [PATCH 3/4] Bug fix
| didn't close div This was happening because the pattern would match 'a' for the div rather than 'div' since we grab the first occurrence of a tag in the line. http://stackoverflow.com/questions/11865845 --- ftplugin/html_autoclosetag.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/html_autoclosetag.vim b/ftplugin/html_autoclosetag.vim index b0264f8..1efcf91 100644 --- a/ftplugin/html_autoclosetag.vim +++ b/ftplugin/html_autoclosetag.vim @@ -16,7 +16,7 @@ let s:did_auto_closetag = 1 " Gets the current HTML tag by the cursor. fun s:GetCurrentTag() - return matchstr(matchstr(getline('.'), '<\zs.\+>\%'.col('.').'c'), '^\w*') + return matchstr(matchstr(getline('.'), '.*<\zs.\+>\%'.col('.').'c'), '^\w*') endf " Cleanly return after autocompleting an html/xml tag. From 9f154a78b38901ac3c5e86d3332ab1d686b50b1b Mon Sep 17 00:00:00 2001 From: Ashin Date: Fri, 22 Jul 2016 09:29:57 +0800 Subject: [PATCH 4/4] Amend the current tag regex to match tags like my-tag --- ftplugin/html_autoclosetag.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/html_autoclosetag.vim b/ftplugin/html_autoclosetag.vim index 1efcf91..6bcd194 100644 --- a/ftplugin/html_autoclosetag.vim +++ b/ftplugin/html_autoclosetag.vim @@ -16,7 +16,7 @@ let s:did_auto_closetag = 1 " Gets the current HTML tag by the cursor. fun s:GetCurrentTag() - return matchstr(matchstr(getline('.'), '.*<\zs.\+>\%'.col('.').'c'), '^\w*') + return matchstr(matchstr(getline('.'), '.*<\zs.\+>\%'.col('.').'c'), '^[0-9A-Za-z_\-]*') endf " Cleanly return after autocompleting an html/xml tag.