-- TIME_STAMP 2021-04-15 14:02:19 --[[ After a file was saved, the event OnSave will fired. Now will checked: - needs this file typ the BOM? - If Yes: Has this file already the BOM? - If No: Write the BOM sequence at the beginning of the file If you want register other types as "au3" for set BOM use this property in SciTEUser.properties: #~ File types, that needs byte order mark #~ "au3" is predefined and does not need to be set here BOM.File.Types=extension_1 extension_2 ]] CheckBOM = EventClass:new(Common) CheckBOM.OnSave = function(self, _file) if not self:NeedsBOM(props['FileExt']) then return nil end if not self:StartsWithBOM(_file) then scite.MenuCommand(153) end return nil end CheckBOM.StartsWithBOM = function(self, _file) local ToHex = function(_s) if _s == nil then return "DEAD" end return (_s:gsub('.', function(_c) return ('%02X'):format(_c:byte()) end)) end local fh = io.open(_file, "rb") local read = fh:read(3) fh:close() return (ToHex(read) == "EFBBBF") end CheckBOM.NeedsBOM = function(self, _ext) local extensions = props['BOM.File.Types']:lower()..' au3' if extensions:find(_ext:lower()) then return true else return false end end