您的位置:首页 > 其它

[转]Source Insight使用小技巧小结

2014-12-05 15:20 330 查看
Source Insight是一款强大的代码查看工具,本身支持扩展性很好。下面我们就介绍2个扩展用例。

1、快速打开当前文件所在的目录,这个功能类似于eclipse的easyshell插件,就是能快速定位到文件所在的目录,这个在代码查看的时候是很有好处的。

按照以下步骤,首先进入【option】->【Custom Commands】



自定的命令名,个人发挥,关键是填入 explorer.exe %d,



设置快捷键CTRL+T



也可以将自定义命令加入Menu菜单中



到此设置完毕,可以通过快捷键CTRL+T,直接打开当前文件所在的目录。

2、与eclipse中快捷方便的注释反注释相比较,sI是有点古板和不方便额。但是可以通过自定义的宏块来改善这个情况。

首先,打开Projcet->Open project,选择base,可以看到utils.em文件,将下列宏添加到该文件中。



MultiLineComment宏功能就是可以注释、反注释代码

[cpp] view plaincopyprint?

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) != "/"){ //需要添加注释

buf = Cat("//", buf)

if(Ln == Lnfirst){

buf = Cat(buf,"//removed by jhy")//注释作者信息

}

PutBufLine(hbuf, Ln, buf)

}

Ln = Ln + 1

}

SetWndSel(hwnd, selection)

}

[cpp] view plaincopyprint?

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) != "/"){ //需要添加注释

buf = Cat("//", buf)

if(Ln == Lnfirst){

buf = Cat(buf,"//removed by jhy")//注释作者信息

}

PutBufLine(hbuf, Ln, buf)

}

Ln = Ln + 1

}

SetWndSel(hwnd, selection)

}

保存后,打开新的工程:options->key assignments(设置快捷键)

到此为止,我们在代码中使用ALT+X的快捷键看看,效果如下:



3、我们再来贴一个快速插入时间的宏,类似于UltraEdit中的F7快捷键功能

[cpp] view plaincopyprint?

macro MonthToName(MonthNum)

{

if (MonthNum== 1)

return "Jan"

if (MonthNum== 2)

return "Feb"

if (MonthNum== 3)

return "Mar"

if (MonthNum== 4)

return "Apr"

if (MonthNum== 5)

return "May"

if (MonthNum== 6)

return "Jun"

if (MonthNum== 7)

return "Jul"

if (MonthNum== 8)

return "Aug"

if (MonthNum== 9)

return "Sep"

if (MonthNum== 10)

return "Oct"

if (MonthNum== 11)

return "Nov"

if (MonthNum== 12)

return "Dec"

}

macro DisplayDate()

{

szTime = GetSysTime(1)

Day = szTime.Day

Month = szTime.Month

Year = szTime.Year

if (Day < 10)

szDay = "0@Day@"

else

szDay = Day

szMonth = MonthToName(Month)

hbuf = GetCurrentBuf()

SetBufSelText(hbuf, "@szMonth@ @szDay@, @Year@")

}

[cpp] view plaincopyprint?

macro MonthToName(MonthNum)

{

if (MonthNum== 1)

return "Jan"

if (MonthNum== 2)

return "Feb"

if (MonthNum== 3)

return "Mar"

if (MonthNum== 4)

return "Apr"

if (MonthNum== 5)

return "May"

if (MonthNum== 6)

return "Jun"

if (MonthNum== 7)

return "Jul"

if (MonthNum== 8)

return "Aug"

if (MonthNum== 9)

return "Sep"

if (MonthNum== 10)

return "Oct"

if (MonthNum== 11)

return "Nov"

if (MonthNum== 12)

return "Dec"

}

macro DisplayDate()

{

szTime = GetSysTime(1)

Day = szTime.Day

Month = szTime.Month

Year = szTime.Year

if (Day < 10)

szDay = "0@Day@"

else

szDay = Day

szMonth = MonthToName(Month)

hbuf = GetCurrentBuf()

SetBufSelText(hbuf, "@szMonth@ @szDay@, @Year@"

转:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: