找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 9391|回复: 0
打印 上一主题 下一主题
收起左侧

搞定SourceInsight的半个汉字的问题

[复制链接]
跳转到指定楼层
楼主
ID:71235 发表于 2014-12-27 23:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    近日发现一款支持语法高亮,代码自动完成的通用代码编辑器《Source Insight》,试用了一下,貌似还不错,但是跟许多国外软件一样,都存在半个汉字的问题,就是按BACKSPACK键删除汉字字符时,一次只能删除半个汉字,剩下的那半个就显示为?,比较的不方便。
    还好这款软件有汉化版的,汉化版还附带了一个解决方案,但是作者的说明不是很清楚,这里我把我自己操作过程写一下,以免以后忘记了。
    它其实是利用了SourceInsight的键映射到宏的功能。
    1。解决方案里附带了一个宏文件“SuperBackspace.em”,用记事本打开这个文件,将内容复制到剪贴板备用,
    2。选择菜单“项目->打开项目”,打开Base项目,再打开右侧文件列表里的“Utils.em"文件,将刚才的代码粘贴到文档里,保存。
    3。选择菜单“选项->自定义命令”,添加一个“Marco: SuperBackspace()”,保存。
    4。选择菜单“键关联”,在命令列表里选中刚才新建的自定义命令“Marco: SuperBackspace()”,点击分配新键,按弹出窗口提示,按下BACKSPACE键,确认。
    5。重启Source Insight。
    要注意的是Source Insight默认的复制粘贴键是alt-c alt-v,可以自行修改成ctrl-c ctrl-v,另外在win7下运行Source Insight是需要管理员权限的,在启动文件Insight3上“右键->属性->兼容性”,勾选以“管理员身份运行此程序”即可
下面是这个宏的源代码
/**
*       ╭︿︿︿╮
*       {/ . .\}
*       (  (oo)  )
*        ︶︶︶︶
*      猪 哥  作 品
*
* 2006 丁兆杰 Ding Zhaojie
*
* SuperBackspace Version 0.1beta
*
* 代替SourceInsight原有的Backspace功能(希望如此)
* 增加了对双字节汉字的支持,在删除汉字的时候也能同时删除汉字的高字节而缓解半个汉字问题
* 能够对光标在汉字中间的情况进行自动修正
*
* 安装:
* ① 复制入SourceInsight安装目录;
* ② Project→Open Project,打开Base项目;
* ③ 将复制过去的SuperBackspace.em添加入Base项目;
* ④ 重启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;
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表