source insight中文显示和处理

浏览网页的时候突然看到一篇介绍关于source insight中文显示修正的方法,感觉非常好,也比较全面,于是在自己的source insight中又重新设置了一下。

1、首先设置中文的显示,使中文能像英文或中文在vc中的显示一样比较紧凑,便于浏览,不过在进行实际的设置前说先要做一下说明:在代码中使用中文较多的主要有两个地方一个是函数或语句前的“/**/“注释,另一个就是语句右面的“//”注释。因此为了尽量的减少对配置的修改,我们只需要对这两处稍作修改就行了:

”/**/“修改(把文字改为中文字体,斜体关掉),选项-->样式属性:

”//“修改(把字体选为中文,斜体关闭),选项-->样式属性:

基本上来说,修改了这两处后我们所使用的中文就可以正常显示了,如果那里还存在问题,基本上都可以同样的方式进行修改。

不过做到这里只是能是中文正常显示了,但是左移光标、右移光标、左选一个字、右选一个字、回退和删除等却只能对汉字进行半个字的操作,因此还需要进一步处理,使之操作类似如下:

a、打开base项目中的utils.em文件,添加如下代码:

/*====================================================================== 1、BackSpace后退键 ======================================================================*/ macro SuperBackspace() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) 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(1); 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 == 0 || len == 0) { if (ln <= 0) stop; // top of file ln = ln - 1; // 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 = 1; // del one char if (ipos >= 1) { // process Chinese character i = ipos; count = 0; while (AsciiFromChar(text[i - 1]) >= 160) { i = i - 1; count = count + 1; if (i == 0) break; } if (count > 0) { // I think it might be a two-byte character num = 2; // This idiot does not support mod and bitwise operators if ((count / 2 * 2 != count) && (ipos < len)) ipos = ipos + 1; // adjust cursor position } } // keeping safe if (ipos - num < 0) num = ipos; // del char(s) text = cat(strmid(text, 0, 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 == 0) 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(1); stop; } // copy current line text = GetBufLine(hbuf, ln); // get string length len = strlen(text); if (ipos == len || len == 0) { totalLn = GetBufLineCount (hbuf); lastText = GetBufLine(hBuf, totalLn-1); lastLen = strlen(lastText); if (ipos == lastLen)// end of file stop; ln = ln + 1; // 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-1); DelBufLine(hbuf, ln-1); // insert the combined one InsBufLine(hbuf, ln-1, text); // set the cursor position SetBufIns(hbuf, ln-1, len); stop; } num = 1; // del one char if (ipos > 0) { // process Chinese character i = ipos; count = 0; while (AsciiFromChar(text[i-1]) >= 160) { i = i - 1; count = count + 1; if (i == 0) break; } if (count > 0) { // I think it might be a two-byte character num = 2; // This idiot does not support mod and bitwise operators if (((count / 2 * 2 != count) || count == 0) && (ipos < len-1)) ipos = ipos + 1; // adjust cursor position } // keeping safe if (ipos - num < 0) num = ipos; } else { i = ipos; count = 0; while(AsciiFromChar(text) >= 160) { i = i + 1; count = count + 1; if(i == len-1) break; } if(count > 0) { num = 2; } } text = cat(strmid(text, 0, 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 == 0) return 0; //当前位置 pos = GetWndSelIchFirst(hwnd); //当前行数 ln = GetBufLnCur(hbuf); //得到当前行 text = GetBufLine(hbuf, ln); //得到当前行长度 len = strlen(text); //从头计算汉字字符的个数 if(pos > 0) { i=pos; count=0; while(AsciiFromChar(text[i-1]) >= 160) { i = i - 1; count = count+1; if(i == 0) break; } if((count/2)*2==count|| count==0) return 0; else return 1; } return 0; } macro moveleft() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) stop; // empty buffer ln = GetBufLnCur(hbuf); ipos = GetWndSelIchFirst(hwnd); if(GetBufSelText(hbuf) != "" || (ipos == 0 && ln == 0)) // 第0行或者是选中文字,则不移动 { SetBufIns(hbuf, ln, ipos); stop; } if(ipos == 0) { preLine = GetBufLine(hbuf, ln-1); SetBufIns(hBuf, ln-1, strlen(preLine)-1); } else { SetBufIns(hBuf, ln, ipos-1); } } macro SuperCursorLeft() { moveleft(); if(IsComplexCharacter()) moveleft(); } /*====================================================================== 4、右移键——SuperCursorRight.em ======================================================================*/ macro moveRight() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) 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)-1 && ln == totalLn-1) // 末行 stop; if(ipos == strlen(text)) { SetBufIns(hBuf, ln+1, 0); } else { SetBufIns(hBuf, ln, ipos+1); } } macro SuperCursorRight() { moveRight(); if(IsComplexCharacter()) // defined in SuperCursorLeft.em moveRight(); } /*====================================================================== 5、shift+右移键——ShiftCursorRight.em ======================================================================*/ macro IsShiftRightComplexCharacter() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) return 0; selRec = GetWndSel(hwnd); pos = selRec.ichLim; ln = selRec.lnLast; text = GetBufLine(hbuf, ln); len = strlen(text); if(len == 0 || len < pos) return 1; //Msg("@len@;@pos@;"); if(pos > 0) { i=pos; count=0; while(AsciiFromChar(text[i-1]) >= 160) { i = i - 1; count = count+1; if(i == 0) break; } if((count/2)*2==count|| count==0) return 0; else return 1; } return 0; } macro shiftMoveRight() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) 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+1 || curLen == 0) { if(selRec.lnLast == totalLn -1) stop; selRec.lnLast = selRec.lnLast + 1; selRec.ichLim = 1; SetWndSel(hwnd, selRec); if(IsShiftRightComplexCharacter()) shiftMoveRight(); stop; } selRec.ichLim = selRec.ichLim+1; SetWndSel(hwnd, selRec); } macro SuperShiftCursorRight() { if(IsComplexCharacter()) SuperCursorRight(); shiftMoveRight(); if(IsShiftRightComplexCharacter()) shiftMoveRight(); } /*====================================================================== 6、shift+左移键——ShiftCursorLeft.em ======================================================================*/ macro IsShiftLeftComplexCharacter() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) return 0; selRec = GetWndSel(hwnd); pos = selRec.ichFirst; ln = selRec.lnFirst; text = GetBufLine(hbuf, ln); len = strlen(text); if(len == 0 || len < pos) return 1; //Msg("@len@;@pos@;"); if(pos > 0) { i=pos; count=0; while(AsciiFromChar(text[i-1]) >= 160) { i = i - 1; count = count+1; if(i == 0) break; } if((count/2)*2==count|| count==0) return 0; else return 1; } return 0; } macro shiftMoveLeft() { hwnd = GetCurrentWnd(); hbuf = GetCurrentBuf(); if (hbuf == 0) 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 == 0) { if(selRec.lnFirst == 0) stop; selRec.lnFirst = selRec.lnFirst - 1; selRec.ichFirst = GetBufLineLength(hbuf, selRec.lnFirst)-1; SetWndSel(hwnd, selRec); if(IsShiftLeftComplexCharacter()) shiftMoveLeft(); stop; } selRec.ichFirst = selRec.ichFirst-1; SetWndSel(hwnd, selRec); } macro SuperShiftCursorLeft() { if(IsComplexCharacter()) SuperCursorLeft(); shiftMoveLeft(); if(IsShiftLeftComplexCharacter()) shiftMoveLeft(); } /*---END---*/

保存后,打开选项-->键分配,将新添加的宏依次与相应按键绑定,需要绑定的宏如下:

  Marco: SuperBackspace绑定到BackSpace键;
  Marco: SuperCursorLeft绑定到<-键,
  Marco: SuperCursorRight绑定到->键,
  Marco: SuperShiftCursorLeft绑定到Shift+<-,
  Macro: SuperShiftCursorRight绑定到shift+->,
  Macro: SuperDelete绑定到del。

过程结束后重新打开source insight打开新的项目,就可以对里面的中文进行正常的操作了。

原始贴出自: http://bbs.eetop.cn/thread-227848-1-1.html

后来发现最早的中文修正基本都是参考丁兆杰的工作进行的,因此也把他的工作给个链接:

http://blog.163.com/zhaojie_ding/blog/static/17297289520062309242166/

 

非常感谢他们的帮助,中文处理方便多了!!!

转载于:https://www.cnblogs.com/fangzhengshu/archive/2011/09/15/2210718.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值