Jump to content

SciTE - UTF8BOM only for au3 files

Recommended Posts

If you have set the property 


each file, that will created in SciTE, get this encoding.

If you work only with au3-files, it's OK. But if you also use e.g. lua-files, the BOM must removed.

Therefore I've made another solution:

-- 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

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))
	local fh = io.open(_file, "rb")
	local read = fh:read(3)
	return (ToHex(read) == "EFBBBF")

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

Load the "CheckBOM.lua" with your "SciTEStartup.lua" and, if required, create the property "BOM.File.Types" to add other file types for using BOM.


Best Regards BugFix  

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...