@@ -61,17 +61,15 @@ ft["zig"] = "// %s"
6161ft [" zscript" ] = " // %s"
6262ft [" zsh" ] = " # %s"
6363
64- local last_ft
65-
6664function 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
7674end
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
178176function 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
205203end
206204
205+ function preinit ()
206+ config .RegisterCommonOption (" comment" , " type" , " " )
207+ end
208+
207209function init ()
208210 config .MakeCommand (" comment" , comment , config .NoComplete )
209211 config .TryBindKey (" Alt-/" , " lua:comment.comment" , false )
0 commit comments