我使用的source insight 宏

 

在source insight打开Base工程,加入myutils.em文件。

文件myutils.em的内容: (下载地址:http://download.csdn.net/source/2729309)

 使用“Options” -- “Menu Assignments” 新建一个菜单项Work,然后把Macro:SetAuthorName, Macro:NewHeaderFileStruct, Macro:NewSrcFileStruct, Macro:InsertFileHeader, Macro:InsertFunctionHeader加入这个自定义的菜单里。


/* Utils.em - a small collection of useful editing macros */ macro SetAuthorName() { szAuthorName = Ask("Please Input Your Name:") szAuthorName = StrTrim(szAuthorName) SetReg(REG_AUTHOR_NAME, szAuthorName) } /*----------------------------------------------------------------------------- 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 InsertFunctionHeader() { // 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() nLine = GetSymbolLine(szFunc) szMyName = GetReg(REG_AUTHOR_NAME) szDate = GetCurDate() InsBufLine(hbuf, nLine, " ") InsBufLine(hbuf, nLine + 1, "/******************************************************************************") InsBufLine(hbuf, nLine + 2, " Function: @szFunc@") InsBufLine(hbuf, nLine + 3, " Description: ") InsBufLine(hbuf, nLine + 4, " INPUT: ") InsBufLine(hbuf, nLine + 5, " OUTPUT: ") InsBufLine(hbuf, nLine + 6, " Return: ") InsBufLine(hbuf, nLine + 7, " Revision: ") InsBufLine(hbuf, nLine + 8, " 1. Author: @szMyName@") InsBufLine(hbuf, nLine + 9, " Date: @szDate@") InsBufLine(hbuf, nLine + 10, " Changes: First create ") InsBufLine(hbuf, nLine + 11, " ******************************************************************************/") // put the insertion point inside the header comment SetBufIns(hbuf, nLine, 12) } macro InsertMaintenanceComment() { // Get a handle to the current file buffer and the name // and location of the current symbol where the cursor is. hbuf = GetCurrentBuf() nLine = GetBufLnCur(hbuf) szCurLine = GetBufLine(hbuf, nLine) szMyName = GetReg(REG_AUTHOR_NAME) szDate = GetCurDate() if (IsBlankLine(szCurLine)) { szBlank = szCurLine } else { szBlank = GetBlankString(szCurLine) InsBufLine(hbuf, nLine + 1, szBlank) nLine = nLine + 1 } InsBufLine(hbuf, nLine + 1, "@szBlank@/*Sart: ID: SVN: ,@szMyName@ @szDate@ */") InsBufLine(hbuf, nLine + 2, szBlank) InsBufLine(hbuf, nLine + 3, "@szBlank@/*End : ID: SVN: ,@szMyName@ @szDate@ */") } /* 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() { hbuf = GetCurrentBuf() szFilePath = GetBufName(hbuf) szFileName = GetFileNameFromPath(szFilePath) szMyName = GetReg(REG_AUTHOR_NAME) szDate = GetCurDate() InsBufLine(hbuf, 0, " ") InsBufLine(hbuf, 1, "/******************************************************************************") InsBufLine(hbuf, 2, " Copyright (c), 1991-2007, My Company.") InsBufLine(hbuf, 3, " ") InsBufLine(hbuf, 4, " File: @szFileName@") InsBufLine(hbuf, 5, " Description: ") InsBufLine(hbuf, 6, " Function List: //List main functions") InsBufLine(hbuf, 7, " Revision:") InsBufLine(hbuf, 8, " 1. Author: @szMyName@") InsBufLine(hbuf, 9, " Date: @szDate@") InsBufLine(hbuf, 10, " Changes: First create file") InsBufLine(hbuf, 11, " ******************************************************************************/") return 12 /* line number of inserted */ } macro NewHeaderFileStruct() { hbuf = GetCurrentBuf() szFilePath = GetBufName(hbuf) szFileName = GetFileNameFromPath(szFilePath) szFileMainName = GetFileMainName(szFileName) szFileExtName = GetFileExtName(szFileName) szFileMainName = toupper(szFileMainName) szFileExtName = toupper(szFileExtName) InsBlankLine(hbuf, 0, 2) InsBufLine(hbuf, 0, "#endif /* __@szFileMainName@_@szFileExtName@__ */") InsBlankLine(hbuf, 0, 2) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * END * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 10) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * FUNCTION * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 10) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * STRUCT * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 10) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * ENUM * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 10) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * MACRO * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 2) InsBufLine(hbuf, 0, "#define __@szFileMainName@_@szFileExtName@__") InsBufLine(hbuf, 0, "#ifndef __@szFileMainName@_@szFileExtName@__") InsBlankLine(hbuf, 0, 2) InsertFileHeader() } macro NewSrcFileStruct() { hbuf = GetCurrentBuf() szFilePath = GetBufName(hbuf) szFileName = GetFileNameFromPath(szFilePath) szFileMainName = GetFileMainName(szFileName) szFileExtName = GetFileExtName(szFileName) szFileMainName = toupper(szFileMainName) szFileExtName = toupper(szFileExtName) InsBlankLine(hbuf, 0, 2) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * END * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 10) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * FUNCTION * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 10) InsBufLine(hbuf, 0, " ******************************************************************************/") InsBufLine(hbuf, 0, " * GLOBAL * ") InsBufLine(hbuf, 0, "/****************************************************************************** ") InsBlankLine(hbuf, 0, 4) InsertFileHeader() } macro GetCurDate() { stCurTime = GetSysTime(1) szDate = cat(stCurTime.Year, "-") szDate = cat(szDate, stCurTime.Month) szDate = cat(szDate, "-") szDate = cat(szDate, stCurTime.Day) return szDate } macro StrTrim(szSrc) { szDst = StrTrimLeft(szSrc) szDst = StrTrimRight(szDst) return szDst } macro StrTrimLeft(szSrc) { len = strlen(szSrc) i = 0 while (i < len) { if (" " != szSrc[i] && "/t" != szSrc[i]) { szDst = strmid(szSrc, i, len) return szDst } i = i + 1 } return "" } macro StrTrimRight(szSrc) { len = strlen(szSrc) i = len - 1 while (i >= 0) { if (" " != szSrc[i] && "/t" != szSrc[i]) { szDst = strmid(szSrc, 0, i + 1) return szDst } i = i - 1 } return "" } macro GetFileNameFromPath(path) { namelen = strlen(path) i = namelen while (i > 0) { if ("//" == path[i]) { break; } i = i -1 } if (i <= 0) { return path } j = namelen - i file = strmid(path, i + 1, namelen) return file } macro GetFileMainName(fileName) { namelen = strlen(fileName) i = namelen while (i > 0) { if ("." == fileName[i]) { break; } i = i -1 } if (i <= 0) { return fileName } file = strmid(fileName, 0, i) return file } macro GetFileExtName(fileName) { namelen = strlen(fileName) i = namelen while (i > 0) { if ("." == fileName[i]) { break; } i = i -1 } file = strmid(fileName, i + 1, namelen) return file } macro InsBlankLine(hbuf, startLine, lineCount) { i = lineCount while (i > 0) { InsBufLine(hbuf, startLine, "") i = i -1 } } macro IsBlankLine(szLine) { len = strlen(szLine) i = 0 while (i < len) { if (" " != szLine[i] && "/t" != szLine[i]) return False i = i + 1 } return True } macro GetBlankString(szLine) { len = strlen(szLine) i = 0 while (i < len) { if (" " != szLine[i] && "/t" != szLine[i]) { szBlank = strmid(szLine, 0, i) return szBlank } i = i + 1 } return szLine } // 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 } macro SuperBackspace() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) stop; // empty buffer // get current cursor postion ipos = GetWndSelIchFirst(hwnd); // get current line number ln = GetBufLnCur(hbuf); if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) { // sth. was selected, del selection SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight :( // del the " " SuperBackspace(1); stop; } // copy current line text = GetBufLine(hbuf, ln); // get string length len = strlen(text); // if the cursor is at the start of line, combine with prev line if (ipos == 0 || len == 0) { if (ln <= 0) stop; // top of file ln = ln - 1; // do not use "ln--" for compatibility with older versions prevline = GetBufLine(hbuf, ln); prevlen = strlen(prevline); // combine two lines text = cat(prevline, text); // del two lines DelBufLine(hbuf, ln); DelBufLine(hbuf, ln); // insert the combined one InsBufLine(hbuf, ln, text); // set the cursor position SetBufIns(hbuf, ln, prevlen); stop; } num = 1; // del one char if (ipos >= 1) { // process Chinese character i = ipos; count = 0; while (AsciiFromChar(text[i - 1]) >= 160) { i = i - 1; count = count + 1; if (i == 0) break; } if (count > 0) { // I think it might be a two-byte character num = 2; // This idiot does not support mod and bitwise operators if ((count / 2 * 2 != count) && (ipos < len)) ipos = ipos + 1; // adjust cursor position } } // keeping safe if (ipos - num < 0) num = ipos; // del char(s) text = cat(strmid(text, 0, ipos - num), strmid(text, ipos, len)); DelBufLine(hbuf, ln); InsBufLine(hbuf, ln, text); SetBufIns(hbuf, ln, ipos - num); stop; } macro AddStruct() { hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) var szTypeName szTypeName = Ask("请输入结构名称:") szTypeName = toupper(szTypeName) InsBufLine(hbuf, ln, "typedef struct tag_@szTypeName@") ln = ln + 1 InsBufLine(hbuf, ln, "{") ln = ln + 1 InsBufLine(hbuf, ln, " ") ln = ln + 1 InsBufLine(hbuf, ln, "} @szTypeName@;") ln = ln + 1 } /*=========================================================================*/ /* Function: UniformCommentStyle */ /* Description: Change all // to /* */ */ /*=========================================================================*/ macro UniformCommentStyle() { var hbuf hbuf = GetCurrentBuf () // current file var dwTotalLine dwTotalLine = GetBufLineCount(hbuf) var dwLine dwLine = 0 while (dwLine < dwTotalLine) { var szLine szLine = GetBufLine(hbuf, dwLine) var nLineLen var nPos nLineLen = strlen(szLine) nPos = 0 while (nPos < nLineLen) { if (nPos > 0) { if (szLine[nPos] == "/" && szLine[nPos - 1] == "/") { szLine[nPos] = "*" szLine = Cat(szLine, "*/") PutBufLine (hbuf, dwLine, szLine) break; } } nPos = nPos+1; } dwLine = dwLine + 1; } } /*=========================================================================*/ /* Function: AddCodeGroup */ /* Description: Add {} and auto indent */ /*=========================================================================*/ macro AddCodeGroup() { hbuf = GetCurrentBuf() ln = GetBufLnCur(hbuf) + 1 szText = GetBufLine (hBuf, ln-1) nIndent = 0; nSpace = 0; while (nIndent < strlen(szText)) { if (szText[nIndent] == " ") { nIndent = nIndent + 1; nSpace = nSpace + 1; } else if (szText[nIndent] == " ") { nIndent = nIndent + 1; nSpace = nSpace + 4; } else break; } szDate = GetCurDate() szSpace = "" nIndent = 0; while (nIndent < nSpace) { szSpace = Cat(szSpace, " "); nIndent = nIndent + 1; } szBrace = Cat(szSpace, "{"); InsBufLine(hbuf, ln, szBrace) ln = ln + 1 szBrace = Cat(szSpace, " "); InsBufLine(hbuf, ln, szBrace) ln = ln + 1 szBrace = Cat(szSpace, "}"); InsBufLine(hbuf, ln, szBrace) ln = ln - 1; SetBufIns(hbuf, ln, nSpace + 4) }

 

 

 

你可能感兴趣的:(function,File,header,buffer,Path,character)