X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=runtime%2Fplugins%2Fcomment%2Fcomment.lua;h=bcf91c6c910f3ef8287dd9c364787af7ddeb32be;hb=HEAD;hp=4c3032c6088bd490e1f55d175006551a3ef0c422;hpb=621e4e9e4dac3e037936d7e33bdb272f0f58c997;p=micro.git diff --git a/runtime/plugins/comment/comment.lua b/runtime/plugins/comment/comment.lua index 4c3032c6..bcf91c6c 100644 --- a/runtime/plugins/comment/comment.lua +++ b/runtime/plugins/comment/comment.lua @@ -35,6 +35,7 @@ ft["markdown"] = "" ft["nginx"] = "# %s" ft["nim"] = "# %s" ft["objc"] = "// %s" +ft["ocaml"] = "(* %s *)" ft["pascal"] = "{ %s }" ft["perl"] = "# %s" ft["php"] = "// %s" @@ -59,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 @@ -78,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 @@ -99,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 @@ -148,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*")