@@ -61,17 +61,34 @@ ft["zig"] = "// %s"
6161ft [" zscript" ] = " // %s"
6262ft [" zsh" ] = " # %s"
6363
64- local last_ft
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" ]
78+ end
79+ -- Update filetype
80+ bp .Settings [" commentfiletype" ] = bp .Settings [" filetype" ]
6581
66- function updateCommentType ( buf )
67- if buf .Settings [" commenttype " ] == nil or ( last_ft ~= buf .Settings [" filetype" ] and last_ft ~= nil ) then
68- if ft [buf .Settings [" filetype" ]] ~= nil then
69- buf .Settings [" commenttype" ] = ft [buf .Settings [" filetype" ]]
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" ]]
7086 else
71- buf .Settings [" commenttype" ] = " # %s"
87+ bp .Settings [" commenttype" ] = " # %s"
7288 end
7389
74- last_ft = buf .Settings [" filetype" ]
90+ -- Update filetype
91+ bp .Settings [" commentfiletype" ] = bp .Settings [" filetype" ]
7592 end
7693end
7794
0 commit comments