source insight使用技巧

Source Insight 使用技巧总结 总结了一些Source Insight使用中遇到的经验与问题。 查看工程中所有的类及其成员 点击:project Window下面的Project Symbol Classes: 更改字体 Options->Document Options 点击Screen Fonts进行设置,一般设为“Courier New”,字体等宽对齐,对于查看代码较好, 也可以 阅读详情
1 sourceinsight screen font 的默认字体是Verdana的,它是一直变宽字体。在Document style中可以将字体改为定宽的 Courier             

2   勾掉indent Open Brace和Indent Close Brace的效果: 继上一段,在相对缩进行里, 如果输入"{"或"}", 则自动和上一行列对齐

3 今天把一个用sourceinsight排版整齐的C文件,偶然用VC打开一看,全乱了。研究了半天,发现SI对每个字符的宽度不太一致。

    发现选上" view --> draft view", 就可以让每个字符的宽度一致了。快捷键是 " Alt + F12"
4选中几行代码按tab键或者shift+tab可以左右移动代码,调整代码时很有用。

配置成简单好用的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>

5使用最强大的宏功能,真的达到的完美境界

说明:
    该宏文件实现一些编码程中能会到的功能, 如添加文件头、函数说明和宏定义等, 使用时能自动添加文件名、函数名和当前日期.

使用说明:
    1. Project->Open Project... 打开Base工程(该工程一般在"我的文档/Source Insight/Projects/Base"中);
    2. Project->Add and Remove Project Files... 加入宏文件(即mymacro.em);
    3. Options->Menu Assignments 打开Menu Assignments窗口, 在Command中输入Macro, 选中要使用的宏, 添加到合适的菜单中.
在http://www.sourceinsight.com/public/macros/可以找到很多宏定义文件,但大多数没什么用。
/*附上宏定义文件(一下是我精心挑选的十分好用的宏定义,不试不知道,一试真有用)*/
/* mymacro.em - a small collection of useful editing macros */


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

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

 

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

//
// Comment the selected block of text using single line comments and indent it
//
macro CommentBlock()
{
hbuf = GetCurrentBuf();
hwnd = GetCurrentWnd();

sel = GetWndSel(hwnd);

iLine = sel.lnFirst;

while (iLine <= sel.lnLast)
{
   szLine = GetBufLine(hbuf, iLine);
   szLine = cat("// ", szLine);
   PutBufLine(hbuf, iLine, szLine);
   iLine = iLine + 1;
}

if (sel.lnFirst == sel.lnLast)
{
   tabSize = _tsGetTabSize() - 1;
   sel.ichFirst = sel.ichFirst + tabSize;
   sel.ichLim = sel.ichLim + tabSize;
}
SetWndSel(hwnd, sel);
}


//
// Undo the CommentBlock for the selected text.
//
macro UnCommentBlock()
{
hbuf = GetCurrentBuf();
hwnd = GetCurrentWnd();

sel = GetWndSel(hwnd);

iLine = sel.lnFirst;


tabSize = 0;
while (iLine <= sel.lnLast)
{
   szLine = GetBufLine(hbuf, iLine);
   len = strlen(szLine);
   szNewLine = "";
   if (len > 1)
   {
    if (szLine[0] == "/" && szLine[1] == "/")
    {
     if (len > 2)
     {
      if (AsciiFromChar(szLine[2]) == 9)
      {
       tabSize = _tsGetTabSize() - 1;
       szNewLine = strmid(szLine, 3, strlen(szLine));
      }
     }

     if (szNewLine == "")
     {
      szNewLine = strmid(szLine, 2, strlen(szLine));
      tabSize = 2;
     }
    
     PutBufLine(hbuf, iLine, szNewLine);
    }
   }
   iLine = iLine + 1;
}

if (sel.lnFirst == sel.lnLast)
{
   sel.ichFirst = sel.ichFirst - tabSize;
   sel.ichLim = sel.ichLim - tabSize;
}

SetWndSel(hwnd, sel);
}

 

macro _tsGetTabSize()
{
szTabSize = GetReg("TabSize");

if (szTabSize != "")
{
   tabSize = AsciiFromChar(szTabSize[0]) - AsciiFromChar("0");
}
else
{
   tabSize = 4;
}

return tabSize;
}

 


//
// Reformat a selected comment block to wrap text at 80 columns.
// The start of the selection (upper left most character of the selection) is
// handled specially, in that it specifies the left most column at which all
// lines will begin. For example, if the following block was selected starting
// at the @ symbol, through the last line of the block...
//------------------------------------------------------------------------------
// preamble: @ This is a line that will be wrapped keeping the "at" symbol in its current column.
// All lines following it that are selected will use that as their starting column. See below to see how the wrapping
// works for this block of text.
//------------------------------------------------------------------------------
// preamble: @ This is a line that will be wrapped keeping the "at" symbol in
//     its current column. All lines following it that are selected
//     will use that as their starting column. See below to see how
//     the wrapping works for this block of text.
//
macro tsReformatCommentBlock()
{
hbuf = GetCurrentBuf();
hwnd = GetCurrentWnd();

sel = GetWndSel(hwnd);

tabSize = _tsGetTabSize();
leftTextCol = 0 - 1;
colWrap = 80;

// Find the starting column, and create a Margin string
ichFirst = sel.ichFirst;

// Single line comment reformat?
if (sel.ichFirst == sel.ichLim && sel.lnFirst == sel.lnLast)
{
   ichFirst = 0;
}

rec = _tsGetStartColumn(hbuf, ichFirst, sel.lnFirst);

if (rec == "")
   stop;

colLeftMargin = rec.colMargin;
szMargin = "";

colComment = 0;
if (rec.colComment >= 0)
{
   colComment = rec.colComment + 2
   szMargin = _tsAddWhiteToColumn(szMargin, 0, rec.colComment, tabSize);
   szMargin = cat(szMargin, "//");
}

szMargin = _tsAddWhiteToColumn(szMargin, colComment, rec.colMargin, tabSize);

rec = "";

szCurMargin = "";
if (ichFirst != 0)
{
   szLine = GetBufLine(hbuf, sel.lnFirst);
   szCurMargin = strmid(szLine, 0, ichFirst);
}
else
{
   szCurMargin = szMargin;
   szMargin = "";
}

insertLine = sel.lnFirst;
iLine = sel.lnFirst;
szRemainder = "";
while (1)
{
//   msg("$0-" # iLine # ":" # szRemainder);
   rec = _tsGetNextCommentString(hbuf, ichFirst, szRemainder, iLine, sel.lnLast, colWrap);
   ichFirst = 0;

   if (rec == "")
    break;

//   msg("$1-" # rec.ln # ":" # rec.szComment);
   szLine = rec.szComment;

   ich = 0;
   col = colLeftMargin;
   len = strlen(szLine);
  
   ichPrevCharToWhite = 0-1;
   ichPrevWhiteToChar = 0-1;
//   msg("Leftovers @szRemainder@");

   while (ich < len)
   {
    if (AsciiFromChar(szLine[ich]) == 9)
    {
     col = (((col + tabSize) / tabSize) * tabSize);
    }
    else
    {
     col = col + 1;
    }

    if (col > colWrap)
     break;

    fIsWhitespace = _tsIsWhitespaceChar(szLine[ich]);
    fIsWhitespace1 = 1;

    if (ich + 1 < len)
    {
     fIsWhitespace1 = _tsIsWhitespaceChar(szLine[ich + 1]);
    }

    if (!fIsWhitespace && fIsWhitespace1)
     ichPrevCharToWhite = ich;
   
    ich = ich + 1;
   }

   if (ichPrevCharToWhite > 0)
   {
//    msg("$2:" # strmid(szLine, 0, ichPrevCharToWhite + 1));
    ich = ichPrevCharToWhite + 1;

    while (ich < len)
    {
     if (!_tsIsWhitespaceChar(szLine[ich]))
     {
      ichPrevWhiteToChar = ich - 1;
//      msg("$3:" # strmid(szLine, ichPrevWhiteToChar + 1, len));
      break;
     }
     ich = ich + 1;
    }
   }

   if (ichPrevCharToWhite > 0 && col > colWrap)
   {
    szNewLine = cat(szCurMargin, strmid(szLine, 0, ichPrevCharToWhite + 1));
    szRemainder = "";
    if (ichPrevWhiteToChar > 0)
     szRemainder = strmid(szLine, ichPrevWhiteToChar + 1, len);
    
    if (ichPrevCharToWhite > ichPrevWhiteToChar)
     msg("!!!Wrap, duplicating word " # ichPrevWhiteToChar # " " # ichPrevCharToWhite # " " # szNewLine # " >>> " # szRemainder);
//     msg(szLine);
//     msg(col # " " # ichPrevWhiteToChar # " " # ichPrevCharToWhite # " " # szNewLine # " >>> " # szRemainder);
   }
   else if (szLine != "")
   {
    szNewLine = cat(szCurMargin, szLine );
    szRemainder = "";
//    sel.lnLast = sel.lnLast + 1;
   }

   iLine = rec.ln;
   if (insertLine == iLine)
   {
    iLine = iLine + 1;
    sel.lnLast = sel.lnLast + 1;
   
//    msg("$5-" # insertLine # ":" # szNewLine);
    InsBufLine(hbuf, insertLine, szNewLine);
   }
   else
   {
    szLine = GetBufLine(hbuf, insertLine);
    if (szLine != szNewLine)
    {
//     msg("$6-" # insertLine # ":" # szNewLine);
     PutBufLine(hbuf, insertLine, szNewLine);
    }
   }
   insertLine = insertLine + 1;

   if (szMargin != "")
   {
    szCurMargin = szMargin;
    szMargin = "";
   }
}

while (insertLine <= sel.lnLast)
{
   DelBufLine(hbuf, insertLine);
   sel.lnLast = sel.lnLast - 1;
}

len = GetBufLineLength(hbuf, insertLine-1);

sel.ichFirst = len;
sel.ichLim = len;
sel.lnFirst = sel.lnLast;
SetWndSel(hwnd, sel);
}


macro _tsAddWhiteToColumn(sz, col0, col, tabSize)
{
szTabs = "                               ";
szSpaces = "                ";

tabs0 = col0 / tabSize;
tabs = (col / tabSize) - tabs0;

if (tabs == 0)
   foo = col0;
else
   foo = (tabs + tabs0) * tabSize;
spaces = col - foo;
// msg(col0 # " " # col # " " # tabs # " " # spaces # " " # tabs0);

if (tabs)
   sz = cat(sz, strmid(szTabs, 0, tabs));

if (spaces)
   sz = cat(sz, strmid(szSpaces, 0, spaces));

return sz;
}

macro _tsGetStartColumn(hbuf, ichBegin, ln)
{
szLine = GetBufLine(hbuf, ln);
len = strlen(szLine);
tabSize = _tsGetTabSize();
ich = 0;

colMargin = 0;
colComment = 0-1;

rec = "";
rec.colMargin = colMargin;
rec.colComment = colComment;

while (ich < len)
{
   if (AsciiFromChar(szLine[ich]) == 9)
   {
    colMargin = (((colMargin + tabSize) / tabSize) * tabSize);
   }
   else
   {
    colMargin = colMargin + 1;
   }

   if (colComment < 0)
   {
    if (ich + 1 < len)
    {
     if (szLine[ich] == "/" && szLine[ich+1] == "/")
     {
      colComment = colMargin - 1;
      ich = ich + 2;
      colMargin = colMargin + 1;
      continue;
     }
    }
   }

   if (ich >= ichBegin)
   {
    if (!_tsIsWhitespaceChar(szLine[ich]))
    {
     rec.colMargin = colMargin - 1;
     rec.colComment = colComment;
//     msg(szLine[ich]);
     return rec;
    }
   }

   ich = ich + 1;
}

return rec;
}

macro _tsGetNextCommentString(hbuf, ichSkip, szRemainder, ln, lnLast, colWrap)
{
rec = "";

// Go until we get a string that is at least long enough to fill a line
// or, we run out of lines.
if (szRemainder == "" && ln > lnLast)
   return "";
  
ichFirst = ichSkip;
// msg(ichSkip);
while (1)
{
   if (ln > lnLast)
   {
    rec.szComment = szRemainder;
    rec.ln = ln;
    return rec;
   }

   cchRemainder = strlen(szRemainder);

   if (cchRemainder > colWrap)
   {
    rec.szComment = szRemainder;
    rec.ln = ln;
    return rec;
   }

   szLine = GetBufLine(hbuf, ln);
   len = strlen(szLine);

   if (ichSkip == 0)
    ichFirst = _tsSkipPastCommentAndWhitespace(szLine, len);
   ichSkip = 0;
   
   ichLast = len - 1;

   // Now, strip out all whitespace at the end of the line
   while (ichLast >= ichFirst)
   {
    if (!_tsIsWhitespaceChar(szLine[ichLast]))
    {
     break;
    }
    ichLast = ichLast - 1;
   }

   // Entire line is whitespace?
   if (ichLast < ichFirst)
   {
    if (szRemainder == "")
     ln = ln + 1;
    rec.szComment = szRemainder;
    rec.ln = ln;
    return rec;

   }
   // length of the non whitespaced comment + 1 space + cchRemainder
   if ((ichLast + 1) - ichFirst + cchRemainder + 1 > 255)
   {
    // It may not format the current line quite right, but
    // but at least we won't throw away some of the comment.
    rec.szComment = szRemainder;
    rec.ln = ln;
    return rec;
   }

   if (szRemainder != "")
    szRemainder = cat(szRemainder, " ");
   szRemainder = cat(szRemainder, strmid(szLine, ichFirst, ichLast + 1));
   ln = ln + 1;
}
}

 

macro _tsSkipPastCommentAndWhitespace(szLine, len)
{
ichFirst = 0;
// Skip past the comment initiator "//" if there is one.
while (ichFirst < len)
{
   if (ichFirst + 1 < len)
   {
    if (szLine[ichFirst] == "/" && szLine[ichFirst+1] == "/")
    {
     ichFirst = ichFirst + 2;
     break;
    }
   }
   ichFirst = ichFirst + 1;
}

// If no comment found in line, then start from the beginning
if (ichFirst >= len)
   ichFirst = 0;

ichFirst = ichFirst;
// Now, strip out all whitespace after the comment start.
while (ichFirst < len)
{
   if (!_tsIsWhitespaceChar(szLine[ichFirst]))
   {
    break;
   }
   ichFirst = ichFirst + 1;
}

return ichFirst;
}

 
sourceinsight-最强代码阅读工具-安装包与字体设置 道友:人们总是相信别人是单纯的坏人,而自己是复杂的好人。 阅读详情

相关推荐

sourceInsight常用设置和功能汇总(不断更新)(RGB、高亮、全路径、鼠标、宏、TODO高亮)

Ctrl+M 添加标签(注意尽量将所有的都放在右边 把project symbol context folder mark全部放在一起并列 然后使用快捷键快速调出来)新功能(niubility):Ctrl + Alt + W(web搜索,打开默认搜索引擎) (牛逼功能) —— 这个需要养成习惯好好使用。复制该位置邮编的该行字符:ctrl+shift+k。Ctrl+shift+M 查看搜索过的历史记录。Ctrl + Alt + C查看函数被哪些调用。重画屏幕 : Ctrl+Alt+Space。

技术札记 3977

SourceInsight基本使用

一、创建工程 二、添加符号表 三、窗口布局/配置 1、窗口布局 2、行号 3、辅助线,编辑选项 4、背景色 5、字体大小 6、编码 四、阅读/编辑 1、快速定位指定位置 2、函数调用上下文 3、查找工具 4、编辑功能 五、快捷键 *外挂(插件) 一、创建工程 1、打开软件后的默认界面: 2、准备创建工程: 在菜单栏中点击Project > New Project ,然后会出现对话框如下,分别为当前工程名称和后期该工程数据文件的位置,工程名建议起一个...

分享空间 2万+

Source Insight 4.0关键位置设置

1.编码格式 --在 Options->Preferences->Files 中的最下面,Default enconding 为UTF-8 2.tab转空格 其他相关设置如下: 以下是一些新特性的展示: 1、文件对比 这个功能在->Tools 中,可以支持当前文件和备份文件对比,也支持两个文件对比。甚至支持文件夹内容对比。简单使用后发现...

智能硬件研发,欢迎交流 456

【Source insight】 工具安装及使用方法

一、Source Insight简介​ Source Insight工具是一款功能强大的代码阅读器,它能使大量的代码产生联系,方便阅读,而且支持各种语言的程序代码。二、Source Insight安装。

咖喱年糕的博客 1万+

手把手教你用DCA1000EVM解析IWR6843毫米波雷达数据(附MATLAB代码)

本文提供了一份详尽的实战指南,手把手教你使用DCA1000EVM采集并解析TI毫米波雷达IWR6843的原始数据。内容涵盖硬件连接配置、mmWave Studio参数设置、LVDS数据流结构解析,并附有核心MATLAB代码,详细演示了从原始二进制文件到距离-速度谱的信号处理全链路,帮助开发者快速掌握数据解析与处理的关键步骤。

terraform7cloud的博客 228

王道考研计算机网络课件全解析:从零搭建你的知识框架(附B站视频+PPT下载)

本文全面解析王道考研计算机网络课程的核心知识体系,从OSI七层模型到TCP/IP四层架构,详细讲解物理层、数据链路层、网络层、传输层和应用层的关键技术。提供高效学习路径、实战案例和常见误区警示,帮助考生系统构建计算机网络知识框架,适合计算机考研备考者参考学习。

leaf8的博客 564

Source Insight 4.0使用技巧

新功能 1、文件对比 这个功能在->Tools 中,可以支持当前文件和备份文件对比,也支持两个文件对比。甚至支持文件夹内容对比。简单使用后发现效果好不错,这是替代 UltraCompare 的节奏啊,不过应该不支持文件信息的二进制版本对比。 2、代码 Reformat这个功能也在->Tools 中,可以支持几种常见的代码风格,例如:ANSI、GNU、K&R,也支持自定义,这和Eclipse 中的一样。代码风格是非常个人化的东西,看着舒服就好。这个功能在拷贝粘贴代码的时候很实...

sunnytony的专栏 6132

Dify工作流教程|以抓取网页并更新知识库为例详细讲解工作流编排过程(附DSL文件)

{"name": "{新建的title变量}","text": "新建的content变量","indexing_technique": "high_quality","process_rule": {"mode": "automatic"}}有没有很痛苦,明明添加书签的网页,当你想阅读的时候,总是找不到或者好不容易找到了,发现网页404了。如果有个小工具,直接能把你输入的链接内容抓取下来,并且加入到你的知识库中,你说他香不香。无法获取授权的,也可以使用网页抓取工具,这个是免费的,抓取效果也可以。

同名公众号:dify实验室 1万+

source insight 使用技巧

研发

FLYTOSKY的专栏 1275

ADS学习笔记 2. 低噪声放大器设计

ADS学习笔记 2. 低噪声放大器设计。设计了一个中心频率433MHz,增益18.206dB,NF=0.134dB,S11带宽较好的低噪声放大器

u014087103的博客 9510

JavaSwing_4.2: JDialog、JOptionPane(对话框)

JDialog,对话框。使用 JDialog 类可以创建自定义有的对话框,或者调用 JOptionPane 中的多个静态方法快速创建各种标准的对话框。JOptionPane是 JavaSwing 内部已实现好的,以静态方法的形式提供调用,能够快速方便的弹出要求用户提供值或向其发出通知的标准对话框。

谢TS的博客 7万+

Source insight 使用技巧方法

Source Insight工具是一款功能强大的代码阅读器,它能使大量的代码产生联系,方便阅读,而且支持各种语言的程序代码。

Zwgsnm的博客 956

【嘉立创EDA】PCB金属包边设计快捷方法

本文使用嘉立创EDA,描述如何在PCB设计时,快速增加边框包边设计,特别是金属包边(伪)——这里标记(伪)是因为该这里的包边特指不含边缘壁。请参考本文时特别注意!本文将此过程记录,以供有需要的读者参考。

l64481000的博客 1746

source insight的自动缩进 以及网上的一些使用技巧

让source insight的 if(ddd)      {      } 变成: if(ddd) { } 不过在{}中的第一行还是不能又自动缩进4个字符 方法如下: options --> Document Options -->Auto Indent Auto Indent Type 选择Simple Smart Indent Options 都选上

幸福大街28号 9203

WinClaw安全实战 02|五层纵深防护体系全解析:从原理到实操,打造零风险AI智能体

2026年AI智能体爆发式普及,OpenClaw以27.3万GitHub星标成为现象级工具,但恶意Skill投毒、提示词注入、数据外泄等安全事故频发,国家互联网应急中心、工信部等多部门接连发布风险警示。威努特基于国家关键信息基础设施安全防护经验,打造WinClaw安全版AI智能体,其核心竞争力在于**五层纵深防护体系**。本文从安全痛点切入,通过真实事故案例揭示风险本质,全景解构五层防护的架构设计与技术原理,逐层拆解身份认证、安装审查、消息拦截、执行约束、监控审计的实现逻辑,搭配20+实操演示、对比表格

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 498

Qt C++ + Qt 3D 的数字孪生工厂

以下是一个基于 **Qt C++ + Qt 3D** 的数字孪生工厂完整源码示例,集成了 **Qt 3D** 产线建模和 **WebSocket** 实时数据交互。ui->qualifiedProductsLabel->setText(QString("合格产品: %1").arg(data.qualifiedProducts));ui->totalProductsLabel->setText(QString("总产量: %1").arg(data.totalProducts));

寒寒豆豆软件公司的博客 149

Source Insight的一些技巧

Source Insight的一些技巧

uffgfbft的博客 297

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Source Insight 4.0使用技巧(进阶教程)

上一次我们讲到了Source Insight 4.0使用教程,今天我们继续来分享一些使用技巧,这些使用技巧可以帮助用户更有效率的编写程序。 1,Snippets的使用 使用Snippets面板,可以快速编辑或插入代码片段。点击,如下图所示: 在这个窗口下,我们可以编辑、新建或者删除代码段,我们编辑一个新的代码段,如下图: 比如,我们在程序中插入for代码段,我们只需要输入代码段的名字就会弹出窗口选择,如下: 我们选择第一个,就会插入如下代码段: 我们依次进行填写就可以啦。 2,

qq_36986070的博客 1万+

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

insight切换窗口 source_Source Insight使用技巧

1、背景色选择要改变背景色Options->preference->windows background->color设置背景色2、解决字符等宽对齐问题。SIS默认字体是VERDANA,很漂亮。这网页上应该也是用的VERDANA字体。但由于美观的缘故,VERDANA字体是不等宽的。比如下面两行llllllllllMMMMMMMMMM同样10个字符,长度差多了.用VERDANA来看...

weixin_33681937的博客 1064

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

source Insight使用技巧与问题解决

1.遇到窗口无法恢复到默认状态 进入我的文档里面SourceInsight\Settings文件夹里面关闭SI,把settings里边的配置文件删掉,重新打开SI,就恢复默认的全部设置了。 2.source insight函数调用关系设置 可以设置显示调用关系为调用关系或者被调用关系。 通过对圈子里的按钮进行配置,修改下图中的红框里面的内容为Referenced by Fu...

1433

source insight快捷键及使用技巧

source insight快捷键及使用技巧 退出程序 : Alt+F4 重画屏幕 : Ctrl+Alt+Space 完成语法 : Ctrl+E 复制一行...

a9j77749的博客 138

Source Insight应用技巧汇总

我们现在开发基本都用Source Insight源代码

yangrendong的专栏 1029

Source Insight的使用技巧

Tips:Source Insight的使用技巧1.使一整块代码左、右缩进,使用 shift+tab是左缩进,直接使用tab是右缩进;2.主题,背景等的设置3.代码文本的设置4.关闭自动补齐中的函数参数填充,取消Auto completion中的insert parameters for function即可。...

菠萝菠萝哒X 816

Source insight4 使用技巧

tab转空格双击高亮,F8高亮,你懂的代码格式化,自己调整,本来想上传配置文件的,我看还是算了,自己调整吧

cyd411的专栏 3232
上一篇: kdump starting failure in CentOS6.2
下一篇: 弹出网页窗口全攻略
-逗你玩儿-
博客等级 码龄14年 76粉丝 121原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值