找回密码
 加入
搜索
查看: 1234|回复: 3

[系统综合] SciTE设置UTF8BOM格式

[复制链接]
发表于 2021-4-16 09:09:13 | 显示全部楼层 |阅读模式
本帖最后由 redapple2008 于 2021-4-16 10:30 编辑

https://www.autoitscript.com/forum/topic/205631-scite-utf8bom-only-for-au3-files/

如果设置了属性
NewFileEncoding = UTF8BOM
将在SciTE中创建的每个文件都将获得此编码。
如果仅使用au3-文件,则可以。但是,如果您还使用例如lua文件,则必须删除BOM。
因此,我提出了另一种解决方案:
<pre class="ipsCode prettyprint lang-c prettyprinted" style="box-sizing: border-box; font-family: Consolas, "Courier New", "Andale Mono", monospace; font-size: 12px; overflow: auto; tab-size: 4; white-space: pre-wrap; line-height: 13.2px; text-rendering: optimizespeed; background: rgb(248, 248, 248); clear: both; direction: ltr; overflow-wrap: normal; padding: 5px; border: 1px solid rgb(201, 201, 201); margin-left: 10px; max-height: 500px; color: rgb(53, 60, 65);">-- 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</pre>
用“ SciTEStartup.lua”加载“ CheckBOM.lua”,并根据需要创建属性“ BOM.File.Types”以添加其他文件类型以使用BOM。

发表于 2021-4-16 10:18:34 | 显示全部楼层
转帖注明出处,代码也不完整
CheckBOM.NeedsBOM = function(self, _ext)
        local extensions = props['BOM.File.Types']:lower()..' au3'
        if extensions:find(_ext:lower()) then r
这明显不完整

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
 楼主| 发表于 2021-4-16 10:30:35 | 显示全部楼层
afan 发表于 2021-4-16 10:18
转帖注明出处,代码也不完整
这明显不完整

地址加上了。
发表于 2021-4-16 10:40:26 | 显示全部楼层

代码编辑后又多了两处 html 标签,唉
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-17 07:05 , Processed in 0.095776 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表