Update comment filetype when commenting

This commit is contained in:
Zachary Yedidia
2021-08-20 14:42:38 -04:00
parent a4c3f7dad9
commit bb609467dd
2 changed files with 13 additions and 9 deletions

View File

@@ -60,13 +60,11 @@ ft["zig"] = "// %s"
ft["zscript"] = "// %s"
ft["zsh"] = "# %s"
function onBufferOpen(buf)
if buf.Settings["commenttype"] == nil then
if ft[buf.Settings["filetype"]] ~= nil then
buf.Settings["commenttype"] = ft[buf.Settings["filetype"]]
else
buf.Settings["commenttype"] = "# %s"
end
function updateCommentType(buf)
if ft[buf.Settings["filetype"]] ~= nil and ft[buf.Settings["filetype"]] ~= nil then
buf.Settings["commenttype"] = ft[buf.Settings["filetype"]]
elseif buf.Settings["commenttype"] == nil then
buf.Settings["commenttype"] = "# %s"
end
end
@@ -79,6 +77,8 @@ function isCommented(bp, lineN, commentRegex)
end
function commentLine(bp, lineN)
updateCommentType(bp.Buf)
local line = bp.Buf:Line(lineN)
local commentType = bp.Buf.Settings["commenttype"]
local sel = -bp.Cursor.CurSelection
@@ -100,6 +100,8 @@ function commentLine(bp, lineN)
end
function uncommentLine(bp, lineN, commentRegex)
updateCommentType(bp.Buf)
local line = bp.Buf:Line(lineN)
local commentType = bp.Buf.Settings["commenttype"]
local sel = -bp.Cursor.CurSelection
@@ -149,6 +151,8 @@ function toggleCommentSelection(bp, startLine, endLine, commentRegex)
end
function comment(bp, args)
updateCommentType(bp.Buf)
local commentType = bp.Buf.Settings["commenttype"]
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)"):gsub("%s+", "%s*")