@@ -61,13 +61,34 @@ ft["zig"] = "// %s"
6161ft [" zscript" ] = " // %s"
6262ft [" zsh" ] = " # %s"
6363
64- function updateCommentType (buf )
65- if buf .Settings [" commenttype" ] == nil then
66- if ft [buf .Settings [" filetype" ]] ~= nil then
67- buf .Settings [" commenttype" ] = ft [buf .Settings [" filetype" ]]
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
6876 else
69- buf .Settings [" commenttype " ] = " # %s "
77+ ft [ bp .Settings [" filetype " ]] = bp . Settings [ " commenttype " ]
7078 end
79+ -- Update filetype
80+ bp .Settings [" commentfiletype" ] = bp .Settings [" filetype" ]
81+
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" ]]
86+ else
87+ bp .Settings [" commenttype" ] = " # %s"
88+ end
89+
90+ -- Update filetype
91+ bp .Settings [" commentfiletype" ] = bp .Settings [" filetype" ]
7192 end
7293end
7394
0 commit comments