-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing comment plugin not using user settings when overriding default setting #3424
base: master
Are you sure you want to change the base?
Changes from 3 commits
d40a952
b4920fb
7134d3f
5dc41ce
f12b941
414c319
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ VERSION = "1.0.0" | |
local util = import("micro/util") | ||
local config = import("micro/config") | ||
local buffer = import("micro/buffer") | ||
local micro = import("micro") | ||
|
||
local ft = {} | ||
|
||
|
@@ -61,17 +62,20 @@ ft["zig"] = "// %s" | |
ft["zscript"] = "// %s" | ||
ft["zsh"] = "# %s" | ||
|
||
local last_ft | ||
|
||
function updateCommentType(buf) | ||
if buf.Settings["commenttype"] == nil or (last_ft ~= buf.Settings["filetype"] and last_ft ~= nil) then | ||
if buf.Settings["commenttype"] ~= nil then | ||
micro.InfoBar():Error("\"commenttype\" option has been renamed to \"comment.type\"", | ||
", please update your configuration") | ||
end | ||
|
||
-- NOTE: Don't use SetOptionNative() to set "comment.type", | ||
-- otherwise "comment.type" can't be reset by a "filetype" change. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not nearly obvious why can't it be reset by a "filetype" change if we use Or actually it seems better to:
...Another option would be to somehow extend There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Would adding a function like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As matter of fact, the line between internal and external functions here is pretty blurred. (Technically
Maybe... @JoeKar what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I thought you can remember, after the long review road of #3343. 😉
So The word BTW: Wasn't the extension with a further parameter of these functions temporary part of #3343, but rejected due to the fact a of the introduction of a further parameter? Anyway, if fine with that adjustment, in case it helps to improve the code/interfaces. Indeed we can then drop the introduced comment in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what @Neko-Box-Coder meant is a separate function just for toggling the option's persistence state, independently of setting the option value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And also I forgot to mention is I would like to not break back compatibility as well for So ideally changing those 2 functions (name and parameters I guess) would be our last resort if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, these two should stay as they are, but we can rename those two called from them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, why not simply:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine to add documentation I think but it would be difficult to rename or change the function signature afterwards if we decide to use it in the plugin (which other people will follow and do the same as well if needed) I still stand by what I said before:
Or even a step further where we make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think Also I hope it is unlikely that any other plugin will actually want to use it. The
|
||
if buf.Settings["comment.type"] == "" then | ||
if ft[buf.Settings["filetype"]] ~= nil then | ||
buf:SetOptionNative("commenttype", ft[buf.Settings["filetype"]]) | ||
buf.Settings["comment.type"] = ft[buf.Settings["filetype"]] | ||
else | ||
buf:SetOptionNative("commenttype", "# %s") | ||
buf.Settings["comment.type"] = "# %s" | ||
end | ||
|
||
last_ft = buf.Settings["filetype"] | ||
end | ||
end | ||
|
||
|
@@ -88,7 +92,7 @@ function commentLine(bp, lineN, indentLen) | |
updateCommentType(bp.Buf) | ||
|
||
local line = bp.Buf:Line(lineN) | ||
local commentType = bp.Buf.Settings["commenttype"] | ||
local commentType = bp.Buf.Settings["comment.type"] | ||
local sel = -bp.Cursor.CurSelection | ||
local curpos = -bp.Cursor.Loc | ||
local index = string.find(commentType, "%%s") - 1 | ||
|
@@ -114,7 +118,7 @@ function uncommentLine(bp, lineN, commentRegex) | |
updateCommentType(bp.Buf) | ||
|
||
local line = bp.Buf:Line(lineN) | ||
local commentType = bp.Buf.Settings["commenttype"] | ||
local commentType = bp.Buf.Settings["comment.type"] | ||
local sel = -bp.Cursor.CurSelection | ||
local curpos = -bp.Cursor.Loc | ||
local index = string.find(commentType, "%%s") - 1 | ||
|
@@ -178,7 +182,7 @@ end | |
function comment(bp, args) | ||
updateCommentType(bp.Buf) | ||
|
||
local commentType = bp.Buf.Settings["commenttype"] | ||
local commentType = bp.Buf.Settings["comment.type"] | ||
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)") | ||
|
||
if bp.Cursor:HasSelection() then | ||
|
@@ -204,6 +208,10 @@ function string.starts(String,Start) | |
return string.sub(String,1,string.len(Start))==Start | ||
end | ||
|
||
function preinit() | ||
config.RegisterCommonOption("comment", "type", "") | ||
end | ||
|
||
function init() | ||
config.MakeCommand("comment", comment, config.NoComplete) | ||
config.TryBindKey("Alt-/", "lua:comment.comment", false) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After changing
commenttype
tocomment.type
insettings.json
and running thereload
command, micro still stubbornly shows this error.