1、 把indent.em、NetEyeutils.em、utils.em放到C:\Documents and Settings\Administrator\My Documents\Source Insight\Projects\Base目录下
2、 打开Source Insight的Base工程,把上述3个宏文件加入到工程中
3、 选取Option -> MenuAssignment,在Command下输入Marco查找、选取宏,然后在Menu -> Menu Contends选取要把宏绑定在哪个系统选项位置下,点击Insert插入。
4、 关闭Base工程
5、 打开一个新工程,在相应的选项下即可使用该宏。
indent.em
1 | macroindent() |
2 | { |
3 | execIndent="C:\\ProgramFiles\\GnuWin32\\bin\\indent.exe"; |
4 | sPara="-br"; |
5 | //sPara="-kr"; |
6 | //sPara="--no-tabs-i3-bl-nce-bls-bli0--line-length120-kr"; |
7 | |
8 | hbuf=GetCurrentBuf(); |
9 | sFile=GetBufName(hbuf); |
10 | if(checkExtension(sFile)) |
11 | { |
12 | SaveBuf(hbuf);//saveBufferfirst,thenopenacmdexecutewindowswithminimizedstate[2]. |
13 | msg("CmdLine=\"@execIndent@\"@sPara@\"@sFile@\""); |
14 | exitcode=ShellExecute("open","\"@execIndent@\"","@sPara@\"@sFile@\"-o\"@sFile@\"","",2); |
15 | //PSDonotREMOVEthefollowingstatementthatseemnouse,orwillcauseReloadProblem. |
16 | exitcode=RunCmdLine("cmd/cecho\"Reflushing...\";cmd/cexit",".",true); |
17 | |
18 | RunCmd("ReloadFile"); |
19 | RunCmd("ReloadModifiedFiles"); |
20 | RunCmd("ParseFileNow"); |
21 | } |
22 | } |
23 | |
24 | macroCheckExtension(sFile) |
25 | { |
26 | nLength=strlen(sFile) |
27 | while(nLength>0) |
28 | { |
29 | if(sFile[nLength]==".") |
30 | break |
31 | nLength=nLength-1 |
32 | } |
33 | ext=strmid(sFile,nLength+1,strlen(sFile)) |
34 | if(ext=="c" |
35 | ||ext=="cpp" |
36 | ||ext=="h" |
37 | ||ext=="hpp") |
38 | returnTrue |
39 | else |
40 | returnFalse |
41 | } |
42 |
NetEyeutils.em
/* NetEyeUtils.em - a small collection of useful editing macros */
/*Save system's information*/
macro SaveSysInfo( )
{
Name = Ask( "Please enter your name:" )
Version = Ask( "Version:" )
DefineStr = Ask( "#ifdef:" )
hSysBuf = NewBuf( "SystemInfo" )
if( hSysBuf == hNil ){
return 1
}
AppendBufLine( hSysBuf, Name )//line 0
AppendBufLine( hSysBuf, Version )//line 1
AppendBufLine( hSysBuf, DefineStr )//line 2
SaveBufAs( hSysBuf, "system.ini" )
}
macro AddModInfo()
{
hSysBuf = OpenBuf( "system.ini" )
if( hSysBuf == hNil ){
return 1
}
MyName = GetBufLine( hSysBuf, 0 )
Version = GetBufLine( hSysBuf, 1 )
SysTime = GetSysTime( 0 )
year = SysTime.Year
month = SysTime.Month
day = SysTime.Day
hour = SysTime.Hour + 8
minute= SysTime.Minute
/*
j = 0
counter = 0
head = 0
tail = 0
while( 1 ){
if( AsciiFromChar( SysTime[j] ) == 34 ){
counter = counter + 1
}
if( counter == 1 && head == 0 ){
head = j
}
if( counter == 2 && tail == 0 ){
tail = j
break;
}
j = j + 1
}
date = StrMid( SysTime, head + 1, tail )
*/
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst( hwnd )
lnLast = GetWndSelLnLast( hwnd )
hbuf = GetCurrentBuf()
//modified on 2003.12.10
if( lnFirst != lnLast ){
firstBuf = ""
lastBuf = ""
spaceBuf = ""
referencedBuf = GetBufLine( hbuf, lnFirst )
i = 0
while( referencedBuf[i] == " " || referencedBuf[i] == "\t" ){
if( referencedBuf[i] == " " ){
spaceBuf = cat( spaceBuf, " " )//space
}else{
spaceBuf = cat( spaceBuf, "\t" )//Tab
}
i = i + 1
}
firstBuf = cat( spaceBuf, "/*Start of @MyName@ on @year@-@month@-@day@ @hour@:@minute@ @Version@*/" )
lastBuf = cat( spaceBuf, "/*End of @MyName@ on @year@-@month@-@day@ @hour@:@minute@ @Version@*/" )
InsBufLine( hbuf, lnFirst, firstBuf )
InsBufLine( hbuf, lnLast + 2, lastBuf )
}
else
{
lastBuf = ""
spaceBuf = ""
referencedBuf = GetBufLine( hbuf, lnFirst )
i = 0
while( referencedBuf[i] == " " || referencedBuf[i] == "\t" ){
if( referencedBuf[i] == " " ){
spaceBuf = cat( spaceBuf, " " )//space
}else{
spaceBuf = cat( spaceBuf, "\t" )//Tab
}
i = i + 1
}
firstBuf = cat( spaceBuf, "//Modify by @MyName@ on @year@-@month@-@day@ @hour@:@minute@ " )
InsBufLine( hbuf, lnFirst, firstBuf )
}
CloseBuf( hSysBuf )
}
macro AddCommentInfo()
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst( hwnd )
lnLast = GetWndSelLnLast( hwnd )
hbuf = GetCurrentBuf()
curFirstText = GetBufLine( hbuf, lnFirst )
i = 0
tmpFirstText = ""
while( curFirstText[i] == " " || curFirstText[i] == "\t" ){
if( curFirstText[i] == " " ){
tmpFirstText = cat( tmpFirstText, " " )
}else{
tmpFirstText = cat( tmpFirstText, "\t" )
}
i = i + 1
}
len = strlen( curFirstText )
newFirstText = strmid( curFirstText, i, len )
if( lnFirst == lnLast ){
/*
GetWndSelIchFirst (hwnd)
GetWndSelIchLim (hwnd)
*/
//modified on 2003.12.10
tmpFirstText = cat( tmpFirstText, "/*" )
newFirstText = cat( tmpFirstText, newFirstText )
newFirstText = cat( newFirstText, "*/" )
DelBufLine( hbuf, lnFirst )
InsBufLine( hbuf, lnFirst, newFirstText )
}else{
tmpFirstText = cat( tmpFirstText, "/*" )
newFirstText = cat( tmpFirstText, newFirstText )
curLastText = GetBufLine( hbuf, lnLast )
newLastText = cat( curLastText, "*/" )
DelBufLine( hbuf, lnFirst )
InsBufLine( hbuf, lnFirst, newFirstText )
DelBufLine( hbuf, lnLast )
InsBufLine( hbuf, lnLast, newLastText )
}
}
macro AddIf0Identifier()
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst( hwnd )
lnLast = GetWndSelLnLast( hwnd )
hbuf = GetCurrentBuf()
curFirstText = GetBufLine( hbuf, lnFirst )
if( strlen( curFirstText) <= 0 ){
return 1
}
i = 0
tmpFirstText = ""
while( curFirstText[i] == " " || curFirstText[i] == "\t" ){
if( curFirstText[i] == " " ){
tmpFirstText = cat( tmpFirstText, " " )
}else{
tmpFirstText = cat( tmpFirstText, "\t" )
}
i = i + 1
}
if( lnFirst <= 1 ){
return 1
}
newText = cat( tmpFirstText, "#if 0" )
InsBufLine( hbuf, lnFirst, newText )
newText = cat( tmpFirstText, "#endif" )
InsBufLine( hbuf, lnLast + 2, newText )
}
/*-------------------------------------------------------------------------
I N S E R T H E A D E R
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 AddFuncHeader()
{
hSysBuf = OpenBuf( "system.ini" )
if( hSysBuf == hNil ){
return 1
}
szMyName = GetBufLine( hSysBuf, 0 )
szVersion = GetBufLine( hSysBuf, 1 )
SysTime = GetSysTime( 0 )
date = StrMid( SysTime, 6, 19 )
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
if( hbuf == hNil ){
return 1
}
ln = GetBufLnCur( hbuf )
// begin assembling the title string
//InsBufLine(hbuf, ln+1, "/*-------------------------------------------------------------------------*")
/* if owner variable exists, insert Owner: name */
/*if (strlen(szMyName) > 0){
InsBufLine( hbuf, ln + 2, "Function:" )
InsBufLine( hbuf, ln + 3, "Created By: @szMyName@" )
InsBufLine( hbuf, ln + 4, "Created Date: @date@" )
InsBufLine( hbuf, ln + 5, "Modified By:" )
InsBufLine( hbuf, ln + 6, "Modified Date:" )
InsBufLine( hbuf, ln + 7, "Parameters:" )
InsBufLine( hbuf, ln + 8, "Returns:" )
InsBufLine( hbuf, ln + 9, "Calls:" )
InsBufLine( hbuf, ln + 10, "Called By:" )
ln = ln + 10
}else{
ln = ln + 2
}*/
lnStartPos = ln + 2;
if (strlen(szMyName) > 0){
InsBufLine( hbuf, ln + 1, "/*" )
InsBufLine( hbuf, ln + 2, " * Function: " )
InsBufLine( hbuf, ln + 3, " * Description: " )
InsBufLine( hbuf, ln + 4, " * Calls: " )
InsBufLine( hbuf, ln + 5, " * Called By: " )
InsBufLine( hbuf, ln + 6, " * Table Accessed: " )
InsBufLine( hbuf, ln + 7, " * Table Updated: " )
InsBufLine( hbuf, ln + 8, " * Input: " )
InsBufLine( hbuf, ln + 9, " * Output: " )
InsBufLine( hbuf, ln + 10, " * Return: " )
InsBufLine( hbuf, ln + 11, " * Others: " )
ln = ln + 11
}else{
ln = ln + 2
}
//InsBufLine(hbuf, ln+1, "*-------------------------------------------------------------------------*/")
InsBufLine( hbuf, ln + 1, " */" )
// put the insertion point inside the header comment
SetBufIns( hbuf, lnStartPos, 20 )
CloseBuf( hSysBuf )
}
/* 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 AddFileHeader()
{
hSysBuf = OpenBuf( "system.ini" )
if( hSysBuf == hNil ){
return 1
}
szMyName = GetBufLine( hSysBuf, 0 )
Version = GetBufLine( hSysBuf, 1 )
SysTime = GetSysTime( 0 )
//modified on 2003.12.10
//date = StrMid( SysTime, 6, 19 )
year = SysTime.Year
month = SysTime.Month
day = SysTime.Day
hbuf = GetCurrentBuf()
//InsBufLine( hbuf, 0, "/*=========================================================================*" )
InsBufLine( hbuf, 0, "/*" )
/* if owner variable exists, insert Owner: name */
/*InsBufLine( hbuf, 1, "FileName:" )
InsBufLine( hbuf, 2, "Created by:@szMyName@" )
InsBufLine( hbuf, 3, "Created date:@date@" )
InsBufLine( hbuf, 4, "Content:" )
InsBufLine( hbuf, 5, "Modified records:" )
InsBufLine( hbuf, 6, "1. YYYY.MM.DD:Mr Bill Gates add ......" )
InsBufLine( hbuf, 7, " Mr. Bill Gates add ......" )*/
InsBufLine( hbuf, 1, " * FileName: " )
InsBufLine( hbuf, 2, " * Author: @szMyName@ Version: @Version@ Date: @year@-@month@-@day@" )
InsBufLine( hbuf, 3, " * Description: " )
InsBufLine( hbuf, 4, " * Version: " )
InsBufLine( hbuf, 5, " * Function List: " )
InsBufLine( hbuf, 6, " * 1." )
InsBufLine( hbuf, 7, " * History: " )
InsBufLine( hbuf, 8, " * " )
InsBufLine( hbuf, 9, " */" )
SetBufIns( hbuf, 1, 19 )
//InsBufLine( hbuf, 8, "*=========================================================================*/" )
CloseBuf( hSysBuf )
}
utils.em
1 | /*Utils.em-asmallcollectionofusefuleditingmacros*/ |
2 | |
3 | |
4 | |
5 | /*------------------------------------------------------------------------- |
6 | INSERTHEADER |
7 | |
8 | Insertsacommentheaderblockatthetopofthecurrentfunction. |
9 | Thisactuallyworksonanytypeofsymbol,notjustfunctions. |
10 | |
11 | Tousethis,defineanenvironmentvariable"MYNAME"andsetit |
12 | toyouremailname.eg.setMYNAME=raygr |
13 | -------------------------------------------------------------------------*/ |
14 | macroInsertHeader() |
15 | { |
16 | //Gettheowner'snamefromtheenvironmentvariable:MYNAME. |
17 | //Ifthevariabledoesn'texist,thentheownerfieldisskipped. |
18 | szMyName=getenv(MYNAME) |
19 | |
20 | //Getahandletothecurrentfilebufferandthename |
21 | //andlocationofthecurrentsymbolwherethecursoris. |
22 | hbuf=GetCurrentBuf() |
23 | szFunc=GetCurSymbol() |
24 | ln=GetSymbolLine(szFunc) |
25 | |
26 | //beginassemblingthetitlestring |
27 | sz="/*" |
28 | |
29 | /*convertsymbolnametoTEXTLIKETHIS*/ |
30 | cch=strlen(szFunc) |
31 | ich=0 |
32 | while(ich<cch) |
33 | { |
34 | ch=szFunc[ich] |
35 | if(ich>0) |
36 | if(isupper(ch)) |
37 | sz=cat(sz,"") |
38 | else |
39 | sz=cat(sz,"") |
40 | sz=Cat(sz,toupper(ch)) |
41 | ich=ich+1 |
42 | } |
43 | |
44 | sz=Cat(sz,"*/") |
45 | InsBufLine(hbuf,ln,sz) |
46 | InsBufLine(hbuf,ln+1,"/*-------------------------------------------------------------------------") |
47 | |
48 | /*ifownervariableexists,insertOwner:name*/ |
49 | if(strlen(szMyName)>0) |
50 | { |
51 | InsBufLine(hbuf,ln+2," |