Source Insight 3.5 注释快捷键

1.新建文件comment.em,内容如下:

// 添加多行注释
macro MultiLineComment()
{
    hwnd = GetCurrentWnd()
    selection = GetWndSel(hwnd)
    LnFirst =GetWndSelLnFirst(hwnd) //取首行行号
    LnLast =GetWndSelLnLast(hwnd) //取末行行号
    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) //取Ln对应的行
    if(buf ==""){ //跳过空行
    Ln = Ln + 1
    continue
    }
    if(StrMid(buf, 0, 1) == "/"){ //需要取消注释,防止只有单字符的行
    if(StrMid(buf, 1, 2) == "/"){
    PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))
    }
    }
    if(StrMid(buf,0,1) !="/"){ //需要添加注释
    PutBufLine(hbuf, Ln, Cat("//", buf))
    }
    Ln = Ln + 1
    }
    SetWndSel(hwnd, selection)
}

// 添加 #if 0  #endif
macro AddMacroComment()  
{  
    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) 
            lnFirst = lnFirst - 1  
            lnLast = lnLast - 1 
    }else{  
            InsBufLine(hbuf, lnFirst, "#if 0")  
            InsBufLine(hbuf, lnLast+2, "#endif")  
            lnFirst = lnFirst + 1  
            lnLast = lnLast + 1  
    }  
   
    SetWndSel( hwnd, sel )  
} 

2.将comment.em拷贝到Source Insight base工程目录,如C:UsersAdministratorDocumentsSource InsightProjectsBase

3. 创建sourceinsight工程,将工程所需的源代码与上一步骤中的***.em文件都添加到工程中。

4. 重建工程: Project->Rebuilt Project; (若是在工程建好后再添加.em文件,此步很重要)

4.添加快捷键: Options->Key Assignment,在command编辑框下敲入MultiLineComment会出现Macro:MultiLineComment, 点击Assign New Key...,输入快捷键,常用的是Ctrl+\, 若该快捷键已被占用,可使用Ctrl+shift+或其他习惯用的。

5.添加工具栏菜单: Options->Menu Assignment, 同样在command编辑框下敲入MultiLineComment, 点击右边的Menu下拉框,选择想要放的菜单栏,例如放在edit菜单栏下,再点击MeauContents下的<end of menu>,点击右边的Insert按钮,插入子菜单名称即可,如MultiLineComment, 再点击OK。

6.此时选择多行代码按快捷键就可以注释和非注释某些代码了。主菜单下会有edit菜单项,Work下有MultiLineComment子菜单项,并且显示了快捷键,选择需要注释的代码段,点击子菜单或使用快捷键即可实现多行注释,再点击快捷键或子菜单即可消除多行注释。

原文地址:https://www.cnblogs.com/risunlee/p/12882380.html