转载地址: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@ @szMyName@.xmyanfa @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@ @szMyName@.xmyanfa @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, /*@szMyName@.xmyanfa @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

(1)Options菜单àPreferencesàTyping卡,勾掉下面两项∶

Typing tab indents line,regardless of selection,空行按tab无法前进

Typing tab replaces current selection,选定部分内容、再按tab时会清除所选

(2)Options菜单àDocument Options(针对不同文件类型,分别进行设置)à下拉左上文件类型框、选择合适类型(c源文件)àEditing Options框中,tab width=2à Editing Options框中,勾选Expand tabs(这样,按tab键、等价于输入2个空格)

(3)Options菜单àDocument Optionsà选择合适的文件类型à点击右边中间的Auto Indent钮à在弹出的框中,左边一定要点Smart,右边有两个复选框Indent Open Brace和Indent Close Brace,具体效果可以看SIS的HELP。按照部门里的编程风格要求,最方便的就是把两个复选框都取消掉,然后点OK。

勾选Auto Indent之SMART的效果∶在C程序里, 如果遇到行末没有分号的语句,如IF, WHILE, SWITCH等, 写到该行末按回车,则新行自动相对上一行缩进两列。

勾掉Indent Open Brace和Indent Close Brace的效果∶继上一段,在相对缩进行里, 如果输入"}", 则自动和上一行列对齐(好像勾不勾都会有这个功能);而输入"{"时,不会与下面的行对齐(这是勾上Indent Open Brace时的效果)。

2、向项目中添加文件时,只添加特定类型的文件(文件类型过滤器)

有个同事比较生猛,得整汇编代码,但在SIS里建立PROJECT并ADD TREE的时候,根据默认设置并不会把该TREE里面所有汇编文件都包含进来,只加了.inc和.asm后缀的,.s后缀的没有。而且用SIS打开.s的文件,一片黑白没有色彩,感觉回到DOS的EDIT时代了…… 解决方法是在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…命令,在弹出的框中、选择搜索模式、并填入相应的正则表达式串,点OK,SIS就会解析当前文件,如果有匹配,就创建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.1在SourceInsight中提供的正则表达式

正则表达式,是用来匹配复杂模式的特殊搜索用字符串。正则表达式串中,许多字符具有特殊的含义。例如,有个特殊的字符代表 “行首”。

下面是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 #n,n=1,2,…;组的概念在替换时很有用。

例如∶

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

利用21来替换(abc)(xyz),替换结果为xyzabc。

3.2 正则表达式在配置tc编译器中的应用∶

正则表达式格式与源代码文件路径相对应,这里我的tc安装目录为d:tc,tc源文件放在d:tcsrc下,并命名为qn.c或qtn.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_HOME是c:jdk,我的java源文件放于d:javasrc中,并命名为qn.java或qtn.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 First、SIS会在运行命令前先检查文件是否保存

à勾选Control Group框中的Pause When Done、SIS会在命令结束后暂停、方便检查

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

source insight常用宏

转自: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
}

Source insight 宏的使用相关推荐

  1. Source Insight利用宏文件实现多行快速注释以及其他超级好用的功能

    前言 Source insight是一款非常优秀的代码阅读软件,但是有些地方还是不够完善,比如没有快速对一段代码进行注释的功能.对于此类需求,我们可以借助宏来实现.网上有很多source insigh ...

  2. Source Insight中无法正确判断宏定义的问题

    Source Insight阅读C语言项目,会出现#ifdef无法正确判断宏定义值导致无法正确跳转到#else的问题,因为软件本身只能识别TRUE和FALSE,解决方法是右键该宏定义选择"E ...

  3. Source Insight【3】扩展宏的使用

    本文将介绍Quicker.em宏扩展的功能.安装及使用,对Source Insight中宏使用进行一个初级说明. 不要被它众多的功能和宏定义所吓倒,看完怎样使用,你会发现是真的超级简单和方便! 一.功 ...

  4. 让Source Insight完美支持中文注释 (转)

    如何让source insight支持中文注释,解决回车删除,移动光标出现乱码的问题?下面是解决方案: -------Source Insight3 中文操作(左右键.删除和后退键)支持宏------ ...

  5. source insight 4.0的基本使用方法

    一.项目管理 1.新建一个项目 快捷键Alt+Shift+N可以打开新建项目对话框,然后根据提示填好项目存储位置,源文件位置等,然后会出现添加删除项目文件对话框,选中自己想要编辑和浏览的文件添加即可, ...

  6. Source Insight中的多行注释

    我们经常要对一整段代码进行注释,很多代码编辑器都提供了这样的功能:用快捷键"Ctrl + /"来实现"//"的多行注释. 但是在用source insight的 ...

  7. 给Source Insight做个外挂系列之六--“TabSiPlus”的其它问题

    关于如何做一个Source Insight外挂插件的全过程都已经写完了,这么一点东西拖了一年的时间才写完,足以说明我是一个很懒的人,如果不是很多朋友的关心和督促,恐怕是难以完成了.许多朋友希望顺着本文 ...

  8. Parse Too complex in xxxx.cpp --------source insight

    Source Insight,某些文件出现"parse too complex",如何解决? 查看网上的解决方案都是 SI的一个很有用的功能是可以列出所有的函数名和变量名,然而在S ...

  9. Source Insight Source Navigator使用技巧

    Source Insight & Source Navigator使用技巧 一.Source Insight实用技巧: Source Insight(下文的SI指的也是它)就是这样的一个东西: ...

最新文章

  1. Python使用matplotlib函数subplot可视化多个不同颜色的折线图、在折线图上为每个数据点添加日期数据标签
  2. Python大战C++,谁能更胜一筹?
  3. 随机组卷python_关于随机自动组卷的算法,二维数组
  4. 世界读书日 阿里人是这样看书的?
  5. 数据中心柴油发电机系统的使用和维护
  6. 保护 wp cron.php,wp-cron.php任务的定时执行和控制
  7. php怎样完成批量审核,CMS_DedeCMS 批量取消审核文档的实现方法,今天修改了几个地方的代码 实 - phpStudy...
  8. python导入包的输入法_python 模块和包的导入
  9. 使用微服务失败的12个原因
  10. 版本管理工具git常用命令
  11. 人人对战五子棋 C++
  12. AR/VR---沉浸式体验
  13. 前端传图片file给后端,后端接收为空,0kb
  14. 如何在r的图片中画出特定点的水平线和垂直线_平面设计新手如何利用点线面进行构图...
  15. 成都java开发学习要多久
  16. 今天杂志今天杂志社今天编辑部2022年第6期目录
  17. 指令级并行(ILP)技术
  18. RRPP相切环配置示例
  19. HM编码器代码阅读(5)——参考帧的选择
  20. 搜索推广营销五步曲之三:方案制作之如何写好创意

热门文章

  1. vue 分布式微服务_分布式微服务架构选项
  2. LoRa开发板升级的时候,为什么需要修改跳线帽?
  3. 云桌面几大应用场景,你需要的都在这里
  4. 人力资源管理材料课程100多题库
  5. 牛码宝宝 - Sprint collection
  6. 【宇麦科技】单向同步+在线编辑 ,群晖Drive APP迎来了更新
  7. HTML 中表格table 的相关知识
  8. css定位元素-随心记
  9. 面试官问你关于node的那些事(基础篇)
  10. Java PropertyDescriptor对象