让Source Insight完美支持中文注释

如何让source insight支持中文注释,解决回车删除,移动光标出现乱码的问题?下面是解决方案:
-------Source Insight3 中文操作(左右键、删除和后退键)支持宏-------
感谢丁兆杰(zhaojie.ding@gmail.com)及互联网上辛勤耕耘的朋友们!!!
Evan: sdcw@163.com

① Project→Open Project,打开Base项目,将文中代码框中的所有内容函数复制到utils.em文件的最后;
② 重启SourceInsight;
③ Options→Key Assignments,将下面宏依次与相应按键绑定:
Marco: SuperBackspace绑定到BackSpace键;
Marco: SuperCursorLeft绑定到<-键,
Marco: SuperCursorRight绑定到->键,
Marco: SuperShiftCursorLeft绑定到Shift+<-,
Macro: SuperShiftCursorRight绑定到shift+->,
Macro: SuperDelete绑定到del。
④ Enjoy

------------解决source insight 中文间距的方法:-----------------
默认情况下,往Source Insight里输入中文,字间距相当的大,要解决这个问题,具体设置如下:
1. Options->Style Properties
2. 在左边Style Name下找到Comment Multi Line和Comment.在其右边对应的Font属性框下的
Font Name中选“Pick...” 设置为宋体、常规、小四。确定,退回Style Properties界面,
Size设为10。最后设置Clolors框下Foreground,点“Pick...”选择一种自己喜欢的颜色就OK了。


代码:

  1. /*======================================================================
  2. 1、BackSpace后退键
  3. ======================================================================*/
  4. macro SuperBackspace()
  5. {
  6.     hwnd = GetCurrentWnd();
  7.     hbuf = GetCurrentBuf();
  8.     if (hbuf == 0)
  9.         stop; // empty buffer
  10.     // get current cursor postion
  11.     ipos = GetWndSelIchFirst(hwnd);
  12.     // get current line number
  13.     ln = GetBufLnCur(hbuf);
  14.     if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
  15.         // sth. was selected, del selection
  16.         SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight
  17.         // del the " "
  18.         SuperBackspace(1);
  19.         stop;
  20.     }
  21.     // copy current line
  22.     text = GetBufLine(hbuf, ln);
  23.     // get string length
  24.     len = strlen(text);
  25.     // if the cursor is at the start of line, combine with prev line
  26.     if (ipos == 0 || len == 0) {
  27.         if (ln <= 0)
  28.             stop; // top of file
  29.         ln = ln - 1; // do not use "ln--" for compatibility with older versions
  30.         prevline = GetBufLine(hbuf, ln);
  31.         prevlen = strlen(prevline);
  32.         // combine two lines
  33.         text = cat(prevline, text);
  34.         // del two lines
  35.         DelBufLine(hbuf, ln);
  36.         DelBufLine(hbuf, ln);
  37.         // insert the combined one
  38.         InsBufLine(hbuf, ln, text);
  39.         // set the cursor position
  40.         SetBufIns(hbuf, ln, prevlen);
  41.         stop;
  42.     }
  43.     num = 1; // del one char
  44.     if (ipos >= 1) {
  45.         // process Chinese character
  46.         i = ipos;
  47.         count = 0;
  48.         while (AsciiFromChar(text[- 1]) >= 160) {
  49.             i = i - 1;
  50.             count = count + 1;
  51.             if (== 0)
  52.                 break;
  53.         }
  54.         if (count > 0) {
  55.             // I think it might be a two-byte character
  56.             num = 2;
  57.             // This idiot does not support mod and bitwise operators
  58.             if ((count / 2 * 2 != count) && (ipos < len))
  59.                 ipos = ipos + 1; // adjust cursor position
  60.         }
  61.     }
  62.     // keeping safe
  63.     if (ipos - num < 0)
  64.         num = ipos;
  65.     // del char(s)
  66.     text = cat(strmid(text, 0, ipos - num), strmid(text, ipos, len));
  67.     DelBufLine(hbuf, ln);
  68.     InsBufLine(hbuf, ln, text);
  69.     SetBufIns(hbuf, ln, ipos - num);
  70.     stop;
  71. }
  72. /*======================================================================
  73. 2、删除键——SuperDelete.em
  74. ======================================================================*/
  75. macro SuperDelete()
  76. {
  77.     hwnd = GetCurrentWnd();
  78.     hbuf = GetCurrentBuf();
  79.     if (hbuf == 0)
  80.         stop; // empty buffer
  81.     // get current cursor postion
  82.     ipos = GetWndSelIchFirst(hwnd);
  83.     // get current line number
  84.     ln = GetBufLnCur(hbuf);
  85.     if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {
  86.         // sth. was selected, del selection
  87.         SetBufSelText(hbuf, " "); // stupid & buggy sourceinsight
  88.         // del the " "
  89.         SuperDelete(1);
  90.         stop;
  91.     }
  92.     // copy current line
  93.     text = GetBufLine(hbuf, ln);
  94.     // get string length
  95.     len = strlen(text);

  96.     if (ipos == len || len == 0) {
  97. totalLn = GetBufLineCount (hbuf);
  98. lastText = GetBufLine(hBuf, totalLn-1);
  99. lastLen = strlen(lastText);
  100.         if (ipos == lastLen)// end of file
  101.    stop;
  102.         ln = ln + 1; // do not use "ln--" for compatibility with older versions
  103.         nextline = GetBufLine(hbuf, ln);
  104.         nextlen = strlen(nextline);
  105.         // combine two lines
  106.         text = cat(text, nextline);
  107.         // del two lines
  108.         DelBufLine(hbuf, ln-1);
  109.         DelBufLine(hbuf, ln-1);
  110.         // insert the combined one
  111.         InsBufLine(hbuf, ln-1, text);
  112.         // set the cursor position
  113.         SetBufIns(hbuf, ln-1, len);
  114.         stop;
  115.     }
  116.     num = 1; // del one char
  117.     if (ipos > 0) {
  118.         // process Chinese character
  119.         i = ipos;
  120.         count = 0;
  121.       while (AsciiFromChar(text[i-1]) >= 160) {
  122.             i = i - 1;
  123.             count = count + 1;
  124.             if (== 0)
  125.                 break;
  126.         }
  127.         if (count > 0) {
  128.             // I think it might be a two-byte character
  129.             num = 2;
  130.             // This idiot does not support mod and bitwise operators
  131.             if (((count / 2 * 2 != count) || count == 0) && (ipos < len-1))
  132.                 ipos = ipos + 1; // adjust cursor position
  133.         }
  134. // keeping safe
  135. if (ipos - num < 0)
  136.             num = ipos;
  137.     }
  138.     else {
  139. = ipos;
  140. count = 0;
  141. while(AsciiFromChar(text) >= 160) {
  142.      i = i + 1;
  143.      count = count + 1;
  144.      if(== len-1)
  145.    break;
  146. }
  147. if(count > 0) {
  148.      num = 2;
  149. }
  150.     }

  151.     text = cat(strmid(text, 0, ipos), strmid(text, ipos+num, len));
  152.     DelBufLine(hbuf, ln);
  153.     InsBufLine(hbuf, ln, text);
  154.     SetBufIns(hbuf, ln, ipos);
  155.     stop;
  156. }
  157. /*======================================================================
  158. 3、左移键——SuperCursorLeft.em
  159. ======================================================================*/
  160. macro IsComplexCharacter()
  161. {
  162. hwnd = GetCurrentWnd();
  163. hbuf = GetCurrentBuf();
  164. if (hbuf == 0)
  165.    return 0;
  166. //当前位置
  167. pos = GetWndSelIchFirst(hwnd);
  168. //当前行数
  169. ln = GetBufLnCur(hbuf);
  170. //得到当前行
  171. text = GetBufLine(hbuf, ln);
  172. //得到当前行长度
  173. len = strlen(text);
  174. //从头计算汉字字符的个数
  175. if(pos > 0)
  176. {
  177.    i=pos;
  178.    count=0;
  179.    while(AsciiFromChar(text[i-1]) >= 160)
  180.    {
  181.     i = i - 1;
  182.     count = count+1;
  183.     if(== 0)
  184.      break;
  185.    }
  186.    if((count/2)*2==count|| count==0)
  187.     return 0;
  188.    else
  189.     return 1;
  190. }
  191. return 0;
  192. }
  193. macro moveleft()
  194. {
  195. hwnd = GetCurrentWnd();
  196. hbuf = GetCurrentBuf();
  197. if (hbuf == 0)
  198.         stop; // empty buffer

  199. ln = GetBufLnCur(hbuf);
  200. ipos = GetWndSelIchFirst(hwnd);
  201. if(GetBufSelText(hbuf) != "" || (ipos == 0 && ln == 0)) // 第0行或者是选中文字,则不移动
  202. {
  203.    SetBufIns(hbuf, ln, ipos);
  204.    stop;
  205. }
  206. if(ipos == 0)
  207. {
  208.    preLine = GetBufLine(hbuf, ln-1);
  209.    SetBufIns(hBuf, ln-1, strlen(preLine)-1);
  210. }
  211. else
  212. {
  213.    SetBufIns(hBuf, ln, ipos-1);
  214. }
  215. }
  216. macro SuperCursorLeft()
  217. {
  218. moveleft();
  219. if(IsComplexCharacter())
  220.    moveleft();
  221. }
  222. /*======================================================================
  223. 4、右移键——SuperCursorRight.em
  224. ======================================================================*/
  225. macro moveRight()
  226. {
  227. hwnd = GetCurrentWnd();
  228. hbuf = GetCurrentBuf();
  229. if (hbuf == 0)
  230.         stop; // empty buffer
  231. ln = GetBufLnCur(hbuf);
  232. ipos = GetWndSelIchFirst(hwnd);
  233. totalLn = GetBufLineCount(hbuf);
  234. text = GetBufLine(hbuf, ln);
  235. if(GetBufSelText(hbuf) != "") //选中文字
  236. {
  237.    ipos = GetWndSelIchLim(hwnd);
  238.    ln = GetWndSelLnLast(hwnd);
  239.    SetBufIns(hbuf, ln, ipos);
  240.    stop;
  241. }
  242. if(ipos == strlen(text)-&& ln == totalLn-1) // 末行
  243.    stop;
  244. if(ipos == strlen(text))
  245. {
  246.    SetBufIns(hBuf, ln+1, 0);
  247. }
  248. else
  249. {
  250.    SetBufIns(hBuf, ln, ipos+1);
  251. }
  252. }
  253. macro SuperCursorRight()
  254. {
  255. moveRight();
  256. if(IsComplexCharacter()) // defined in SuperCursorLeft.em
  257.    moveRight();
  258. }
  259. /*======================================================================
  260. 5、shift+右移键——ShiftCursorRight.em
  261. ======================================================================*/
  262. macro IsShiftRightComplexCharacter()
  263. {
  264. hwnd = GetCurrentWnd();
  265. hbuf = GetCurrentBuf();
  266. if (hbuf == 0)
  267.    return 0;
  268. selRec = GetWndSel(hwnd);
  269. pos = selRec.ichLim;
  270. ln = selRec.lnLast;
  271. text = GetBufLine(hbuf, ln);
  272. len = strlen(text);
  273. if(len == 0 || len < pos)
  274. return 1;
  275. //Msg("@len@;@pos@;");
  276. if(pos > 0)
  277. {
  278.    i=pos;
  279.    count=0;
  280.    while(AsciiFromChar(text[i-1]) >= 160)
  281.    {
  282.     i = i - 1;
  283.     count = count+1;
  284.     if(== 0)
  285.      break;
  286.    }
  287.    if((count/2)*2==count|| count==0)
  288.     return 0;
  289.    else
  290.     return 1;
  291. }
  292. return 0;
  293. }
  294. macro shiftMoveRight()
  295. {
  296. hwnd = GetCurrentWnd();
  297. hbuf = GetCurrentBuf();
  298. if (hbuf == 0)
  299.         stop; 

  300. ln = GetBufLnCur(hbuf);
  301. ipos = GetWndSelIchFirst(hwnd);
  302. totalLn = GetBufLineCount(hbuf);
  303. text = GetBufLine(hbuf, ln);
  304. selRec = GetWndSel(hwnd);
  305. curLen = GetBufLineLength(hbuf, selRec.lnLast);
  306. if(selRec.ichLim == curLen+|| curLen == 0)
  307. {
  308.    if(selRec.lnLast == totalLn -1)
  309.     stop;
  310.    selRec.lnLast = selRec.lnLast + 1;
  311.    selRec.ichLim = 1;
  312.    SetWndSel(hwnd, selRec);
  313.    if(IsShiftRightComplexCharacter())
  314.     shiftMoveRight();
  315.    stop;
  316. }
  317. selRec.ichLim = selRec.ichLim+1;
  318. SetWndSel(hwnd, selRec);
  319. }
  320. macro SuperShiftCursorRight()
  321. {
  322. if(IsComplexCharacter())
  323.    SuperCursorRight();
  324. shiftMoveRight();
  325. if(IsShiftRightComplexCharacter())
  326.    shiftMoveRight();
  327. }
  328. /*======================================================================
  329. 6、shift+左移键——ShiftCursorLeft.em
  330. ======================================================================*/
  331. macro IsShiftLeftComplexCharacter()
  332. {
  333. hwnd = GetCurrentWnd();
  334. hbuf = GetCurrentBuf();
  335. if (hbuf == 0)
  336.    return 0;
  337. selRec = GetWndSel(hwnd);
  338. pos = selRec.ichFirst;
  339. ln = selRec.lnFirst;
  340. text = GetBufLine(hbuf, ln);
  341. len = strlen(text);
  342. if(len == 0 || len < pos)
  343.    return 1;
  344. //Msg("@len@;@pos@;");
  345. if(pos > 0)
  346. {
  347.    i=pos;
  348.    count=0;
  349.    while(AsciiFromChar(text[i-1]) >= 160)
  350.    {
  351.     i = i - 1;
  352.     count = count+1;
  353.     if(== 0)
  354.      break;
  355.    }
  356.    if((count/2)*2==count|| count==0)
  357.     return 0;
  358.    else
  359.     return 1;
  360. }
  361. return 0;
  362. }
  363. macro shiftMoveLeft()
  364. {
  365. hwnd = GetCurrentWnd();
  366. hbuf = GetCurrentBuf();
  367. if (hbuf == 0)
  368.         stop; 

  369. ln = GetBufLnCur(hbuf);
  370. ipos = GetWndSelIchFirst(hwnd);
  371. totalLn = GetBufLineCount(hbuf);
  372. text = GetBufLine(hbuf, ln);
  373. selRec = GetWndSel(hwnd);
  374. //curLen = GetBufLineLength(hbuf, selRec.lnFirst);
  375. //Msg("@curLen@;@selRec@");
  376. if(selRec.ichFirst == 0)
  377. {
  378.    if(selRec.lnFirst == 0)
  379.     stop;
  380.    selRec.lnFirst = selRec.lnFirst - 1;
  381.    selRec.ichFirst = GetBufLineLength(hbuf, selRec.lnFirst)-1;
  382.    SetWndSel(hwnd, selRec);
  383.    if(IsShiftLeftComplexCharacter())
  384.     shiftMoveLeft();
  385.    stop;
  386. }
  387. selRec.ichFirst = selRec.ichFirst-1;
  388. SetWndSel(hwnd, selRec);
  389. }
  390. macro SuperShiftCursorLeft()
  391. {
  392. if(IsComplexCharacter())
  393.    SuperCursorLeft();
  394. shiftMoveLeft();
  395. if(IsShiftLeftComplexCharacter())
  396.    shiftMoveLeft();
  397. }
  398. /*---END---*/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值