主要解决与光标所在行对齐的问题
代码:
/*-----------------------------------------------
函 数 名 : InsertPRINTF
功 能 : 插入常用打印 快捷键: Crt+p
修 改 者 : dtcwyp
日 期 : 2016/05/03
-------------------------------------------------*/
macro InsertPRINTF()//插入常用的打印
{
hwnd = GetCurrentWnd()
selection = GetWndSel(hwnd)
LnFirst =GetWndSelLnFirst(hwnd) //取首行行号
hbuf = GetCurrentBuf()
buf = GetBufLine(hbuf, LnFirst)
index = 0
while(index <= strlen(buf))
{
if(strlen(buf) == 0)
{
PutBufLine(hbuf, LnFirst, "printf(\"dtc[%s][%d]\\n\",__FUNCTION__,__LINE__);")
}
else if(index == strlen(buf))
{
PutBufLine(hbuf, LnFirst, cat(StrMid(buf,0,index),"printf(\"dtc[%s][%d]\\n\",__FUNCTION__,__LINE__);"))
break
}
else if(((StrMid(buf, index, index+1) != " ")&&(StrMid(buf, index, index+1) != "\t"))
{
InsBufLine(hbuf, LnFirst, cat(StrMid(buf,0,index),"printf(\"dtc[%s][%d]\\n\",__FUNCTION__,__LINE__);"))
break
}
index++
}
SetWndSel(hwnd, selection)
}
主要解决多行注释只在每行的行首:(缺点:要注意每行是否有“//”)
/*-----------------------------------------------
函 数 名 : MultiLineComment
功 能 : 多 行 注 释 快捷键: Ctrl+/
修 改 者 : dtcwyp
日 期 : 2017/01/05
-------------------------------------------------*/
macro 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
}
index = 0
while(index < strlen(buf))
{
if(((StrMid(buf, index, index+1) != " ")&&(StrMid(buf, index, index+1) != "\t"))
{
if(strlen(StrMid(buf, index, Strlen(buf))) > 1)
{
if((StrMid(buf, index, index+1) == "/")&&(StrMid(buf,index+ 1, index+2) == "/"))
{//需要取消注释,防止只有单字符的行
PutBufLine(hbuf, Ln, cat(StrMid(buf,0,index),StrMid(buf, index+2, Strlen(buf))))
break
}
}
if(StrMid(buf,index,index+1) !="/")
{//需要添加注释
PutBufLine(hbuf, Ln, cat(StrMid(buf,0,index),Cat("//", StrMid(buf, index, Strlen(buf)))))
break
}
}
index++
}
Ln = Ln + 1
}
SetWndSel(hwnd, selection)
}