方法1
利用Astyle等插件对SourceInsight中的代码,进行格式化。
然后使用ALT + ] 来快速定位
//备注:要注意,此时格式化后的条件编译指令,必须在行首,且行首不能有空格。(这是ATL + ] 机制决定的,我一般仅仅用他来作为括号的配对查询)
方法2
利用宏定义,在utils.em中添加如下代码,并且设定快捷键ATL + [ 。
代码如下:
/*======================================================================
2、智能匹配#if #elif #endif #ifndefine #ifdef:
======================================================================*/
macro GetCMacroHead(Str)
{
lenMax = strlen(Str)
len = 0
while(len < lenMax)
{
if(Str[len] == "\t" || Str[len] == " " )
{
len = len + 1
continue;
}
break;
}
if(len + 3 > lenMax)
{
return
}
tempStr = strmid(Str,len,len + 3)
return tempStr
}
//将该宏设定快捷键
macro FindNextBlock()
{
hbuf = GetCurrentBuf()
lnMax = GetBufLineCount(hbuf)
lnCur = GetBufLnCur(hbuf)
tempStr = GetBufLine (hbuf, lnCur)
tempHead = GetCMacroHead(tempStr)
flag = 0
if(tempHead != "#if" && tempHead !="#el" && tempHead != "#en")
{
Msg("本行没有条件预编译指令");
return
}
else
{
EndFlag = 0;
if(tempHead == "#en")
{
EndFlag = 1;
}
if(EndFlag == 0)
{
while(lnCur <lnMax)
{
lnCur = lnCur + 1
tempStr = GetBufLine (hbuf, lnCur)
tempHead = GetCMacroHead(tempStr)
if(flag == 0)
{
if(tempHead == "#el" || tempHead == "#en")
{
SetBufIns (hbuf, lnCur, 0)
return
}
}
if(tempHead == "#en")
{
flag = flag - 1
}
if(tempHead == "#if")
{
flag = flag + 1
}
}
}
else
{
while(lnCur > 0)
{
lnCur = lnCur - 1
tempStr = GetBufLine (hbuf, lnCur)
tempHead = GetCMacroHead(tempStr)
if(flag == 0)
{
if(tempHead == "#if")
{
SetBufIns (hbuf, lnCur , 0)
return
}
}
if(tempHead == "#if")
{
flag = flag - 1
}
if(tempHead == "#en")
{
flag = flag + 1
}
}
}
}
}
最后,感谢"caz28"!我是参考他的初始代码修改完善的。
他的博客地址:http://blog.youkuaiyun.com/caz28/article/details/7251250