source insight 宏的使用
2012-09-25 18:38
281 查看
使用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()
}
}
使用方法
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()
}
}
相关文章推荐
- source insight使用技巧
- Ubuntu 10.04使用Wine安装Source Insight 转自:http://www.linuxidc.com/
- SourceInsight使用技巧
- Source Insight:使用Source Insight查看C/C++源代码
- ubuntu下使用source Insight
- 【Linux/Ubuntu学习2】ubuntu-ubuntu10.04使用wine安装SourceInsight
- source insight快捷键及使用技巧
- ubuntu上使用wine安装Source Insight
- Source Insight使用技巧
- Source Insight 的使用
- Source_Insight的使用
- Source Insight 的基本使用之查看 Android Source
- Source Insight使用技巧
- Linux使用Wine 安装source insight
- [SI]source insight使用
- Source Insight 使用技巧
- 打造linux下的source insight——vim插件安装使用总结
- source insight使用教程
- ubuntu10.04通过wine使用source insight
- 【转】Source Insight的Alt + W键不能使用的解决办法