相信阅读过大型源代码的,都知道Source Insight。
今天花了点时间,整理了两个宏,使用快捷键生成代码注释。很方便。
废话少说,进入主题!
①打开Source Insight > Project > Open Project > Base > OK
②打开Utils.em 宏文件
③添加以下宏(跟C语言的函数差不多)
//多行代码注释 macro MultiLineComment() { hwnd = GetCurrentWnd() //获得文本窗口 selection = GetWndSel(hwnd) //获得选择对象 LnFirst = GetWndSelLnFirst(hwnd) //取首行行号 LnLast = GetWndSelLnLast(hwnd) //取末行行号 hbuf = GetCurrentBuf() //获得当前窗口文本 Ln = LnFirst while(Ln <= Lnlast) { //取Ln对应的行 buf = GetBufLine(hbuf, 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))) //调整光标位置 selection.ichFirst = selection.ichFirst - 2; selection.ichLim = selection.ichLim - 2; } } if(StrMid(buf,0,1) != "/"){ //添加注释 PutBufLine(hbuf, Ln, Cat("//", buf)) //调整光标位置 selection.ichFirst = selection.ichFirst + 2; selection.ichLim = selection.ichLim + 2; } Ln = Ln + 1 } //最后产生效果 SetWndSel(hwnd, selection) }
//生成单行注释 macro SingleLineComment() { hwnd = GetCurrentWnd() //获得文本窗口 selection = GetWndSel(hwnd) //获得选择对象 LnFirst = GetWndSelLnFirst(hwnd) //取首行行号 hbuf = GetCurrentBuf() //获得当前窗口文本 //得到当前时间 szTime = GetSysTime(1) Hour = szTime.Hour Minute = szTime.Minute Second = szTime.Second Day = szTime.Day Month = szTime.Month Year = szTime.Year if (Day < 10) szDay = "0@Day@" else szDay = Day if (Month < 10) szMonth = "0@Month@" else szMonth = Month //名字 szMyName = "yarkey" buf = GetBufLine( hbuf, LnFirst ) //yarkey@20130321 Remark: commentAdd = "//@szMyName@\@@Year@@szMonth@@szDay@ Remark:" commentAddLen = Strlen( commentAdd ) PutBufLine( hbuf, LnFirst, Cat(buf, commentAdd) ) selection.ichFirst = selection.ichFirst + commentAddLen; selection.ichLim = selection.ichLim + commentAddLen; SetWndSel( hwnd, selection ) }
④添加完后 > Ctrl + s 保存
⑤打开自己的工程 > Option > Key Assignments 可以找到:
Macro : MultiLineComment
Macro : SingleLineComment
⑥点击Assign New Key ...
好了,设置自己习惯的快捷键吧!^^
可以是Alt Ctrl 等等组合。