Skip to content

Commit f12b941

Browse files
Using DoSetOptionNative for comment.type ...
Using DoSetOptionNative for comment.type, Updating comments in comment plugin, Allow use of commenttype but with warning
1 parent 5dc41ce commit f12b941

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

runtime/plugins/comment/comment.lua

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,21 @@ ft["zscript"] = "// %s"
6363
ft["zsh"] = "# %s"
6464

6565
function updateCommentType(buf)
66-
-- NOTE: Don't use SetOptionNative() to set "comment.type",
67-
-- otherwise "comment.type" can't be reset by a "filetype" change.
68-
if buf.Settings["comment.type"] == "" then
66+
-- NOTE: Using DoSetOptionNative to avoid LocalSettings[option] = true
67+
-- so that "comment.type" can be reset by a "filetype" change to default.
68+
if (buf.Settings["comment.type"] == "") then
69+
-- NOTE: This won't get triggered if a filetype is change via `setlocal filetype`
70+
-- since it is not registered with `RegisterGlobalOption()``
6971
if buf.Settings["commenttype"] ~= nil then
7072
micro.InfoBar():Error("\"commenttype\" option has been renamed to \"comment.type\"",
7173
", please update your configuration")
72-
end
73-
74-
if ft[buf.Settings["filetype"]] ~= nil then
75-
buf.Settings["comment.type"] = ft[buf.Settings["filetype"]]
74+
buf:DoSetOptionNative("comment.type", buf.Settings["commenttype"])
7675
else
77-
buf.Settings["comment.type"] = "# %s"
76+
if (ft[buf.Settings["filetype"]] ~= nil) then
77+
buf:DoSetOptionNative("comment.type", ft[buf.Settings["filetype"]])
78+
else
79+
buf:DoSetOptionNative("comment.type", "# %s")
80+
end
7881
end
7982
end
8083
end

0 commit comments

Comments
 (0)