Source Insight provides macro implementation and command implementation.
Command implementation:
1. Code layout
Use the indent tool. You can download GnuWin32 and install most Linux commands.
Indent layout is simple.
Add command: indent.exe-npro-nip-nlp-npsl-i4-ts4-sob-l80-ss-bl-bli 0% f
% F indicates the current file.
Souce Insight can add menus and shortcuts to commands.
2. Encoding conversion
The iconv tool is required. You can download the libiconv tool.
Use the iconv.exe command:
Iconv.exe-f UTF-8-t gbk sourceFile> targetFile
Because iconv.exe does not support sourceFile> sourceFile, you can consider adding a temporary file for conversion.
Add command: copy % f d: \ tmppoliciconv.exe-f UTF-8-t gbk "d: \ tmp"> % f; del d: \ tmp;
The command format determines the encoding of the current file and the target file. Not very convenient to use.
In this case, macro can be used.
Macro implementation:
Macro _ GetSourceCode () {str = Ask ("Enter the source code:") return str} macro _ GetTargetCode () {str = Ask ("Enter the target code :") return str} macro CodeConvert () {codeConvert = "iconv.exe"; sCode = _ GetSourceCode () tCode = _ GetTargetCode () hbuf = GetCurrentBuf () sFile = GetBufName (hbuf) msg ("Convert @ [email protected] to @ [email protected]") exitcode = RunCmdLine ("cmd/c copy \" @ [email protected] \ "\" @ [email protected] _ bak \";",". ", true) exitcode = RunCmdLine ("cmd/c iconv.exe-f @ [email protected]-t @ [email protected] \" @ [email protected] _ bak \ "> \" @ [email protected] \ "; ",". ", true) exitcode = RunCmdLine (" cmd/c del \ "@ [email protected] _ bak \";",". ", true) RunCmd (" Reload File "); RunCmd (" Reload Modified Files "); RunCmd (" Parse File Now ");}
In this way, the source and target codes can be dynamically obtained.
You can use iconv.exe-l to query Supported encodings.
The iconv.exe conversion fails and the file content is incorrectly modified. It is best to determine the source encoding type.
In addition, the Bom and Bom are different for Windows encoding types. This must be differentiated.
Source Insight adds code layout and encoding conversion