Skip to content

Commit d40a952

Browse files
Updating comment plugin option and fixing comment option reset bug
Updating comment plugin option to be comment.type Fixing unwanted comment option reset when switching buffers
1 parent cc195b6 commit d40a952

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

runtime/plugins/comment/comment.lua

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,15 @@ ft["zig"] = "// %s"
6161
ft["zscript"] = "// %s"
6262
ft["zsh"] = "# %s"
6363

64-
local last_ft
65-
6664
function updateCommentType(buf)
67-
if buf.Settings["commenttype"] == nil or (last_ft ~= buf.Settings["filetype"] and last_ft ~= nil) then
65+
-- NOTE: Don't use SetOptionNative() to set "comment.type",
66+
-- otherwise "comment.type" can't be reset by a "filetype" change.
67+
if buf.Settings["comment.type"] == "" then
6868
if ft[buf.Settings["filetype"]] ~= nil then
69-
buf:SetOptionNative("commenttype", ft[buf.Settings["filetype"]])
69+
buf.Settings["comment.type"] = ft[buf.Settings["filetype"]]
7070
else
71-
buf:SetOptionNative("commenttype", "# %s")
71+
buf.Settings["comment.type"] = "# %s"
7272
end
73-
74-
last_ft = buf.Settings["filetype"]
7573
end
7674
end
7775

@@ -88,7 +86,7 @@ function commentLine(bp, lineN, indentLen)
8886
updateCommentType(bp.Buf)
8987

9088
local line = bp.Buf:Line(lineN)
91-
local commentType = bp.Buf.Settings["commenttype"]
89+
local commentType = bp.Buf.Settings["comment.type"]
9290
local sel = -bp.Cursor.CurSelection
9391
local curpos = -bp.Cursor.Loc
9492
local index = string.find(commentType, "%%s") - 1
@@ -114,7 +112,7 @@ function uncommentLine(bp, lineN, commentRegex)
114112
updateCommentType(bp.Buf)
115113

116114
local line = bp.Buf:Line(lineN)
117-
local commentType = bp.Buf.Settings["commenttype"]
115+
local commentType = bp.Buf.Settings["comment.type"]
118116
local sel = -bp.Cursor.CurSelection
119117
local curpos = -bp.Cursor.Loc
120118
local index = string.find(commentType, "%%s") - 1
@@ -178,7 +176,7 @@ end
178176
function comment(bp, args)
179177
updateCommentType(bp.Buf)
180178

181-
local commentType = bp.Buf.Settings["commenttype"]
179+
local commentType = bp.Buf.Settings["comment.type"]
182180
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)")
183181

184182
if bp.Cursor:HasSelection() then
@@ -204,6 +202,10 @@ function string.starts(String,Start)
204202
return string.sub(String,1,string.len(Start))==Start
205203
end
206204

205+
function preinit()
206+
config.RegisterCommonOption("comment", "type", "")
207+
end
208+
207209
function init()
208210
config.MakeCommand("comment", comment, config.NoComplete)
209211
config.TryBindKey("Alt-/", "lua:comment.comment", false)

0 commit comments

Comments
 (0)