Multi-line comment in source insight

Source: Internet
Author: User

We often needCodeMany code editors provide the following functions: use shortcuts"Ctrl + /"To achieve"//".

HoweverSource insightIt was found that such a feature was not available. So I searched the internet,SourceinsightThe multiline annotations in can be implemented using macros.

The following is the macro code that implements multi-line annotation (on other websitesCopyAfter testing, it is still very useful ):

Macro multilinecomment ()

{

Hwnd = getcurrentwnd ()

Selection = getwndsel (hwnd)

Lnfirst = getwndsellnfirst (hwnd) // obtain the row number of the first line

Lnlast = getwndsellnlast (hwnd) // obtain the row number of the last row

Hbuf = getcurrentbuf ()

 

If (getbufline (hbuf, 0) = "// magic-number: tph85666031 "){

Stop

}

 

Ln = lnfirst

Buf = getbufline (hbuf, LN)

Len = strlen (BUF)

 

While (LN <= lnlast ){

Buf = getbufline (hbuf, LN) // obtain the row corresponding to ln

If (BUF = "") {// skip empty rows

Ln = ln + 1

Continue

}

 

If (strmid (BUF, 0, 1) = "/") {// The comment must be canceled to prevent single-character rows.

If (strmid (BUF, 1, 2) = "/"){

Putbufline (hbuf, LN, strmid (BUF, 2, strlen (BUF )))

}

}

 

If (strmid (BUF, 0, 1 )! = "/") {// Add comments

Putbufline (hbuf, LN, CAT ("//", Buf ))

}

Ln = ln + 1

}

 

Setwndsel (hwnd, selection)

}

Save the preceding code as XXX. em file, open source insight Add the file to the project, in options-> keyassignments you can see this macro, the macro name is multilinecomments , and then assign the shortcut key " Ctrl +/" , and then you can.

Here is a copy to add"# Ifdef 0"And"# Endif"Macro code:

Macro addm1_comment ()

{

Hwnd = getcurrentwnd ()

Sel = getwndsel (hwnd)

Lnfirst = getwndsellnfirst (hwnd)

Lnlast = getwndsellnlast (hwnd)

Hbuf = getcurrentbuf ()

 

If (lnfirst = 0 ){

Szifstart = ""

} Else {

Szifstart = getbufline (hbuf, LnFirst-1)

}

Szifend = getbufline (hbuf, lnlast + 1)

If (szifstart = "# If 0" & szifend = "# endif "){

Delbufline (hbuf, lnlast + 1)

Delbufline (hbuf, lnFirst-1)

Sel. lnfirst = SEL. lnfirst-1

Sel. lnlast = SEL. lnlast-1

} Else {

Insbufline (hbuf, lnfirst, "# If 0 ")

Insbufline (hbuf, lnlast + 2, "# endif ")

Sel. lnfirst = SEL. lnfirst + 1

Sel. lnlast = SEL. lnlast + 1

}

 

Setwndsel (hwnd, Sel)

}

The macro code can comment out the rows displayed by the cursor:

Macro commentsingleline ()

{

Hbuf = getcurrentbuf ()

Ln = getbuflncur (hbuf)

STR = getbufline (hbuf, LN)

STR = CAT ("/*", STR)

STR = CAT (STR ,"*/")

Putbufline (hbuf, LN, STR)

}

Comment out the selected part of a row with the mouse:

Macro commentselstr ()

{

Hbuf = getcurrentbuf ()

Ln = getbuflncur (hbuf)

STR = getbufseltext (hbuf)

STR = CAT ("/*", STR)

STR = CAT (STR ,"*/")

Setbufseltext (hbuf, STR)

}

FinallySource insightMacro-related resources:

·Source insightOfficial macro library

·Source insightOfficial help documentation

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.