Skip to content

Commit 4d8a040

Browse files
Adding tracker per bufferpane for comment plugin
1 parent 589452d commit 4d8a040

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

runtime/plugins/comment/comment.lua

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,34 @@ ft["zig"] = "// %s"
6161
ft["zscript"] = "// %s"
6262
ft["zsh"] = "# %s"
6363

64-
function updateCommentType(buf)
65-
if buf.Settings["commenttype"] == nil then
66-
if ft[buf.Settings["filetype"]] ~= nil then
67-
buf.Settings["commenttype"] = ft[buf.Settings["filetype"]]
64+
function updateCommentType(bp)
65+
-- This is the first time doing comment in this bp
66+
if bp.Settings["commentfiletype"] == nil then
67+
-- If commenttype is not registered, use the comment table we have
68+
if bp.Settings["commenttype"] == nil then
69+
if ft[bp.Settings["filetype"]] ~= nil then
70+
bp.Settings["commenttype"] = ft[bp.Settings["filetype"]]
71+
else
72+
bp.Settings["commenttype"] = "# %s"
73+
end
74+
-- Otherwise if the commenttype is registered, that means this is coming from the settings,
75+
-- or set manually by the user. We should update our comment table
6876
else
69-
buf.Settings["commenttype"] = "# %s"
77+
ft[bp.Settings["filetype"]] = bp.Settings["commenttype"]
7078
end
79+
-- Update filetype
80+
bp.Settings["commentfiletype"] = bp.Settings["filetype"]
81+
82+
-- Otherwise, check if the filetype has changed manually. If so, use the comment table
83+
elseif bp.Settings["commentfiletype"] ~= bp.Settings["filetype"] then
84+
if ft[bp.Settings["filetype"]] ~= nil then
85+
bp.Settings["commenttype"] = ft[bp.Settings["filetype"]]
86+
else
87+
bp.Settings["commenttype"] = "# %s"
88+
end
89+
90+
-- Update filetype
91+
bp.Settings["commentfiletype"] = bp.Settings["filetype"]
7192
end
7293
end
7394

0 commit comments

Comments
 (0)