Source Insight中代码块注释(利用/**/)及取消注释实现方法
2012-05-12 19:10
357 查看
用了许久source Insight写C/C++代码,发现其中没有块注释功能很不方便,于是今天研究了下怎样让sourceInsight实现块注释。
网上介绍了很多方法实现块注释,但是都是对代码利用“//”逐行注释,没有用“/* */”实现的,我个人比较倾向于用/* */注释代码块,所以今天自己动手写了利用”/* */“实现块注释代码。
好了,废话不多说,直接上宏代码,后面会介绍使用方法:
下面介绍下使用方法:
1) 首先,打开sourceInsight 的"项目->打开项目->base”中的Utils.em文件,将以上宏代码复制到文件末尾,然后保存。
2) 启用宏。 菜单 “Options” -> “Key assignment”(中文版是选项->菜单关联)。 在列表框中找到下面的宏:CommentBlock_Joyce、UnCommentBlock_Joyce
3) 给这些宏分配按键。点击“键..”,选中你需要分配按键的宏,点击“分配新键..”,然后在键盘上选择你喜欢的按键吧~设置好之后,点击“好”。
好了,设置完毕,试试吧~
下面把网上有大神写的单行注释和利用“//”进行多行注释的代码一起贴上来,方便大家使用,设置方法和前面的一样。
网上介绍了很多方法实现块注释,但是都是对代码利用“//”逐行注释,没有用“/* */”实现的,我个人比较倾向于用/* */注释代码块,所以今天自己动手写了利用”/* */“实现块注释代码。
好了,废话不多说,直接上宏代码,后面会介绍使用方法:
macro _tsGetTabSize() { szTabSize = GetReg("TabSize"); if (szTabSize != "") { tabSize = AsciiFromChar(szTabSize[0]) - AsciiFromChar("0"); } else { tabSize = 4; } return tabSize; } macro CommentBlock_Joyce() { hbuf = GetCurrentBuf(); hwnd = GetCurrentWnd(); sel = GetWndSel(hwnd); iLine = sel.lnFirst; // indicate the comment char according to the file type // for example, using "#" for perl file(.pl) and "/* */" for C/C++. filename = tolower(GetBufName(hbuf)); suffix = ""; len = strlen(filename); i = len - 1; while (i >= 0) { if (filename[i-1] == ".") { suffix = strmid(filename, i, len) break; } i = i -1; } if ( suffix == "pl" ) { filetype = 2; // PERL } else { filetype = 1; // C } szLine = GetBufLine(hbuf, iLine); if (filetype == 1) // C { szLine = cat("/* ", szLine); } else // PERL { szLine = cat("# ", szLine); } PutBufLine(hbuf, iLine, szLine); iLine = sel.lnLast; szLine = GetBufLine(hbuf, iLine); if (filetype == 1) // C { szLine = cat(szLine, "*/ "); } else // PERL { szLine = cat("# ", szLine); } PutBufLine(hbuf, iLine, szLine); if (sel.lnFirst == sel.lnLast) { tabSize = _tsGetTabSize() - 1; sel.ichFirst = sel.ichFirst + tabSize; sel.ichLim = sel.ichLim + tabSize; } SetWndSel(hwnd, sel); } // // Undo the CommentBlock for the selected text. // macro UnCommentBlock_Joyce() { hbuf = GetCurrentBuf(); hwnd = GetCurrentWnd(); sel = GetWndSel(hwnd); iLine = sel.lnFirst; // indicate the comment char according to the file type // for example, using "#" for perl file(.pl) and "/* */" for C/C++. filename = tolower(GetBufName(hbuf)); suffix = ""; len = strlen(filename); i = len - 1; while (i >= 0) { if (filename[i-1] == ".") { suffix = strmid(filename, i, len) break; } i = i -1; } if ( suffix == "pl" ) { filetype = 2; // PERL } else { filetype = 1; // C } tabSize = 0; endLine = GetBufLine(hbuf, sel.lnLast); endLineLen = strlen(endLine); szLine = GetBufLine(hbuf, iLine); len = strlen(szLine); szNewLine = ""; commentState = 1; if (szLine[0] == "/" && szLine[1] == "*") { if(endLine[endLineLen-2] == "/" && endLine[endLineLen-3] == "*") { if (filetype == 1) // C { if (len > 1) { if (szLine[0] == "/" && szLine[1] == "*") { if (len > 2) { if (AsciiFromChar(szLine[2]) == 9) { tabSize = _tsGetTabSize() - 1; szNewLine = strmid(szLine, 3, strlen(szLine)); } } if (szNewLine == "") { szNewLine = strmid(szLine, 2, strlen(szLine)); tabSize = 2; } PutBufLine(hbuf, iLine, szNewLine); } } } if (filetype == 2) // PERL { if (len > 0) { if (szLine[0] == "#") { if (len > 1) { if (AsciiFromChar(szLine[1]) == 9) { tabSize = _tsGetTabSize() - 1; szNewLine = strmid(szLine, 2, strlen(szLine)); } } if (szNewLine == "") { szNewLine = strmid(szLine, 1, strlen(szLine)); tabSize = 2; } PutBufLine(hbuf, iLine, szNewLine); } } } iLine = sel.lnLast; szLine = GetBufLine(hbuf, iLine); len = strlen(szLine); szNewLine = ""; if (filetype == 1) // C { if (len > 1) { if (szLine[strlen(szLine)-2] == "/" && szLine[strlen(szLine)-3] == "*") { if (len > 2) { if (AsciiFromChar(szLine[2]) == 9) { tabSize = _tsGetTabSize() - 1; szNewLine = strmid(szLine, 0, strlen(szLine)-2); } } if (szNewLine == "") { szNewLine = strmid(szLine, 0, strlen(szLine)-3); tabSize = 2; } PutBufLine(hbuf, iLine, szNewLine); } } } if (filetype == 2) // PERL { if (len > 0) { if (szLine[0] == "#") { if (len > 1) { if (AsciiFromChar(szLine[1]) == 9) { tabSize = _tsGetTabSize() - 1; szNewLine = strmid(szLine, 2, strlen(szLine)); } } if (szNewLine == "") { szNewLine = strmid(szLine, 1, strlen(szLine)); tabSize = 2; } PutBufLine(hbuf, iLine, szNewLine); } } } } } if (sel.lnFirst == sel.lnLast) { sel.ichFirst = sel.ichFirst - tabSize; sel.ichLim = sel.ichLim - tabSize; } SetWndSel(hwnd, sel); }
下面介绍下使用方法:
1) 首先,打开sourceInsight 的"项目->打开项目->base”中的Utils.em文件,将以上宏代码复制到文件末尾,然后保存。
2) 启用宏。 菜单 “Options” -> “Key assignment”(中文版是选项->菜单关联)。 在列表框中找到下面的宏:CommentBlock_Joyce、UnCommentBlock_Joyce
3) 给这些宏分配按键。点击“键..”,选中你需要分配按键的宏,点击“分配新键..”,然后在键盘上选择你喜欢的按键吧~设置好之后,点击“好”。
好了,设置完毕,试试吧~
下面把网上有大神写的单行注释和利用“//”进行多行注释的代码一起贴上来,方便大家使用,设置方法和前面的一样。
macro SingleLineComment() { szMyName = "Joyce" // Get a handle to the current file buffer and the name // and location of the current symbol where the cursor is. hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) // Get current time 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 = "0@Day@" else szDay = Day //szMonth = NumToName(Month) if (Month < 10) szMonth = "0@Month@" else szMonth = Month szDescription = Ask("请输入修改原因") // begin assembling the title string InsBufLine(hbuf, ln+1, "/*@szDescription@ @szMyName@.xmyanfa @Year@-@szMonth@-@szDay@*/") } macro MultiLineCommentHeader() { szMyName = "Joyce" // Get a handle to the current file buffer and the name // and location of the current symbol where the cursor is. hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) // Get current time 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 = "0@Day@" else szDay = Day //szMonth = NumToName(Month) if (Month < 10) szMonth = "0@Month@" else szMonth = Month szDescription = Ask("请输入修改原因:") // begin assembling the title string InsBufLine(hbuf, ln + 1, "/*@szDescription@ @szMyName@.xmyanfa @Year@-@szMonth@-@szDay@ begin*/") } macro MultiLineCommentEnd() { szMyName = "Joyce" // Get a handle to the current file buffer and the name // and location of the current symbol where the cursor is. hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) // Get current time 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 = "0@Day@" else szDay = Day //szMonth = NumToName(Month) if (Month < 10) szMonth = "0@Month@" else szMonth = Month InsBufLine(hbuf, ln + 1, "/*@szMyName@.xmyanfa @Year@-@szMonth@-@szDay@ end*/") } // // Comment the selected block of text using single line comments and indent it // macro CommentBlock() { hbuf = GetCurrentBuf(); hwnd = GetCurrentWnd(); sel = GetWndSel(hwnd); iLine = sel.lnFirst; // added by Yongqiang, indicate the comment char according to the file type // for example, using "#" for perl file(.pl) and "//" for others. filename = tolower(GetBufName(hbuf)); suffix = ""; len = strlen(filename); i = len - 1; while (i >= 0) { if (filename[i-1] == ".") { suffix = strmid(filename, i, len) break; } i = i -1; } if ( suffix == "pl" ) { filetype = 2; // PERL } else { filetype = 1; // C } while (iLine <= sel.lnLast) { szLine = GetBufLine(hbuf, iLine); if (filetype == 1) // C { szLine = cat("// ", szLine); } else // PERL { szLine = cat("# ", szLine); } PutBufLine(hbuf, iLine, szLine); iLine = iLine + 1; } if (sel.lnFirst == sel.lnLast) { tabSize = _tsGetTabSize() - 1; sel.ichFirst = sel.ichFirst + tabSize; sel.ichLim = sel.ichLim + tabSize; } SetWndSel(hwnd, sel); } // // Undo the CommentBlock for the selected text. // macro UnCommentBlock() { hbuf = GetCurrentBuf(); hwnd = GetCurrentWnd(); sel = GetWndSel(hwnd); iLine = sel.lnFirst; // added by Yongqiang, indicate the comment char according to the file type // for example, using "#" for perl file(.pl) and "//" for others. filename = tolower(GetBufName(hbuf)); suffix = ""; len = strlen(filename); i = len - 1; while (i >= 0) { if (filename[i-1] == ".") { suffix = strmid(filename, i, len) break; } i = i -1; } if ( suffix == "pl" ) { filetype = 2; // PERL } else { filetype = 1; // C } tabSize = 0; while (iLine <= sel.lnLast) { szLine = GetBufLine(hbuf, iLine); len = strlen(szLine); szNewLine = ""; if (filetype == 1) // C { if (len > 1) { if (szLine[0] == "/" && szLine[1] == "/") { if (len > 2) { if (AsciiFromChar(szLine[2]) == 9) { tabSize = _tsGetTabSize() - 1; szNewLine = strmid(szLine, 3, strlen(szLine)); } } if (szNewLine == "") { szNewLine = strmid(szLine, 2, strlen(szLine)); tabSize = 2; } PutBufLine(hbuf, iLine, szNewLine); } } } if (filetype == 2) // PERL { if (len > 0) { if (szLine[0] == "#") { if (len > 1) { if (AsciiFromChar(szLine[1]) == 9) { tabSize = _tsGetTabSize() - 1; szNewLine = strmid(szLine, 2, strlen(szLine)); } } if (szNewLine == "") { szNewLine = strmid(szLine, 1, strlen(szLine)); tabSize = 2; } PutBufLine(hbuf, iLine, szNewLine); } } } iLine = iLine + 1; } if (sel.lnFirst == sel.lnLast) { sel.ichFirst = sel.ichFirst - tabSize; sel.ichLim = sel.ichLim - tabSize; } SetWndSel(hwnd, sel); }
相关文章推荐
- Source Insight中代码块注释(利用/**/)及取消注释实现方法
- Source Insight中代码块注释及取消注释实现方法
- 利用原生js和jQuery实现单选框的勾选和取消操作的方法
- 利用VBA 宏实现vc6.0的自动添加注释和自动取消注释
- 利用GLUT实现在OpenGL中绘制文本的简单方法
- iPhone 上利用MKMapView实现简单地图的方法
- 利用Python实现在同一网络中的本地文件共享方法
- 利用mui 实现上传图片到服务器,抛 multipart/form-data 解决方法
- js小方法+Canvas 利用js 实现浏览器保存图片到本地
- 需要区分在接口方法注释和方法实现的注释.
- Go语言利用time.After实现超时控制的方法详解
- AngularJS 购物车全选/取消全选功能的实现方法
- 如何利用jquery实现一句话全选/取消全选的实例代码
- 在ASP.Net中两种利用CSS实现多界面的方法.
- iOS 实现多个按钮,点选一个其它都取消选中状态的最佳方法
- 利用匿名内部类实现Java接口方法
- Webservice_18_利用Handler实现方法认证
- php利用ob缓存机制实现页面静态化方法全解
- 利用非递归方法实现二叉树的先序遍历
- EasyUI带选择框的DataGrid实现点击行"不选中或取消选中"的解决方法。