Source insight 宏


//
推荐快捷键 ctrl+shift+/ //将选择的行添加双斜杠注释或取消双斜杠注释 macro WangQiGuo_MultiLineComment() { 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) } // 推荐快捷键 ctrl+3 //对选择的代码添加 或取消#if 0 #endif 包围 macro WangQiGuo_AddMacroComment() { hwnd = GetCurrentWnd(); sel = GetWndSel ( hwnd ); lnFirst = GetWndSelLnFirst ( hwnd ); lnLast = GetWndSelLnLast ( hwnd ); hbuf = GetCurrentBuf(); if ( LnFirst == 0 ) { szIfStart = ""; } else { szIfStart = GetBufLine ( hbuf, LnFirst - 1 ); } szIfEnd = GetBufLine ( hbuf, lnLast + 1 ); if ( szIfStart == "#if 0" && szIfEnd == "#endif" ) { DelBufLine ( hbuf, lnLast + 1 ); DelBufLine ( hbuf, lnFirst - 1 ); //sel.lnFirst = sel.lnFirst + 1; //sel.lnLast = sel.lnLast + 1; } else { InsBufLine ( hbuf, lnFirst, "#if 0" ); InsBufLine ( hbuf, lnLast + 2, "#endif" ); sel.lnFirst = sel.lnFirst + 1; sel.lnLast = sel.lnLast + 1; } SetWndSel ( hwnd, sel ); } // 推荐快捷键 ctrl+shift+p //添加函数描述信息 macro getFunType() { var fType; fType = ASK ( "请输入函数返回类型" ); return fType; } macro getFunName() { var fName; fName = ASK ( "请输入函数名字" ); return fName; } macro getFunDesc() { var fDesc; fDesc = ASK ( "请输入函数描述" ); return fDesc; } macro getFunParamNum() { var fParamNum; fParamNum = ASK ( "请输入参数个数" ) ; return fParamNum; } macro getAuthor() { var fAuthor; fAuthor = ASK ( "请输入作者姓名、工作邮箱" ) ; return fAuthor; } macro getCommentsTime() { var year; var month; var day; var commTime; var sysTime; sysTime = GetSysTime ( 1 ); year = sysTime.Year; month = sysTime.month; day = sysTime.day; commTime = "@year@-@month@-@day@"; return commTime; } macro insertFunComment() { var hBuff; var line; var ftype; var fname; var fdesc; var fiparam; var fiparam2; var fauthor; var time; var comments; var num; var num2; var num3; num = getFunParamNum(); num2 = num; time = getCommentsTime(); fauthor = getAuthor(); ftype = getFunType(); fname = getFunName(); fdesc = getFunDesc(); hBuff = GetCurrentBuf(); line = GetBufLnCur ( hBuff ); InsBufLine ( hBuff, line, "/*************************************************************" ); comments = "* function name : "; //函数名 comments = cat ( comments, fname ); InsBufLine ( hBuff, line + 1, comments ); comments = "* author : "; //编制者 comments = cat ( comments, fauthor ); InsBufLine ( hBuff, line + 2, comments ); comments = "* parameter list : "; //参数列表 if ( num == 0 ) //参数为零时 { comments = "* parameter list : void"; num3 = 1; fiparam2 = void; InsBufLine ( hBuff, line + 2 + num3, comments ); } else { while ( num-- ) { num3 = num2 - num; fiparam = ASK ( "本函数共@num2@个参数,请输入第@num3@个参数" ); if ( num3 == num2 ) fiparam2 = cat ( fiparam2, fiparam ); else { fiparam2 = cat ( fiparam2, fiparam ); fiparam2 = cat ( fiparam2, ", " ); } if ( num3 == 1 ) { comments = cat ( comments, fiparam ); InsBufLine ( hBuff, line + 2 + num3, comments ); } else { comments = "* "; comments = cat ( comments, fiparam ); InsBufLine ( hBuff, line + 2 + num3, comments ); } } } comments = "* return type : "; //返回值类型 comments = cat ( comments, ftype ); InsBufLine ( hBuff, line + 3 + num3, comments ); comments = "* Compile times : "; //编制时间 comments = cat ( comments, time ); InsBufLine ( hBuff, line + 4 + num3, comments ); comments = "* function description : "; //函数描述 comments = cat ( comments, fdesc ); InsBufLine ( hBuff, line + 5 + num3, comments ); InsBufLine ( hBuff, line + 6 + num3, "*************************************************************/" ); //下来是生成函数体部分 //函数定义部分 comments = ""; comments = cat ( comments, ftype ); comments = cat ( comments, " " ); comments = cat ( comments, fname ); comments = cat ( comments, "(" ); comments = cat ( comments, fiparam2 ); comments = cat ( comments, ")" ); InsBufLine ( hBuff, line + 7 + num3, comments ); InsBufLine ( hBuff, line + 8 + num3, "{" ); InsBufLine ( hBuff, line + 9 + num3, " " ); comments = " "; InsBufLine ( hBuff, line + 10 + num3, "}" ); }

// 插入/* ... */ 形式的注释
// 多行注释,只对第一行非空行,且以“/*” 或是空格开头的取消注释,
//“/*”处于语句中间的,视为将对其进行注释
macro Comments_UnComments_With_Multiple()
{
hwnd = GetCurrentWnd()
hbuf = GetCurrentBuf()
if(hbuf ==0)
stop

// debugBuf只是为了调试
// debugBuf = NewBuf("debugBuf")
// ClearBuf(debugBuf)

lnSelFirst = GetWndSelLnFirst(hwnd) // 获得选中内容的第一行
lnSelLast = GetWndSelLnLast(hwnd) // 获得选中内容的最后一行

const_space = " " // 空格
const_comments_begin = "/*" // 多行注释符号-开始
const_comments_end = "*/" // 多行注释符号-结束
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_begin) // 以“/*”开头,取消注释
{
isCancelComments = 1

dest_text = strmid(orig_text, subIndex+2, strlen(orig_text))
if(strlen(dest_text) == 0)
{
DelBufLine(hbuf, line_index) // 本行只有“/*”时,删除
}
else
{
PutBufLine (hbuf, line_index, dest_text) // 替换以前的text
}
line_index = line_index + 1
}
else // 进行注释
{
InsBufLine(hbuf, lnSelFirst, "/*")
InsBufLine(hbuf, lnSelLast+2, "*/")

stop
}

// 遍历所有选中的行
// line_index = lnSelFirst // 前面已经跳过开头的空行
// while(line_index <= lnSelLast) // 对选中的内容进行操作
while(line_index < GetBufLineCount(hbuf)) //or 从当前行开始,查找到第一个“*/”为止或到结尾
{
orig_text = GetBufLine(hbuf, line_index) // 获得以前的text
if (strlen(orig_text) > 1) // 如果是空行或只有一个字符,则跳过
{
dest_text = ""
if(isCancelComments == 1) // 取消注释
{
// 查找注释符“*/”
subIndex = 0
while(subIndex < strlen(orig_text)-2 && strmid(orig_text, subIndex, subIndex+2) != const_comments_end)
subIndex = subIndex + 1

if (strmid(orig_text, subIndex, subIndex+2) == const_comments_end) // 找到“*/”,进行处理
{
prefixText = strmid(orig_text, 0, subIndex) // 前面的text
lastText = strmid(orig_text, subIndex+2, strlen(orig_text)) // 后面的text
dest_text = cat(prefixText, lastText)

if(strlen(dest_text) == 0)
{
DelBufLine(hbuf, line_index) // 本行只有“*/”时,删除
}
else
{
PutBufLine (hbuf, line_index, dest_text) // 替换以前的text
}


break // 退出
}
}
}

line_index = line_index + 1
}
}

 

//快捷键 ctrl+shift+.
//添加文件头部注释
macro InsertFileHeader_new()
{
//get crrunt time
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year


hbuf = GetCurrentBuf()
filename = GetBufName(hbuf)
InsBufLine(hbuf, 0, " /**")
InsBufLine(hbuf, 1, "***************************************************************************")
InsBufLine(hbuf, 2, "* \@file name : @filename@") //文件名称
InsBufLine(hbuf, 3, "* \@author : alw ") //作者
InsBufLine(hbuf, 4, "* \@times : @Year@-@Month@-@Day@")
InsBufLine(hbuf, 5, "* \@version : 1.1.0")
InsBufLine(hbuf, 6, "* \@describe :") //描述
InsBufLine(hbuf, 7 , "**************************************************************************")
InsBufLine(hbuf, 8, " */")
}

 

 

 编辑 mycomment.em 文件,存放到 Base 工程下,为宏添加快捷键 

 

posted @ 2021-12-15 10:18  丶Future  阅读(277)  评论(0编辑  收藏  举报