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