让Source Insight完美支持中文注释——删除、选择完整的中文字符

本文转自:http://blog.chinaunix.net/uid-10540984-id-3214137.html

效果很好,很好用。做了修改,分享给大家,也收藏下。

——-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
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*======================================================================
 1、BackSpace后退键
 ======================================================================*/

 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 &amp; 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 &lt;= 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 &gt;= 1) {
 // process Chinese character
 i = ipos;
 count = 0;
 while (AsciiFromChar(text[i - 1]) &gt;= 160) {
 i = i - 1;
 count = count + 1;
 if (i == 0)
 break;
 }
 if (count &gt; 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) &amp;&amp; (ipos &lt; len))
 ipos = ipos + 1; // adjust cursor position
 }
 }
 // keeping safe
 if (ipos - num &lt; 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、删除键&mdash;&mdash;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 &amp; 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 &gt; 0) {
 // process Chinese character
 i = ipos;
 count = 0;
 while (AsciiFromChar(text[i-1]) &gt;= 160) {
 i = i - 1;
 count = count + 1;
 if (i == 0)
 break;
 }
 if (count &gt; 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) &amp;&amp; (ipos &lt; len-1))
 ipos = ipos + 1; // adjust cursor position
 }
 // keeping safe
 if (ipos - num &lt; 0)             num = ipos;     }     else { i = ipos; count = 0; while(AsciiFromChar(text) &gt;= 160) {
 i = i + 1;
 count = count + 1;
 if(i == len-1)
 break;
 }
 if(count &gt; 0) {
 num = 2;
 }
 }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<p>text = cat(strmid(text, 0, ipos), strmid(text, ipos+num, len));
 DelBufLine(hbuf, ln);
 InsBufLine(hbuf, ln, text);
 SetBufIns(hbuf, ln, ipos);
 stop;
 }
 /*======================================================================
 3、左移键&mdash;&mdash;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 &gt; 0)
 {
 i=pos;
 count=0;
 while(AsciiFromChar(text[i-1]) &gt;= 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 &amp;&amp; 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、右移键&mdash;&mdash;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 &amp;&amp; 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+右移键&mdash;&mdash;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 &lt; pos) return 1; //Msg("@len@;@pos@;"); if(pos &gt; 0)
 {
 i=pos;
 count=0;
 while(AsciiFromChar(text[i-1]) &gt;= 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+左移键&mdash;&mdash;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 &lt; pos)    return 1; //Msg("@len@;@pos@;"); if(pos &gt; 0)
 {
 i=pos;
 count=0;
 while(AsciiFromChar(text[i-1]) &gt;= 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;</p>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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();
 }
 /*---END---*/

分享到: 更多
版权申明:

本站保留所有原创文章的版权,本站地址:奔跑的博客[http://www.elecbench.com]

原创文章转载时请注明出处,并添加文章所在页面的链接:http://www.elecbench.com/%e8%ae%a9source-insight%e5%ae%8c%e7%be%8e%e6%94%af%e6%8c%81%e4%b8%ad%e6%96%87%e6%b3%a8%e9%87%8a-%e5%88%a0%e9%99%a4%e3%80%81%e9%80%89%e6%8b%a9%e5%ae%8c%e6%95%b4%e7%9a%84%e4%b8%ad/

本站所有 2010年3月4日 以后发表、未标明为“转载”的文章均是本站原创。

发表评论?

3 条评论。

  1. 这个真的有用吗249118697

发表评论


(设置自己的个性头像)

*

申请属于你的免费顶级域名