smartsheep的笔记 https://passport2.21ic.com/?79109 [收藏] [复制] [RSS] 本人专业从事嵌入式系统设计,欢迎志同道合者共同探讨!

日志

source insight 宏的使用

已有 3844 次阅读2009-11-4 03:31 |个人分类:Tool|系统分类:兴趣爱好| sourceinsight

使用source insight 的宏可以给编程工作带来较高的效率, 编写宏并不难, 只要参看已有的宏,基本就能写出自己想要的宏, 另外可以参考source insight的官方网站的帮助 http://www.sourceinsight.com/v2help/htm/helpcontents1.htm .

使用方法
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, 选中要使用的宏, 添加到比如work菜单中.

还可以自定义快捷键;


SI官方的宏库:http://www.sourceinsight.com/public/macros/


注意: 下面的例子宏中,有些是相当于子函数,不可以直接使用

示例宏:

/*将光标所在行的代码用/**/注释掉*/
macro CommentSingleLine()
{
    hbuf = GetCurrentBuf()
    ln = GetBufLnCur(hbuf)
    str = GetBufLine (hbuf, ln)
    str = cat("/*",str)
    str = cat(str,"*/")
    PutBufLine (hbuf, ln, str)
   
}
/*将一行中鼠标选中部分注释掉*/
macro CommentSelStr()
{
    hbuf = GetCurrentBuf()
    ln = GetBufLnCur(hbuf)
    str = GetBufSelText(hbuf)
    str = cat("/*",str)
    str = cat(str,"*/")
    SetBufSelText (hbuf, str)
}

/*
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 = "0@Day@"
else
szDay = Day
if (Month < 10)
szMonth = "0@Month@"
else
szMonth = Month
szDeion = "by"
szInfo ="@szDeion@ @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()
}
}


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)