Source insight 宏的使用

轉載地址:http://mitianshenyu.blog.163.com/blog/static/137539022201132114957890/

在Source Insight中添加自定義功能的步驟如下:
1.Source Insight中,Options->Custom Commands...->Add...,New Command name 隨便寫,我的是"Edit with Vim"
2.Run中寫入: "C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f
意思是在當前已經打開的gvim窗口裏面打開當前的文件,並且跳轉到指定行
%l爲當前的行號,%f爲文件名
使用 --remote-silent 的作用是,如果已經打開了對應文件,就不會打開第二次,而是在已經打開的文件裏跳轉到對應行
3.還是同一個對話框裏面,選擇Keys->Assign New Key...->按F12,如果你已經將F12設置給其他命令,選擇其他的按鍵就行了

下面是一些常用自定義功能:( CUSTOM COMMANDS )

打開資源管理器並選中當前文件
ShellExecute open explorer /e,/select,%f
查看log
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:log /path:%f /notempfile /closeonend
diff
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:diff /path:%f /notempfile /closeonend
取得鎖定(check out)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:lock /path:%f /notempfile /closeonend
提交(check in)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:commit /path:%f /notempfile /closeonend
更新(update)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:%f /notempfile /closeonend
更新整個目錄(update all)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:update /path:*.* /notempfile /closeonend
取消鎖定(undo check out)
"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:revert /path:%f /notempfile /closeonend
在ultriEdit中編輯
"C:\Program Files\UltraEdit-32/uedit32" %f
在vim中編輯並定位到當前行
"C:\Program Files\Vim\vim63\gvim.exe" --remote-silent +%l %f

彙總其他小技巧:

讓{ 和 } 不縮進:

Options->Document Options->Auto Indent->Indent Open Brace/Indent Close Brace

hao space: SourceInsight 小技巧
1、按住"ctrl", 再用鼠標指向某個變量,點擊一下,就能進入這個變量的定義。

2、今天把一個用sourceinsight排版整齊的C文件,偶然用VC打開一看,全亂了。研究了半天,發現SI對每個字符的寬度不太一致。
    請教同事發現選上"view --> draft view", 就可以讓每個字符的寬度一致了。快捷鍵是 "Alt + F12"

3、"shift+F8" 標亮所有文本中光標所在位置的單詞

4、跳到某一行:"ctrl + g"

Source Insight是閱讀和編寫代碼的好東東,基本上也算得上是經典之作了,雖然還有一點點小bug,不過對於我們這些C程序員來說可是一旦擁有別無所求。下列小技巧是在工作中同事整理總結的,對提高工作效率多少有點幫助,其中有些是對應於SVN的,沒有使用SVN做版本管理的人就不要白費力氣了。

ShellExecute open explorer /e,/select,%f
        /*作用是在資源管理器中打開當前編輯文件並選中*/
        /*可以設置快捷鍵如ctrl+e,這樣能很方便的在資源管理器打開對應的文件,並進行tortoiseSVN的相關操作*/

X:\Progra~1\TortoiseSVN\bin\TortoiseProc.exe /command:log /path:% /notempfile /closeonend
        /*使用前注意更改對應的bin安裝路徑*/
        /*作用是直接查看當前文件的svn log*/
        /*可以設置快捷鍵如ctrl+l*/

X:\Progra~1\TortoiseSVN\bin\TortoiseProc.exe /command:diff /path:% /notempfile /closeonend
        /*使用前注意更改對應的bin安裝路徑*/
        /*作用是直接查看當前文件和基準版本的比較*/
        /*可以設置快捷鍵如ctrl+d*/

在Source Insight中快速添加註釋
      將以下代碼保存成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.

    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 string
    sz = "/*   "
   
    /* convert symbol name to T E X T   L I K E   T H I S */
    cch = strlen(szFunc)
    ich = 0
    while (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 already
    InsBufLine(hbuf, ln+1, "-------------------------------------------------------------------------*/")
   
    // put the insertion point inside the header comment
    SetBufIns(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 <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

}

/*

    written by yubind

                                                            */

macro SingleLineComment()
{
szMyName = "chenjsa"
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)

// Get current time
szTime = GetSysTime(1)
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
  szDay = "0@Day@"
else
  szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
  szMonth = Month

szDescription = Ask("請輸入修改原因")
// begin assembling the title string
InsBufLine(hbuf, ln+1, "/*@szDescription@ @[email protected] @Year@-@szMonth@-@szDay@*/")
}

macro MultiLineCommentHeader()
{
szMyName = "chenjsa"
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)

// Get current time
szTime = GetSysTime(1)
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
  szDay = "0@Day@"
else
  szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
  szMonth = Month

szDescription = Ask("請輸入修改原因:")
// begin assembling the title string
InsBufLine(hbuf, ln + 1, "/*@szDescription@ @[email protected] @Year@-@szMonth@-@szDay@ begin*/")
}

macro MultiLineCommentEnd()
{
szMyName = "chenjsa"
// Get a handle to the current file buffer and the name
// and location of the current symbol where the cursor is.
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)

// Get current time
szTime = GetSysTime(1)
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
  szDay = "0@Day@"
else
  szDay = Day
//szMonth = NumToName(Month)
if (Month < 10)
     szMonth = "0@Month@"
else
  szMonth = Month

InsBufLine(hbuf, ln + 1, /*@[email protected] @Year@-@szMonth@-@szDay@ end*/)
}


使用說明:可以實現在sourceinsight中快速添加修改註釋。

    1. Project->Open Project... 打開Base工程(該工程一般在我的文檔\\Source Insight\\Projects\\Base中);
    2. 搜索utils.em 裏的字串"chenjsa" 改成自己的姓名
    3. Project->Add and Remove Project Files... 加入宏文件(即utils.em);
    4. Options->Menu Assignments 打開Menu Assignments窗口, 在Command中輸入Macro, 選中要使用的宏(SingleLineComment ,MultiLineCommentHeader,MultiLineCommentEnd), 添加到合適的菜單中.



配置成簡單好用的c/java代碼編輯器

1、縮進與tab

1Options菜單àPreferencesàTyping卡,勾掉下面兩項∶

Typing tab indents lineregardless of selection,空行按tab無法前進

Typing tab replaces current selection,選定部分內容、再按tab時會清除所選

2Options菜單àDocument Options(針對不同文件類型,分別進行設置)à下拉左上文件類型框、選擇合適類型(c源文件)àEditing Options框中,tab width=2à Editing Options框中,勾選Expand tabs(這樣,按tab鍵、等價於輸入2個空格)

3Options菜單àDocument Optionsà選擇合適的文件類型à點擊右邊中間的Auto Indentà在彈出的框中,左邊一定要點Smart,右邊有兩個複選框Indent Open BraceIndent Close Brace,具體效果可以看SISHELP。按照部門裏的編程風格要求,最方便的就是把兩個複選框都取消掉,然後點OK

勾選Auto IndentSMART的效果∶在C程序裏, 如果遇到行末沒有分號的語句,IF, WHILE, SWITCH, 寫到該行末按回車,則新行自動相對上一行縮進兩列。

勾掉Indent Open BraceIndent Close Brace的效果∶繼上一段,在相對縮進行裏, 如果輸入"}", 則自動和上一行列對齊(好像勾不勾都會有這個功能);而輸入"{"時,不會與下面的行對齊(這是勾上Indent Open Brace時的效果)。

2、向項目中添加文件時,只添加特定類型的文件(文件類型過濾器)

有個同事比較生猛,得整彙編代碼,但在SIS裏建立PROJECTADD TREE的時候,根據默認設置並不會把該TREE裏面所有彙編文件都包含進來,只加了.inc.asm後綴的,.s後綴的沒有。而且用SIS打開.s的文件,一片黑白沒有色彩,感覺回到DOSEDIT時代了…… 解決方法是在Options->Document Options裏面,點左上的Document Type下拉菜單,選擇x86 Asm Source File,然後在右邊的File filter*.asm*.inc的後面加上*.s;接着CLOSE就可以了。上面兩個問題解決了,但注意加入*.s後還需要重新ADD TREE一遍才能把這些彙編加到PROJECT裏面。

3、去掉功能強大但是無用的自動完成功能

Options菜單àPreferences àTypingàAuto Completion框,勾掉Use automatic symbol completion window(這裏是SIS的全局設置)

Options菜單àDocument OptionsàEditing Options框中,勾掉Allow auto-complete(局部設置)

上面兩項必須全部勾選,才能啓用Auto Completion功能

4、恢復小鍵盤的“+-*/”功能

Options菜單àKey assignments,通過關鍵詞Scroll 找到Scroll Half Page Up,取消小鍵盤/;通過關鍵詞Scroll 找到Scroll Half Page Down取消小鍵盤*;通過關鍵詞Function找到Function Up,取消小鍵盤-,通過關鍵詞Function找到Function down,取消小鍵盤+

5、恢復ctrl+a的全選功能

通過關鍵詞save 找到save all,更改爲ctrl+shift+a,通過關鍵詞select找到select all 更改爲ctrl +a

6、解決字符等寬對齊問題。

SIS默認字體是VERDANA,很漂亮。這網頁上應該也是用的VERDANA字體。但由於美觀的緣故,VERDANA字體是不等寬的。比如下面兩行

llllllllll

MMMMMMMMMM

同樣10個字符,長度差多了.VERDANA來看程序,有些本應該對齊的就歪了。解放方法是使用等寬的字體,但肯定比較醜。可以用DOS字體,也就是記事本里的默認字體sysfixed 很醜,要有心理準備。比較推薦的是用Courier New

SourceInsight提供的功能

1、解析日誌信息時非常有用的Source Link

總地說來,SourceLink根據特定的搜索模式,把當前文件中滿足模式的行、鏈接到由該行指定的其他源文件中。

所謂特定的搜索模式,共有兩種“File, then line”和“Line, then file”,其中前後兩部分依靠正則表達式的組的概念來予以分割。如果當前文件具有匹配行,比如“Error d:tcsrcq5.c 18: Lvalue required in function jsSort”,那麼SourceInsight在該行創建SourceLink、把該行鏈接到由該行指定的文件中(即d:tcsrcq5.c,第18行)。

1.1 創建SourceLink

運行Search菜單的Parse Source Links…命令,在彈出的框中、選擇搜索模式、並填入相應的正則表達式串,點OKSIS就會解析當前文件,如果有匹配,就創建SourceLink

1.2 在解析日誌信息時,使用SourceLink

可以打開日誌信息,運行Parse Source Links命令,日誌中能夠匹配模式的每一行(通常是含有錯誤信息的行)、就會被設置上一個SourceLink

1.3在解析自定義命令輸出時,使用SourceLink

首先勾選Custom Command 中的“Parse Links in Output”,然後選擇特定的搜索模式,最後填入合適的正則表達式。這樣,Source Insight把輸出信息作爲當前搜索用文件;並且,如果有匹配行(通常即編譯錯誤信息行),SIS 該行創建SourceLink、並把每一個錯誤信息中給定的文件(和行號)作爲link目的地,這對於我們修改源代碼錯誤非常有幫助。

2、替換(Replace VS 上下文敏感的智能重命名(Context-Sensitive Smart Rename

2.1 替換(Replace

目前來說,普通的替換命令、快捷鍵爲ctrl+H,足以已滿足工作要求。

在彈出的替換窗口中,在Search框中勾選Selection來只在所選文本區域中替換(當然這時你要先選定區域然後再按ctrl+H)、勾選WholeFile來在整個當前文件內替換、兩者都不勾選來從當前光標處替換至文件末尾;點右邊的Files…按鈕,可選擇替換多個文件的內容。

2.2上下文敏感的智能重命名(Context-Sensitive Smart Rename

Smart Rename命令、快捷鍵是Ctrl+’,是上下文敏感的全局搜索替換。它可以智能地重命名全部項目文件中的一個標示符。SourceInsight的搜索索引(search index)使得搜索過程進行地非常快。而且,使用Smart Rename所做的替換會被記錄在Search Results窗口中,每一條替換記錄旁有一個SourceLink鏈接到替換發生地文件。

Smart Rename可以用來重命名標記(symbol)。如果勾選了Smart Reference Matching選項,Smart Rename就只在正確的上下文範圍內進行重命名。它可以智能地重命名全部項目文件中的一個標示符;它可以重命名函數本地變量,類或結構體成員、函數。

在彈出的Smart Rename窗口中有下面幾項∶

Old Name 填舊名稱。光標下的詞會被自動加載;光標的位置非常重要,這是因爲Source Insight會根據本地上下文背景、準確地確定你想要重命名哪一個標記。

推薦只填單個詞、而不是字符串。

如果你在命名成員變量、或本地變量(),Old Name框中會顯示完全標記名、即上層容器名+標記名。例如,框中的“DocDraw.paintStruc”代表DocDraw是函數名,paintStruc是函數的本地成員變量。

New Name 填新名稱。只填標記名,不填上層容器名。

Output Search Results 如果勾選,搜索替換結果日誌會被輸出到Search Results窗口中。可以通過Windows菜單來切換,或ctrl+tab切換察看。並且每一條記錄旁會有SourceLink鏈接到替換發生地文件。

Confirm Each Replacement 每次替換詢問。

Skip Comments 不重名註釋部分。

【使用心得列表】

(1)如何用Smart Rename重命名數組的數組名?如果只選取數組名,會報錯!

(2)如果勾掉Smart Reference Matching,會搜索全部項目文件,並且Old Name框中不顯示完全限定名;如果勾選Smart Reference Matching,無法重命名數組名,而且鼠標位置不正確時會報錯。應該如何應對?

3、在SourceInsight中提供的正則表達式

3.1SourceInsight中提供的正則表達式

正則表達式,是用來匹配複雜模式的特殊搜索用字符串。正則表達式串中,許多字符具有特殊的含義。例如,有個特殊的字符代表 行首

下面是SourceInsight提供的所有可用特殊字符∶

Table 4.3: Regular Expression Characters

Character

Matches

^ (at the beginning only)

beginning of line。如^Hello,匹配Hello在句首。

.

any single character

[abc]

any single character that belongs to the set abc

[^abc]

any single character that does not belong to the set abc

*

zero or more occurrences of the preceding character

+

one or more occurrences of the preceding character

t

a tab character

s

a space character

w

white space (a tab or a space character)

$

the end of the line。如TRUE$,匹配TRUE在句尾。

轉義字符。如果在它後面有元字符,取消其特殊含義。

可利用 “(” “)”、把正則表達式分割成不同的;模式中的每個組自左向右指定爲 Group #nn=1,2,…組的概念在替換時很有用。

例如∶

abc(xyz)可匹配abcxyz,其中xyz被認爲是group#1

利用21來替換(abc)(xyz),替換結果爲xyzabc

3.2 正則表達式在配置tc編譯器中的應用∶

正則表達式格式與源代碼文件路徑相對應,這裏我的tc安裝目錄爲d:tctc源文件放在d:tcsrc下,並命名爲qn.cqtn.c(其中n=1,2,…)。

觀察Tc編譯器某一次輸出錯誤信息的格式∶

Error d:tcsrcq5.c 18: Lvalue required in function jsSort

則我們要匹配“d:tcsrcq5.c 18”部分,進一步地,按照SourceInsight捕捉輸出並加以解析時的要求,要以組的形式、分別匹配“d:tcsrcq5.c 18”中的文件部分和行號部分∶

行號([1-9][0-9]*)

空格行號s([1-9][0-9]*)

文件名(d:tcsrc[qQ][tT][1-9][0-9]*.[cC])

全部加起來爲∶

(d:tcsrc[qQ][tT]*[1-9][0-9]*.[cC])s([1-9][0-9]*)

3.3 正則表達式在配置javac編譯器中的應用∶

我的JAVA_HOMEc:jdk,我的java源文件放於d:javasrc中,並命名爲qn.javaqtn.java(其中n=1,2,…)。

觀察JDK編譯器某一次輸出錯誤信息的格式∶

D:javasrcQ3.java:3: ';' expected

正則表達式爲∶

([dD]:javasrc[qQ][tT]*[1-9][0-9]*.java):([1-9][0-9]*)

4、自定義命令

自定義命令與項目相關,在一個項目中定義的所有自定義命令屬於該項目、只對該項目有效(包括快捷鍵等)。

自定義命令類似於命令行批處理文件。SIS允許自定義命令在後臺運行;並可以捕捉自定義命令的輸出、放置於文件中、或粘貼入當前光標插入點。

分別利用上面SIS對輸出信息的處理方式,自定義命令對集成編譯器相當有用,可以捕捉編譯器輸出並創建SourceLink尋錯;自定義命令對於文本過濾也相當有用,可選中待過濾區塊、運行Sort自定義命令、粘貼回選定區塊、即完成文本過濾。

請按下面步驟創建自定義命令∶

Options菜單àCustom Command

à點右邊Add鈕、填入新自定義命令名稱,或下拉左邊Commands、選擇命令進行修改

àRun框、填入待執行命令行,可含有特殊元字符,見後面的元字符表

àDir框、執行命令行時應處的目錄,如不填,以源代碼文件所在目錄爲命令執行目錄

à勾選Output框的Capture Output、輸出被捕捉,如果勾選Paste Output,輸出被粘貼

à勾選Control Group框中的Save Files FirstSIS會在運行命令前先檢查文件是否保存

à勾選Control Group框中的Pause When DoneSIS會在命令結束後暫停、方便檢查

à勾選Source Links in Output框中的Parse Source Links,?/p>

轉自:http://blog.csdn.net/Jupin/archive/2005/02/04/281020.aspx

說明:
    該宏文件實現一些編碼程中能會到的功能, 如添加文件頭、函數說明和宏定義等, 使用時能自動添加文件名、函數名和當前日期.

使用說明:
    1. Project->Open Project... 打開Base工程(該工程一般在"我的文檔\Source Insight\Projects\Base"中);
    2. Project->Add and Remove Project Files... 加入宏文件(即Gaoke.em);
    3. Options->Menu Assignments 打開Menu Assignments窗口, 在Command中輸入Macro, 選中要使用的宏, 添加到合適的菜單中.

/*附上宏定義文件*/
/* t357.em - a small collection of useful editing macros */


/******************************************************************************
* InsFileHeader -- insert the information of file
*
* modification history
* --------------------
* 01a, 23mar2003, added DESCRIPTION by t357
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
/*-------------------------------------------------------------------------
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 "szMyName" and set it
to your email name.  eg. set szMyName=raygr
-------------------------------------------------------------------------*/

macro InsFileHeader()
{

/*#########################################################
  #########################################################
  #######  Set szMyName variable to your name    ########
  #######  for example    szMyName = "t357"     ########
  #########################################################   
  #########################################################*/
szMyName = ""

// Get current time
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
  szDay = "
0@Day@"
else
  szDay = Day
szMonth = NumToName(Month)

hBuf = GetCurrentBuf()
szpathName = GetBufName(hBuf)
szfileName = GetFileName(szpathName)
nlength = StrLen(szfileName)
szInf = Ask("Enter the information of file:")
    szDescription = Ask("Enter the description of file:")

hbuf = GetCurrentBuf()
// begin assembling the title string
InsBufLine(hbuf, 0, "/******************************************************************************")
InsBufLine(hbuf, 1, " * @szfileName@ - @szInf@")
InsBufLine(hbuf, 2, " * ")
InsBufLine(hbuf, 3, " * Copyright 1998-2003 Guangzhou Gaoke Communication Technology Co.,Ltd.")
InsBufLine(hbuf, 4, " * ")
InsBufLine(hbuf, 5, " * DESCRIPTION: - ")
InsBufLine(hbuf, 6, " *     @szDescription@")
InsBufLine(hbuf, 7, " * modification history")
InsBufLine(hbuf, 8, " * --------------------")
InsBufLine(hbuf, 9, " * 01a, @szDay@@szMonth@@Year@, @szMyName@ written")
InsBufLine(hbuf, 10, " * --------------------")
InsBufLine(hbuf, 11, " ******************************************************************************/")

// put the insertion point inside the header comment
SetBufIns(hbuf, 1, nlength + strlen(szInf) + 8)
}

/******************************************************************************
* InsFunHeader -- insert function's information
*
* modification history
* --------------------
* 01a, 23mar2003, added DESCRIPTION by t357
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro InsFunHeader()
{
// Get the owner's name from the environment variable: szMyName.
// If the variable doesn't exist, then the owner field is skipped.

/*#########################################################
  #########################################################
  #######  Set szMyName variable to your name    ########
  #######  for example    szMyName = "t357"     ########
  #########################################################   
  #########################################################*/
szMyName = ""

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

// Get current time
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
  szDay = "
0@Day@"
else
  szDay = Day
szMonth = NumToName(Month)
szInf = Ask("Enter the information of function:")
szDescription = Ask("Enter the description of function:")

// begin assembling the title string
sz = "/******************************************************************************"
InsBufLine(hbuf, ln, sz)
InsBufLine(hbuf, ln + 1, " * @szFunc@ - @szInf@")
InsBufLine(hbuf, ln + 2, " * DESCRIPTION: - ")
    InsBufLine(hbuf, ln + 3, " *    @szDescription@ ")
// remove by t357.    CutWord(szDescription)
InsBufLine(hbuf, ln + 4, " * Input: ")
InsBufLine(hbuf, ln + 5, " * Output: ")
InsBufLine(hbuf, ln + 6, " * Returns: ")
InsBufLine(hbuf, ln + 7, " * ")
InsBufLine(hbuf, ln + 8, " * modification history")
InsBufLine(hbuf, ln + 9, " * --------------------")
InsBufLine(hbuf, ln + 10, " * 01a, @szDay@@szMonth@@Year@, @szMyName@ written")
InsBufLine(hbuf, ln + 11, " * --------------------")
InsBufLine(hbuf, ln + 12, " ******************************************************************************/")

// put the insertion point inside the header comment
SetBufIns(hbuf, ln + 1, strlen(szFunc) + strlen(szInf) + 8)
}


/******************************************************************************
* NumToName -- change the month number to name
*
* modification history
* --------------------
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro NumToName(Month)
{
if (Month == 1)
  return "jan"
if (Month == 2)
  return "feb"
if (Month == 3)
  return "mar"
if (Month == 4)
  return "apr"
if (Month == 5)
  return "may"
if (Month == 6)
  return "jun"
if (Month == 7)
  return "jul"
if (Month == 8)
  return "aug"
if (Month == 9)
  return "sep"
if (Month == 10)
  return "oct"
if (Month == 11)
  return "nov"
if (Month == 12)
  return "dec"
}

/******************************************************************************
* CutWord -- auto newline
*
* modification history
* --------------------
* 01a, 24mar2003, t357 fix some bug
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro CutWord(ncurLine, szInf)
{
LENGTH = 63
nlength = StrLen(szInf)
i = 0 /* loop control */
begin = 0 /* first character's index of current line */
pre = 0 /* preceding word's index */
hbuf = GetCurrentBuf()
// nline = GetBufLnCur()
while (i < nlength)
{
/* remove by t357
  nrow = 0
  sz = ""
  while (nrow < 80)
  {
   if (nlength < 0)
    break
   sz = Cat(sz, szInf[nrow])
   nrow = nrow + 1
   nlength = nlength - 1
  }
  InsBufLine(hbuf, nline, sz)
  szInf = szInf[nrow]
}
*/
        c = szInf[i]
        if (" " == @c@ && (i - b < LENGTH))
        {
            pre = i
        }
        else if (" " == @c@)
        {
            szOutput = ""
            k = begin /* loop control */
            while (k < pre)
            {
                szOutput = Cat(szOutput, szInf[k])
                k = k + 1
            }
            InsBufLine(hbuf, ncurLine, sz)
            ncurLine = ncurLine + 1
            begin = pre
        }
        i = i + 1
    }
    if (h != i - 1)
    {
        szOutput = ""
        k = begin /* loop control */
        while (k < pre)
        {
            szOutput = Cat(szOutput, szInf[k])
            k = k + 1
        }
        InsBufLine(hbuf, ncurLine, sz)
        ncurLine = ncurLine + 1
    }
}

/******************************************************************************
* GetFileName -- get the filename only from the path
*
* modification history
* --------------------
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro GetFileName(pathName)
{
nlength = strlen(pathName)
i = nlength - 1
name = ""
while (i + 1)
{
  ch = pathName[i]
  if ("\\" == "@ch@")
   break
  i = i - 1
}
i = i + 1
while (i < nlength)
{
  name = cat(name, pathName[i])
  i = i + 1
}

return name
}

/******************************************************************************
* ReturnTrueOrFalse -- Inserts "Returns True or False" at the current line
*
* modification history
* --------------------
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro ReturnTrueOrFalse()
{
szReturns = "return True if successful or False if errors."
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)
szCurLine = GetBufLine(hbuf, ln)
DelBufLine(hbuf, ln)
InsBufLine(hbuf, ln, "@szCurLine@@szReturns@")
SetBufIns(hbuf, ln, StrLen(szReturns) + StrLen(szCurLine) + 3)
}

/******************************************************************************
* InsHeaderDef -- Inserts the header define in the headerfile
*
* modification history
* --------------------
* 01a, 05mar2003, t357 written
* --------------------
******************************************************************************/
macro InsHeaderDef()
{
hBuf = GetCurrentBuf()
szpathName = GetBufName(hBuf)
szfileName = GetFileName(szpathName)
szfileName = toupper(szfileName)
nlength = StrLen(szfileName)
i = 0 /* loop control */
szdefineName = ""
while (i < nlength)
{
  if (szfileName[i] == ".")
   szdefineName = Cat(szdefineName, "_")
  else
   szdefineName = Cat(szdefineName, szfileName[i])
  i = i + 1
}
szdefineName = Cat("_", szdefineName)
IfdefineSz(szdefineName)
}

/******************************************************************************
* PrintDate - print date on where the cursor point to
* DESCRIPTION: -
*
* Input:
* Output:
* Returns:
*
* modification history
* --------------------
* 01a, 23mar2003, t357 written
* --------------------
******************************************************************************/
macro PrintDate()
{
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
if (Day < 10)
  szDay = "
0@Day@"
else
  szDay = Day
szMonth = NumToName(Month)
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)
szCurLine = GetBufLine(hbuf, ln)
DelBufLine(hbuf, ln)
InsBufLine(hbuf, ln, "@szCurLine@ @szDay@@szMonth@@Year@")
SetBufIns(hbuf, ln, StrLen(szCurLine) + 10)
}


// Ask user for ifdef condition and wrap it around current
// selection.
// 28mar2003, modified by t357.
// 26mar2003, modified by t357.
macro InsIfdef()
{
sz = Ask("Enter ifdef condition:")
if (sz != "")
{
  // IfdefSz(sz);
  hwnd = GetCurrentWnd()
     sel = GetWndSel(hwnd)
  hbuf = GetWndBuf(hwnd)
  // get line the selection (insertion point) is on
  szLine = GetBufLine(hbuf, sel.lnFirst - 1);
  chTab = CharFromAscii(9)
  // prepare a new indented blank line to be inserted.
  // keep white space on left and add a tab to indent.
  // this preserves the indentation level.
  i = 0 /* loop control */
  ich = ""
  while (szLine[i] == " " || szLine[i] == chTab)
  {
   ich = Cat(ich, szLine[i])
   i = i + 1
  }

  InsBufLine(hbuf, sel.lnFirst, "")
     InsBufLine(hbuf, sel.lnFirst + 1, "@ich@#ifdef @sz@")
     InsBufLine(hbuf, sel.lnFirst + 2, "@ich@" # chTab)
     InsBufLine(hbuf, sel.lnFirst + 3, "@ich@#endif  /* @sz@ */")
     SetBufIns(hbuf, sel.lnFirst + 2, StrLen(ich) + StrLen(chTab))
    }
}

// Wrap ifdeinef <sz> .. endif around the current selection
macro IfdefineSz(sz)
{
hwnd = GetCurrentWnd()
lnFirst = GetWndSelLnFirst(hwnd)
lnLast = GetWndSelLnLast(hwnd)

hbuf = GetCurrentBuf()
InsBufLine(hbuf, lnFirst, "#ifndef @sz@")
InsBufLine(hbuf, lnFirst + 1, "#define @sz@")
InsBufLine(hbuf, lnLast + 3,  "#endif  /* @sz@ */")
SetBufIns(hbuf, lnFirst + 2, 0)
}


/*   A U T O   E X P A N D   */
/*-------------------------------------------------------------------------
    Automatically expands C statements like if, for, while, switch, etc..

    To use this macro,
     1. Add this file to your project or your Base project.

  2. Run the Options->Key Assignments command and assign a
  convenient keystroke to the "AutoExpand" command.

  3. After typing a keyword, press the AutoExpand keystroke to have the
  statement expanded.  The expanded statement will contain a ### string
  which represents a field where you are supposed to type more.

  The ### string is also loaded in to the search pattern so you can
  use "Search Forward" to select the next ### field.

For example:
  1. you type "for" + AutoExpand key
  2. this is inserted:
   for (###; ###; ###)
   {
    ###
   }
  3. and the first ### field is selected.
-------------------------------------------------------------------------*/
/******************************************************************************
* AutoExpand - Automatically expands C statements
*
* DESCRIPTION: - Automatically expands C statements like if, for, while,
*    switch, etc..
*
* Input:
* Output:
* Returns:
*
* modification history
* --------------------
* 01a, 27mar2003, t357 modified
* --------------------
******************************************************************************/
macro AutoExpand()
{
// get window, sel, and buffer handles
hwnd = GetCurrentWnd()
if (hwnd == 0)
  stop
sel = GetWndSel(hwnd)
if (sel.ichFirst == 0)
  stop
hbuf = GetWndBuf(hwnd)

// get line the selection (insertion point) is on
szLine = GetBufLine(hbuf, sel.lnFirst);

// parse word just to the left of the insertion point
wordinfo = GetWordLeftOfIch(sel.ichFirst, szLine)
ln = sel.lnFirst;

chTab = CharFromAscii(9)

// prepare a new indented blank line to be inserted.
// keep white space on left and add a tab to indent.
// this preserves the indentation level.
ich = 0
while (szLine[ich] == ' ' || szLine[ich] == chTab)
  {
  ich = ich + 1
  }

szLine = strmid(szLine, 0, ich)
sel.lnFirst = sel.lnLast
sel.ichFirst = wordinfo.ich
sel.ichLim = wordinfo.ich

// expand szWord keyword...


if (wordinfo.szWord == "if" ||
  wordinfo.szWord == "while" ||
  wordinfo.szWord == "elseif")
  {
  SetBufSelText(hbuf, " (###)")
  InsBufLine(hbuf, ln + 1, "@szLine@" # "{");
  InsBufLine(hbuf, ln + 2, "@szLine@" # chTab);
  InsBufLine(hbuf, ln + 3, "@szLine@" # "}");
  }
else if (wordinfo.szWord == "for")
  {
  SetBufSelText(hbuf, " (###)")
  InsBufLine(hbuf, ln + 1, "@szLine@" # "{");
  InsBufLine(hbuf, ln + 2, "@szLine@" # chTab);
  InsBufLine(hbuf, ln + 3, "@szLine@" # "}");
  }
else if (wordinfo.szWord == "switch")
  {
  SetBufSelText(hbuf, " (###)")
  InsBufLine(hbuf, ln + 1, "@szLine@" # "{")
  InsBufLine(hbuf, ln + 2, "@szLine@" # "case ")
  InsBufLine(hbuf, ln + 3, "@szLine@" # chTab)
  InsBufLine(hbuf, ln + 4, "@szLine@" # chTab # "break;")
  InsBufLine(hbuf, ln + 5, "@szLine@" # "default:")
  InsBufLine(hbuf, ln + 6, "@szLine@" # chTab)
  InsBufLine(hbuf, ln + 7, "@szLine@" # "}")
  }
else if (wordinfo.szWord == "do")
  {
  InsBufLine(hbuf, ln + 1, "@szLine@" # "{")
  InsBufLine(hbuf, ln + 2, "@szLine@" # chTab);
  InsBufLine(hbuf, ln + 3, "@szLine@" # "} while ();")
  }
else if (wordinfo.szWord == "case")
  {
  SetBufSelText(hbuf, " ###")
  InsBufLine(hbuf, ln + 1, "@szLine@" # chTab)
  InsBufLine(hbuf, ln + 2, "@szLine@" # chTab # "break;")
  }
else
  stop

SetWndSel(hwnd, sel)
LoadSearchPattern("###", true, false, false);
Search_Forward
}


/*   G E T   W O R D   L E F T   O F   I C H   */
/*-------------------------------------------------------------------------
    Given an index to a character (ich) and a string (sz),
    return a "wordinfo" record variable that describes the
    text word just to the left of the ich.

    Output:
     wordinfo.szWord = the word string
     wordinfo.ich = the first ich of the word
     wordinfo.ichLim = the limit ich of the word
-------------------------------------------------------------------------*/
macro GetWordLeftOfIch(ich, sz)
{
wordinfo = "" // create a "wordinfo" structure

chTab = CharFromAscii(9)

// scan backwords over white space, if any
ich = ich - 1;
if (ich >= 0)
  while (sz[ich] == " " || sz[ich] == chTab)
   {
   ich = ich - 1;
   if (ich < 0)
    break;
   }

// scan backwords to start of word
ichLim = ich + 1;
asciiA = AsciiFromChar("A")
asciiZ = AsciiFromChar("Z")
while (ich >= 0)
  {
  ch = toupper(sz[ich])
  asciiCh = AsciiFromChar(ch)
  if ((asciiCh < asciiA || asciiCh > asciiZ) && !IsNumber(ch))
   break // stop at first non-identifier character
  ich = ich - 1;
  }

ich = ich + 1
wordinfo.szWord = strmid(sz, ich, ichLim)
wordinfo.ich = ich
wordinfo.ichLim = ichLim;

return wordinfo
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章