添加#if 0 .. #endif
可以当做多行注释来用。
macro AddMacroComment()
{
hwnd=GetCurrentWnd()
sel=GetWndSel(hwnd)
lnFirst=GetWndSelLnFirst(hwnd)
lnLast=GetWndSelLnLast(hwnd)
hbuf=GetCurrentBuf()
if (LnFirst == 0)
{
szIfStart = ""
}
else
{
szIfStart = GetBufLine(hbuf, LnFirst)
}
szIfEnd = GetBufLine(hbuf, lnLast)
if (szIfStart == "#if 0" && szIfEnd =="#endif")
{
DelBufLine(hbuf, lnLast)
DelBufLine(hbuf, lnFirst)
}
else
{
InsBufLine(hbuf, lnFirst, "#if 0")
InsBufLine(hbuf, lnLast+2, "#endif")
}
}
添加头文件
macro AddInclude()
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnFirst, "#include \"\"")
len = strlen("#include \"")
SetBufIns (hbuf, lnFirst, len)
}
添加单行注释
"/**/"类型的注释,添加完毕后光标自动跳转到"/**/"之间。
macro AddCommit02()
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
sz = GetBufLine(hbuf,lnFirst)
sz = sz # "/* */"
PutBufLine (hbuf, lnFirst, sz)
len = strlen(sz)
len = len-strlen(" */")
SetBufIns (hbuf, lnFirst, len)
}
"//"类型的注释,添加完毕光标自动跳转到"//"之后,支持在代码之后添加注释。
macro AddCommit01()
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
hbuf = GetCurrentBuf()
sz = GetBufLine(hbuf,lnFirst)
sz = sz # "//"
PutBufLine (hbuf, lnFirst, sz)
len = strlen(sz)
SetBufIns (hbuf, lnFirst, len)
}
添加函数注释
//提示框中输入参数个数,产生不同的注释
macro MyCommit()
{
sz = Ask("Number Of Parameters:")
if (sz != "")
AddCommit(sz);
}
//添加注释的宏
macro AddCommit(sz)
{
num = sz
num2 = 0
hwnd = GetCurrentWnd()
lnLast = GetWndSelLnLast(hwnd)
hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnLast, "/**")
InsBufLine(hbuf, lnLast+1, " * \@brief ")
ln=lnLast+2
while (num > 0) {
num2 = num2+1
InsBufLine(hbuf, ln, " * \@param@num2@ ")
ln = ln+1
num = num-1
}
InsBufLine(hbuf, ln, " * \@expl ")
InsBufLine(hbuf, ln+1, " * \@return 0:success -1:failure")
InsBufLine(hbuf, ln+2, " */")
}
头文件与源文件切换
这里仅实现了头文件的源文件在同一个文件夹下时的切换。
macro switch_cpp_hpp()
{
hwnd = GetCurrentWnd()
hCurOpenBuf = GetCurrentBuf()
if (hCurOpenBuf == 0)
stop
curOpenFileName = GetBufName(hCurOpenBuf)
curOpenFileNameLen = strlen(curOpenFileName)
// 文件类型临时缓冲区
strFileExt = NewBuf("strFileExtBuf")
ClearBuf(strFileExt)
// 头文件类型
index_hpp_begin = 0
AppendBufLine(strFileExt, ".h")
AppendBufLine(strFileExt, ".hpp")
index_hpp_end = GetBufLineCount(strFileExt)
// 源文件类型
index_cpp_begin = index_hpp_end
AppendBufLine(strFileExt, ".c")
AppendBufLine(strFileExt, ".cpp")
AppendBufLine(strFileExt, ".cc")
AppendBufLine(strFileExt, ".cx")
AppendBufLine(strFileExt, ".cxx")
index_cpp_end = GetBufLineCount(strFileExt)
isCppFile = 0
curOpenFileExt = ""
index = index_hpp_begin
while(index < index_cpp_end)
{
curExt = GetBufLine(strFileExt, index)
curExtLen = strlen(curExt)
curOpenFileExt = strmid(curOpenFileName, curOpenFileNameLen-curExtLen, curOpenFileNameLen)
if(curOpenFileExt == curExt)
{
if (index < index_hpp_end)
isCppFile = 1
else
isCppFile = 2
break
}
index = index + 1
}
index_replace_begin = index_hpp_begin
index_replace_end = index_hpp_end
if (isCppFile == 1)
{
index_replace_begin = index_cpp_begin
index_replace_end = index_cpp_end
}
else if(isCppFile == 2)
{
index_replace_begin = index_hpp_begin
index_replace_end = index_hpp_end
}
else
{
index_replace_begin = 9999
index_replace_end = index_replace_begin
}
index = index_replace_begin
while(index < index_replace_end)
{
destExt = GetBufLine(strFileExt, index)
destFileName = strmid(curOpenFileName, 0, curOpenFileNameLen-strlen(curOpenFileExt)) // 不包括扩展名,绝对路径
// 尝试当前目标扩展名是否能够打开
destFilePath = cat(destFileName, destExt)
hCurOpenBuf = OpenBuf(destFilePath)
if(hCurOpenBuf != 0)
{
SetCurrentBuf(hCurOpenBuf)
break
}
index = index + 1
}
CloseBuf(strFileExt)
}