让Source Insight完美支持中文注释

时间:2023-03-08 19:24:02
如何让source insight支持中文注释,解决回车删除,移动光标出现乱码的问题?下面是解决方案:
-------Source Insight3 中文操作(左右键、删除和后退键)支持宏-------
感谢丁兆杰(zhaojie.ding@gmail.com)及互联网上辛勤耕耘的朋友们!!!
Evan: sdcw@163.com
① Project→Open Project,打开Base项目,将文中代码框中的所有内容函数复制到utils.em文件的最后;
② 重启SourceInsight;
③ Options→Key Assignments,将下面宏依次与相应按键绑定:
Marco: SuperBackspace绑定到BackSpace键;
Marco: SuperCursorLeft绑定到<-键,
Marco: SuperCursorRight绑定到->键,
Marco: SuperShiftCursorLeft绑定到Shift+<-,
Macro: SuperShiftCursorRight绑定到shift+->,
Macro: SuperDelete绑定到del。
④ Enjoy
------------解决source insight 中文间距的方法:-----------------
默认情况下,往Source Insight里输入中文,字间距相当的大,要解决这个问题,具体设置如下:
1. Options->Style Properties
2. 在左边Style Name下找到Comment Multi Line和Comment.在其右边对应的Font属性框下的
Font Name中选“Pick...” 设置为宋体、常规、小四。确定,退回Style Properties界面,
Size设为10。最后设置Clolors框下Foreground,点“Pick...”选择一种自己喜欢的颜色就OK了。
/*======================================================================
1、BackSpace后退键
======================================================================*/
macro SuperBackspace()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
stop; // empty buffer
// get current cursor postion
ipos = GetWndSelIchFirst(hwnd);
// get current line number
ln = GetBufLnCur(hbuf);
if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
// sth. was selected, del selection
SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight
// del the " "
SuperBackspace();
stop;
}
// copy current line
text = GetBufLine(hbuf, ln);
// get string length
len = strlen(text);
// if the cursor is at the start of line, combine with prev line
if (ipos == || len == ) {
if (ln <= )
stop; // top of file
ln = ln - ; // do not use "ln--" for compatibility with older versions
prevline = GetBufLine(hbuf, ln);
prevlen = strlen(prevline);
// combine two lines
text = cat(prevline, text);
// del two lines
DelBufLine(hbuf, ln);
DelBufLine(hbuf, ln);
// insert the combined one
InsBufLine(hbuf, ln, text);
// set the cursor position
SetBufIns(hbuf, ln, prevlen);
stop;
}
num = ; // del one char
if (ipos >= ) {
// process Chinese character
i = ipos;
count = ;
while (AsciiFromChar(text[i - ]) >= ) {
i = i - ;
count = count + ;
if (i == )
break;
}
if (count > ) {
// I think it might be a two-byte character
num = ;
// This idiot does not support mod and bitwise operators
if ((count / * != count) && (ipos < len))
ipos = ipos + ; // adjust cursor position
}
}
// keeping safe
if (ipos - num < )
num = ipos;
// del char(s)
text = cat(strmid(text, , ipos - num), strmid(text, ipos, len));
DelBufLine(hbuf, ln);
InsBufLine(hbuf, ln, text);
SetBufIns(hbuf, ln, ipos - num);
stop;
}
/*======================================================================
2、删除键——SuperDelete.em
======================================================================*/
macro SuperDelete()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
stop; // empty buffer
// get current cursor postion
ipos = GetWndSelIchFirst(hwnd);
// get current line number
ln = GetBufLnCur(hbuf);
if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
// sth. was selected, del selection
SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight
// del the " "
SuperDelete();
stop;
}
// copy current line
text = GetBufLine(hbuf, ln);
// get string length
len = strlen(text); if (ipos == len || len == ) {
totalLn = GetBufLineCount (hbuf);
lastText = GetBufLine(hBuf, totalLn-);
lastLen = strlen(lastText);
if (ipos == lastLen)// end of file
stop;
ln = ln + ; // do not use "ln--" for compatibility with older versions
nextline = GetBufLine(hbuf, ln);
nextlen = strlen(nextline);
// combine two lines
text = cat(text, nextline);
// del two lines
DelBufLine(hbuf, ln-);
DelBufLine(hbuf, ln-);
// insert the combined one
InsBufLine(hbuf, ln-, text);
// set the cursor position
SetBufIns(hbuf, ln-, len);
stop;
}
num = ; // del one char
if (ipos > ) {
// process Chinese character
i = ipos;
count = ;
while (AsciiFromChar(text[i-]) >= ) {
i = i - ;
count = count + ;
if (i == )
break;
}
if (count > ) {
// I think it might be a two-byte character
num = ;
// This idiot does not support mod and bitwise operators
if (((count / * != count) || count == ) && (ipos < len-))
ipos = ipos + ; // adjust cursor position
}
// keeping safe
if (ipos - num < )
num = ipos;
}
else {
i = ipos;
count = ;
while(AsciiFromChar(text) >= ) {
i = i + ;
count = count + ;
if(i == len-)
break;
}
if(count > ) {
num = ;
}
} text = cat(strmid(text, , ipos), strmid(text, ipos+num, len));
DelBufLine(hbuf, ln);
InsBufLine(hbuf, ln, text);
SetBufIns(hbuf, ln, ipos);
stop;
}
/*======================================================================
3、左移键——SuperCursorLeft.em
======================================================================*/
macro IsComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
return ;
//当前位置
pos = GetWndSelIchFirst(hwnd);
//当前行数
ln = GetBufLnCur(hbuf);
//得到当前行
text = GetBufLine(hbuf, ln);
//得到当前行长度
len = strlen(text);
//从头计算汉字字符的个数
if(pos > )
{
i=pos;
count=;
while(AsciiFromChar(text[i-]) >= )
{
i = i - ;
count = count+;
if(i == )
break;
}
if((count/)*==count|| count==)
return ;
else
return ;
}
return ;
}
macro moveleft()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
stop; // empty buffer ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
if(GetBufSelText(hbuf) != "" || (ipos == && ln == )) // 第0行或者是选中文字,则不移动
{
SetBufIns(hbuf, ln, ipos);
stop;
}
if(ipos == )
{
preLine = GetBufLine(hbuf, ln-);
SetBufIns(hBuf, ln-, strlen(preLine)-);
}
else
{
SetBufIns(hBuf, ln, ipos-);
}
}
macro SuperCursorLeft()
{
moveleft();
if(IsComplexCharacter())
moveleft();
}
/*======================================================================
4、右移键——SuperCursorRight.em
======================================================================*/
macro moveRight()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
stop; // empty buffer
ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln);
if(GetBufSelText(hbuf) != "") //选中文字
{
ipos = GetWndSelIchLim(hwnd);
ln = GetWndSelLnLast(hwnd);
SetBufIns(hbuf, ln, ipos);
stop;
}
if(ipos == strlen(text)- && ln == totalLn-) // 末行
stop;
if(ipos == strlen(text))
{
SetBufIns(hBuf, ln+, );
}
else
{
SetBufIns(hBuf, ln, ipos+);
}
}
macro SuperCursorRight()
{
moveRight();
if(IsComplexCharacter()) // defined in SuperCursorLeft.em
moveRight();
}
/*======================================================================
5、shift+右移键——ShiftCursorRight.em
======================================================================*/
macro IsShiftRightComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
return ;
selRec = GetWndSel(hwnd);
pos = selRec.ichLim;
ln = selRec.lnLast;
text = GetBufLine(hbuf, ln);
len = strlen(text);
if(len == || len < pos)
return ;
//Msg("@len@;@pos@;");
if(pos > )
{
i=pos;
count=;
while(AsciiFromChar(text[i-]) >= )
{
i = i - ;
count = count+;
if(i == )
break;
}
if((count/)*==count|| count==)
return ;
else
return ;
}
return ;
}
macro shiftMoveRight()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
stop; ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln);
selRec = GetWndSel(hwnd);
curLen = GetBufLineLength(hbuf, selRec.lnLast);
if(selRec.ichLim == curLen+ || curLen == )
{
if(selRec.lnLast == totalLn -)
stop;
selRec.lnLast = selRec.lnLast + ;
selRec.ichLim = ;
SetWndSel(hwnd, selRec);
if(IsShiftRightComplexCharacter())
shiftMoveRight();
stop;
}
selRec.ichLim = selRec.ichLim+;
SetWndSel(hwnd, selRec);
}
macro SuperShiftCursorRight()
{
if(IsComplexCharacter())
SuperCursorRight();
shiftMoveRight();
if(IsShiftRightComplexCharacter())
shiftMoveRight();
}
/*======================================================================
6、shift+左移键——ShiftCursorLeft.em
======================================================================*/
macro IsShiftLeftComplexCharacter()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
return ;
selRec = GetWndSel(hwnd);
pos = selRec.ichFirst;
ln = selRec.lnFirst;
text = GetBufLine(hbuf, ln);
len = strlen(text);
if(len == || len < pos)
return ;
//Msg("@len@;@pos@;");
if(pos > )
{
i=pos;
count=;
while(AsciiFromChar(text[i-]) >= )
{
i = i - ;
count = count+;
if(i == )
break;
}
if((count/)*==count|| count==)
return ;
else
return ;
}
return ;
}
macro shiftMoveLeft()
{
hwnd = GetCurrentWnd();
hbuf = GetCurrentBuf();
if (hbuf == )
stop; ln = GetBufLnCur(hbuf);
ipos = GetWndSelIchFirst(hwnd);
totalLn = GetBufLineCount(hbuf);
text = GetBufLine(hbuf, ln);
selRec = GetWndSel(hwnd);
//curLen = GetBufLineLength(hbuf, selRec.lnFirst);
//Msg("@curLen@;@selRec@");
if(selRec.ichFirst == )
{
if(selRec.lnFirst == )
stop;
selRec.lnFirst = selRec.lnFirst - ;
selRec.ichFirst = GetBufLineLength(hbuf, selRec.lnFirst)-;
SetWndSel(hwnd, selRec);
if(IsShiftLeftComplexCharacter())
shiftMoveLeft();
stop;
}
selRec.ichFirst = selRec.ichFirst-;
SetWndSel(hwnd, selRec);
}
macro SuperShiftCursorLeft()
{
if(IsComplexCharacter())
SuperCursorLeft();
shiftMoveLeft();
if(IsShiftLeftComplexCharacter())
shiftMoveLeft();
}
/*---END---*/

Code