對於一直使用sourceinsight編輯C/C++代碼的工程師們,sourceinsight是一個非常好用的編輯工具可以任意定位,跳轉,回退,本人一直使用該工具做C/C++開發,sourceinsight能夠滿足我的大部分需求,但是有些功能沒有總覺得是一個缺憾。源碼鏈接:鏈接:https://pan.baidu.com/s/1DpGV75XeSpQrP1BlFbYHHg 密碼:bqq6
<1>.在SourceInsight里使用"#if 0 #endif"注釋,可用下面的方法添加宏插件。
- 在C:\Users\計算機名\Documents\Source Insight\Projects\Base中有個utils.em文件.打開編輯(注:最好預先備份utils.em)
- 在文檔的最后添加以下代碼.
1 macro Custom_AddMacroComment()//Alt+1 2 { //add #if 0 #endif 3 hwnd=GetCurrentWnd() 4 sel=GetWndSel(hwnd) 5 lnFirst=GetWndSelLnFirst(hwnd) 6 lnLast=GetWndSelLnLast(hwnd) 7 hbuf=GetCurrentBuf() 8 9 if (LnFirst == 0) 10 { 11 szIfStart = "" 12 } 13 else 14 { 15 szIfStart = GetBufLine(hbuf, LnFirst-1) 16 } 17 18 szIfEnd = GetBufLine(hbuf, lnLast+1) 19 20 if (szIfStart == "#if 0" && szIfEnd =="#endif") 21 { 22 DelBufLine(hbuf, lnLast+1) 23 DelBufLine(hbuf, lnFirst-1) 24 sel.lnFirst = sel.lnFirst – 1 25 sel.lnLast = sel.lnLast – 1 26 } 27 else 28 { 29 InsBufLine(hbuf, lnFirst, "#if 0") 30 InsBufLine(hbuf, lnLast+2, "#endif") 31 sel.lnFirst = sel.lnFirst + 1 32 sel.lnLast = sel.lnLast + 1 33 } 34 SetWndSel( hwnd, sel ) 35 }
- 打開任意一個SI工程,點擊Project->Open Project->Base,以此打開Base工程(此工程是SI的默認基礎工程,如果不打開Base工程,在后面的操作中將不會顯示所添加的宏),然后關閉此工程.
- 再打開任意一個SI工程,點擊Options->Key Assignments,然后查找Custom_AddMacroComment

- 點擊Assign New Key,此時輸入鍵盤上想設置的快捷鍵(覺得Alt+X比較順手).點擊OK.

<2>.在SourceInsight里使用多行“//”注釋,可用下面代碼添加宏插件,方法如<1>.
1 macro Custom_MultiLineComment()//Alt+2 2 { //comment multiple lines 3 hwnd = GetCurrentWnd() 4 selection = GetWndSel(hwnd) 5 LnFirst = GetWndSelLnFirst(hwnd) 6 LnLast = GetWndSelLnLast(hwnd) 7 hbuf = GetCurrentBuf() 8 9 if(GetBufLine(hbuf, 0) == "//magic-number:tph85666031") 10 { 11 stop 12 } 13 14 Ln = Lnfirst 15 buf = GetBufLine(hbuf, Ln) 16 len = strlen(buf) 17 18 while(Ln <= Lnlast) 19 { 20 buf = GetBufLine(hbuf, Ln) 21 if(buf == "") 22 { 23 Ln = Ln + 1 24 continue 25 } 26 27 if(StrMid(buf, 0, 1) == "/") 28 { 29 if(StrMid(buf, 1, 2) == "/") 30 { 31 PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf))) 32 } 33 } 34 35 if(StrMid(buf,0,1) != "/") 36 { 37 PutBufLine(hbuf, Ln, Cat("//", buf)) 38 } 39 Ln = Ln + 1 40 } 41 42 SetWndSel(hwnd, selection) 43 }
<3>.在SourceInsight里去除多行“//”注釋,可用下面代碼添加宏插件,方法如<1>.
1 macro Custom_RemoveMultiLineComment()//Alt+3 2 { //Uncomment multiple lines 3 hwnd = GetCurrentWnd() 4 selection = GetWndSel( hwnd ) 5 lnFirst = GetWndSelLnFirst( hwnd ) 6 lnLast = GetWndSelLnLast( hwnd ) 7 8 hbuf = GetCurrentBuf() 9 ln = lnFirst 10 while( ln <= lnLast ) 11 { 12 buf = GetBufLine( hbuf, ln ) 13 len = strlen( buf ) 14 if( len >= 2 ) 15 { 16 start = 0 17 18 while( strmid( buf, start, start + 1 ) == CharFromAscii(32) || strmid( buf, start, start + 1 ) == CharFromAscii(9) ) 19 { 20 start = start + 1 21 if( start >= len ) 22 break 23 } 24 if( start < len - 2 ) 25 { 26 if( strmid( buf, start, start + 2 ) == "//" ) 27 { 28 buf2 = cat( strmid( buf, 0, start ), strmid( buf, start + 2, len ) ) 29 PutBufLine( hbuf, ln, buf2 ) 30 } 31 } 32 } 33 ln = ln + 1 34 } 35 SetWndSel( hwnd, selection ) 36 }
