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.PRmacro xzy_get_proj_dir()
{buf = GetCurrentProj();dir = GetProjDir(buf);cch = strlen(dir);proj_top_dir=nil;dir1=nilif(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(idx0){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=nilif(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 windowRunCmd("Activate Symbol Window");//active force to showRunCmd("Symbol Window");//hide//以下两句自动关闭open fileRunCmd("Activate Project Window");//active force to showRunCmd("Project Window");//hide//以下关掉再显示Context WindowRunCmd("Activate Context Window");//active force to showRunCmd("Context Window");//hideRunCmd("Context Window");//show again//以下关掉再显示Relation WindowRunCmd("Activate Relation Window");//active force to showRunCmd("Relation Window");//hideRunCmd("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 = Lnfirstbuf = GetBufLine(hbuf, Ln)len = strlen(buf)while(Ln <= Lnlast){buf = GetBufLine(hbuf, Ln)  //取Ln对应的行if(buf == ""){       //跳过空行Ln = Ln + 1continue}  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 = Lnfirstbuf = GetBufLine(hbuf, Ln)len = strlen(buf)while(Ln <= Lnlast){buf = GetBufLine(hbuf, Ln)  //取Ln对应的行if(buf == ""){       //跳过空行Ln = Ln + 1continue}i=0;while(i 0 ){nIdx = nIdx - 1if((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 stringsz = "/*   "/* convert symbol name to TEXT LIKE THIS */cch = strlen(szFunc)ich = 0while(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 alreadyInsBufLine(hbuf, ln + 1, "-------------------------------------------------------------------------*/")// put the insertion point inside the header commentSetBufIns(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  .. 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()
{PasteEmptyBuf(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 = 0while(isym < isymMax){AppendBufLine(hbufOutput, GetBufSymName(hbuf, isym))isym = isym + 1}CloseBuf(hbuf)return hbufOutput
}
//##########################################################################


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部