source insight用于C语言编程的工具脚本
简单来说,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语言编程的工具脚本的更多相关文章
- Source Insight 中使用 AStyle 代码格式工具
Source Insight 中使用 AStyle 代码格式工具 彭会锋 2015-05-19 23:26:32 Source Insight是较好的代码阅读和编辑工具,不过source in ...
- Ideone:在线多语言编程执行器工具
Ideone:在线多语言编程执行器工具此网站提供40种编程语言以上, 能在线直接做编译和执行的动作,该工具是一款简易的编程测试工具,虽然不能替代专业版的工具,但是其功能非常全面. Ideone,一款在 ...
- 免费的文件比较工具和beyondcomare和source insight的比较工具
Linux下,meld就够了,命令行用用diff也行,kdiff3也不错. 参考 http://www.cnblogs.com/itech/archive/2009/08/13/1545344.htm ...
- 华为C语言编程规范
DKBA华为技术有限公司内部技术规范DKBA 2826-2011.5C语言编程规范2011年5月9日发布 2011年5月9日实施华为技术有限公司Huawei Technologies Co., Ltd ...
- 打造linux下的source insight——vim插件安装使用总结
source insight是windows下的优秀编辑器,适合阅读管理代码,主要有以下功能: 查找函数,变量或者宏的定义. 查找函数,变量或者宏的引用位置. 查找函数被调用的位置 查找某个符号在工程 ...
- source insight 注册码
分享一下google来的 呵呵 Source Insight,一个无比强大的工具.一个很好的查看代码的工具.到它的官网上去看一下,就知道,世界上基本上所有的大的软件公司,都在用这个工具.习惯了这个工具 ...
- 代码阅读工具:Source Navigator和Source Insight
(摘自http://www.cnblogs.com/yc_sunniwell/archive/2010/08/25/1808322.html) 一.Source Insight实用技巧: Source ...
- 【工利其器】必会工具之(一)Source Insight篇
前言 “Source Insight(以下简称SI)是世界上最好的编辑器”,说这句话不知道会不会出门被打呢?-_- 中国古话说得好,“文无第一,武无第二”,所以不敢说SI是最好的,但是 ...
- 阅读linux内核代码的工具-- Source Insight
http://blog.csdn.net/luckyaslan/article/details/7869235 Step 1:安装Source Insight并启动程序 可以进入图1界面,在工具条上有 ...
随机推荐
- RDLC添加页码
页脚显示页码并总页数首先添加页脚,在页脚拖一textbox,textbox的表达式输入:="第" & Globals!PageNumber & "页 共& ...
- 页面中插入flash,并且给flash添加单击事件控制播放,以及获取相关参数.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="100%" hei ...
- 微信红包签名算法 C#代码实现
string stringA = "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=100001 ...
- [SQL]patindex的用法
返回指定表达式中某模式第一次出现的起始位置:如果在全部有效的文本和字符数据类型中没有找到该模式,则返回零. Transact-SQL 语法约定 语法 PATINDEX ( '%pattern%' , ...
- MongoDB添加用户
1.添加超级管理员用户 1)切换到admin数据库 >use admin 2)添加管理员用户 >db.addUser("admin","admin" ...
- addAll()报NullPointer原因
如下代码在注释行会报错,原因是:getSeatTravelerInfo()时值为空,对空对象addAll会报错 SeatBookingInfo b=new SeatBookingInfo(); b.s ...
- springMVC导入excel案例poi
直接上代码: 第一步,controller 引入 private static final String CHECK_FILE = "checkExceFile"; /** * 对 ...
- SQL 如果存在就更新,如果不存在就添加,使用 Merge 函数(SQL2008版本及以上)
USE [NationalUnion] GO /****** Object: StoredProcedure [dbo].[proc_DataSummary] Script Date: 07/03/2 ...
- 部署Ossim
650) this.width=650;" title="29-1.jpg" alt="095310750.jpg" src="http:/ ...
- 织梦dedecms简略标题调用标签用法指南
我们在使用织梦DEDECMS建站过程中,为了使调用的文章标题简短且相对完整(原文标题太长),只好使用了调用简略标题这个方法,使标题显示为简短标题,指向标题时显示完整的标题.并获得文章静态地址链接 下面 ...