Skip to content

Commit 321d5d4

Browse files
Merge branch 'CommentPluginFix' into dev
2 parents c16ec82 + 5dc41ce commit 321d5d4

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
> - [Adding Jumping to opening and closing brace logic and actions #3384](https://github.com/zyedidia/micro/pull/3384)
1515
> - [Allowing plugin to add cursor in custom Loc #3441](https://github.com/zyedidia/micro/pull/3441)
1616
> - [Adding auto complete support for multi cursors #3442](https://github.com/zyedidia/micro/pull/3442)
17+
> - [Fixing comment plugin not using user settings when overriding default setting #3424](https://github.com/zyedidia/micro/pull/3424)
1718
>
1819
> To see the diff between this and upstream master, click [here](https://github.com/zyedidia/micro/compare/master...Neko-Box-Coder:micro-dev:dev)
1920

runtime/plugins/comment/comment.lua

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ VERSION = "1.0.0"
33
local util = import("micro/util")
44
local config = import("micro/config")
55
local buffer = import("micro/buffer")
6+
local micro = import("micro")
67

78
local ft = {}
89

@@ -61,34 +62,20 @@ ft["zig"] = "// %s"
6162
ft["zscript"] = "// %s"
6263
ft["zsh"] = "# %s"
6364

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
76-
else
77-
ft[bp.Settings["filetype"]] = bp.Settings["commenttype"]
65+
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
69+
if buf.Settings["commenttype"] ~= nil then
70+
micro.InfoBar():Error("\"commenttype\" option has been renamed to \"comment.type\"",
71+
", please update your configuration")
7872
end
79-
-- Update filetype
80-
bp.Settings["commentfiletype"] = bp.Settings["filetype"]
8173

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"]]
74+
if ft[buf.Settings["filetype"]] ~= nil then
75+
buf.Settings["comment.type"] = ft[buf.Settings["filetype"]]
8676
else
87-
bp.Settings["commenttype"] = "# %s"
77+
buf.Settings["comment.type"] = "# %s"
8878
end
89-
90-
-- Update filetype
91-
bp.Settings["commentfiletype"] = bp.Settings["filetype"]
9279
end
9380
end
9481

@@ -105,7 +92,7 @@ function commentLine(bp, lineN, indentLen)
10592
updateCommentType(bp.Buf)
10693

10794
local line = bp.Buf:Line(lineN)
108-
local commentType = bp.Buf.Settings["commenttype"]
95+
local commentType = bp.Buf.Settings["comment.type"]
10996
local sel = -bp.Cursor.CurSelection
11097
local curpos = -bp.Cursor.Loc
11198
local index = string.find(commentType, "%%s") - 1
@@ -131,7 +118,7 @@ function uncommentLine(bp, lineN, commentRegex)
131118
updateCommentType(bp.Buf)
132119

133120
local line = bp.Buf:Line(lineN)
134-
local commentType = bp.Buf.Settings["commenttype"]
121+
local commentType = bp.Buf.Settings["comment.type"]
135122
local sel = -bp.Cursor.CurSelection
136123
local curpos = -bp.Cursor.Loc
137124
local index = string.find(commentType, "%%s") - 1
@@ -195,7 +182,7 @@ end
195182
function comment(bp, args)
196183
updateCommentType(bp.Buf)
197184

198-
local commentType = bp.Buf.Settings["commenttype"]
185+
local commentType = bp.Buf.Settings["comment.type"]
199186
local commentRegex = "^%s*" .. commentType:gsub("%%","%%%%"):gsub("%$","%$"):gsub("%)","%)"):gsub("%(","%("):gsub("%?","%?"):gsub("%*", "%*"):gsub("%-", "%-"):gsub("%.", "%."):gsub("%+", "%+"):gsub("%]", "%]"):gsub("%[", "%["):gsub("%%%%s", "(.*)")
200187

201188
if bp.Cursor:HasSelection() then
@@ -221,6 +208,10 @@ function string.starts(String,Start)
221208
return string.sub(String,1,string.len(Start))==Start
222209
end
223210

211+
function preinit()
212+
config.RegisterCommonOption("comment", "type", "")
213+
end
214+
224215
function init()
225216
config.MakeCommand("comment", comment, config.NoComplete)
226217
config.TryBindKey("Alt-/", "lua:comment.comment", false)

0 commit comments

Comments
 (0)