标签:style blog color ar 使用 sp 文件 div on
Source Insight 提供了宏实现和命令实现。
命令实现:
1、代码排版
需要借助indent工具。可以下载GnuWin32,可以安装大多数Linux命令。
indent排版很简单。
添加命令:indent.exe -npro -nip -nlp -npsl -i4 -ts4 -sob -l80 -ss -bl -bli 0 %f
%f代表当前文件。
Souce Insight可以给命令添加菜单和快捷键。
2、编码转换
需要借助iconv工具。可以下载libiconv工具。
iconv.exe命令使用:
iconv.exe -f utf-8 -t gbk sourceFile > targetFile
由于iconv.exe不能将sourceFile > sourceFile,可以考虑添加临时文件进行转换。
添加命令:copy %f d:\tmp;iconv.exe -f utf-8 -t gbk "d:\tmp" > %f;del d:\tmp;
由于命令的格式确定了当前文件的编码和目标文件的编码。不是很方便使用。
这时候可以使用宏来实现。
宏实现:
macro _GetSourceCode()
{
str = Ask ("请输入源编码:")
return str
}
macro _GetTargetCode()
{
str = Ask ("请输入目标编码:")
return str
}
macro CodeConvert()
{
codeConvert = "iconv.exe";
sCode = _GetSourceCode()
tCode = _GetTargetCode()
hbuf = GetCurrentBuf()
sFile = GetBufName(hbuf)
msg("Convert @sCode@ to @tCode@")
exitcode = RunCmdLine ("cmd /c copy \"@sFile@\" \"@sFile@_bak\";",".",true)
exitcode = RunCmdLine ("cmd /c iconv.exe -f @sCode@ -t @tCode@ \"@sFile@_bak\" > \"@sFile@\";",".",true)
exitcode = RunCmdLine ("cmd /c del \"@sFile@_bak\";",".",true)
RunCmd("Reload File");
RunCmd("Reload Modified Files");
RunCmd("Parse File Now");
}
这样可以动态的获取源编码和目标编码。
可以通过iconv.exe -l来查询所支持的编码。
可能出现的问题,iconv.exe转换编码失败,文件的内容会被错误的修改。最好能够确定源编码类型。
另外Windows的编码类型会有Bom和无Bom的区别。这个还要进行区分。
标签:style blog color ar 使用 sp 文件 div on
原文地址:http://www.cnblogs.com/ying-/p/4081370.html