Source Insight中的多行注释
我們經(jīng)常要對一整段代碼進(jìn)行注釋,很多代碼編輯器都提供了這樣的功能:用快捷鍵“Ctrl + /”來實(shí)現(xiàn)“//”的多行注釋。
但是在用source insight的時(shí)候,發(fā)現(xiàn)竟然沒有這樣的功能。于是在網(wǎng)上搜了一下,sourceinsight里面的多行注釋可以用宏來實(shí)現(xiàn)。
以下是實(shí)現(xiàn)多行注釋的宏代碼(在別的網(wǎng)站copy過來的,經(jīng)過測試,還是很好用的):
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對應(yīng)的行
????????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)
}
將上面的代碼另存為xxx.em文件,打開source insight,將該文件添加到工程中,然后在Options->KeyAssignments中你就可以看到這個(gè)宏了,宏的名字是MultiLineComments,然后我們?yōu)樗峙淇旖萱I“Ctrl + /”,然后就可以了。
這里還有一份添加“#ifdef 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)
????????????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 )
}
這份宏的代碼可以把光標(biāo)顯示的行注釋掉:
macro CommentSingleLine()
{
????hbuf = GetCurrentBuf()
????ln = GetBufLnCur(hbuf)
str = GetBufLine (hbuf, ln)
????str = cat("/*",str)
????str = cat(str,"*/")
????PutBufLine (hbuf, ln, str)
}
將一行中鼠標(biāo)選中部分注釋掉:
macro CommentSelStr()
{
????hbuf = GetCurrentBuf()
????ln = GetBufLnCur(hbuf)
????str = GetBufSelText(hbuf)
????str = cat("/*",str)
????str = cat(str,"*/")
????SetBufSelText (hbuf, str)
}
最后是source insight與宏有關(guān)的資源:
·?????????????????source insight官方的宏庫
·?????????????????source?insight官方幫助文檔
轉(zhuǎn)載于:https://www.cnblogs.com/dongzhiquan/archive/2013/03/04/2943448.html
總結(jié)
以上是生活随笔為你收集整理的Source Insight中的多行注释的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 读卡器启动U盘
- 下一篇: [html] marquee详解