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

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宏功能就是可以注释、反注释代码

  1. macro MultiLineComment()  
  2. {  
  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.         stop  
  11.     }  
  12.    
  13.     Ln = Lnfirst  
  14.     buf = GetBufLine(hbuf, Ln)  
  15.     len = strlen(buf)  
  16.    
  17.     while(Ln <= Lnlast) {  
  18.         buf = GetBufLine(hbuf, Ln)  //取Ln对应的行  
  19.         if(buf == ""){                    //跳过空行  
  20.             Ln = Ln + 1  
  21.             continue  
  22.         }  
  23.    
  24.         if(StrMid(buf, 0, 1) == "/") {       //需要取消注释,防止只有单字符的行  
  25.             if(StrMid(buf, 1, 2) == "/"){  
  26.                 PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))  
  27.             }  
  28.         }  
  29.    
  30.         if(StrMid(buf,0,1) != "/"){          //需要添加注释  
  31.             buf = Cat("//", buf)  
  32.             if(Ln == Lnfirst){  
  33.                 buf = Cat(buf,"//removed by jhy")//注释作者信息  
  34.             }  
  35.                 PutBufLine(hbuf, Ln, buf)  
  36.         }  
  37.         Ln = Ln + 1  
  38.     }  
  39.    
  40.     SetWndSel(hwnd, selection)  
  41. }  
  1. macro MultiLineComment()  
  2. {  
  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.         stop  
  11.     }  
  12.    
  13.     Ln = Lnfirst  
  14.     buf = GetBufLine(hbuf, Ln)  
  15.     len = strlen(buf)  
  16.    
  17.     while(Ln <= Lnlast) {  
  18.         buf = GetBufLine(hbuf, Ln)  //取Ln对应的行  
  19.         if(buf == ""){                    //跳过空行  
  20.             Ln = Ln + 1  
  21.             continue  
  22.         }  
  23.    
  24.         if(StrMid(buf, 0, 1) == "/") {       //需要取消注释,防止只有单字符的行  
  25.             if(StrMid(buf, 1, 2) == "/"){  
  26.                 PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))  
  27.             }  
  28.         }  
  29.    
  30.         if(StrMid(buf,0,1) != "/"){          //需要添加注释  
  31.             buf = Cat("//", buf)  
  32.             if(Ln == Lnfirst){  
  33.                 buf = Cat(buf,"//removed by jhy")//注释作者信息  
  34.             }  
  35.                 PutBufLine(hbuf, Ln, buf)  
  36.         }  
  37.         Ln = Ln + 1  
  38.     }  
  39.    
  40.     SetWndSel(hwnd, selection)  
  41. }  

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

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

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

  1. macro MonthToName(MonthNum)  
  2. {  
  3.   
  4.     if (MonthNum== 1)  
  5.         return "Jan"  
  6.     if (MonthNum== 2)  
  7.         return "Feb"  
  8.     if (MonthNum== 3)  
  9.         return "Mar"  
  10.     if (MonthNum== 4)  
  11.         return "Apr"  
  12.     if (MonthNum== 5)  
  13.         return "May"  
  14.     if (MonthNum== 6)  
  15.         return "Jun"  
  16.     if (MonthNum== 7)  
  17.         return "Jul"  
  18.     if (MonthNum== 8)  
  19.         return "Aug"  
  20.     if (MonthNum== 9)  
  21.         return "Sep"  
  22.     if (MonthNum== 10)  
  23.         return "Oct"  
  24.     if (MonthNum== 11)  
  25.         return "Nov"  
  26.     if (MonthNum== 12)  
  27.         return "Dec"  
  28. }  
  29.   
  30. macro DisplayDate()  
  31. {  
  32.     szTime = GetSysTime(1)  
  33.     Day = szTime.Day  
  34.     Month = szTime.Month  
  35.     Year = szTime.Year  
  36.     if (Day < 10)  
  37.         szDay = "0@Day@"  
  38.     else  
  39.         szDay = Day  
  40.     szMonth = MonthToName(Month)  
  41.   
  42.     hbuf = GetCurrentBuf()  
  43.     SetBufSelText(hbuf, "@szMonth@ @szDay@, @Year@")  
  44. }  
    1. macro MonthToName(MonthNum)  
    2. {  
    3.   
    4.     if (MonthNum== 1)  
    5.         return "Jan"  
    6.     if (MonthNum== 2)  
    7.         return "Feb"  
    8.     if (MonthNum== 3)  
    9.         return "Mar"  
    10.     if (MonthNum== 4)  
    11.         return "Apr"  
    12.     if (MonthNum== 5)  
    13.         return "May"  
    14.     if (MonthNum== 6)  
    15.         return "Jun"  
    16.     if (MonthNum== 7)  
    17.         return "Jul"  
    18.     if (MonthNum== 8)  
    19.         return "Aug"  
    20.     if (MonthNum== 9)  
    21.         return "Sep"  
    22.     if (MonthNum== 10)  
    23.         return "Oct"  
    24.     if (MonthNum== 11)  
    25.         return "Nov"  
    26.     if (MonthNum== 12)  
    27.         return "Dec"  
    28. }  
    29.   
    30. macro DisplayDate()  
    31. {  
    32.     szTime = GetSysTime(1)  
    33.     Day = szTime.Day  
    34.     Month = szTime.Month  
    35.     Year = szTime.Year  
    36.     if (Day < 10)  
    37.         szDay = "0@Day@"  
    38.     else  
    39.         szDay = Day  
    40.     szMonth = MonthToName(Month)  
    41.   
    42.     hbuf = GetCurrentBuf()  
    43.     SetBufSelText(hbuf, "@szMonth@ @szDay@, @Year@"

转:

原文地址:https://www.cnblogs.com/yangxia-test/p/4146745.html