updated autotag2.lua

Brandon [08-08-17 - 09:03]
updated autotag2.lua

Now scans entire document when deciding whether or not to place a closing tag, in addition to the current line.

If a second tag is really intended to be placed that is identical to one already present in the file, pressing the '>' key a second time will override the default behavior and place an nth closing tag. It will then delete the extra chevron automatically.

Sets of tags still need to be entered one set per line for the script to behave as intended. Trying to do <tag1><tag2></tag2></tag1> is still beyond the scope of this script.
Filename
autotag2.lua
diff --git a/autotag2.lua b/autotag2.lua
index c4fbe37..5263717 100644
--- a/autotag2.lua
+++ b/autotag2.lua
@@ -11,10 +11,21 @@ return {
             if tag:find([[</]]) then
                 goto breakout
             end
-            if tag:find([[<[%w%d%s"'=]+/>]]) then
-                goto breakout
+            if tag:find([[/>]]) then
+                return
             end
+            local document = editor:GetText()
             local tagtoclose = tag:match("<([%a%d]+)")
+            local fullclosingtag = "</"..tagtoclose..">"
+            local fullopeningtag = "<"..tagtoclose..">"
+            if document:find(fullopeningtag..">") then
+                editor:AddText(fullclosingtag)
+                editor:SetEmptySelection(curpos)
+                editor:DeleteRange(curpos-1, 1)
+                return
+            elseif document:find(fullclosingtag) then
+                return
+            end
             editor:AddText("</"..tagtoclose..">")
             editor:SetEmptySelection(curpos)
             ::breakout::