瀏覽網頁的時候突然看到一篇介紹關於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打開新的項目,就可以對里面的中文進行正常的操作了。