Source Insight常用功能设置

 

 

    熟悉工具的使用能在一定程度上提高工作效率,但工具永远只是工具,大家要把重点放在内功的修炼上。

符号导航

    符号(变量、宏定义、结构定义、枚举、函数等等)在SI 中的检索非常方便。Ctrl+鼠标左键或Ctrl+=可以立即转到符号的定义处,Alt+/可以打开一个窗口查看符号的定义。F7 浏览或查找工程的全局变量和函数,F8 浏览查找当前文件的全局变量和函数(Source Insight 4 不可用)。Ctrl+/打开 Lookup Reference 窗口用于搜索符号在工程中的索引,所有搜索结果在搜索窗口中显示,点击搜索结果左边的红色源链接即可打开其所在位置。Lookup Reference 是在整个工程文件中进行搜索,要只在当前文件或特定的目录下进行搜索,使用 Ctrl+H 或Ctrl+Shfit+H 进行搜索,F3 和 F4 是上一个、下一个搜索结果的快捷键。

    使用Shift+F8 可以让当前的符号在整个工程文件中高亮显示。(Source Insight 4 使用F8让当前的符号在整个工程文件中高亮显示)

参数设置

    SI 有很自由的自定义功能,几乎所有的窗口都可以自定义字体、颜色,可以轻松地把各种类型关键字、变量、标志符、函数、宏、注释等定义为不同的颜色和显示方式(正体或斜体、加粗或正常、加下划线、放大显示等),可以随意的增加修改删除菜单项和快捷键。更重要的是,可以通过自定义命令执行外部程序,也可以通过 SI 自己的宏语言,自己写一段程序实现特定的功能,这些可以提高我们工作的效率,从重复繁琐的工作中解脱出来。 

  字体选择

     在 SI 中样式是可以被继承,如果要从根本上改变字体,最简单的方式就是直接修改根样式中的字体,因为其它样式都会由此继承而来。选择 Options/Document Options 页面内的 Font Options 中的Screen Fonts 字体,即可改变根样式中的字体。

    SI 中的默认配置为Verdana 字体,是一种非等宽字体,为了使编写的代码在各种编辑器中看起来都有良好的对齐效果,强烈建议使用等宽字体,Courier、New Courier 和宋体等都是较好的选择。

  背景色设置

    Options->preference->color->windows background设置背景色

 缩进设置

      选择 Options/Document Options 页面,点击其内的Auto Indent 按钮,在弹出的Auto Indenting 窗口中,Auto Indent Type 选择 Smart,取消勾选Smart Indent Options 中的两个可选项。同时 Options->Document Options 中,Tab Width 输入4,取消Expand tabs 复选框。 

Edit Condition

      当中代码中有大量的预编译定义,在阅读这样的代码时最痛苦的是不能简单判断程序实际执行的代码分支。大量分支同时存在,常常会混淆我们的视听。比如对于下面的代码:

#ifdef DEV1 
…… 
#else 
…… 
#endif 

     如果确定我们当前分析的是 DEV1 的执行情况,那么可以选择上下文件菜单的Edit Condition 选项,在弹出的 Conditional Parsing 窗口中把DEV1 的值设置为True,那么#ifdef DEV1 就等价于#if 1 了,相当注释掉了#else 分枝的代码。反之,设置为 Flase 时,则注释掉#ifdef DEV1 分枝的代码。

   中文间距过大问题

        默认情况下,往Source Insight 里输入中文,字间距相当的大。是因为字体设置的原因,进行如下设置如下可解决: 
  1. Options->Style Properties,打开样式对话框; 
  2. 在左边 Style Name 下找到Comment Multi Line 和 Comment.在其右边对应的 Font 属性框下的Font Name 中选“Pick...” 设置为宋体、常规、小四。确定,退回Style Properties 界面,Size 设为 10。

Smart Rename

     在上下文件菜单中选 Smart Rename 或按Ctrl+'组合键,即可弹出Smart Rename 窗口。它有很强大的功能,但最便捷的使用方式是更改函数内局部变量的名字,操作只作用于函数内部,速度非常快。

 恢复 Ctrl+A 的全选功能

      利用自定义快捷键,把功能定义成熟悉的按键。比如一般的编辑器,按下 Ctrl+A 是全选功能,但默认是 SI 的全选没有快捷键,Ctrl+A 默认是保存全部的操作。在 Custom Key 对话框中,通过关键词save 找到save all,更改为Ctrl+Shift+A,通过关键词select 找到select all,更改为Ctrl+A。

  添加文件类型

         用户可以定义自己的类型,Options->Document Options->add type,定义文件类型名以及文件名后缀。 勾选 include when adding to projects 在添加目录下文件到工程时该类文件就会添加进 SI 的工程。如果需要将所有文件添加进 SI 的工程,可以定义一种文件类型*.*。

   列操作

       先按下Alt 键,接着鼠标左键拖动鼠标进行列选择,然后就可以删除指定的列。

   添加自定义功能

        在 SI 中可以自定义命令,方便的调用外部程序。举个例子: 
  1. Options->Custom Commands...->Add...,New Command name 随便填入命令的名字; 
  2. Run 中写入: ShellExecute open explorer /e,/select,%f; 
    意思是打开资源管理器并选中当前文件。%f 为文件名。 
  3. 还是同一个对话框里面,选择 Keys->Assign New Key...->按下执行该命令的快捷键下面是一些关于TortoiseSVN 的常用自定义功能(需要更改相应的TSVN 安装目录): 
    查看修改(diff): "C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe" /command:diff /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

宏语言使用

             大家可能很少用到SI的宏语言(Source Insight macro language),这是一种功能强大的编程语言,几乎可以实现在编程过程可能使用到的各种功能。这里不准备对如何使用宏语言进行编程作介绍(可参阅SI帮助文档中的“Macro Language Guide”部分。),只介绍如何使用已编好的程序。更多的宏文件在http://www.sourceinsight.com/public/macros/下载。

    宏文件导入与使用

         宏文件,以.em 为后缀使用宏语言编写的文件,源文件中的每个“macro 宏名()”定义一个宏函数(功能),为宏名定义菜单或快捷键即可使用该功能。宏文件的使用方法如下: 
  1. Project->Open Project 
  打开 Base 工程(该工程一般在"我的文档/Source Insight/Projects/Base"中); 
  2. Project->Add and Remove Project Files 
  加入宏文件; 
  3. Options->Menu Assignments(或者把该宏功能定义为快捷键) 
  打开 Menu Assignments 窗口,在Command 中输入Macro,选中要使用的宏,添加到合适的菜单中。或者打开 Key Assignment 窗口,选中要使用的宏,点Assigned New Key,选择要使用的快捷键。设置完后,选择对应的菜单项或按快捷键,即可实现宏函数功能。

参考资料

           首选SI 自带的帮助文档(按F1 启动),有非常详细的说明。

 

原文:https://www.cnblogs.com/chinhao/p/4630144.html

 

macro InsFileHeader()
{
    szMyName = "XXX"    /* Enter your name */

    /* Get current time */
    szTime = GetSysTime(1)
    Day = szTime.Day
    Month = szTime.Month
    Year = szTime.Year
    if (Day < 10)
        szDay = "0@Day@"
    else
        szDay = Day
    if (Month < 10)
        szMonth = "0@Month@"
    else
        szMonth = Month;    
    
    szFileName        =    Ask("Enter file name and its extention, for example, \"main.c\": ");    

    /*    promote the description of the file*/
    szDescription    = Ask("Enter the description of file:")
    
    hBuf = GetCurrentBuf()
    hbuf = GetCurrentBuf()    
    InsBufLine(hbuf, 0,   "/*")
    InsBufLine(hbuf, 1,   " *")
    InsBufLine(hbuf, 2,   " *")
    InsBufLine(hbuf, 3,   " *\\file     @szfileName@")
    InsBufLine(hbuf, 4,   " *\\brief    @szDescription@.")
    InsBufLine(hbuf, 5,   " *")
    InsBufLine(hbuf, 6,   " *\\author   @szMyName@")
    InsBufLine(hbuf, 7,   " *\\version  1.0.0")
    InsBufLine(hbuf, 8,   " *\\date     @szMonth@\/@szDay@\/@Year@")
    InsBufLine(hbuf, 9,   " *")
    InsBufLine(hbuf, 10,  " *\\history  \\arg 1.0.0 @szMonth@\/@szDay@\/@Year@, @szMyName@, Create file.")
    InsBufLine(hbuf, 11,  " */")
}

macro InsFunHeader()
{
    // 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)

    szDescription = Ask("Enter the description of function:")

    // begin assembling the title string
    InsBufLine(hbuf, ln + 0,  "/*!")
    InsBufLine(hbuf, ln + 1,  " *\\fn              @szFunc@()")
    InsBufLine(hbuf, ln + 2,  " *\\brief           @szDescription@.")
    InsBufLine(hbuf, ln + 3,  " *\\details        ")
    InsBufLine(hbuf, ln + 4,  " * ")
    InsBufLine(hbuf, ln + 5,  " *\\param[in]    N\/A.")
    InsBufLine(hbuf, ln + 6,  " *\\param[out]   N\/A.")
    InsBufLine(hbuf, ln + 7,  " * ")
    InsBufLine(hbuf, ln + 8,  " *\\return        N\/A.")
    InsBufLine(hbuf, ln + 9,  " *\\retval        N\/A.")
    InsBufLine(hbuf, ln + 10, " * ")
    InsBufLine(hbuf, ln + 11, " *\\note")
    InsBufLine(hbuf, ln + 12, " */")
}

macro InsVarComments()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    szDef         = Ask("Enter the name of the variable:")
    szDescription = Ask("Enter the description of Varaables:")
    
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln + 0,  "/*!")
    InsBufLine(hbuf, ln + 1,  " *\\def          @szDef@")
    InsBufLine(hbuf, ln + 2,  " *\\brief           @szDescription@")
    InsBufLine(hbuf, ln + 3,  " */")
}

macro addNameTime()
{    
    szMyName = "XXX"    /* Enter your name */

    hwnd = GetCurrentWnd()
    se = getwndsel(hwnd)
    ln    = GetWndSelLnFirst(hwnd)
    hbuf = GetCurrentBuf()
    str = GetBufSelText(hbuf)

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

    if (se.fExtended)
    {
        str = "/*!<" #str# "*/"
        SetBufSelText(hbuf, str)
    }
    else
    {
        str = "/*!<  @szMyName@ : @szMonth@/@szDay@/@Year@*/"
        se.ichFirst = se.iChFirst + 3
        se.ichLim = se.ichLim + 3
        SetBufSelText(hbuf, str)        
        SetBufIns (hbuf, ln, se.iChFirst)    
        SetWndSel(hwnd, se)        
    }
}

macro preventIncludeRepeatly()
{
    hwnd    = GetCurrentWnd()
    lnFirst    = GetWndSelLnFirst(hwnd)
    lnLast    = GetWndSelLnLast(hwnd)

    /* get file name */
    szFileName    =    Ask("Enter name of header file:")    
    szFileName    =    toupper(szFileName)
    szFileName    =    cat("__", szFileName)
    szFileName    =    cat(szFileName, "_H__")
     
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, lnFirst,    "#ifndef @szFileName@")
    InsBufLine(hbuf, lnFirst +1,    "#define @szFileName@")
    InsBufLine(hbuf, lnFirst +2,    "")
    InsBufLine(hbuf, lnLast  +4,    "")
    InsBufLine(hbuf, lnLast  +5,    "#endif /* @szFileName@ */")
}


macro InsertCPlusPlus()
{
    hwnd    = GetCurrentWnd()
    lnFirst    = GetWndSelLnFirst(hwnd)
    lnLast    = GetWndSelLnLast(hwnd)
     
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, lnFirst,    "#ifdef __cplusplus")
    InsBufLine(hbuf, lnFirst +1,    "extern \"C\" {")
    InsBufLine(hbuf, lnFirst +2,    "#endif")    
    InsBufLine(hbuf, lnFirst +3,    "")
    
    InsBufLine(hbuf, lnLast  +5,    "")
    InsBufLine(hbuf, lnLast  +6,    "#ifdef __cplusplus")
    InsBufLine(hbuf, lnLast  +7,    "}")
    InsBufLine(hbuf, lnLast  +8,    "#endif")
}

macro addComment()
{
    hwnd = GetCurrentWnd()
    se = getwndsel(hwnd)
    ln    = GetWndSelLnFirst(hwnd)
    hbuf = GetCurrentBuf()
    str = GetBufSelText(hbuf)
    
    if (se.fExtended)
    {
        str = "/*!<" #str# "*/"
        SetBufSelText(hbuf, str)
    }
    else
    {
        str = "/*!<  */"
        se.ichFirst = se.iChFirst + 3
        se.ichLim = se.ichLim + 3
        SetBufSelText(hbuf, str)        
        SetBufIns (hbuf, ln, se.iChFirst)    
        SetWndSel(hwnd, se)        
    }
    
}

macro addFileInformation()
{
    addGlobalFunctions()
    addPublicFunctions()
    addLocalFunctions()
    addLocalPrototypes()
    addExternPrototypes()
    addFunctions()
    addVariables()
    addTypes()
    addDefines()
    addIncludeFiles()
    addConfigrations()    
}

macro addConfigrations()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                          CONFIGURATIONS                            */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")    
}

macro addIncludeFiles()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                          INCLUDE_FILES                             */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addDefines()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                           DEFINES                                  */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addTypes()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            TYPES                                   */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addVariables()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            VARIABLES                               */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addFunctions()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            FUNCTIONS                               */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addExternPrototypes()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            EXTERN_PROTOTYPES                       */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addLocalPrototypes()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            LOCAL_PROTOTYPES                        */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addLocalFunctions()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            LOCAL_FUNCTIONS                         */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addPublicFunctions()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            PUBLIC_FUNCTIONS                        */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}

macro addGlobalFunctions()
{
    hwnd = GetCurrentWnd()
    ln     = GetWndSelLnFirst(hwnd)

    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln,    "/**********************************************************************/")
    InsBufLine(hbuf, ln +1,    "/*                            GLOBAL_FUNCTIONS                        */")
    InsBufLine(hbuf, ln +2,    "/**********************************************************************/")

}
/*======================================================================
* -------Source Insight3 中文操作(左右键、删除和后退键)支持宏-------
* 用原来作者提供的方法使用工程中有的问题,于是换了种方式试了一下,测试OK,
* 现在只需按照下面的说明①--③应用即可,已经测试OK
* 感谢丁兆杰([email protected])及互联网上辛勤耕耘的朋友们!!!  
*                                                 Evan: [email protected]
*
* ① Project→Open Project,打开Base项目,将本文中的所有内容函数复制到utils.em文件的最后
* ② 重启SourceInsight;
* ③ Options→Key Assignments,将下面宏依次与相应按键绑定:
          Marco: SuperBackspace绑定到BackSpace键;
          Marco: SuperCursorLeft绑定到<-键,
          Marco: SuperCursorRight绑定到->键,
          Marco: SuperShiftCursorLeft绑定到Shift+<-,
          Macro: SuperShiftCursorRight绑定到shift+->,
          Macro: SuperDelete绑定到del。
* ④ Enjoy

======================================================================*/
/*======================================================================
1、BackSpace后退键
======================================================================*/
macro SuperBackspace()
{
    hwnd = GetCurrentWnd();
    hbuf = GetCurrentBuf();
    if (hbuf == 0)
        stop;   // empty buffer
    // get current cursor postion
    ipos = GetWndSelIchFirst(hwnd);
    // get current line number
    ln = GetBufLnCur(hbuf);
    if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
        // sth. was selected, del selection
        SetBufSelText(hbuf, " ");  // stupid & buggy sourceinsight 
        // del the " "
        SuperBackspace(1);
        stop;
    }
    // copy current line
    text = GetBufLine(hbuf, ln);
    // get string length
    len = strlen(text);
    // if the cursor is at the start of line, combine with prev line
    if (ipos == 0 || len == 0) {
        if (ln <= 0)
            stop;   // top of file
        ln = ln - 1;    // do not use "ln--" for compatibility with older versions
        prevline = GetBufLine(hbuf, ln);
        prevlen = strlen(prevline);
        // combine two lines
        text = cat(prevline, text);
        // del two lines
        DelBufLine(hbuf, ln);
        DelBufLine(hbuf, ln);
        // insert the combined one
        InsBufLine(hbuf, ln, text);
        // set the cursor position
        SetBufIns(hbuf, ln, prevlen);
        stop;
    }
    num = 1; // del one char
    if (ipos >= 1) {
        // process Chinese character
        i = ipos;
        count = 0;
        while (AsciiFromChar(text[i - 1]) >= 160) {
            i = i - 1;
            count = count + 1;
            if (i == 0)
                break;
        }
        if (count > 0) {
            // I think it might be a two-byte character
            num = 2;
            // This idiot does not support mod and bitwise operators
            if ((count / 2 * 2 != count) && (ipos < len))
                ipos = ipos + 1;    // adjust cursor position
        }
    }
    // keeping safe
    if (ipos - num < 0)
        num = ipos;
    // del char(s)
    text = cat(strmid(text, 0, ipos - num), strmid(text, ipos, len));
    DelBufLine(hbuf, ln);
    InsBufLine(hbuf, ln, text);
    SetBufIns(hbuf, ln, ipos - num);
    stop;
}
/*======================================================================
2、删除键——SuperDelete.em
======================================================================*/
macro SuperDelete()
{
    hwnd = GetCurrentWnd();
    hbuf = GetCurrentBuf();
    if (hbuf == 0)
        stop;   // empty buffer
    // get current cursor postion
    ipos = GetWndSelIchFirst(hwnd);
    // get current line number
    ln = GetBufLnCur(hbuf);
    if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
        // sth. was selected, del selection
        SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight 
        // del the " "
        SuperDelete(1);
        stop;
    }
    // copy current line
    text = GetBufLine(hbuf, ln);
    // get string length
    len = strlen(text);
      
    if (ipos == len || len == 0) {
totalLn = GetBufLineCount (hbuf);
lastText = GetBufLine(hBuf, totalLn-1);
lastLen = strlen(lastText);
        if (ipos == lastLen)// end of file
   stop;
        ln = ln + 1;    // do not use "ln--" for compatibility with older versions
        nextline = GetBufLine(hbuf, ln);
        nextlen = strlen(nextline);
        // combine two lines
        text = cat(text, nextline);
        // del two lines
        DelBufLine(hbuf, ln-1);
        DelBufLine(hbuf, ln-1);
        // insert the combined one
        InsBufLine(hbuf, ln-1, text);
        // set the cursor position
        SetBufIns(hbuf, ln-1, len);
        stop;
    }
    num = 1; // del one char
    if (ipos > 0) {
        // process Chinese character
        i = ipos;
        count = 0;
      while (AsciiFromChar(text[i-1]) >= 160) {
            i = i - 1;
            count = count + 1;
            if (i == 0)
                break;
        }
        if (count > 0) {
            // I think it might be a two-byte character
            num = 2;
            // This idiot does not support mod and bitwise operators
            if (((count / 2 * 2 != count) || count == 0) && (ipos < len-1))
                ipos = ipos + 1;    // adjust cursor position
        }
// keeping safe
if (ipos - num < 0)
            num = ipos;
    }
    else {
i = ipos;
count = 0;
while(AsciiFromChar(text) >= 160) {
     i = i + 1;
     count = count + 1;
     if(i == len-1)
   break;
}
if(count > 0) {
     num = 2;
}
    }
   
    text = cat(strmid(text, 0, ipos), strmid(text, ipos+num, len));
    DelBufLine(hbuf, ln);
    InsBufLine(hbuf, ln, text);
    SetBufIns(hbuf, ln, ipos);
    stop;
}
/*======================================================================
3、左移键——SuperCursorLeft.em
======================================================================*/
macro IsComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
   return 0;
//当前位置
pos = GetWndSelIchFirst(hwnd);
//当前行数
ln = GetBufLnCur(hbuf);
//得到当前行
text = GetBufLine(hbuf, ln);
//得到当前行长度
len = strlen(text);
//从头计算汉字字符的个数
if(pos > 0)
{
   i=pos;
   count=0;
   while(AsciiFromChar(text[i-1]) >= 160)
   { 
    i = i - 1;
    count = count+1;
    if(i == 0) 
     break;
   }
   if((count/2)*2==count|| count==0)
    return 0;
   else
    return 1;
}
return 0;
}
macro moveleft()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
        stop;   // empty buffer
       
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
if(GetBufSelText(hbuf) != "" || (ipos == 0 && ln == 0))   // 第0行或者是选中文字,则不移动
{
   SetBufIns(hbuf, ln, ipos);
   stop;
}
if(ipos == 0)
{
   preLine = GetBufLine(hbuf, ln-1);
   SetBufIns(hBuf, ln-1, strlen(preLine)-1);
}
else
{
   SetBufIns(hBuf, ln, ipos-1);
}
}
macro SuperCursorLeft()
{
moveleft();
if(IsComplexCharacter())
   moveleft();
}
/*======================================================================
4、右移键——SuperCursorRight.em
======================================================================*/
macro moveRight()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
        stop;   // empty buffer
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln); 
if(GetBufSelText(hbuf) != "")   //选中文字
{
   ipos = GetWndSelIchLim(hwnd);
   ln = GetWndSelLnLast(hwnd);
   SetBufIns(hbuf, ln, ipos);
   stop;
}
if(ipos == strlen(text)-1 && ln == totalLn-1) // 末行
   stop;      
if(ipos == strlen(text))
{
   SetBufIns(hBuf, ln+1, 0);
}
else
{
   SetBufIns(hBuf, ln, ipos+1);
}
}
macro SuperCursorRight()
{
moveRight();
if(IsComplexCharacter()) // defined in SuperCursorLeft.em
   moveRight();
}
/*======================================================================
5、shift+右移键——ShiftCursorRight.em
======================================================================*/
macro IsShiftRightComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
   return 0;
selRec = GetWndSel(hwnd);
pos = selRec.ichLim;
ln = selRec.lnLast;
text = GetBufLine(hbuf, ln);
len = strlen(text);
if(len == 0 || len < pos)
return 1;
//Msg("@len@;@pos@;");
if(pos > 0)
{
   i=pos;
   count=0; 
   while(AsciiFromChar(text[i-1]) >= 160)
   { 
    i = i - 1;
    count = count+1;   
    if(i == 0) 
     break;    
   }
   if((count/2)*2==count|| count==0)
    return 0;
   else
    return 1;
}
return 0;
}
macro shiftMoveRight()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
        stop; 
       
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln); 
selRec = GetWndSel(hwnd);   
curLen = GetBufLineLength(hbuf, selRec.lnLast);
if(selRec.ichLim == curLen+1 || curLen == 0)
{ 
   if(selRec.lnLast == totalLn -1)
    stop;
   selRec.lnLast = selRec.lnLast + 1; 
   selRec.ichLim = 1;
   SetWndSel(hwnd, selRec);
   if(IsShiftRightComplexCharacter())
    shiftMoveRight();
   stop;
}
selRec.ichLim = selRec.ichLim+1;
SetWndSel(hwnd, selRec);
}
macro SuperShiftCursorRight()
{       
if(IsComplexCharacter())
   SuperCursorRight();
shiftMoveRight();
if(IsShiftRightComplexCharacter())
   shiftMoveRight();
}
/*======================================================================
6、shift+左移键——ShiftCursorLeft.em
======================================================================*/
macro IsShiftLeftComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
   return 0;
selRec = GetWndSel(hwnd);
pos = selRec.ichFirst;
ln = selRec.lnFirst;
text = GetBufLine(hbuf, ln);
len = strlen(text);
if(len == 0 || len < pos)
   return 1;
//Msg("@len@;@pos@;");
if(pos > 0)
{
   i=pos;
   count=0; 
   while(AsciiFromChar(text[i-1]) >= 160)
   { 
    i = i - 1;
    count = count+1;   
    if(i == 0) 
     break;    
   }
   if((count/2)*2==count|| count==0)
    return 0;
   else
    return 1;
}
return 0;
}
macro shiftMoveLeft()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == 0)
        stop; 
       
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln); 
selRec = GetWndSel(hwnd);   
//curLen = GetBufLineLength(hbuf, selRec.lnFirst);
//Msg("@curLen@;@selRec@");
if(selRec.ichFirst == 0)
{ 
   if(selRec.lnFirst == 0)
    stop;
   selRec.lnFirst = selRec.lnFirst - 1;
   selRec.ichFirst = GetBufLineLength(hbuf, selRec.lnFirst)-1;
   SetWndSel(hwnd, selRec);
   if(IsShiftLeftComplexCharacter())
    shiftMoveLeft();
   stop;
}
selRec.ichFirst = selRec.ichFirst-1;
SetWndSel(hwnd, selRec);
}
macro SuperShiftCursorLeft()
{
if(IsComplexCharacter())
   SuperCursorLeft();
shiftMoveLeft();
if(IsShiftLeftComplexCharacter())
   shiftMoveLeft();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章