因为有时会使用到一行中某部分代码需要注释,每次都去输入感觉太麻烦了所以根据网上资料自己修改的在source insight 自定义宏 用/* */注释一行鼠标选中部分代码,如果选中部分代码已经使用/* */注释则取消注释。
macro CommentSelStr() { hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) str = GetBufSelText(hbuf) len = strlen(str) str_star = 0; while(str_star < len-3) { if(StrMid(str, str_star, str_star+1) == " ") { str_star = str_star + 1; continue; } if(StrMid(str, str_star, str_star+1) == "/" && StrMid(str, str_star+1, str_star+2) == "*" ) { str_end = len; while(str_end > 1) { if(StrMid(str, str_end-1, str_end) == " ") { str_end = str_end-1; continue; } if(StrMid(str, str_end-2, str_end-1) == "*" && StrMid(str, str_end-1, str_end) == "/") { buf = StrMid(str, str_star+2, str_end-2); while(str_star > 0) //前补空格 { str_star = str_star-1; buf = cat(" ",buf); } while(str_end < len) //后补空格 { str_end = str_end+1; buf = cat(buf, " "); } SetBufSelText (hbuf, buf); } else//注释不对称 { str = cat("/*",str) str = cat(str,"*/") SetBufSelText (hbuf, str) } break; } } else//不为空也没注释 { str = cat("/*",str) str = cat(str,"*/") SetBufSelText (hbuf, str) } break; } }
原文地址:https://www.cnblogs.com/weishanglai/p/12359478.html
时间: 2024-10-16 01:06:06