source insight 宏进阶功能

当你使用SI,想进入源文件的路径时,不好意思没有打开文件路径功能,
你是不是要先打开资源管理器,然后一路从盘符,点到子文件夹.孙文件夹...最后再到工程文件夹,而且要一直对比有没有点错,找到对应源代码的时候, 是否有一种黄花菜都凉的感觉,而且每天都在重复这个动作,这是在强制摸鱼,下面会介绍一键打开路径并定位到文件的神奇操作,就是这么快

当你想快速注释掉一段代码或者取消注释时是不是要手动去加注释符号,取消时还要手动取消,如果看到一大段//的注释是不是要一行行地去取消,不用这么麻烦,下面会介绍三种不同的注释

你是不是常碰到复制SI的中文到其他地方乱码,那就试试一键使用notepad++打开吧,再复制没有乱码了

你是不是碰到代码打着打着突然,右边的界面就僵住了,不管怎么上下滚动,只有看到左边的代码,右边的被截断了,都是拖影,主代码窗口出现了,内容查看的窗口也出现了,一般情况是关掉再重新打开就可以消除这个情况,一直不断的重复,思路都被打断,灵感都消失了,怎么办

 

试试xzy_reopen_file_and_jump_line(),这个宏的原理就是关掉窗口,再打开,由于缓冲区是旧的,所以连撤销数据还在,同时其他小窗口也通过开关刷新了下

既然能打开其他应用程序,所以当然也想到了打开命令行,并定位到源文件路径上,也可以打开命令行定位到工程路径上,(工程路径组织如下)一般在工程要目录下存放编译批处理,直接调用可以通过makefile编译整个工程

 //工程路径一般以SI或si工程文件夹名,上一级工程路径
 //要求工程路径这样  proj_folder/proj_top_dir/....
 //                              proj_folder/si/mysi.PR

既然能打开命令行,打开git的话也不例外,当然要自己修改路径到你本机上的软件路径,并且要把\改成\\,下面有打开工程git,打开TortoiseGit查看差异,查看历史,查看与上一版差异等


宏汇总如下

1.注释是SI短板,通过宏扩展增加了注释与解除注释的快捷键

a.单行注释//

b.多选注释/*....*/

c.宏注释 #if 0 ... #endif

d.插入宏XFLAG

2.路径定位功能a.打开命令行定位到当前文件路径/打开命令行定位到工程(.PR)路径,凡是以si,SI为工程的路径则定位命令行到上一级

b.打开资源文件夹,定位到当前文件

3.使用notepad++打开当前文件,需要指定你的电脑上的notepad++路径,路径\要用\\代替

4.解决界面只显示一半源文件问题,原理是先关掉文件窗口,再重新打开防止界面错乱界面重新刷新,实测不影响未保存内容,ALT+R

5.切换当前源文件的同一目录下同名的.h 与.c /.cpp

6.GIT功能调用 

通过options/key asssignments绑定快捷键来调用 macro:xzy_xxx

下载地址
链接:https://pan.baidu.com/s/1ZnlkSD6i3THLFqY4dOSYGA?pwd=tjco 
 

 //取得以SI或si工程文件夹的工程路径,上一级工程路径
 //要求工程  proj_folder/proj_top_dir/....
 //          proj_folder/si/mysi.PR
 
macro xzy_get_proj_dir()
{
	buf = GetCurrentProj();
	dir = GetProjDir(buf);
	cch = strlen(dir);
	proj_top_dir=nil;
	dir1=nil
	if(cch>3){
		if((dir[cch-2]=="s" && dir[cch-1]=="i" ) || (dir[cch-2]=="S" && dir[cch-1]=="I" )){
			dir1=strtrunc(dir,cch-3)	
		}
	}
	if(dir1 != nil){
		dir=dir1		
		buf = GetCurrentBuf();
		curFilePath = GetBufName(buf);
		cch_current_file = strlen(curFilePath);
		cch_top_dir=strlen(dir)
		min=cch_current_file;
		if(cch_current_file >cch_top_dir){
			min=cch_top_dir
		}
		idx=0;
		while(idx<min){
		    if(dir[idx]!=curFilePath[idx]){
				break;
		    }
			idx=idx+1;
		}
		if(idx==cch_top_dir){
			i=idx+1;
			while(i<cch_current_file){			 
				 if(curFilePath[i]=="\\"){
					proj_top_dir=strtrunc(curFilePath,i);
					break;
				}
				i=i+1;
			}

		}
     	//msg(proj_top_dir)
	}
	StartMsg("Wait opening file...")
	RunCmdLine(cmdLine, nil, 0);
	EndMsg() 
	return proj_top_dir
}


//打开当前的文件指向的git命令行,ALT+`
macro xzy_git_cmdline()
{
	dir=xzy_get_proj_dir()
	if (dir!=nil){	
			StartMsg("Wait opening file...")
ShellExecute("open","D:\\software\\install\\git\\git-bash.exe ","--cd=\"@dir@\"","",0);

			EndMsg()      
     }
}
//TortoiseGit窗口查看当前工程的差异,ALT+1
macro xzy_git_proj_diff() 
{
	dir=xzy_get_proj_dir()
	if (dir!=nil){	
			StartMsg("Wait opening file...")!!!路径一定要改成双\\
			ShellExecute("open","C:\\Program Files\\TortoiseGit\\bin\\TortoiseGitProc.exe","/command:diff /path:\"@dir@\"","",0);
			EndMsg()      
	    	break;
		}
		i= i-1
	}
}
//TortoiseGit窗口查看当前工程与前一次提交的差异,ALT+3
macro xzy_git_proj_log() 
{
	dir=xzy_get_proj_dir()
	if (dir!=nil){	
			StartMsg("Wait opening file...")!!!路径一定要改成双\\
			ShellExecute("open","C:\\Program Files\\TortoiseGit\\bin\\TortoiseGitProc.exe","/command:log /path:\"@dir@\"","",0);
			EndMsg()      
	    	break;
		}
		i= i-1
	}
}

//在命令行打开当前文件路径,ALT+Q
macro xzy_open_cmd_at_current_file_dir() //open cmd.exe and cd to current file dir
{
    buf = GetCurrentBuf();
    curFilePath = GetBufName(buf);
    cch = strlen(curFilePath);
    i = cch-1;
    while(i>0){
        if(curFilePath[i]=="\\"){
            dir=strtrunc(curFilePath,i)    
            cmdLine = "cmd /k cd /d \"@dir@\"";  
            StartMsg("Wait opening file...")
            RunCmdLine(cmdLine, nil, 0);
            EndMsg()      
            break;
        }
        i= i-1
    }
}
//在命令行打开工程文件路径,ALT+W
macro xzy_open_cmd_at_proj_dir() //open cmd.exe and cd to project dir
{
    buf = GetCurrentProj();
    dir = GetProjDir(buf);
    cch = strlen(dir);
    dir1=nil
    if(cch>3){//以si,SI为路径则取上一级路径
        if((dir[cch-2]=="s" && dir[cch-1]=="i")||
           (dir[cch-2]=="S" && dir[cch-1]=="I")){
            dir1=strtrunc(dir,cch-3)    
        }
    }
    if(dir1 != nil){
        dir=dir1
    }
    cmdLine = "cmd /k cd /d \"@dir@\"";  
    StartMsg("Wait opening file...")
    RunCmdLine(cmdLine, nil, 0);
    EndMsg()      
}

//先关掉文件再重新打开防止界面错乱,ALT+R
macro xzy_reopen_file_and_jump_line()
{
    hwnd = GetCurrentWnd()
    selection = GetWndSel(hwnd)
    line =     GetWndVertScroll(hwnd)
    buf = GetCurrentBuf();
    curFilePath = GetBufName(buf);
    CloseWnd(hwnd)
    OpenMiscFile(curFilePath)
    hwnd = GetCurrentWnd()    
    ScrollWndVert(hwnd, line)//ScrollWndToLine(hwnd,line)此语句会移动到第一行
    //以下两句自动关闭symbol window
    RunCmd("Activate Symbol Window");//active force to show
    RunCmd("Symbol Window");//hide
    
    //以下两句自动关闭open file
    RunCmd("Activate Project Window");//active force to show
    RunCmd("Project Window");//hide
    
    //以下关掉再显示Context Window
    RunCmd("Activate Context Window");//active force to show
    RunCmd("Context Window");//hide
    RunCmd("Context Window");//show again

    //以下关掉再显示Relation Window
    RunCmd("Activate Relation Window");//active force to show
    RunCmd("Relation Window");//hide
    RunCmd("Relation Window");//show again
}

//使用notepad++打开当前文件,防止source insight复制中文乱码,ALT+T
macro xzy_open_file_with_notepad()
{
    buf = GetCurrentBuf();
    curFilePath = GetBufName(buf);
    //cmdLine = "D:\\software\\NOTPAD7\\notepad++.exe \"@curFilePath@\"";  
    cmdLine = "D:\\soft\\notepad\\notepad++.exe \"@curFilePath@\"";  
    StartMsg("Wait opening file...")
    RunCmdLine(cmdLine, nil, 0);
    EndMsg()
}

//切换源文件与头文件,ALT+C
macro xzy_open_switch_src_and_h_file()
{
    hcurrentbuf = getcurrentbuf()
    bname = getbufname(hcurrentbuf)
    len = strlen(bname)
    if(".cpp" == tolower(strmid(bname, len-4, len))){
        filename = strmid(bname, 0, len-4)#".h"
    }
    else if(".c" ==tolower( strmid(bname,len-2,len))){
        filename = strmid(bname, 0, len-2)#".h"
    }
    else if(".h" ==tolower(strmid(bname, len-2, len))){
        cpp_name= strmid(bname, 0, len-2)#".cpp"
        c_name=strmid(bname,0,len-2)#".c"
            hit_cpp= openbuf(cpp_name)
            hit_c = openbuf(c_name)  
            if(hit_cpp !=hnil){
                setcurrentbuf(hit_cpp)
            }else if(hit_c !=hnil){
                setcurrentbuf(hit_c)
            }
            stop
    }else{
        filename = nil
    }
    if(filename != nil){
        hbufnext = openbuf(filename)
        if(hbufnext != hnil){
            setcurrentbuf(hbufnext)
        }
    }
}

//在我的电脑中打开当前文件夹并选择,ALT+D
macro xzy_open_in_exporer_and_select()
{
    buf = GetCurrentBuf();
    file = GetBufName(buf);
    cmdLine = "explorer.exe /select,@file@"; //@file@ 在字符串中引用变量 
    StartMsg("wait...")
    RunCmdLine(cmdLine, nil, 0);
    EndMsg()
}

//将选择的行添加一个双斜杠//注释,CTRL+/
macro xzy_double_slash_add()
{
    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
        }  
        PutBufLine(hbuf, Ln, Cat("//", buf))
        Ln = Ln + 1
    }
    SetWndSel(hwnd,selection)
}
//删除一个//注释,ALT+CTRL+/
macro xzy_double_slash_remove()
{
    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
        }
        i=0;
        while(i<len-1){//not support for statement
            if(buf[i] =="/" ){
                if(buf[i+1]=="/"){
                    buf[i] =" "
                    buf[i+1]=" "
                    PutBufLine(hbuf, Ln,Cat(StrMid(buf,0,i), StrMid(buf,i+2, Strlen(buf))))
                    break;
                }
            }else{
                if(buf[i] != " "){
                    break;
                }
            }
            i=i+1
        }
        Ln = Ln + 1
    }
    SetWndSel(hwnd, selection)
}
//添加宏#ifdef MACRO #endif,ALT+CTRL+SHIFT+'
macro xzy_sharp_ifdef_end()
{
    hwnd = GetCurrentWnd()
    sel = GetWndSel(hwnd)
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd)
    hbuf = GetCurrentBuf()
    if(LnFirst == 0){
        szIfStart = ""
    }else{
        szIfStart = GetBufLine(hbuf, LnFirst - 1) //被选择的第一行的上一行的内容
    }
    szIfEnd = GetBufLine(hbuf, lnLast + 1) //被选择的代码块的最后一行的下一行内容
    szCodeStart = GetBufLine(hbuf, LnFirst) //被选择的代码块的第一行内容
    szCodeEnd = GetBufLine(hbuf, lnLast)//被选择的代码块的最后一行内容
    start_space_count = 0 //第一行代码的前面的空白个数  只计算Tab个数,忽略空格
    end_space_count = 0  //最后一行的代码的前面的空白个数
    insert_space_count = 0 //我们要插入的#if 0 字符串前面应该插入多少个Tab
    index = 0
    while(index < strlen(szCodeStart)){
        if(AsciiFromChar(szCodeStart[index]) == 9){   //9是Tab字符的ASCII
           start_space_count = start_space_count + 1
        }
        index = index + 1
    }
    index = 0
    while(index < strlen(szCodeEnd)){
        if(AsciiFromChar(szCodeEnd[index]) == 9){
               end_space_count = end_space_count + 1
        }
        index = index + 1
    }
    //代码块的第一行和最后一行前面的Tab个数,取比较小的那个值
    if(start_space_count < end_space_count){
        insert_space_count = start_space_count - 1
    }else{  
        insert_space_count = end_space_count - 1
    }
    str_start_insert = ""
    str_end_insert = ""
    index = 0
    while(index < insert_space_count){
        str_start_insert = str_start_insert#"    " //这里添加的Tab字符
        str_end_insert = str_end_insert#"    " //这里添加的也是Tab字符
        index = index + 1
    } 
    str_start_insert = str_start_insert#"#if defined(XFLAG)"  //在#if 0 开始符号和结束符号前都添加Tab字符,比代码行前面的空白少一个
    str_end_insert = str_end_insert#"#endif"
    if(TrimString(szIfStart) == "#if defined(XFLAG)" && TrimString(szIfEnd) == "#endif"){
        DelBufLine(hbuf, lnLast + 1)
        DelBufLine(hbuf, lnFirst - 1)
        sel.lnFirst = sel.lnFirst - 1
        sel.lnLast = sel.lnLast - 1
    }else{
        InsBufLine(hbuf, lnFirst, str_start_insert)
        InsBufLine(hbuf, lnLast + 2, str_end_insert)
        sel.lnFirst = sel.lnFirst + 1
        sel.lnLast = sel.lnLast + 1
    }
    SetWndSel(hwnd, sel )
}

//对选择的代码添加 或取消#if 0 ... #endif 包围,,ALT+CTRL+SHIFT+/
macro xzy_sharp_if_0_endif()
{
    hwnd = GetCurrentWnd()
    sel = GetWndSel(hwnd)
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd)
    hbuf = GetCurrentBuf()

    if(LnFirst == 0){
        szIfStart = ""
    }else{
        szIfStart = GetBufLine(hbuf, LnFirst - 1) //被选择的第一行的上一行的内容
    }
    szIfEnd = GetBufLine(hbuf, lnLast + 1) //被选择的代码块的最后一行的下一行内容
    szCodeStart = GetBufLine(hbuf, LnFirst) //被选择的代码块的第一行内容
    szCodeEnd = GetBufLine(hbuf, lnLast)//被选择的代码块的最后一行内容
    start_space_count = 0 //第一行代码的前面的空白个数  只计算Tab个数,忽略空格
    end_space_count = 0  //最后一行的代码的前面的空白个数
    insert_space_count = 0 //我们要插入的#if 0 字符串前面应该插入多少个Tab
    index = 0
    while(index < strlen(szCodeStart)){
        if(AsciiFromChar(szCodeStart[index]) == 9){   //9是Tab字符的ASCII
           start_space_count = start_space_count + 1
        }
        index = index + 1
    }
    index = 0
    while(index < strlen(szCodeEnd)){
        if(AsciiFromChar(szCodeEnd[index]) == 9){
               end_space_count = end_space_count + 1
        }
        index = index + 1
    }

    //代码块的第一行和最后一行前面的Tab个数,取比较小的那个值
    if(start_space_count < end_space_count){
        insert_space_count = start_space_count - 1
    }else{
        insert_space_count = end_space_count - 1
    }
    str_start_insert = ""
    str_end_insert = ""
    index = 0
    while(index < insert_space_count){
        str_start_insert = str_start_insert#"    " //这里添加的Tab字符
        str_end_insert = str_end_insert#"    " //这里添加的也是Tab字符
        index = index + 1
    }
    str_start_insert = str_start_insert#"#if 0"  //在#if 0 开始符号和结束符号前都添加Tab字符,比代码行前面的空白少一个
    str_end_insert = str_end_insert#"#endif"
    if(TrimString(szIfStart) == "#if 0" && TrimString(szIfEnd) == "#endif"){
        DelBufLine(hbuf, lnLast + 1)
        DelBufLine(hbuf, lnFirst - 1)
        sel.lnFirst = sel.lnFirst - 1
        sel.lnLast = sel.lnLast - 1
    }else{
        InsBufLine(hbuf, lnFirst, str_start_insert)
        InsBufLine(hbuf, lnLast + 2, str_end_insert)
        sel.lnFirst = sel.lnFirst + 1
        sel.lnLast = sel.lnLast + 1
    }
    SetWndSel(hwnd, sel )
}

//将选中的代码块添加多行注释/**/,ALT+/
macro xzy_slash_star_add_remove()
{
    hwnd = GetCurrentWnd()
    sel = GetWndSel(hwnd)
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd)
    hbuf = GetCurrentBuf()
    if(LnFirst == 0){
        szIfStart = ""
    }else{
        szIfStart = GetBufLine(hbuf, LnFirst - 1) //被选择的第一行的上一行的内容
    }
    szIfEnd = GetBufLine(hbuf, lnLast + 1) //被选择的代码块的最后一行的下一行内容
    szCodeStart = GetBufLine(hbuf, LnFirst) //被选择的代码块的第一行内容
    szCodeEnd = GetBufLine(hbuf, lnLast)//被选择的代码块的最后一行内容
    start_space_count = 0 //第一行代码的前面的空白个数  只计算Tab个数,忽略空格
    end_space_count = 0  //最后一行的代码的前面的空白个数
    insert_space_count = 0
    index = 0
    while(index < strlen(szCodeStart)){
        if(AsciiFromChar(szCodeStart[index]) == 9){   //9是Tab字符的ASCII
               start_space_count = start_space_count + 1
        }
        index = index + 1
    }
    index = 0
    while(index < strlen(szCodeEnd)){
        if(AsciiFromChar(szCodeEnd[index]) == 9){
               end_space_count = end_space_count + 1
        }
        index = index + 1
    }
    if(start_space_count < end_space_count){
        insert_space_count = start_space_count - 1
    }else{
        insert_space_count = end_space_count - 1
    }
    str_start_insert = ""
    str_end_insert = ""
    index = 0
    while(index < insert_space_count){
        str_start_insert = str_start_insert#"    " //这里添加的Tab字符
        str_end_insert = str_end_insert#"    "
        index = index + 1
    }
    str_start_insert = str_start_insert#"/*"  //在注释开始符号和结束符号前都添加Tab字符,比代码行前面的空白少一个
    str_end_insert = str_end_insert#"*/"
    if(TrimString(szIfStart) == "/*" && TrimString(szIfEnd) == "*/"){
        DelBufLine(hbuf, lnLast + 1)
        DelBufLine(hbuf, lnFirst - 1)
        sel.lnFirst = sel.lnFirst - 1
        sel.lnLast = sel.lnLast - 1
    }else{
        InsBufLine(hbuf, lnFirst, str_start_insert)
        InsBufLine(hbuf, lnLast + 2, str_end_insert)
        sel.lnFirst = sel.lnFirst + 1
        sel.lnLast = sel.lnLast + 1
    }
    SetWndSel(hwnd, sel )
}

//###########################################################################

//去掉左边空格,Tab等
macro TrimLeft(szLine)
{
    nLen = strlen(szLine)
    if(nLen == 0){
        return szLine
    }
    nIdx = 0
    while(nIdx < nLen ){
        if((szLine[nIdx] != " ") &&(szLine[nIdx] != "\t") ){
           break
        }
        nIdx = nIdx + 1
    }
    return strmid(szLine, nIdx, nLen)
}

//去掉字符串右边的空格
macro TrimRight(szLine)
{
    nLen = strlen(szLine)
    if(nLen == 0){
        return szLine
    }
    nIdx = nLen
    while(nIdx > 0 ){
        nIdx = nIdx - 1
        if((szLine[nIdx] != " ") &&(szLine[nIdx] != "\t") ){
           break
        }
    }
    return strmid(szLine, 0, nIdx + 1)
}

//去掉字符串两边空格
macro TrimString(szLine)
{
    szLine = TrimLeft(szLine)
    szLIne = TrimRight(szLine)
    return szLine
}




/*-------------------------------------------------------------------------
INSERT HEADER
Inserts a comment header block at the top of the current function.
This actually works on any type of symbol, not just functions.

To use this, define an environment variable "MYNAME" and set it
to your email name.  eg. set MYNAME=raygr
-------------------------------------------------------------------------*/
macro InsertHeader()
{
    // Get the owner's name from the environment variable: MYNAME.
    // If the variable doesn't exist, then the owner field is skipped.
    szMyName = getenv(MYNAME)

    // Get a handle to the current file buffer and the name
    // and location of the current symbol where the cursor is.
     hbuf = GetCurrentBuf()
    szFunc = GetCurSymbol()
    ln = GetSymbolLine(szFunc)

    // begin assembling the title string
    sz = "/*   "

    /* convert symbol name to TEXT LIKE THIS */
    cch = strlen(szFunc)
    ich = 0
    while(ich < cch){
        ch = szFunc[ich]
        if(ich > 0) {
            if(isupper(ch)){
               sz = cat(sz, "   ")
            }else{
               sz = cat(sz, " ")
                sz = Cat(sz, toupper(ch))
                ich = ich + 1
            }
         }
    }
    sz = Cat(sz, "   */")
    InsBufLine(hbuf, ln, sz)
    InsBufLine(hbuf, ln + 1, "/*-------------------------------------------------------------------------")

    /* if owner variable exists, insert Owner: name */
    if(strlen(szMyName) > 0){
        InsBufLine(hbuf, ln + 2, "    Owner: @szMyName@")
        InsBufLine(hbuf, ln + 3, " ")
        ln = ln + 4
    }else{
        ln = ln + 2
    }

    InsBufLine(hbuf, ln,   "    ") // provide an indent already
    InsBufLine(hbuf, ln + 1, "-------------------------------------------------------------------------*/")

    // put the insertion point inside the header comment
    SetBufIns(hbuf, ln, 4)
}


/* InsertFileHeader:

Inserts a comment header block at the top of the current function.
This actually works on any type of symbol, not just functions.

To use this, define an environment variable "MYNAME" and set it
to your email name.  eg. set MYNAME=raygr
*/

macro InsertFileHeader()
{
    szMyName = getenv(MYNAME)
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, 0, "/*-------------------------------------------------------------------------")
    /* if owner variable exists, insert Owner: name */
    InsBufLine(hbuf, 1, "    ")
    if(strlen(szMyName) > 0){
        sz = "    Owner: @szMyName@"
        InsBufLine(hbuf, 2, " ")
        InsBufLine(hbuf, 3, sz)
        ln = 4
    }else{
        ln = 2
    }
    InsBufLine(hbuf, ln, "-------------------------------------------------------------------------*/")
}



// Inserts "Returns True .. or False..." at the current line
macro ReturnTrueOrFalse()
{
    hbuf = GetCurrentBuf()
    ln = GetBufLineCur(hbuf)
    InsBufLine(hbuf, ln, "    Returns True if successful or False if errors.")
}



/* Inserts ifdef REVIEW around the selection */
macro IfdefReview()
{
    IfdefSz("REVIEW");
}


/* Inserts ifdef BOGUS around the selection */
macro IfdefBogus()
{
    IfdefSz("BOGUS");
}


/* Inserts ifdef NEVER around the selection */
macro IfdefNever()
{
    IfdefSz("NEVER");
}


// Ask user for ifdef condition and wrap it around current
// selection.
macro InsertIfdef()
{
    sz = Ask("Enter ifdef condition:")
    if(sz != ""){
        IfdefSz(sz);
    }
}

macro InsertCPlusPlus()
{
    IfdefSz("__cplusplus");
}


// Wrap ifdef <sz> .. endif around the current selection
macro IfdefSz(sz)
{
    hwnd = GetCurrentWnd()
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd)
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, lnFirst, "#ifdef @sz@")
    InsBufLine(hbuf, lnLast + 2, "#endif /* @sz@ */")
}


// Delete the current line and appends it to the clipboard buffer
macro KillLine()
{
    hbufCur = GetCurrentBuf();
    lnCur = GetBufLnCur(hbufCur)
    hbufClip = GetBufHandle("Clipboard")
    AppendBufLine(hbufClip, GetBufLine(hbufCur, lnCur))
    DelBufLine(hbufCur, lnCur)
}


// Paste lines killed with KillLine(clipboard is emptied)
macro PasteKillLine()
{
    Paste
    EmptyBuf(GetBufHandle("Clipboard"))
}



// delete all lines in the buffer
macro EmptyBuf(hbuf)
{
    lnMax = GetBufLineCount(hbuf)
    while(lnMax > 0){
        DelBufLine(hbuf, 0)
        lnMax = lnMax - 1
    }
}


// Ask the user for a symbol name, then jump to its declaration
macro JumpAnywhere()
{
    symbol = Ask("What declaration would you like to see?")
    JumpToSymbolDef(symbol)
}


// list all siblings of a user specified symbol
// A sibling is any other symbol declared in the same file.
macro OutputSiblingSymbols()
{
    symbol = Ask("What symbol would you like to list siblings for?")
    hbuf = ListAllSiblings(symbol)
    SetCurrentBuf(hbuf)
}


// Given a symbol name, open the file its declared in and
// create a new output buffer listing all of the symbols declared
// in that file.  Returns the new buffer handle.
macro ListAllSiblings(symbol)
{
    loc = GetSymbolLocation(symbol)
    if(loc == ""){
        msg("@symbol@ not found.")
        stop
    }
    hbufOutput = NewBuf("Results")
    hbuf = OpenBuf(loc.file)
    if(hbuf == 0){
        msg("Can't open file.")
        stop
    }
    isymMax = GetBufSymCount(hbuf)
    isym = 0
    while(isym < isymMax){
        AppendBufLine(hbufOutput, GetBufSymName(hbuf, isym))
        isym = isym + 1
    }
    CloseBuf(hbuf)
    return hbufOutput
}
//##########################################################################




  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值