参考下面的(并不能直接运行,仅供参考),SendEditor弄成外部调用函数,还有因为有些不知道具体类型,不好弄而且可能出错
另外转成ps,还不如用C#之类封装一下...- $SCI_GETCURRENTPOS=2008
- $SCI_LINEFROMPOSITION=2166
- $SCI_GETCHARAT=2007
- $SCI_WORDSTARTPOSITION=2266
- $SCI_POSITIONFROMLINE=2167
- $SCI_BRACEMATCH=2353
- $SCI_GETLINEINDENTATION=2127
- $SCI_SETTARGETSTART=2190
- $SCI_SETTARGETEND=2192
- $SCI_REPLACETARGET=2194
- $SCI_REPLACESEL=2170
-
- #int pos = SendEditor(SCI_GETCURRENTPOS); //取得当前位置
- $pos =[int]SendEditor($SCI_GETCURRENTPOS);
-
- #int line = SendEditor(SCI_LINEFROMPOSITION,pos); //取得当前行
- $line =[int]SendEditor($SCI_LINEFROMPOSITION,$pos);
-
-
- $strchr=$false;
- $aaaaaa=[byte[]][char[]]"})>]";
- $aaaaaa.foreach({if($_ -eq $LastProcessedChar){$strchr=$true}})
-
-
- #//如果最后输入的字符是右括号的话就自动让当前行缩进和它匹配的左括号所在行一致
- #if( strchr("})>]",LastProcessedChar) &&
- if($strchr -and
-
- # isspace(SendEditor(SCI_GETCHARAT,pos-2)) && //要求右括号左边是空白字符
- (SendEditor($SCI_GETCHARAT,$pos-2) -eq 0x20) -and
-
- # LastProcessedChar!=0)
- ($LastProcessedChar -ne 0))
-
- {
- # //找前一个单词起始位置,这里用它来确定右括号左边是否全是空白字符
- # int startpos = SendEditor(SCI_WORDSTARTPOSITION,pos-1,false);
- $startpos =[int]SendEditor($SCI_WORDSTARTPOSITION,$pos-1,$false);
-
- # int linepos = SendEditor(SCI_POSITIONFROMLINE,line); //当前行起始位置
- $linepos = SendEditor($SCI_POSITIONFROMLINE,$line);
-
- # if(startpos == linepos) //这样相当于判断右括号左边是否全是空白字符
- if($startpos -eq $linepos)
-
- {
- # int othpos = SendEditor(SCI_BRACEMATCH,pos-1); //得到对应的左括号所在的位置
- $othpos =[int]SendEditor($SCI_BRACEMATCH,$pos-1);
-
- # int othline = SendEditor(SCI_LINEFROMPOSITION,othpos); //左括号所在行
- $othline =[int]SendEditor($SCI_LINEFROMPOSITION,$othpos);
-
- # int nIndent = SendEditor(SCI_GETLINEINDENTATION,othline);//左括号所在行的缩进值
- $nIndent =[int]SendEditor($SCI_GETLINEINDENTATION,$othline);
-
- # // 替换右括号前面的空白字符,使之与左括号缩进一致
- # char space[1024];
- $space=[char[]]::new(1024);
-
- # memset(space,' ',1024);
- (0..1023).foreach({$space[$_]=' '})
-
- # SendEditor(SCI_SETTARGETSTART, startpos);
- SendEditor($SCI_SETTARGETSTART, $startpos);
-
- # SendEditor(SCI_SETTARGETEND, pos-1);
- SendEditor($SCI_SETTARGETEND, $pos-1);
-
- # SendEditor(SCI_REPLACETARGET,nIndent,(sptr_t)space);
- #这里的space不知道该怎么传递
-
- }
- }
- #// 如果输入的是回车,则保持与上一行缩进一致
- #// 如果上一行最后有效字符为左括号,就多缩进四个空格
- #if(LastProcessedChar == ' ')
- if($LastProcessedChar -eq 0x20)
-
- {
- # if(line > 0)
- if($line -gt 0)
-
- {
- # // 得到上一行缩进设置
- # int nIndent = SendEditor(SCI_GETLINEINDENTATION,line-1);
- $nIndent =[int]SendEditor($SCI_GETLINEINDENTATION,$line-1);
-
- # // 查找上一行最后一个有效字符(非空白字符)
- # int nPrevLinePos = SendEditor(SCI_POSITIONFROMLINE,line-1);
- $nPrevLinePos =[int]SendEditor($SCI_POSITIONFROMLINE,$line-1);
-
- # int c = ' ';
- $c=0x20;
-
- # for(int p = pos-2;
- $p=$pos-2
- while($true){
-
- #p>=nPrevLinePos && isspace(c);
- if(($p -ge $nPrevLinePos) -and ($c -eq 0x20)){break}
-
- #p--, c=SendEditor(SCI_GETCHARAT,p));
- $p-=1;$c=SendEditor($SCI_GETCHARAT,$p);
- }
-
- $strchr=$false;
- $aaaaaa=[byte[]][char[]]"})>]";
- $aaaaaa.foreach({if($_ -eq $LastProcessedChar){$strchr=$true}})
-
-
- # // 如果是左括号,就多缩进四格
- # if(c && strchr("{([<",c)) nIndent+=4;
- if ($c -and $strchr){$nIndent+=4}
-
- # // 缩进...
- # char space[1024];
- $space=[char[]]::new(1024);
-
- # memset(space,' ',1024);
- (0..1023).foreach({$space[$_]=' '})
-
- # space[nIndent] = 0;
- $space[$nIndent] = 0;
-
- # SendEditor(SCI_REPLACESEL, 0, (sptr_t)space);
- #这里的space不知道该怎么传递
-
- }
- }
复制代码
|