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 | macro indent() |
2 | { |
3 | execIndent = "C://Program Files//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);//save Buffer first ,then open a cmd execute windows with minimized state [2]. |
13 | msg("CmdLine = /"@[email protected]/" @[email protected] /"@[email protected]/" "); |
14 | exitcode = ShellExecute("open", "/"@[email protected]/"", "@[email protected] /"@[email protected]/" -o /"@[email protected]/"", "", 2); |
15 | //PS Do not REMOVE the following statement that seem no use , or will cause Reload Problem. |
16 | exitcode = RunCmdLine("cmd /c echo /"Reflushing .../"; cmd /c exit",".",true); |
17 | |
18 | RunCmd("Reload File"); |
19 | RunCmd("Reload Modified Files"); |
20 | RunCmd("Parse File Now"); |
21 | } |
22 | } |
23 | |
24 | macro CheckExtension(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 | return True |
39 | else |
40 | return False |
41 | } |
42 |
NetEyeutils.em
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
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, "" )
lastBuf = cat( spaceBuf, "" )
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 @[email protected] on @[email protected]@[email protected]@[email protected] @[email protected]:@[email protected] " )
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 ){
//modified on 2003.12.10
tmpFirstText = cat( tmpFirstText, "" )
DelBufLine( hbuf, lnFirst )
InsBufLine( hbuf, lnFirst, newFirstText )
}else{
tmpFirstText = cat( tmpFirstText, "" )
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 )
}
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, "
lnStartPos = ln + 2;
if (strlen(szMyName) > 0){
InsBufLine( hbuf, ln + 1, "")
InsBufLine( hbuf, ln + 1, " */" )
// put the insertion point inside the header comment
SetBufIns( hbuf, lnStartPos, 20 )
CloseBuf( hSysBuf )
}
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, 1, " * FileName: " )
InsBufLine( hbuf, 2, " * Author: @[email protected] Version: @[email protected] Date: @[email protected]@[email protected]@[email protected]" )
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 | |
2 | |
3 | |
4 | |
5 | |
14 | macro InsertHeader() |
15 | { |
16 | // Get the owner's name from the environment variable: MYNAME. |
17 | // If the variable doesn't exist, then the owner field is skipped. |
18 | szMyName = getenv(MYNAME) |
19 | |
20 | // Get a handle to the current file buffer and the name |
21 | // and location of the current symbol where the cursor is. |
22 | hbuf = GetCurrentBuf() |
23 | szFunc = GetCurSymbol() |
24 | ln = GetSymbolLine(szFunc) |
25 | |
26 | // begin assembling the title string |
27 | sz = " |
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, " |
49 | if (strlen(szMyName) > 0) |
50 | { |
51 | InsBufLine(hbuf, ln+2, " Owner: @[email protected]") |
52 | InsBufLine(hbuf, ln+3, " ") |
53 | ln = ln + 4 |
54 | } |
55 | else |
56 | ln = ln + 2 |
57 | |
58 | InsBufLine(hbuf, ln, " ") // provide an indent already |
59 | InsBufLine(hbuf, ln+1, "-------------------------------------------------------------------------*/") |
60 | |
61 | // put the insertion point inside the header comment |
62 | SetBufIns(hbuf, ln, 4) |
63 | } |
64 | |
65 | |
66 | |
74 | |
75 | macro InsertFileHeader() |
76 | { |
77 | szMyName = getenv(MYNAME) |
78 | |
79 | hbuf = GetCurrentBuf() |
80 | |
81 | InsBufLine(hbuf, 0, " |
84 | InsBufLine(hbuf, 1, " ") |
85 | if (strlen(szMyName) > 0) |
86 | { |
87 | sz = " Owner: @[email protected]" |
88 | InsBufLine(hbuf, 2, " ") |
89 | InsBufLine(hbuf, 3, sz) |
90 | ln = 4 |
91 | } |
92 | else |
93 | ln = 2 |
94 | |
95 | InsBufLine(hbuf, ln, "-------------------------------------------------------------------------*/") |
96 | } |
97 | |
98 | |
99 | |
100 | // Inserts "Returns True .. or False..." at the current line |
101 | macro ReturnTrueOrFalse() |
102 | { |
103 | hbuf = GetCurrentBuf() |
104 | ln = GetBufLineCur(hbuf) |
105 | |
106 | InsBufLine(hbuf, ln, " Returns True if successful or False if errors.") |
107 | } |
108 | |
109 | |
110 | |
111 | |
112 | macro IfdefReview() |
113 | { |
114 | IfdefSz("REVIEW"); |
115 | } |
116 | |
117 | |
118 | |
119 | macro IfdefBogus() |
120 | { |
121 | IfdefSz("BOGUS"); |
122 | } |
123 | |
124 | |
125 | |
126 | macro IfdefNever() |
127 | { |
128 | IfdefSz("NEVER"); |
129 | } |
130 | |
131 | |
132 | // Ask user for ifdef condition and wrap it around current |
133 | // selection. |
134 | macro InsertIfdef() |
135 | { |
136 | // sz = Ask("Enter ifdef condition:") |
137 | hSysBuf = OpenBuf( "system.ini" ) |
138 | if( hSysBuf == hNil ){ |
139 | return 1 |
140 | } |
141 | |
142 | MyName = GetBufLine( hSysBuf, 0 ) |
143 | Version = GetBufLine( hSysBuf, 1 ) |
144 | sz = GetBufLine( hSysBuf, 2 ) |
145 | if (sz != "") |
146 | IfdefSz(sz); |
147 | } |
148 | |
149 | macro InsertCPlusPlus() |
150 | { |
151 | IfdefSz("__cplusplus"); |
152 | } |
153 | |
154 | |
155 | // Wrap ifdef .. endif around the current selection |
156 | macro IfdefSz(sz) |
157 | { |
158 | hwnd = GetCurrentWnd() |
159 | lnFirst = GetWndSelLnFirst(hwnd) |
160 | lnLast = GetWndSelLnLast(hwnd) |
161 | |
162 | hbuf = GetCurrentBuf() |
163 | InsBufLine(hbuf, lnFirst, "#ifdef @[email protected]") |
164 | InsBufLine(hbuf, lnLast+2, "#endif ") |
165 | } |
166 | |
167 | |
168 | // Delete the current line and appends it to the clipboard buffer |
169 | macro KillLine() |
170 | { |
171 | hbufCur = GetCurrentBuf(); |
172 | lnCur = GetBufLnCur(hbufCur) |
173 | hbufClip = GetBufHandle("Clipboard") |
174 | AppendBufLine(hbufClip, GetBufLine(hbufCur, lnCur)) |
175 | DelBufLine(hbufCur, lnCur) |
176 | } |
177 | |
178 | |
179 | // Paste lines killed with KillLine (clipboard is emptied) |
180 | macro PasteKillLine() |
181 | { |
182 | Paste |
183 | EmptyBuf(GetBufHandle("Clipboard")) |
184 | } |
185 | |
186 | |
187 | |
188 | // delete all lines in the buffer |
189 | macro EmptyBuf(hbuf) |
190 | { |
191 | lnMax = GetBufLineCount(hbuf) |
192 | while (lnMax > 0) |
193 | { |
194 | DelBufLine(hbuf, 0) |
195 | lnMax = lnMax - 1 |
196 | } |
197 | } |
198 | |
199 | |
200 | // Ask the user for a symbol name, then jump to its declaration |
201 | macro JumpAnywhere() |
202 | { |
203 | symbol = Ask("What declaration would you like to see?") |
204 | JumpToSymbolDef(symbol) |
205 | } |
206 | |
207 | |
208 | // list all siblings of a user specified symbol |
209 | // A sibling is any other symbol declared in the same file. |
210 | macro OutputSiblingSymbols() |
211 | { |
212 | symbol = Ask("What symbol would you like to list siblings for?") |
213 | hbuf = ListAllSiblings(symbol) |
214 | SetCurrentBuf(hbuf) |
215 | } |
216 | |
217 | |
218 | // Given a symbol name, open the file its declared in and |
219 | // create a new output buffer listing all of the symbols declared |
220 | // in that file. Returns the new buffer handle. |
221 | macro ListAllSiblings(symbol) |
222 | { |
223 | loc = GetSymbolLocation(symbol) |
224 | if (loc == "") |
225 | { |
226 | msg ("@[email protected] not found.") |
227 | stop |
228 | } |
229 | |
230 | hbufOutput = NewBuf("Results") |
231 | |
232 | hbuf = OpenBuf(loc.file) |
233 | if (hbuf == 0) |
234 | { |
235 | msg ("Can't open file.") |
236 | stop |
237 | } |
238 | |
239 | isymMax = GetBufSymCount(hbuf) |
240 | isym = 0; |
241 | while (isym < isymMax) |
242 | { |
243 | AppendBufLine(hbufOutput, GetBufSymName(hbuf, isym)) |
244 | isym = isym + 1 |
245 | } |
246 | |
247 | CloseBuf(hbuf) |
248 | |
249 | return hbufOutput |
250 | |
251 | } |
252 |