Source Insight adds code layout and encoding conversion

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.