Source Insight中文操作支持的宏

时间:2022-04-15 00:19:19

以下是Source Insight中文字符串支持的宏的实现,在此做个备份。

代码来自网上,非笔者所写。原有代码有个明显的Bug(Del的时候会导致多删除一个字符和多插入一个空格),已经被笔者fix掉。

使用时请将此部分代码贴到Source Insight的Base project的Utils.em文件末尾,并且在Options / Key Assignments添加相应的宏-键映射。

另外,在页面http://www.sourceinsight.com/public/macros/也有很多宏,可以参考使用。

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

Source Insight中文操作支持的宏的更多相关文章

  1. source insight 中文注释为乱码解决

    1. source insight 中文注释为乱码解决 http://blog.csdn.net/bingfeng1210/article/details/7527059 2. Source Insi ...

  2. utf-8转换为ansi和修改文件名的批处理(可解决source insight中文注释乱码问题)

    source insight中文乱码有两个原因,一个是source insight的设置不正确.另外一个原因是源文件是utf-8格式的. 最近在工作中用source insight 查看jsp文件.j ...

  3. Source Insight中文乱码

    搜索都是c++的代码,本来想下一个Vc,想了下,决定下个eclipse for C++,anyway,n次n久时间下载失败后,我接受了推荐,先下了个Source Insight来看代码.然后问题就出现 ...

  4. Source Insight 中文注释为乱码解决办法(完美解决,一键搞定)

    我从网上查了一堆解决办法,但是都是2017年以前的解决方案,并且都是针对于source insight 3.5及以下版本的,目前SI软件版本都到4.0了,应该有新方法出现了. ------------ ...

  5. Source Insight中文注释乱码、字体大小、等宽解决方法

    中文注释乱码解决方法: 用记事本打开源文件,然后,选择文件->另存为,编码选为”ANSI“   字体的调整: Source Insight 菜单栏选择Options->Document O ...

  6. 【转】Source Insight中文注释为乱码的解决办法

    我网上查了一堆解决办法,但是都是2017年以前的,并且都是针对于source insight 3.5及以下版本的解决方案,软件版本都到4.0了,应该有新方法出现. 干货:Source Insight ...

  7. Source Insight中文字体设置

    Source Insight是一个面向项目开发的程序编辑器和代码阅读工具,它拥有内置的对C/C++, C#和Java等程序的分析,分析你的源代 码并在你工作的同时动态维护它自己的符号数据库,并自动为你 ...

  8. source insight 中文乱码解决方法

    options->preferences -> Files-> default encoding: 选择 GB2312 CP:936

  9. source insight 添加 python 支持

    从http://www.sourceinsight.com/public/languages/下载Python的配置文件Python.CLF 选择Options > Preferences,单击 ...

随机推荐

  1. TODO:MongoDB的查询更新删除总结

    TODO:MongoDB的查询更新删除总结 常用查询,条件操作符查询,< .<=.>.>=.!= 对应 MongoDB的查询操作符是$lt.$lte.$gt.$gte.$ne ...

  2. ThinkPHP3&period;1快速入门(1)基础

    学习网址:http://www.thinkphp.cn/document/60.html

  3. ios沙盒路径

    http://www.cnblogs.com/ios-wmm/p/3299695.html iOS沙盒路径的查看和使用 NSString *path = NSHomeDirectory();//主目录 ...

  4. android 77 fragment

    fragment是3.0之后才有的,之前平板是3.0专用,后来手机和平板都用3.0 Activity: package com.itheima.fragment; import android.os. ...

  5. Stage3D&lowbar;Game&lowbar;Programming&colon;渲染3D模型

    OBJ是文件,先来解释下OBJ文件.随便找一个OBJ文件,用文本查看: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # ...

  6. 设置root远程连接ubuntu上mysql

    1.安装mysql,如果是root用户,直接执行一下命令.如果非root,则需要用sudo命令 a. apt-get install mysql-server b. apt-get isntall m ...

  7. hdu3507

    题意: 给n(n<=10^6)个非负数字,放在一个数组num中,再给一个特殊值m.求将这个数组分成任意多个区间,每个区间[a,b]的值定义为( sigma(num[i] | (a<=i&l ...

  8. Spring Cloud Eureka Server高可用注册服务中心的配置

    前言 Eureka 作为一个云端负载均衡,本身是一个基于REST的服务,在 Spring Cloud 中用于发现和注册服务. 那么当成千上万个微服务注册到Eureka Server中的时候,Eurek ...

  9. &lbrack;SequenceFile&lowbar;2&rsqb; SequenceFile 的基本操作

    0. 说明 测试序列文件的读写操作 && 测试序列文件的排序操作 && 测试序列文件的合并操作 && 测试序列文件的压缩方式 && 测试 ...

  10. &period;NET 三层框架

    1.三层架构 三层架构(3-tier architecture) 通常意义上的三层架构就是将整个业务应用划分为:表现层(Presentation layer).业务逻辑层(Business Logic ...