From d8313d9c6b472d6d6c3827ec4be7e1ce9cf817f3 Mon Sep 17 00:00:00 2001 From: Neko Box Coder Date: Wed, 14 Aug 2024 01:35:31 +0100 Subject: [PATCH] Adding tracker per bufferpane for comment plugin --- runtime/plugins/comment/comment.lua | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/runtime/plugins/comment/comment.lua b/runtime/plugins/comment/comment.lua index 22d635ff57..6de19566c2 100644 --- a/runtime/plugins/comment/comment.lua +++ b/runtime/plugins/comment/comment.lua @@ -61,12 +61,30 @@ ft["zig"] = "// %s" ft["zscript"] = "// %s" ft["zsh"] = "# %s" -function updateCommentType(buf) - if buf.Settings["commenttype"] == nil then - if ft[buf.Settings["filetype"]] ~= nil then - buf.Settings["commenttype"] = ft[buf.Settings["filetype"]] +function updateCommentType(bp) + -- This is the first time doing comment in this bp + if bp.Settings["commentfiletype"] == nil then + -- If commenttype is not registered, use the comment table we have + if bp.Settings["commenttype"] == nil then + if ft[bp.Settings["filetype"]] ~= nil then + bp.Settings["commenttype"] = ft[bp.Settings["filetype"]] + else + bp.Settings["commenttype"] = "# %s" + end + -- Otherwise if the commenttype is registered, that means this is coming from the settings, + -- or set manually by the user. We should update our comment table + else + ft[bp.Settings["filetype"]] = bp.Settings["commenttype"] + end + -- Watch for any filetype change + bp.Settings["commentfiletype"] = bp.Settings["filetype"] + + -- Otherwise, check if the filetype has changed manually. If so, use the comment table + elseif bp.Settings["commentfiletype"] ~= bp.Settings["filetype"] then + if ft[bp.Settings["filetype"]] ~= nil then + bp.Settings["commenttype"] = ft[bp.Settings["filetype"]] else - buf.Settings["commenttype"] = "# %s" + bp.Settings["commenttype"] = "# %s" end end end