Source Insight 宏的使用与自定义快捷键

来源:互联网 发布:windows 10 使用手册 编辑:程序博客网 时间:2024/06/05 09:27

    相信阅读过大型源代码的,都知道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.HourMinute = szTime.MinuteSecond = szTime.SecondDay = szTime.DayMonth = szTime.MonthYear = szTime.Yearif (Day < 10)szDay = "0@Day@"elseszDay = Dayif (Month < 10)szMonth = "0@Month@"elseszMonth = 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 等等组合。