Sunirvana 标签: Source Insight中一些好用宏的使用

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


macro indent()

    {

        execIndent = "C://Program Files//GnuWin32//bin//indent.exe";

    sPara = " -br";

        //sPara =  " -kr";  

        //sPara =  " --no -tabs -i3 -bl -nce -bls -bli0 --line  -length120  -kr";


        hbuf = GetCurrentBuf();

        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 = /"@execIndent@/" @sPara@ /"@sFile@/" ");

14 

           exitcode = ShellExecute("open", "/"@execIndent@/"", "@sPara@ /"@sFile@/" -o /"@sFile@/"", "", 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

/* 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


/* Utils.em - a small collection of useful editing macros */




/*-------------------------------------------------------------------------

    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.

10 


11 

    To use this, define an environment variable "MYNAME" and set it

12 

    to your email name.  eg. set MYNAME=raygr

13 

-------------------------------------------------------------------------*/

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 = "/*   "

28 


29 

    /* convert symbol name to T E X T   L I K E   T H I S */

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 

    /* if owner variable exists, insert Owner: name */

49 

    if (strlen(szMyName) > 0)

50 

        {

51 

        InsBufLine(hbuf, ln+2, "    Owner: @szMyName@")

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 

/* InsertFileHeader:

67 


68 

   Inserts a comment header block at the top of the current function. 

69 

   This actually works on any type of symbol, not just functions.

70 


71 

   To use this, define an environment variable "MYNAME" and set it

72 

   to your email name.  eg. set MYNAME=raygr

73 

*/

74 


75 

macro InsertFileHeader()

76 

{

77 

    szMyName = getenv(MYNAME)

78 


79 

    hbuf = GetCurrentBuf()

80 


81 

    InsBufLine(hbuf, 0, "/*-------------------------------------------------------------------------")

82 


83 

    /* if owner variable exists, insert Owner: name */

84 

    InsBufLine(hbuf, 1, "    ")

85 

    if (strlen(szMyName) > 0)

86 

        {

87 

        sz = "    Owner: @szMyName@"

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 

/* Inserts ifdef REVIEW around the selection */

112 

macro IfdefReview()

113 

{

114 

    IfdefSz("REVIEW");

115 

}

116 


117 


118 

/* Inserts ifdef BOGUS around the selection */

119 

macro IfdefBogus()

120 

{

121 

    IfdefSz("BOGUS");

122 

}

123 


124 


125 

/* Inserts ifdef NEVER around the selection */

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 @sz@")

164 

    InsBufLine(hbuf, lnLast+2, "#endif /* @sz@ */")

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 ("@symbol@ 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