简单来说,source insight提供的功能功能还不够傻瓜,用起来还不够方便,所以写了此脚本,提高开发效率。

部分source insight提供的功能也包含了进来,主要是因为我不喜欢使用太多的快捷键。

将代码中wcjMain关联到alt+a快捷键,随后输入你想操作的指令:如cb代表在本行之前添加注释即可。

目前提供的指令有20种左右,后面根据需要在补充。

1. 这个source insight中用的脚本,将其另存为任意名称.em文件

2. base工程中add该脚本

3. 在option->key assignment中将wcjMain关联某个快捷键后即可使用

4. 该脚本功能包括:

  • 类型替换
  • 注释添加
  • 标准的C头文件及实现文件的标准格式添加
  • 部分宏操作
  • 自动添加include
  • 增加var支持
  •  macro _wcjFileName(fullname)
    {
    length = strlen(fullname)
    if (length == )
    return "" index = length
    while ("\\" != fullname[--index]); purename = ""
    while (index < length)
    purename = cat(purename, fullname[++index]) return purename
    }
    /* 获取当前的文件名*/
    macro _wcjCurrentFileName()
    {
    hbuf = GetCurrentBuf()
    fullname = GetBufName(hbuf) return _wcjFileName(fullname)
    } /*头文件定义名称*/
    macro wcjIncDefName()
    {
    filename = _wcjCurrentFileName();
    length = strlen(filename); defname = "__"
    index = ;
    while (index < length)
    {
    if (filename[index] == ".")
    defname = cat(defname, "_")
    else
    defname = cat(defname, toupper(filename[index])) ++index
    } defname = cat(defname, "__") return defname
    } /*获取当前时间*/
    macro wcjGetTime()
    {
    var year
    var month
    var day
    var commTime
    var sysTime sysTime = GetSysTime()
    year = sysTime.Year
    month = sysTime.month
    day = sysTime.day
    commTime = "@year@-@month@-@day@"
    return commTime
    } /**************************************new file related***********************************************/
    macro _wcjCommentFile()
    {
    szMyName = "wangchunjie w00361341" hbuf = GetCurrentBuf()
    ln =
    InsBufLine(hbuf, ln++, "/*-------------------------------------------------------------------------")
    InsBufLine(hbuf, ln++, cat(" File: ", _wcjCurrentFileName())
    InsBufLine(hbuf, ln++, cat(" Author: ", szMyName))
    InsBufLine(hbuf, ln++, cat(" Date: ", wcjGetTime())
    InsBufLine(hbuf, ln++, cat(" Desc: ", ""))
    InsBufLine(hbuf, ln++, "-------------------------------------------------------------------------*/") /* 设置光标正确的位置 */
    SetBufIns(hbuf, ln, ) return true
    } /*在当前行的前一行添加注释*/
    macro _wcjCommentBefore()
    {
    hbuf = GetCurrentBuf()
    ln = GetBufLnCur(hbuf) comment = "" /*补足空格*/
    text = GetBufLine(hbuf, ln)
    index =
    while (true)
    {
    c = text[index++]
    if (c != " " && c != " ")
    break; comment = cat(comment, c)
    } comment = cat(comment, "/**< */") InsBufLine(hbuf, ln, comment) /* 设置光标正确的位置 */
    SetBufIns(hbuf, ln, strlen(comment) - ) return true
    } macro _wcjCommentHeader()
    {
    hbuf = GetCurrentBuf() szFunc = GetCurSymbol()
    ln = GetSymbolLine(szFunc)
    SetBufIns(hbuf, ln, ) return _wcjCommentBefore() } /**************************************new file related***********************************************/
    macro _wcjNewFile(bInc)
    {
    defname = wcjIncDefName() _wcjCommentFile() hbuf = GetCurrentBuf()
    ln = GetBufLnCur(hbuf) if (bInc)
    {
    InsBufLine(hbuf, ln++, "#ifndef @defname@")
    InsBufLine(hbuf, ln++, "#define @defname@")
    InsBufLine(hbuf, ln++, "")
    } InsBufLine(hbuf, ln++, "#ifdef _cplusplus")
    InsBufLine(hbuf, ln++, "#if _cplusplus")
    InsBufLine(hbuf, ln++, "extern \"C\"{")
    InsBufLine(hbuf, ln++, "#endif")
    InsBufLine(hbuf, ln++, "#endif") InsBufLine(hbuf, ln++, "")
    cursorln = ln
    InsBufLine(hbuf, ln++, "")
    InsBufLine(hbuf, ln++, "") InsBufLine(hbuf, ln++, "#ifdef _cplusplus")
    InsBufLine(hbuf, ln++, "#if _cplusplus")
    InsBufLine(hbuf, ln++, "}")
    InsBufLine(hbuf, ln++, "#endif")
    InsBufLine(hbuf, ln++, "#endif") if (bInc)
    InsBufLine(hbuf, ln++, "#endif /* @defname@ */") /* 设置光标正确的位置 */
    SetBufIns(hbuf, cursorln, )
    }
    macro _wcjHandleNewFile(key)
    {
    /*插入C标准的include文件内容*/
    if (key == "newinc") return _wcjNewFile(true)
    /*插入C标准的C文件内容*/
    if (key == "newc") return _wcjNewFile(false) return false
    } /**************************************ufp type related***********************************************/
    macro _wcjInsertCursorText(data)
    {
    /* 获得指定行文本 */
    hbuf = GetCurrentBuf()
    ln = GetBufLnCur(hbuf)
    text = GetBufLine(hbuf, ln) /* 获得光标位置 */
    hwnd = GetCurrentWnd()
    sel = GetWndSel(hwnd)
    column = sel.ichFirst /* 为当前位置插入正确内容 */
    DelBufLine(hbuf, ln)
    before = strtrunc(text, column)
    after = strmid(text, column, strlen(text))
    newtext = "@before@@data@@after@"
    InsBufLine(hbuf, ln, newtext) /* 设置光标正确的位置 */
    pos = column + strlen(data)
    SetBufIns(hbuf, ln, pos)
    }
    /*快捷内容插入*/
    macro _wcjHandleUfpType(key)
    {
    /*key = Ask("Enter ufp type short key");*/
    ufptype = _wcjGetUfpType(key)
    if (ufptype == "")
    return false; _wcjInsertCursorText(ufptype); return true;
    } /**************************************macro related***********************************************/
    /*插入ifdef*/
    macro _wcjIfdefSz()
    {
    data = Ask("Enter ifdef condition:")
    if (data == "")
    return true hwnd = GetCurrentWnd()
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd) hbuf = GetCurrentBuf()
    InsBufLine(hbuf, lnFirst, "#ifdef @data@")
    InsBufLine(hbuf, lnLast+, "#endif /* @data@ */") return true
    } /*插入if*/
    macro _wcjIfSz(data)
    {
    hwnd = GetCurrentWnd()
    lnFirst = GetWndSelLnFirst(hwnd)
    lnLast = GetWndSelLnLast(hwnd) hbuf = GetCurrentBuf()
    InsBufLine(hbuf, lnFirst, "#if @data@")
    InsBufLine(hbuf, lnLast+, "#endif") return true
    } /**************************************windows related***********************************************/
    macro _wcjCloseWindows()
    {
    cwnd = WndListCount()
    iwnd =
    while ()
    {
    hwnd = WndListItem()
    hbuf = GetWndBuf(hwnd)
    SaveBuf(hbuf)
    CloseWnd(hwnd)
    iwnd = iwnd +
    if(iwnd >= cwnd)
    break
    } return true;
    } /**************************************other related***********************************************/
    macro _wcjAddInclude()
    {
    hbuf = GetCurrentBuf()
    ln = GetBufLnCur(hbuf) /* 获得光标位置 */
    hwnd = GetCurrentWnd()
    sel = GetWndSel(hwnd)
    column = sel.ichFirst /*找到正确的符号*/
    //symbol = GetSymbolLocationFromLn(hbuf, ln)
    symbol = GetSymbolFromCursor(hbuf, ln, column)
    if (symbol.Symbol == "")
    {
    msg("check cursor, can't find symbol")
    return true
    } /*文件名抽取*/
    filename = _wcjFileName(symbol.file);
    len = strlen(filename)
    filetype = strmid(filename, len-, len)
    if (filetype == ".c")
    filename = Ask("func imp in @filename@, enter include file name or cancel:") if (filename == "")
    return true includetext = "#include \"@filename@\"" /* 正确的插入位置 */
    count = GetBufLineCount(hbuf)
    ln =
    text = ""
    lasttext = "invalid"
    while(ln < count)
    {
    if(ln != )
    lasttext = text
    text = GetBufLine(hbuf, ln) /*找到合适位置*/
    if (text == "#ifdef _cplusplus")
    {
    /*保证保留一个空格*/
    if (lasttext == "")
    ln--
    else
    InsBufLine(hbuf, ln, "") /* 插入 */
    InsBufLine(hbuf, ln, includetext) return true
    } /*已添加*/
    if (text == includetext)
    {
    return true
    } ln++
    } msg("can't add include, do it by youself")
    return true
    } macro _wcjHandleVar()
    {
    key = Ask("Enter variable name:")
    if (key == "")
    return true hbuf = GetCurrentBuf() text = ""
    if (strtrunc(key, ) == "i") text = "UFP_INT32 @key@"
    if (strtrunc(key, ) == "ui") text = "UFP_UINT32 @key@"
    if (strtrunc(key, ) == "ull") text = "UFP_UINT64 @key@"
    if (strtrunc(key, ) == "uv") text = "UFP_UINTPTR @key@"
    if (strtrunc(key, ) == "v") text = "UFP_VOID @key@"
    if (strtrunc(key, ) == "vp") text = "UFP_PHYS_ADDR @key@"
    if (strtrunc(key, ) == "n") text = "UFP_NULL_PTR @key@" _wcjInsertCursorText(text) return true
    } /**************************************罗列所有快捷键***********************************************/
    macro _wcjHandleWindows(key)
    {
    if (key == "winclose" || key == "wc") return _wcjCloseWindows() return false;
    }
    macro _wcjHandleOther(key)
    {
    if (key == "addinc") return _wcjAddInclude() return false
    } macro _wcjHandleMacro(key)
    {
    if (key == "if0") return _wcjIfSz()
    if (key == "ifdef") return _wcjIfdefSz() return false
    }
    macro _wcjHandleComment(key)
    {
    if (key == "commentfile" || key == "cf") return _wcjCommentFile()
    if (key == "commentbefore" || key == "commentbef" || key == "cb") return _wcjCommentBefore()
    if (key == "commentheader" || key == "ch") return _wcjCommentHeader() return false
    } /*程序中用到的自定义快捷键*/
    macro _wcjGetUfpType(key)
    {
    key = tolower(key); if (key == "i") return "UFP_INT32"
    if (key == "ui" || key=="u") return "UFP_UINT32"
    if (key == "ull") return "UFP_UINT64"
    if (key == "uv") return "UFP_UINTPTR"
    if (key == "v") return "UFP_VOID"
    if (key == "vp") return "UFP_PHYS_ADDR"
    if (key == "n") return "UFP_NULL_PTR" return ""
    } /* 主入口 */
    macro wcjMain()
    {
    key = Ask("Enter anthing you want:")
    if (key == "")
    return "" key = tolower(key); /*ufp type处理*/
    if (_wcjHandleUfpType(key)) return ""
    /*macro相关*/
    if (_wcjHandleMacro(key)) return ""
    /*new file*/
    if (_wcjHandleNewFile(key)) return ""
    /*comment*/
    if (_wcjHandleComment(key)) return ""
    /*窗体相关*/
    if (_wcjHandleWindows(key)) return ""
    /*变量*/
    if (key == "var") return _wcjHandleVar() return _wcjHandleOther(key)
    }

source insight用于C语言编程的工具脚本的更多相关文章

  1. Source Insight 中使用 AStyle 代码格式工具

    Source Insight 中使用 AStyle 代码格式工具 彭会锋 2015-05-19 23:26:32     Source Insight是较好的代码阅读和编辑工具,不过source in ...

  2. Ideone:在线多语言编程执行器工具

    Ideone:在线多语言编程执行器工具此网站提供40种编程语言以上, 能在线直接做编译和执行的动作,该工具是一款简易的编程测试工具,虽然不能替代专业版的工具,但是其功能非常全面. Ideone,一款在 ...

  3. 免费的文件比较工具和beyondcomare和source insight的比较工具

    Linux下,meld就够了,命令行用用diff也行,kdiff3也不错. 参考 http://www.cnblogs.com/itech/archive/2009/08/13/1545344.htm ...

  4. 华为C语言编程规范

    DKBA华为技术有限公司内部技术规范DKBA 2826-2011.5C语言编程规范2011年5月9日发布 2011年5月9日实施华为技术有限公司Huawei Technologies Co., Ltd ...

  5. 打造linux下的source insight——vim插件安装使用总结

    source insight是windows下的优秀编辑器,适合阅读管理代码,主要有以下功能: 查找函数,变量或者宏的定义. 查找函数,变量或者宏的引用位置. 查找函数被调用的位置 查找某个符号在工程 ...

  6. source insight 注册码

    分享一下google来的 呵呵 Source Insight,一个无比强大的工具.一个很好的查看代码的工具.到它的官网上去看一下,就知道,世界上基本上所有的大的软件公司,都在用这个工具.习惯了这个工具 ...

  7. 代码阅读工具:Source Navigator和Source Insight

    (摘自http://www.cnblogs.com/yc_sunniwell/archive/2010/08/25/1808322.html) 一.Source Insight实用技巧: Source ...

  8. 【工利其器】必会工具之(一)Source Insight篇

    前言         “Source Insight(以下简称SI)是世界上最好的编辑器”,说这句话不知道会不会出门被打呢?-_- 中国古话说得好,“文无第一,武无第二”,所以不敢说SI是最好的,但是 ...

  9. 阅读linux内核代码的工具-- Source Insight

    http://blog.csdn.net/luckyaslan/article/details/7869235 Step 1:安装Source Insight并启动程序 可以进入图1界面,在工具条上有 ...

随机推荐

  1. xargs -r

    -r  no-run-if-empty xargs大多数 Linux 命令都会产生输出:文件列表.字符串列表等.但如果要使用其他某个命令并将前一个命令的输出作为参数该怎么办?例如,file 命令显示文 ...

  2. python学习笔记——异常

    转自 http://www.cnblogs.com/rubylouvre/archive/2011/06/22/2086644.html Python内建异常体系结构 BaseException +- ...

  3. 图标的使用————JAVA——Swing

    public class MyImageIcon extends JFrame{    public MyImageIcon()    {    JFrame jf=new JFrame();     ...

  4. 移植samba到ios平台,最新支持ios8.3

    移植samba到ios平台,最新支持ios8.3 下载https://github.com/kolyvan/kxsmb 开源项目 1  cd samba-4.1.14 2  vi Rakefile 修 ...

  5. jQuery与Ajax

    Ajax简介 : Asynchronous Javascript And XML (异步的JavaScript和XML) AJAX 不是新的编程语言,而是一种使用现有标准创建快速动态网页的技术. 通过 ...

  6. 【LeetCode】17. Letter Combinations of a Phone Number

    题目: 思路:设置两个List,一个存储当前层,一个存储最终层 public class Solution { public List<String> letterCombinations ...

  7. 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序的处理方式

    今天客户向我反映一个问题,当他们在用我们的系统导出excel表格时,报错:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序 经过找资料终于得到解决方法,记录一下. 在对应 ...

  8. DWR基本配置

    DWR——Direct Web Remoter Servlet 供给那些想要以一种简单的方式使用Ajax和XMLHttpRequest的开发者.它具有一套JavaScript功能集,它们把从HTML页 ...

  9. 25_android下文件访问的权限

    写文件:FileOutputStream fos = 上下文.openFileOutput("private.txt",Context.MODE_PRIVATR);参数1 文件名, ...

  10. 在Tomcat下部属项目三种方式:

    在Tomcat下部属项目三种方式:       1直接复制:       2. 通过配置虚拟路径的方式    直接修改配置文件 写到tomcat/conf/server.xml     找到<H ...