路漫漫其修远兮,吾将上下而求索
文章目录
- 前言
- 一、快捷键设置
- 二、增加函数功能
- 1.注释多行代码
- 2.取消多行代码注释
- 3、宏定义注释
- 4、快捷文件说明
- 5、快捷函数体说明
- 总结
前言
本文介绍Source Insight如何设置修改快捷键属性,并增加响应快捷设置,贴合日常开发习惯
源文件已上传,可直接下载替换
一、快捷键设置
Source Insight提供快捷键修改、设置,路径为
Options—Key Assignments
左侧为指令类型,右侧为快捷键组合,点击Assign New Key即可为其增加新的快捷键组合。对话框出现后直接按下想设置的组合键即可,或者使用F系列设置为快捷键
我这边修改了Jump to Definition的快捷键组合,左侧Command输入Jump to… 找到Symbol:Jump to Definition 添加新的快捷键,并删除原先默认配置的即可。
二、增加函数功能
打开Source Insight自带基础工程,增加相关功能函数,并为其增加快捷键设置
Project——Open Project下选择Base工程 打开utils.em文件
1.注释多行代码
在utils.em末尾复制粘贴如下函数代码示例,按快捷键设置章节所述打开Key Assignments,输入该函数名MultiLineComment,为其增加快捷键设置,个人设置为
Ctrl+K
macro MultiLineComment()
{ hwnd = GetCurrentWnd() selection = GetWndSel(hwnd) LnFirst = GetWndSelLnFirst(hwnd) //取首行行号 LnLast = GetWndSelLnLast(hwnd) //取末行行号 hbuf = GetCurrentBuf() if(GetBufLine(hbuf, 0) == "//magic-number:tph85666031"){ stop } Ln = Lnfirst buf = GetBufLine(hbuf, Ln) len = strlen(buf) while(Ln <= Lnlast) { buf = GetBufLine(hbuf, Ln) //取Ln对应的行 if(buf == ""){ //跳过空行 Ln = Ln + 1 continue } if(StrMid(buf, 0, 1) == "/") { //需要取消注释,防止只有单字符的行 if(StrMid(buf, 1, 2) == "/"){ PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf))) } } if(StrMid(buf,0,1) != "/"){ //需要添加注释 PutBufLine(hbuf, Ln, Cat("//", buf)) } Ln = Ln + 1 } SetWndSel(hwnd, selection)
}
2.取消多行代码注释
快捷键设置为Ctrl+Shift+K
macro unMultiLineComment()
{ //取消杠杠注释,不选中多行的话,默认只处理当前行 hwnd = GetCurrentWnd() selection = GetWndSel( hwnd ) lnFirst = GetWndSelLnFirst( hwnd ) lnLast = GetWndSelLnLast( hwnd ) hbuf = GetCurrentBuf() ln = lnFirst while( ln <= lnLast ) { buf = GetBufLine( hbuf, ln ) len = strlen( buf ) if( len >= 2 ) { start = 0 while( strmid( buf, start, start + 1 ) == CharFromAscii(32) ||
strmid( buf, start, start + 1 ) == CharFromAscii(9) ) { start = start + 1 if( start >= len ) break } if( start < len - 2 ) { if( strmid( buf, start, start + 2 ) == "//" ) { buf2 = cat( strmid( buf, 0, start ), strmid( buf, start +
2, len ) ) PutBufLine( hbuf, ln, buf2 ) } } } ln = ln + 1 } SetWndSel( hwnd, selection )
}
3、宏定义注释
快捷键设置为Ctrl+/ 效果如下所示,单次注释、再次取消
#if 0
...
#endif
macro AddMacroComment()
{hwnd=GetCurrentWnd()sel=GetWndSel(hwnd)lnFirst=GetWndSelLnFirst(hwnd)lnLast=GetWndSelLnLast(hwnd)hbuf=GetCurrentBuf()if(LnFirst == 0) {szIfStart = ""}else{szIfStart = GetBufLine(hbuf, LnFirst-1)}szIfEnd = GetBufLine(hbuf, lnLast+1)if(szIfStart == "#if 0" && szIfEnd == "#endif") {DelBufLine(hbuf, lnLast+1)DelBufLine(hbuf, lnFirst-1)sel.lnFirst = sel.lnFirst – 1sel.lnLast = sel.lnLast – 1}else{InsBufLine(hbuf, lnFirst, "#if 0")InsBufLine(hbuf, lnLast+2, "#endif")sel.lnFirst = sel.lnFirst + 1sel.lnLast = sel.lnLast + 1}SetWndSel( hwnd, sel )
}
4、快捷文件说明
快捷键设置为Ctrl+0,用于文件说明注释,效果为InsertFileHeader函数输出内容,相关信息直接修改即可
macro GetFileName(pathName)
{nlength = strlen(pathName)i = nlength - 1name = ""while (i + 1){ch = pathName[i]if ("\\" == "@ch@")breaki = i - 1}i = i + 1while (i < nlength){name = cat(name, pathName[i])i = i + 1}return name
}macro InsertFileHeader()
{//get crrunt timeszTime = GetSysTime(1)Day = szTime.DayMonth = szTime.MonthYear = szTime.Yearhbuf = GetCurrentBuf()//申请变量空间,Get a handle to the current file buffer and the namePathName = GetBufName(hBuf)FileName = GetFileName(PathName)hbuf = GetCurrentBuf()InsBufLine(hbuf, 0, "/*******************************************************************************")InsBufLine(hbuf, 1, " * \@file @FileName@")InsBufLine(hbuf, 2, " * \@version v1.0.0")InsBufLine(hbuf, 3, " * \@copyright COPYRIGHT © @Year@ Breo")InsBufLine(hbuf, 4, " * \@author Qiushui")InsBufLine(hbuf, 5, " * \@date @Year@-@Month@-@Day@")InsBufLine(hbuf, 6, " * \@brief")InsBufLine(hbuf, 7, " * \@attention")InsBufLine(hbuf, 8, " * Modification History")InsBufLine(hbuf, 9, " * DATE DESCRIPTION")InsBufLine(hbuf, 10, " * ------------------------")InsBufLine(hbuf, 11, " * - @Year@-@Month@-@Day@ FQY Created")InsBufLine(hbuf, 12,"*******************************************************************************/")
}
5、快捷函数体说明
设置快捷键为Ctrl+1,相关信息内容模板内修改即可。
macro InsertFileHeader()
{//get crrunt timeszTime = GetSysTime(1)Day = szTime.DayMonth = szTime.MonthYear = szTime.Yearhbuf = GetCurrentBuf()//申请变量空间,Get a handle to the current file buffer and the namePathName = GetBufName(hBuf)FileName = GetFileName(PathName)hbuf = GetCurrentBuf()InsBufLine(hbuf, 0, "/*******************************************************************************")InsBufLine(hbuf, 1, " * \@file @FileName@")InsBufLine(hbuf, 2, " * \@version v1.0.0")InsBufLine(hbuf, 3, " * \@copyright COPYRIGHT © @Year@ Breo")InsBufLine(hbuf, 4, " * \@author Qiushui")InsBufLine(hbuf, 5, " * \@date @Year@-@Month@-@Day@")InsBufLine(hbuf, 6, " * \@brief")InsBufLine(hbuf, 7, " * \@attention")InsBufLine(hbuf, 8, " * Modification History")InsBufLine(hbuf, 9, " * DATE DESCRIPTION")InsBufLine(hbuf, 10, " * ------------------------")InsBufLine(hbuf, 11, " * - @Year@-@Month@-@Day@ FQY Created")InsBufLine(hbuf, 12,"*******************************************************************************/")
}macro InsertFunHeader()
{/* 获取光标所在行 */handle = GetCurrentWnd()process_line = GetWndSelLnFirst(handle)/* 获取函数所在行文本 */file_txt = GetCurrentBuf()process_txt = GetBufLine(file_txt,process_line + 1)process_txt_len = strlen(process_txt)if(process_txt == ""){stop}/* 获取函数名 */symbol_rec = GetSymbolLocationFromLn (handle, process_line + 1)if(symbol_rec == ""){stop}fuction_name = symbol_rec.Symbol/* 获取参数个数及参数名 */param_num = 0param_list = SymListNew()i=0,j=0while(i < process_txt_len){if(process_txt[i] == "," || process_txt[i] == ")"){j = iwhile(j > 0){if(process_txt[j] == " " || process_txt[j] == "*" || process_txt[j] == "&" ||process_txt[j] == "("){symbol_rec.Symbol = strmid(process_txt,j+1,i)SymListInsert(param_list,param_num,symbol_rec)param_num = param_num + 1break;}j = j - 1}}i = i + 1}/* 输出注释 */PutBufLine(handle,process_line + 0,"/*******************************************************************************")var temp_buffertemp_buffer = cat(" * \@FunctionName: ",fuction_name)InsBufLine(handle,process_line + 1,temp_buffer)InsBufLine(handle,process_line + 2," * \@Author: Qiushui")sys_time = GetSysTime(1)temp_buffer = " * \@DateTime: "temp_buffer = cat(temp_buffer,sys_time.date)temp_buffer = cat(temp_buffer,"T")temp_buffer = cat(temp_buffer,sys_time.time)temp_buffer = cat(temp_buffer,"+0800")InsBufLine(handle,process_line + 3,temp_buffer)InsBufLine(handle,process_line + 4," * \@Purpose: ")param_line = process_line + 5InsBufLine(handle,param_line,"*******************************************************************************/")if(strmid(process_txt,0,4) != "void"){InsBufLine(handle,param_line," * \@return:")}while(param_num > 0){param_num = param_num - 1symbol_rec = SymListItem(param_list,param_num)temp_buffer = " * \@param: "temp_buffer = cat(temp_buffer,symbol_rec.Symbol)temp_buffer_len = strlen(temp_buffer)temp_buffer_len = 38 - temp_buffer_lenwhile(temp_buffer_len > 0){temp_buffer_len = temp_buffer_len - 1temp_buffer = cat(temp_buffer," ")}//temp_buffer = cat(temp_buffer,"[description]")InsBufLine(handle,param_line,temp_buffer)}SymListFree(param_list)
}
总结
目前修改增加的设置就这些了,记得在Base工程下修改保存,切记函数体添加后,记得在Key Assignments下为其配置组合快捷键。打字、截图不易,看到点个小赞,拜谢(^ - ^ )!