脚本,让你的代码更整洁
脚本,让你的代码更整洁
做为一名硬件工程师,不仅要会硬件的选型,而且也要会下位机程序的编写。多数是使用C语言在各种MCU相应的编译平台下编写,例如Keil、IAR等等,而这些软件的文本编辑器都比较弱,但是可以借助强大的第三方文本编辑器UEStudio来完成,这样,不但有语法着色功能,而且还可以使用脚本等功能,来达到代码整洁的效果。
先来看看下面这张图的示例,嘿嘿,代码还算整洁吧。
以前自己编写代码时,在行尾添加注释时,也就自己添加几个tab键,也就能保证在屏幕内的几行注释代码对齐,但是一旦隔屏就很难做了,还好,UEStudio提供了脚本功能,当每次运行下列代码时,就能自动将其对齐,并将光标定位到文本输入位置。
UltraEdit.activeDocument.write(" ");
UltraEdit.activeDocument.gotoLineSelect(0,80);
UltraEdit.activeDocument.write("/* */");
UltraEdit.activeDocument.gotoLine(0,83);
var a;
var b;
b = UltraEdit.activeDocument.currentColumnNum;
if(b > 100)
{
UltraEdit.messageBox("请换行处理!");
}
else
{
if(b > 80)
{
UltraEdit.activeDocument.write(" ");
UltraEdit.activeDocument.gotoLineSelect(0,100);
UltraEdit.activeDocument.write("/* */");
UltraEdit.activeDocument.gotoLine(0,103);
}
else
{
if(b > 60)
{
UltraEdit.activeDocument.write(" ");
UltraEdit.activeDocument.gotoLineSelect(0,80);
UltraEdit.activeDocument.write("/* */");
UltraEdit.activeDocument.gotoLine(0,83);
}
else
{
for (a=0;a < 2 ; a++)
{
UltraEdit.activeDocument.write(" ");
}
UltraEdit.activeDocument.gotoLineSelect(0,60);
UltraEdit.activeDocument.write("/* */");
UltraEdit.activeDocument.gotoLine(0,63);
}
}
}
UltraEdit.activeDocument.selection;
UltraEdit.activeDocument.deleteText();
UltraEdit.activeDocument.write(" ");
UltraEdit.activeDocument.gotoLine(0, 3);
UltraEdit.activeDocument.write("/* ---- ");
UltraEdit.activeDocument.write(t);
UltraEdit.activeDocument.write(" ");
var col = UltraEdit.activeDocument.currentColumnNum;
if(col < 80)
{
for(a = col; a <78; a++)
{
UltraEdit.activeDocument.write("-");
}
UltraEdit.activeDocument.write(" */");
}
}