1.前言
工欲善其事必先利其器。source insight 在阅读大工程代码时,无疑是神器。
这里介绍source insight 的 两个比较好用的功能。
2.功能增加
⑴在代码当中插入注释
①打开base工程
②插入脚本
③脚本内容
//add by leon 2015-10-12
// insert current date
macro MonthToName(MonthNum)
{
if (MonthNum== 1)
return "01"
if (MonthNum== 2)
return "02"
if (MonthNum== 3)
return "03"
if (MonthNum== 4)
return "04"
if (MonthNum== 5)
return "05"
if (MonthNum== 6)
return "06"
if (MonthNum== 7)
return "07"
if (MonthNum== 8)
return "08"
if (MonthNum== 9)
return "09"
if (MonthNum== 10)
return "10"
if (MonthNum== 11)
return "11"
if (MonthNum== 12)
return "12"
}
macro DisplayDate()
{
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
szMonth = MonthToName(Month)
hbuf = GetCurrentBuf()
SetBufSelText(hbuf, "//mod by leon. @Year@/@szMonth@/@szDay@ @Hour@:@Minute@:@Second@ ")
}
macro InsertCommentsInfo()
{
szTime = GetSysTime(1)
Day = szTime.Day
Month = szTime.Month
Year = szTime.Year
Hour = szTime.Hour
Minute = szTime.Minute
Second = szTime.Second
if (Day < 10)
szDay = "0@Day@"
else
szDay = Day
szMonth = MonthToName(Month)
line_headr = "/***************************************************"
line_1 = " * Function : "
line_2 = " * Author : leon"
line_3 = " * Creat Date : @Year@/@szMonth@/@szDay@ @Hour@:@Minute@:@Second@"
line_4 = " * Description : "
line_5 = " * In-Parameter : "
line_6 = " * Return : "
line_7 = " * Modify : "
line_end = " **************************************************/"
hbuf = GetCurrentBuf()
ln = GetBufLnCur(hbuf)
InsBufLine(hbuf, ln, line_headr)
InsBufLine(hbuf, ln+1, line_1)
InsBufLine(hbuf, ln+2, line_2)
InsBufLine(hbuf, ln+3, line_3)
InsBufLine(hbuf, ln+4, line_4)
InsBufLine(hbuf, ln+5, line_5)
InsBufLine(hbuf, ln+6, line_6)
InsBufLine(hbuf, ln+7, line_7)
InsBufLine(hbuf, ln+8, line_end)
}
macro AddNewFunctionDescription()
{
InsertCommentsInfo()
}
//end by leon
④ 增加快捷键
⑵格式化代码
格式化代码我们需要依赖于开源程序AStyle,可以在官网下载Artistic Style
下载后,笔者放在D:\ 下, 可执行程序路径: D:\AStyle\bin\AStyle.exe
①相关脚本
A.格式化当前文件
D:\AStyle\bin\AStyle.exe --style=linux -s4 -S -N -L -m0 -M40 --pad-oper --suffix=none --convert-tabs %f
Unix统一风格:
D:\AStyle\bin\AStyle.exe --style=linux -s4 -S -N -L -p -m0 -M40 -z2 -q --pad-oper --indent=tab %f
B.格式化当前目录下所有 .c .h 文件
D:\AStyle\bin\AStyle.exe --style=linux -s4 -S -N -L -m0 -M40 --suffix=none --convert-tabs --recursive ./*.c ./*h
Unix统一风格:
D:\AStyle\bin\AStyle.exe --style=ansi -s4 -S -N -L -m0 -M40 --suffix=none --convert-tabs --recursive ./*.c ./*h
②增加命令
③为命令增加快捷键