简单来说,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. Dubbo的Maven打包

    Maven项目的依赖,我们可以通过下面命令看到,打包时,会按照这个依赖编译进去对应模块. 参考:http://www.cnblogs.com/ghj1976/p/5336923.html mvn de ...

  2. 20. Valid Parentheses(stack)

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  3. isPowerOfTwo

    //Given an integer, write a function to determine if it is a power of two. public class isPowerOfTwo ...

  4. net start mysql服务名无效

    解决方案:(参考以下命令) 1.win+R键输入cmd敲回车进入dos界面: 2.输入cd d:/mysql-5.5.25/bin敲回车,发现没变化: 3.输入d:敲回车,定位到d:\mysql-5. ...

  5. css margin-top设置html元素之间的距离

    css margin-top属性设置的是一个元素的顶端与另一个元素之间的距离.这个距离称为上外边距,本文章向大家介绍css margin-top属性的用法和实例,需要的朋友可以参考一下. css ma ...

  6. C#中的委托和事件(续)

    转自张子阳的博客http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-Advanced.aspx 引言 如果你看过了 C#中 ...

  7. MFC学习 事件临界区

    事件: #include <Windows.h> #include <iostream> DWORD WINAPI Func1Pro(LPVOID lpParameter); ...

  8. Basler usb SDK安装在opencv采集图像

    近期,入手一台baslerUSB接口的CCD相机,但是貌似之前图像采集的编程无法调动其摄像头,在网上搜了一下,大家的说法就是安装它的SDK文件包,并且调用它内部函数编写代码.其实新版的Basle相机驱 ...

  9. "开发路上踩过的坑要一个个填起来————持续更新······(7月30日)"

    欢迎转载,请注明出处! https://gii16.github.io/learnmore/2016/07/29/problem.html 踩过的坑及解决方案记录在此篇博文中! 个人理解,如有偏颇,欢 ...

  10. 使用Kinect2.0获取点云以在GLUT中显示

    这篇文章用来记录Kinect2.0如何生成点云. 以下示例源自Kinect提供的example修改完成,其名称会在小标题下方注解. 首先,要获取点云需要获取图像的深度数据和颜色数据.最后再将深度数据与 ...