本文共 1896 字,大约阅读时间需要 6 分钟。
以前用VS2005或是VS2008写代码,习惯了它的注释功能,使用Source Insight后发现没有提供相应的功能,只能自己写宏来实现,下面就是插入单行注释的宏脚本。
功能:对选中的内容进行单行注释(//)
使用:将下面宏脚本写到Source Insight的utils.em文件(Source Insight\Projects\Base下)或是新建一个*.em文件,并加入到Base项目中,通过Key Assignments指定快捷键或是Menu Assignments指定菜单项。
目的:宏的编写纯粹是为了开发的便利,多行注释(/**/)宏,后续会继续做出来。
写的比较乱,但是功能很好用,希望对大家有用,欢迎大家拍!
// 插入单行注释macro Comments_UnComments(){ hwnd = GetCurrentWnd() hbuf = GetCurrentBuf() if(hbuf ==0) stop // debugBuf只是为了调试 // debugBuf = NewBuf("debugBuf") // ClearBuf(debugBuf) lnSelFirst = GetWndSelLnFirst(hwnd) // 获得选中内容的第一行 lnSelLast = GetWndSelLnLast(hwnd) // 获得选中内容的最后一行 const_space = " " // 空格 const_comments = "//" // 单行注释符号 isCancelComments = 0 // 跳过开始的空行,否则下面报错 line_index = lnSelFirst orig_text = GetBufLine(hbuf, line_index) // 获得第一行的text while(strlen(orig_text) == 0) { line_index = line_index + 1 orig_text = GetBufLine(hbuf, line_index) // 获得第一行的text } // 根据第一行选中文本,确定是“注释”,还是“取消注释” // 判断是否以“//”开始,如果是则认为是“取消注释”,首先需要去掉空格 subIndex = 0 while(strmid(orig_text, subIndex, subIndex+1) == const_space) subIndex = subIndex + 1 if (strmid(orig_text, subIndex, subIndex+2) == const_comments) // 以“//”开头,取消注释 { isCancelComments = 1 } // 遍历所有选中的行 // line_index = lnSelFirst // 前面已经跳过开头的空行 while(line_index <= lnSelLast) { orig_text = GetBufLine(hbuf, line_index) // 获得以前的text if (strlen(orig_text) > 0) // 如果是空行,则跳过 { dest_text = "" if(isCancelComments == 1) // 取消注释 { // 查找注释符“//” subIndex = 0 while(strmid(orig_text, subIndex, subIndex+1) == const_space) subIndex = subIndex + 1 if (strmid(orig_text, subIndex, subIndex+2) == const_comments) // 以“//”开头,取消注释 { dest_text = strmid(orig_text, subIndex+2, strlen(orig_text)) } } else { dest_text = cat("//", orig_text) // 添加注释字符 “//” } PutBufLine (hbuf, line_index, dest_text) // 替换以前的text } line_index = line_index + 1 }}
转载地址:http://szwoi.baihongyu.com/