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:\Users\Administrator\Documents\Source Insight\Projects\Base

 

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子菜單項,並且顯示了快捷鍵,選擇需要注釋的代碼段,點擊子菜單或使用快捷鍵即可實現多行注釋,再點擊快捷鍵或子菜單即可消除多行注釋。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM