转自:http://blog.chinaunix.net/u/8681/showart_1356633.html
http://blog.163.com/zhuzhihuacan@126/blog/static/12757945420102123576521/                           
我的版本:

解决汉字乱码的问题,一句话说就是调整字体为宋体

之 后会打开对话框:
之 后注释中就可以正常输入中文了,字距正常。< br>
下面是一个宏定义文件,绑定了Backspace,让它能正确删除一个汉字。
需要先关闭当前项目,打开Base项目,这个Base项目是Source Insight为你自带的,代表项目的项目设置,你的其它自建项目应该是以它为基础。

会 打开下面的对话框,在其中选择Base项目打开。

在Base Project中,新建一个SuperBackSpace.em文件,把下面所给出的代码写到文件中保存到 Base 项目中:
在项目文件列表中用右键单击:
然 后,打开键绑定对话框:
会 打开下面的对话框:刚才添加进来的宏定义文件中新定义的宏 SuperBackspace就列在下面 Command 一栏。

在 Command:下面的字体框中输入Mac, 下面的列表会只显示以Mac开头的项。这样很容易就选择到了这个宏,然后点击"Assign New Key..."按钮,弹出下面的对话框,
此时按下退格键(Backspace),"确定" 退出即可。设置成功后该对话框显示为:

此 时再试一下退格键,可以成功删除一整个汉字了。但是:
用鼠标选择注释中的汉字部分,仍然可以选中“半个“汉字,此时显示为乱码。
而 用左右箭头键移动光标时,仍然可以移动到一个汉字的半中间,就是说移动光标仍然是半个汉字为单位。

上面 一行是鼠标选中半个汉字的情况,下面的那行是光标移到汉字“中”的半中间时,光标闪烁至刚好显示那个小棍棍时的截截。
另外。在base 项目中选中 SuperBackspace.em 本身,在下面的Context窗口中可以看到该文件的内容,这个文件开头的部分是中文注释,显示为乱码,在Context中右键单击,改变字体为宋体,仍 然会显示乱码,汉字有的能正常显示,有的则不能。

Source Insight对汉字的支持,说一句糟糕真不过分。

使用下面的一个宏,即 Project→Open Project,

打开Base项目;

新建一个SuperBackSpace.em文件,将下面的代码加入进去并保存,

把SuperBackSpace.em文件复制到Base工程的工程目录下。选择【Project】→【Add and Remove Project Files...】打开对话框,加入SuperBackSpace.em文件;重启 SourceInsight;

打开Options→Key Assignments(对话框)

将Marco: SuperBackspace绑定到BackSpace键(在Key Assignments 对话框中先选中Commant 一栏的Marco:SuperBackspace,然后点击按钮“Assign New Key” 会弹出一个提示框,接着用手指按下键盘上的“Backspace”键,然后再点击“是/YES”,最后在点击“OK/确认”这样 就可以了,下面类似)

Marco: SuperCursorLeft绑定到<-键

Marco: SuperCursorRight绑定到->键

Marco: SuperShiftCursorLeft绑定到Shift+<-

macro,SuperShiftCursorRight绑定到 shift+->

Macro:SuperDelete绑定到del。

代码:

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[i]) >= 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();
}

注:如果加入SuperBackSpace.em 后出现非法关闭sourceinsight 则需要把原先自带的utils.em从base项目中去掉才行,去掉不影响使用,我的就是出现了这个问题,结果异常关闭之后,每次再打开都是自动异常关闭,最后不得已删除我的文档中的sourceinsight目录,然后重装才搞定,所以最好在Add and Remove Project Files...】SuperBackSpace.em 时,把utils.em给去除掉。

改进Source Insight对汉字的支持的更多相关文章

  1. Source Insight 3.X utf8支持插件震撼发布

    继上次SI多标签插件之后,因为公司内部编码改为utf8编码,因此特意做了这个Source Insight 3.X utf8插件. 下载地址:[点我] 安装说明: 解压msimg32.dll sihoo ...

  2. Source Insight 3.X 插件支持utf8,完美解决中国乱码,连接到美丽的轮廓

    上次SI多标签插件之后,由于公司内部编码改为utf8编码,因此特意做了这个Source Insight 3.X utf8插件. 下载地址:http://pan.baidu.com/s/1mgyZous ...

  3. Source Insight 3.X utf8支持插件更新

    [更新内容] 修复了当UTF8文件外部改变时,SI无法检测到的bug. 实现 [下载地址] 点我 [计划] 未来(无限长)优化utf8编码检测规则,提高准确度.

  4. Source Insight 多标签插件

    Source Insight不仅仅是一个强大的程序编辑器,它还能显示reference trees,class inheritance diagrams和call trees.Source Insig ...

  5. Source Insight 显示中文乱码

    Source Insight 3.X utf8支持插件震撼发布 继上次SI多标签插件之后,因为公司内部编码改为utf8编码,因此特意做了这个Source Insight 3.X utf8插件. 下载地 ...

  6. Source Insight及常用插件

    Source Insight及常用插件 1.Source Insight 2.插件 <1>.使用快捷键注释,单行注释,多行注释,#if 0注释 <2>.跳转到当前文件所在的文件 ...

  7. Source Insight中文操作支持的宏

    以下是Source Insight中文字符串支持的宏的实现,在此做个备份. 代码来自网上,非笔者所写.原有代码有个明显的Bug(Del的时候会导致多删除一个字符和多插入一个空格),已经被笔者fix掉. ...

  8. 让Source Insight完美支持中文注释

    如何让source insight支持中文注释,解决回车删除,移动光标出现乱码的问题?下面是解决方案:     -------Source Insight3 中文操作(左右键.删除和后退键)支持宏-- ...

  9. source insight 支持CC 文件

    今天开始阅读LevelDB的代码,用source insight建立工程,但其不支持cc后缀的C++文件. 找到这篇<source insight看cc文件> 解决的根本办法:Option ...

随机推荐

  1. MySQL数据类型与操作

    内容提要: 建表完整语法规范(create table 表格(字段名1 类型 (宽度) 约束条件)) MySQL数据库数据类型(整型.浮点型.字符类型(char与varchar).日期类型.枚举与集合 ...

  2. (十六)python 3 全局变量局部变量

    全局变量和局部变量 全局变量与局部变量两者的本质区别就是在于作用域. 用通俗的话来理解的话,全局变量是在整个py文件中声明,全局范围内都可以访问.局部变量是在某个函数中声明的,只能在该函数中调用它,如 ...

  3. POJ 2631 Roads in the North (求树的直径)

    Description Building and maintaining roads among communities in the far North is an expensive busine ...

  4. linux 文件三大特殊权限(SUID SGID SBIT)

    SGID(这个应该是文件共享里面最常用权限管理手段) 作用于目录或可执行程序,作用于目录代表在此目录创建的文件或目录,默认的属组继承此目录的属组.例如 我这个testgroup 没有设置SGID .我 ...

  5. linux 在当前目录下查找一个,或者多个文件

    1.find ./ -name "y*" 查找以y开头的文件. find ./ -name "*sql*" 查找包含 sql 的文件名 2.查找redis su ...

  6. Python+fiddler(基于Cookie绕过验证码自动登录)

    案例:使用Cookie绕过百度验证码自动登录账户 步骤: 1.浏览器进入百度首页,点击登录按钮,输入相关信息(注意:暂时不要点击登录按钮) 2.进入fiddler,首先获取证书,Tools--> ...

  7. Leetcode 289.生命游戏

    生命游戏 根据百度百科,生命游戏,简称为生命,是英国数学家约翰·何顿·康威在1970年发明的细胞自动机. 给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞.每个细胞具有一个初始状 ...

  8. 最小生成树求法 Prim + Kruskal

    prim算法的思路 和dijkstra是一样的 每次选取一个最近的点 然后去向新的节点扩张 注意这里的扩张 不再是 以前求最短路时候的到新的节点的最短距离 而是因为要生成一棵树 所以是要连一根最短的连 ...

  9. Swift 入门学习一:简单值

    1.简单值 使用“let”来声明常量,使用“var”来声明变量. 常量,在编译的时候,并不需要有明确的值,但是只能赋值一次.即:可以用常量来表示这样一个值--只需要决定一次,但是需要使用很多次. va ...

  10. HDU 1669 二分图多重匹配+二分

    Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...