Skip to content

Commit 7fec36d

Browse files
Merge branch 'CommentPluginFix' into dev
2 parents 79ff917 + 414c319 commit 7fec36d

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
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

runtime/plugins/comment/help/comment.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ but it is only available for certain filetypes:
8080
* zsh: `# %s`
8181

8282
If your filetype is not available here, you can simply modify
83-
the `commenttype` option:
83+
the `comment.type` option:
8484

8585
```
86-
set commenttype "/* %s */"
86+
set comment.type "/* %s */"
8787
```
8888

8989
Or in your `settings.json`:
9090

9191
```json
9292
{
9393
"*.c": {
94-
"commenttype": "/* %s */"
94+
"comment.type": "/* %s */"
9595
}
9696
}
9797
```

0 commit comments

Comments
 (0)