• 分享:Source Insight常用宏


    /*****************************************************************************************************
    * 功能: Source Insight常用宏(Jamie专用)
    *
    * 文件: Utils_Jamie.em
    *
    * 说明: 1. 修改第一个宏GetName,将名字改为自己的,注意双引号不能删除
    * 2. 运行Soucre Insight,打开Base工程,将Utils_Jamie.em加入到工程中
    * 3. 打开Soucre Insight的Options的Key Assignments菜单,在Command窗口中输入字母"M",选择Macro: JamieHelp
    * 单击Assign New Key对其赋一个热键,例如 ALT + ~ ( ~ 为键ESC下面的键)
    * 4. 在 c或h 源文件按 ALT + ~ ,即可出现帮助宏的效果, 请参照帮助设其他宏快捷键
    * 5. 打开Soucre Insight的Options的Document Options, Tab Width设 4
    *
    * 作者: Jamie 2013/01/17
    *****************************************************************************************************/
    macro GetName()
    {
    szMyName = "Jamie"
    return szMyName
    }

    // 【帮助ALT+0~9 CTRL+1~8 】
    macro JamieHelp()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    lnFirst = ln
    InsBufLine(hbuf, ln++, "/*********************** Utils_Jamie.em 使用帮助(快捷键提示) *********************/");
    InsBufLine(hbuf, ln++, "");
    InsBufLine(hbuf, ln++, "//【【注释类】】");
    InsBufLine(hbuf, ln++, "< ALT + 1 > //JamieFunHead 函数头注释,请将光标放在函数头或函数体的任意地方");
    InsBufLine(hbuf, ln++, "< ALT + 2 > //JamieFunHistory 函数修改注释,请将光标放在函数头或函数体的任意地方");
    InsBufLine(hbuf, ln++, "< ALT + 3 > //JamieCommentLine 语句右侧插入行注释, //前有两个tab键");
    InsBufLine(hbuf, ln++, "< ALT + 4 > //JamieCommentBlock【插入一空行,下一行 // 】, 用于在代码段的 上方 插入块注释 ");
    InsBufLine(hbuf, ln++, "< ALT + 5 > //JamieSlashMask 屏蔽多行,使用多个//");
    InsBufLine(hbuf, ln++, "< ALT + 6 > //JamieSlashUnMask 去掉//多行屏蔽");
    InsBufLine(hbuf, ln++, "< ALT + 7 > //JamieIf0 屏蔽多行,使用条件语句");
    InsBufLine(hbuf, ln++, "< ALT + 8 > //JamieUnIf0 去掉#if0多行屏蔽(也可以去掉选中的头尾行)");
    InsBufLine(hbuf, ln++, "< ALT + 9 > //JamieNewFileC 新的 c 文件模板");
    InsBufLine(hbuf, ln++, "< ALT + 0 > //JamieNewFileH 新的 h 文件模板");
    InsBufLine(hbuf, ln++, "");
    InsBufLine(hbuf, ln++, "//【【结构语句】】");
    InsBufLine(hbuf, ln++, "< CTRL + 1 > //JamieFor");
    InsBufLine(hbuf, ln++, "< CTRL + 2 > //JamieIf");
    InsBufLine(hbuf, ln++, "< CTRL + 3 > //JamieSwitch");
    InsBufLine(hbuf, ln++, "< CTRL + 4 > //JamieWhile");
    InsBufLine(hbuf, ln++, "< CTRL + 5 > //JamiePrintfM【Uart_Printf(有__MODULE__)】,自己加入模块前缀 ");
    InsBufLine(hbuf, ln++, "< CTRL + 6 > //JamiePrintf【Uart_Printf()】,自己加入模块前缀");
    InsBufLine(hbuf, ln++, "");
    InsBufLine(hbuf, ln++, "//【【条件编译】】");
    InsBufLine(hbuf, ln++, "< CTRL + 7 > //JamieIfDef ,条件编译");
    InsBufLine(hbuf, ln++, "");
    InsBufLine(hbuf, ln++, "//【【帮助】】");
    InsBufLine(hbuf, ln++, "< CTRL + 8 > //JamieHelp,帮助信息");
    InsBufLine(hbuf, ln++, "");
    InsBufLine(hbuf, ln++, "");
    InsBufLine(hbuf, ln++, "void CTRL();#define ALT // 用于ALT和CTRL颜色区别");
    InsBufLine(hbuf, ln++, "/* 作者: JamieChen 2013/01/17");
    InsBufLine(hbuf, ln++, " 说明: 此帮助用后需删除。可按这种顺序分配宏,也可DIY。建议TAB键为4个空格!");
    InsBufLine(hbuf, ln++, "**********************************************************************************/");
    }

    // 【新的 C 文件】
    macro JamieNewFileC()
    {
    szMyName = GetName()
    ln = GetBufLnCur(GetCurrentBuf())
    szTime = GetSysTime(1)
    szDay = szTime.Day
    szMonth = szTime.Month
    szYear = szTime.Year
    szFuntion = ASK("请填写该C文件的说明,如: 自动设置")
    hbuf = GetCurrentBuf()
    szFile = GetFileName("f", GetBufName(hbuf))
    szDefine = GetFileName("n", GetBufName(hbuf))
    szDefineCase = toupper(szDefine)
    InsBufLine(hbuf, ln++, "/*******************************************************************************")
    InsBufLine(hbuf, ln++, "* 版 权: XX有限公司")
    lnInc = ln
    InsBufLine(hbuf, lnInc++, "* 项 目: ")
    InsBufLine(hbuf, lnInc++, "* 文 件: @szFile@")
    InsBufLine(hbuf, lnInc++, "* 作 者: @szMyName@")
    InsBufLine(hbuf, lnInc++, "* 时 间: @szYear@-@szMonth@-@szDay@")
    InsBufLine(hbuf, lnInc++, "* 说 明: @szFuntion@")
    InsBufLine(hbuf, lnInc++, "*******************************************************************************/")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// Includes")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// Defines / typedef")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// Global variables")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// code of Function")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "")
    SetBufIns( hbuf, ln, strlen("* 项 目: ") ) // 光标定位
    }

    // 【新的 H 文件】
    macro JamieNewFileH()
    {
    szMyName = GetName()
    ln = GetBufLnCur(GetCurrentBuf())
    szTime = GetSysTime(1)
    szDay = szTime.Day
    szMonth = szTime.Month
    szYear = szTime.Year
    hbuf = GetCurrentBuf()
    szFile = GetFileName("f", GetBufName(hbuf))
    szFileLen = strlen(szFile) - 1 // 判断是不是.h的文件
    if(szFile[szFileLen] == "h" || szFile[szFileLen] == "H")
    {
    }
    else
    {
    msg("该文件的扩展名不是 .h或.H !!!")
    stop
    }
    szDefine = GetFileName("n", GetBufName(hbuf))
    szDefineCase = toupper(szDefine)
    InsBufLine(hbuf, ln++, "/*******************************************************************************")
    InsBufLine(hbuf, ln++, "* 版 权: XX有限公司")
    lnInc = ln
    InsBufLine(hbuf, lnInc++, "* 项 目: ")
    InsBufLine(hbuf, lnInc++, "* 文 件: @szFile@")
    InsBufLine(hbuf, lnInc++, "* 作 者: @szMyName@")
    InsBufLine(hbuf, lnInc++, "* 时 间: @szYear@-@szMonth@-@szDay@")
    InsBufLine(hbuf, lnInc++, "* 说 明: ")
    InsBufLine(hbuf, lnInc++, "*******************************************************************************/")
    InsBufLine(hbuf, lnInc++, "#ifndef _@szDefineCase@_H_")
    InsBufLine(hbuf, lnInc++, "#define _@szDefineCase@_H_")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// Includes")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// Defines / typedef")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// Global variables declaretion")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "// Function prototypes")
    InsBufLine(hbuf, lnInc++, "//---------------------------------------------------------------------------")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "")
    InsBufLine(hbuf, lnInc++, "#endif /* endof #ifndef _@szDefineCase@_H_ */")
    SetBufIns( hbuf, ln, strlen("* 项 目: ") ) // 光标定位
    }

    /*******************************************************************************
    函数名称: JamieFunHead
    函数功能: 【函数头说明】,请将光标放在 函数头(如:int main() )或函数内 的任意地方
    输入参数: 无
    返 回 值: 无
    修 改 人: Jamie 创建时间: 2013-1-28
    *******************************************************************************/
    macro JamieFunHead()
    {
    szMyName = GetName()
    hwnd = GetCurrentWnd()
    hbuf = GetWndBuf(hwnd)
    ln = GetBufLnCur(GetCurrentBuf())
    lnCur = ln
    sel = GetWndSel(hwnd)
    szFuncName = GetCurSymbol()
    szTime = GetSysTime(1) //获取系统时间
    szDay = szTime.Day
    szMonth = szTime.Month
    szYear = szTime.Year
    symbol = GetSymbolLocationFromLn(hbuf, ln)
    if(strlen(symbol) == 0)
    {
    msg("请将光标放在 函数头(如:int main() )或函数内 的任意地方")
    stop
    }
    hTmpBuf = NewBuf("Tempbuf")
    if(hTmpBuf == hNil)
    {
    stop
    }
    szLine = GetFunctionDef(hbuf,symbol) // 将文件参数头整理成一行并去掉了注释和无用的空格
    iBegin = symbol.ichName
    nMaxParamSize = GetWordFromString(hTmpBuf,szLine,iBegin,strlen(szLine),"(",",",")") // 从函数头分离出函数参数
    lnMax = GetBufLineCount(hTmpBuf)
    ln = symbol.lnFirst
    SetBufIns (hbuf, ln, 0)
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln++, "/*******************************************************************************")
    InsBufLine(hbuf, ln++, "* 函数名称: @szFuncName@")
    nLineInc = ln
    InsBufLine(hbuf, nLineInc++, "* 函数功能: ")

    szIns = "* 输入参数: " // 对于已经存在的函数插入函数参数
    if (lnMax == 0)
    {
    szIns = cat(szIns, "无")
    InsBufLine(hbuf, nLineInc++, "@szIns@")
    }
    else
    {
    i = 0
    nVoid = 0
    while ( i < lnMax)
    {
    szTmp = GetBufLine(hTmpBuf, i)
    nLen = strlen(szTmp);

    if (szTmp[0] == "v" && szTmp[1] == "o" && szTmp[2] == "i" && szTmp[3] == "d")
    {
    szTmp = "无"
    nVoid = 1
    }

    szTmp = cat(szIns, szTmp)
    if (nVoid == 0)
    {
    szTmp = cat(szTmp, " ")
    }
    InsBufLine(hbuf, nLineInc++, "@szTmp@")
    szIns = " "
    i = i + 1
    }
    }
    ClearBuf(hTmpBuf)
    CloseBuf(hTmpBuf)
    if (szLine[0] == "v" && szLine[1] == "o" && szLine[2] == "i" && szLine[3] == "d")
    {
    InsBufLine(hbuf, nLineInc++, "* 返 回 值: 无")
    }
    else
    {
    InsBufLine(hbuf, nLineInc++, "* 返 回 值: ")
    }
    InsBufLine(hbuf, nLineInc++, "* 创 建 人: @szMyName@")
    InsBufLine(hbuf, nLineInc++, "* 创建时间: @szYear@-@szMonth@-@szDay@")
    InsBufLine(hbuf, nLineInc++, "*******************************************************************************/")
    SetBufIns( hbuf, ln, strlen("* 函数功能: ") )
    }

    // 【插入函数头修改历史】 光标必须放在函数头反括号 ) 之后
    macro JamieFunHistory()
    {
    szMyName = GetName()
    hwnd = GetCurrentWnd()
    hbuf = GetWndBuf(hwnd)
    ln = GetBufLnCur(GetCurrentBuf())
    symbol = GetSymbolLocationFromLn(hbuf, ln)
    if(strlen(symbol) == 0)
    {
    msg("【插入函数头修改历史】 请将光标放在 函数头(如:int main() )或函数内 的任意地方")
    stop
    }
    ln = symbol.lnFirst
    if(ln == 0)
    {
    msg("【插入函数头修改历史】 改函数没有函数头说明,请先插入函数头说明!")
    stop
    }
    else
    {
    ln = ln - 1
    szLine = GetBufLine(hbuf, ln)
    if(szLine[0] != "*")
    {
    msg("【插入函数头修改历史】 改函数没有函数头说明,请先插入函数头说明!")
    stop
    }
    }

    szTime = GetSysTime(1)
    szDay = szTime.Day
    szMonth = szTime.Month
    szYear = szTime.Year
    szNum = Ask("请输入修改的次数,从 1 开始递增")
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, ln, "---------------------------------- 修改历史 @szNum@ -------------------------------")
    InsBufLine(hbuf, ln + 1, "* 修改内容: ")
    InsBufLine(hbuf, ln + 2, "* 修 改 人: @szMyName@")
    InsBufLine(hbuf, ln + 2, "* 修改时间: @szYear@-@szMonth@-@szDay@")
    SetBufIns( hbuf, ln + 1, strlen("* 修改内容: ") )
    }

    // 【Uart_Printf(有__MODULE__)】,自己加入模块前缀
    macro JamiePrintfM()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    szLineGet = GetBufLine(hbuf, ln)
    szLine = cat(szLineGet, "UartPrintf( "%s(%d): \n", __MODULE__, __LINE__ );" )
    PutBufLine(hbuf, ln, szLine)
    SetBufIns( hbuf, ln , strlen(szLineGet) ) // 定光标位置
    }

    // 【Uart_Printf()】,自己加入模块前缀
    macro JamiePrintf()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    szLineGet = GetBufLine(hbuf, ln)
    szLine = cat(szLineGet, "UartPrintf( " ", 0 );" )
    PutBufLine(hbuf, ln, szLine)
    SetBufIns( hbuf, ln , strlen("UartPrintf(")+2 ) // 定光标位置
    }

    // 【#if 编译的条件 #endif】
    macro JamieIfDef()
    {
    hwnd = GetCurrentWnd()
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd)
    szCondition = Ask("请输入编译的条件,如: DUBUG > 0")
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, lnFirst++, "#if @szCondition@")
    InsBufLine(hbuf, lnFirst, " ")
    InsBufLine(hbuf, lnLast + 2, "#endif")
    SetBufIns(hbuf, lnFirst, 4 ) // 定光标位置
    }

    // 屏蔽多行【#if 0 #endif】
    macro JamieIf0()
    {
    hwnd = GetCurrentWnd()
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd)
    hbuf = GetCurrentBuf()
    InsBufLine(hbuf, lnFirst, "#if 0")
    InsBufLine(hbuf, lnLast+2, "#endif")
    }

    // 去掉多行屏蔽【#if 0 #endif (即去掉选中的 头尾 行)】
    macro JamieUnIf0()
    {
    hwnd = GetCurrentWnd()
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd)
    hbuf = GetCurrentBuf()
    DelBufLine(hbuf, lnFirst)
    DelBufLine(hbuf, lnLast-1)
    }

    // 用 // 屏蔽多行【// int i = 0;】
    macro JamieSlashMask()
    {
    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);
    }

    // 去掉 // 屏蔽多行
    macro JamieSlashUnMask()
    {
    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 JamieCommentBlock()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    InsBufLine(hbuf, ln, "/* */");
    szLineGet = GetBufLine(hbuf, ln);
    SetBufIns( hbuf, ln , strlen(szLineGet)/2) // 定光标位置
    }

    // 【 // 】, //前两个tab键,用于在代码行的 右边 插入块注释
    macro JamieCommentLine()
    {
    hbuf = GetCurrentBuf(); //获得光标所在的所有内容
    ln = GetBufLnCur(hbuf) //当前行序号
    szLineGet = GetBufLine(hbuf, ln); //得到当前行内容
    szLine = cat(szLineGet, " // " ); // /*号前面是两个tab键
    PutBufLine(hbuf, ln, szLine); // 在原位置输出新组合后的内容
    SetBufIns( hbuf, ln , strlen(szLineGet) + strlen( " // ") ) // 定光标位置,/*号前面是两个tab键
    }

    // 【if()】 if前是不能有内容的
    macro JamieIf()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    szLineGet = GetBufLine(hbuf, ln);
    szLine = cat(szLineGet, "if( )" );
    PutBufLine(hbuf, ln, szLine);
    InsBufLine(hbuf, ln + 1, "@szLineGet@{");
    InsBufLine(hbuf, ln + 2, "@szLineGet@ "); // 后面加个tab键
    InsBufLine(hbuf, ln + 3, "@szLineGet@}");
    SetBufIns( hbuf, ln , strlen(szLineGet) + strlen( "if( ") ) // 定光标位置
    }

    // 【for()】
    macro JamieFor()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    szLineGet = GetBufLine(hbuf, ln);
    sVar = ASK("请填写循环的变量,如 i ")
    szLine = cat(szLineGet, "for( @sVar@ = 0; @sVar@ < ; @sVar@++ )" );
    PutBufLine(hbuf, ln, szLine);
    InsBufLine(hbuf, ln + 1, "@szLineGet@{");
    InsBufLine(hbuf, ln + 2, "@szLineGet@ "); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + 3, "@szLineGet@}");
    SetBufIns( hbuf, ln , strlen(szLineGet) + strlen( "for( @sVar@ = 0; @sVar@ < ") ) // 定光标位置
    }

    // 【while() { }】
    macro JamieWhile()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    szLineGet = GetBufLine(hbuf, ln);

    szLine = cat(szLineGet, "while( )" );
    PutBufLine(hbuf, ln, szLine);
    InsBufLine(hbuf, ln + 1, "@szLineGet@{");
    InsBufLine(hbuf, ln + 2, "@szLineGet@ "); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + 3, "@szLineGet@}");

    SetBufIns( hbuf, ln , strlen(szLineGet) + strlen("while( ")) // 定光标位置
    }

    // 【switch(){case:break;case:break;default:break;}】
    macro JamieSwitch()
    {
    hbuf = GetCurrentBuf(); // 获得光标所在的所有内容
    ln = GetBufLnCur(hbuf)
    szLineGet = GetBufLine(hbuf, ln);
    i = 1;
    szLine = cat(szLineGet, "switch( )" );
    PutBufLine(hbuf, ln, szLine);
    InsBufLine(hbuf, ln + i++, "@szLineGet@{");
    InsBufLine(hbuf, ln + i++, "@szLineGet@ case :"); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@ "); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@ break;"); // 后面加个tab键(用4个空格替代)

    InsBufLine(hbuf, ln + i++, "@szLineGet@ case :"); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@ "); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@ break;"); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@"); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@ default:"); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@ "); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i++, "@szLineGet@ break;"); // 后面加个tab键(用4个空格替代)
    InsBufLine(hbuf, ln + i, "@szLineGet@}");

    SetBufIns( hbuf, ln , strlen(szLineGet) + strlen("switch( ")) // 定光标位置
    }

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

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

    return tabSize;
    }

    macro strstr(str1,str2)
    {
    i = 0
    j = 0
    len1 = strlen(str1)
    len2 = strlen(str2)
    if((len1 == 0) || (len2 == 0))
    {
    return 0xffffffff
    }
    while( i < len1)
    {
    if(str1[i] == str2[j])
    {
    while(j < len2)
    {
    j = j + 1
    if(str1[i+j] != str2[j])
    {
    break
    }
    }
    if(j == len2)
    {
    return i
    }
    j = 0
    }
    i = i + 1
    }
    return 0xffffffff
    }

    macro TrimString(szLine)
    {
    szLine = TrimLeft(szLine)
    szLIne = TrimRight(szLine)
    return szLine
    }

    macro TrimLeft(szLine)
    {
    nLen = strlen(szLine)
    if(nLen == 0)
    {
    return szLine
    }
    nIdx = 0
    while( nIdx < nLen )
    {
    if( ( szLine[nIdx] != " ") && (szLine[nIdx] != " ") )
    {
    break
    }
    nIdx = nIdx + 1
    }
    return strmid(szLine,nIdx,nLen)
    }

    macro TrimRight(szLine)
    {
    nLen = strlen(szLine)
    if(nLen == 0)
    {
    return szLine
    }
    nIdx = nLen
    while( nIdx > 0 )
    {
    nIdx = nIdx - 1
    if( ( szLine[nIdx] != " ") && (szLine[nIdx] != " ") )
    {
    break
    }
    }
    return strmid(szLine,0,nIdx+1)
    }

    macro GetWordFromString(hbuf,szLine,nBeg,nEnd,chBeg,chSeparator,chEnd)
    {
    if((nEnd > strlen(szLine) || (nBeg > nEnd))
    {
    return 0
    }
    nMaxLen = 0
    nIdx = nBeg
    //先定位到开始字符标记处
    while(nIdx < nEnd)
    {
    if(szLine[nIdx] == chBeg)
    {
    break
    }
    nIdx = nIdx + 1
    }
    nBegWord = nIdx + 1

    //用于检测chBeg和chEnd的配对情况
    iCount = 0
    nEndWord = 0
    //以分隔符为标记进行搜索
    while(nIdx < nEnd)
    {
    if(szLine[nIdx] == chSeparator)
    {
    szWord = strmid(szLine,nBegWord,nIdx)
    szWord = TrimString(szWord)
    nLen = strlen(szWord)
    if(nMaxLen < nLen)
    {
    nMaxLen = nLen
    }
    AppendBufLine(hbuf,szWord)
    nBegWord = nIdx + 1
    }
    if(szLine[nIdx] == chBeg)
    {
    iCount = iCount + 1
    }
    if(szLine[nIdx] == chEnd)
    {
    iCount = iCount - 1
    nEndWord = nIdx
    if( iCount == 0 )
    {
    break
    }
    }
    nIdx = nIdx + 1
    }
    if(nEndWord > nBegWord)
    {
    szWord = strmid(szLine,nBegWord,nEndWord)
    szWord = TrimString(szWord)
    nLen = strlen(szWord)
    if(nMaxLen < nLen)
    {
    nMaxLen = nLen
    }
    AppendBufLine(hbuf,szWord)
    }
    return nMaxLen
    }

    macro GetFunctionDef(hbuf,symbol)
    {
    ln = symbol.lnName
    szFunc = ""
    if(strlen(symbol) == 0)
    {
    return szFunc
    }
    fIsEnd = 1
    //msg(symbol)
    while(ln < symbol.lnLim)
    {
    szLine = GetBufLine (hbuf, ln)
    //去掉被注释掉的内容
    RetVal = SkipCommentFromString(szLine,fIsEnd)
    szLine = RetVal.szContent
    szLine = TrimString(szLine)
    fIsEnd = RetVal.fIsEnd
    //如果是{表示函数参数头结束了
    ret = strstr(szLine,"{")
    if(ret != 0xffffffff)
    {
    szLine = strmid(szLine,0,ret)
    szFunc = cat(szFunc,szLine)
    break
    }
    szFunc = cat(szFunc,szLine)
    ln = ln + 1
    }
    return szFunc
    }

    macro SkipCommentFromString(szLine,isCommentEnd)
    {
    RetVal = ""
    fIsEnd = 1
    nLen = strlen(szLine)
    nIdx = 0
    while(nIdx < nLen )
    {
    //如果当前行开始还是被注释,或遇到了注释开始的变标记,注释内容改为空格?
    if( (isCommentEnd == 0) || (szLine[nIdx] == "/" && szLine[nIdx+1] == "*"))
    {
    fIsEnd = 0
    while(nIdx < nLen )
    {
    if(szLine[nIdx] == "*" && szLine[nIdx+1] == "/")
    {
    szLine[nIdx+1] = " "
    szLine[nIdx] = " "
    nIdx = nIdx + 1
    fIsEnd = 1
    isCommentEnd = 1
    break
    }
    szLine[nIdx] = " "
    nIdx = nIdx + 1
    }

    //如果已经到了行尾终止搜索
    if(nIdx == nLen)
    {
    break
    }
    }

    //如果遇到的是//来注释的说明后面都为注释
    if(szLine[nIdx] == "/" && szLine[nIdx+1] == "/")
    {
    szLine = strmid(szLine,0,nIdx)
    break
    }
    nIdx = nIdx + 1
    }
    RetVal.szContent = szLine;
    RetVal.fIsEnd = fIsEnd
    return RetVal
    }

    // 获得文件名 如从 c:/main.c 得到 main.c type = "f"获得main.c type = "n"获得main
    macro GetFileName(type, pathName)
    {
    nLength = strlen(pathName)
    i = nLength - 1
    if (type == "n")
    {
    nLength = nLength - 2
    }
    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
    }

    /**
    * ╭︿︿︿╮
    * {/ . .}
    * ( (oo) )
    * ︶︶︶︶
    * 猪 哥 作 品
    *
    * 2006 丁兆杰 Ding Zhaojie
    * zhaojie.ding@gmail.coms
    *
    * SuperBackspace Version 0.1beta
    *
    * 代替SourceInsight原有的Backspace功能(希望如此)
    * 增加了对双字节汉字的支持,在删除汉字的时候也能同时删除汉字的高字节而缓解半个汉字问题
    * 能够对光标在汉字中间的情况进行自动修正
    *
    * 安装:
    * ① 复制入SourceInsight安装目录;
    * ② Project→Open Project,打开Base项目;
    * ③ 将复制过去的SuperBackspace.em添加入Base项目;
    * ④ 重启SourceInsight;
    * ⑤ Options→Key Assignments,将Marco: SuperBackspace绑定到BackSpace键;
    * ⑥ Enjoy!!
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    *
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    */
    macro JamieSuperBackspace()
    {
    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 " "
    JamieSuperBackspace(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;
    }

  • 相关阅读:
    python 输出所有列表元素的乘积
    shell 变量赋值运算
    shell 判断变量是否为空
    js 获取地址栏域名以及URL
    python 获取列表大于指定长度的元素
    python 判断列表字符串元素首尾字符是否相同
    python 通过列表元素值截取列表并获取长度
    python 判断两个列表是否有公共元素
    python 获取列表的键值对
    python 判断列表的包含关系
  • 原文地址:https://www.cnblogs.com/jamiechen/p/sourceinsightmacro.html
Copyright © 2020-2023  润新知