Source Insight 批量注释 多行注释宏

来源:互联网 发布:淘宝指数排行榜 编辑:程序博客网 时间:2024/05/19 05:32

将下面的代码保存为xxx.em并添加到你的工程里,然后在选项(Options)->菜单分配(Menu Assignments)中你就可以看到这个宏了,看不到可以重启si,同步一下试试。名字叫CodeComments,你可以给这个宏添加热键.运行这个宏可以让你当前选择的行在注释与取消注释间切换(只支持//的注释,不支持/**/的注释,而且/**/的注释并不怎么好)

 

 

//magic-number:tph85666031

macro CodeComments(){//多行注释
 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)!="/"){//需要添加注释
   PutBufLine(hbuf,Ln,Cat("//",buf))
  }
  Ln=Ln+1
 }
 SetWndSel( hwnd, selection )
}

原创粉丝点击