用source insight宏自动加入或去除C注释 收藏
我们的项目是主要在linux下的存C开发,SI这个工具无疑是必须的。但是手工加入注释很不方便,网上都是C++的注释风格,自己写了一个C的,共享一下,有兴趣的拿去修改一下。
/* the info like: by guixue 2009-8-19 */ macro getCommentInfo() { szMyName = "guixue " hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) 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 = "@" else szDay = Day if (Month < 10) szMonth = "@" else szMonth = Month szDescription = "by" szInfo ="@szDescription@ @szMyName@ @Year@-@szMonth@-@szDay@" return szInfo } macro SingleLineComment() { hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) szInfo = getCommentInfo() InsBufLine(hbuf, ln+1, "/* @szInfo@ */") } macro C_CommentBlock() { hbuf = GetCurrentBuf(); hwnd = GetCurrentWnd(); sel = GetWndSel(hwnd); /* szLine = GetBufLine(hbuf, sel.lnFirst); szLine = cat("/*", szLine); PutBufLine(hbuf, sel.lnFirst, szLine); */ szInfo = getCommentInfo() szInfo = "/* @szInfo@" InsBufLine(hbuf, sel.lnFirst, szInfo) InsBufLine(hbuf, sel.lnLast+2, "*/") tabSize = 4; sel.ichFirst = sel.ichFirst + tabSize; sel.ichLim = sel.ichLim + tabSize; SetWndSel(hwnd, sel); } macro C_UnCommentBlock() { hbuf = GetCurrentBuf(); hwnd = GetCurrentWnd(); sel = GetWndSel(hwnd); iLine = sel.lnFirst; szLine = GetBufLine(hbuf, iLine); szInfo = getCommentInfo() szInfo = "/* @szInfo@" if (szLine[0] == "/" && szLine[1] == "*") { if(szInfo == szLine) { DelBufLine(hbuf, iLine) } else { return false; } } else { return false; } iLine = sel.lnLast-1; szLine = GetBufLine(hbuf, iLine); len =strlen(szLine) if(len <2) return false; if(szLine== "*/") { DelBufLine(hbuf, iLine) } else { return false; } SetWndSel(hwnd, sel); return true; } macro C_Do_Comment() { flag =C_UnCommentBlock() if(flag==false) { C_CommentBlock() } }
加入方法:
使用方法说明:
1. Project->Open Project... 打开Base工程(该工程一般在"我的文档\Source Insight\Projects\Base"中);
2. Project->Add and Remove Project Files... 加入宏文件(也可以把代码加到已有文件中,如Utils.em文件中);
3. Options->Menu Assignments 打开Menu Assignments窗口, 在Command中输入Macro, 选中要使用的宏, 添加到合适的菜单中.
还可以自定义快捷键;
SI官方的宏库:http://www.sourceinsight.com/public/macros/
source insight常用宏
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/oncoding/archive/2009/08/19/4463830.aspx