|
近日發(fā)現(xiàn)一款支持語法高亮,代碼自動(dòng)完成的通用代碼編輯器《Source Insight》,試用了一下,貌似還不錯(cuò),但是跟許多國(guó)外軟件一樣,都存在半個(gè)漢字的問題,就是按BACKSPACK鍵刪除漢字字符時(shí),一次只能刪除半個(gè)漢字,剩下的那半個(gè)就顯示為?,比較的不方便。
還好這款軟件有漢化版的,漢化版還附帶了一個(gè)解決方案,但是作者的說明不是很清楚,這里我把我自己操作過程寫一下,以免以后忘記了。
它其實(shí)是利用了SourceInsight的鍵映射到宏的功能。
1。解決方案里附帶了一個(gè)宏文件“SuperBackspace.em”,用記事本打開這個(gè)文件,將內(nèi)容復(fù)制到剪貼板備用,
2。選擇菜單“項(xiàng)目->打開項(xiàng)目”,打開Base項(xiàng)目,再打開右側(cè)文件列表里的“Utils.em"文件,將剛才的代碼粘貼到文檔里,保存。
3。選擇菜單“選項(xiàng)->自定義命令”,添加一個(gè)“Marco: SuperBackspace()”,保存。
4。選擇菜單“鍵關(guān)聯(lián)”,在命令列表里選中剛才新建的自定義命令“Marco: SuperBackspace()”,點(diǎn)擊分配新鍵,按彈出窗口提示,按下BACKSPACE鍵,確認(rèn)。
5。重啟Source Insight。
要注意的是Source Insight默認(rèn)的復(fù)制粘貼鍵是alt-c alt-v,可以自行修改成ctrl-c ctrl-v,另外在win7下運(yùn)行Source Insight是需要管理員權(quán)限的,在啟動(dòng)文件Insight3上“右鍵->屬性->兼容性”,勾選以“管理員身份運(yùn)行此程序”即可
下面是這個(gè)宏的源代碼
/**
* ╭︿︿︿╮
* {/ . .\}
* ( (oo) )
* ︶︶︶︶
* 豬 哥 作 品
*
* 2006 丁兆杰 Ding Zhaojie
*
* SuperBackspace Version 0.1beta
*
* 代替SourceInsight原有的Backspace功能(希望如此)
* 增加了對(duì)雙字節(jié)漢字的支持,在刪除漢字的時(shí)候也能同時(shí)刪除漢字的高字節(jié)而緩解半個(gè)漢字問題
* 能夠?qū)鈽?biāo)在漢字中間的情況進(jìn)行自動(dòng)修正
*
* 安裝:
* ① 復(fù)制入SourceInsight安裝目錄;
* ② Project→Open Project,打開Base項(xiàng)目;
* ③ 將復(fù)制過去的SuperBackspace.em添加入Base項(xiàng)目;
* ④ 重啟SourceInsight;
* ⑤ Options→Key Assignments,將Marco: SuperBackspace綁定到BackSpace鍵;
* ⑥ Enjoy!!
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
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;
}
|
|