source insight插件

打开文件所在的文件夹

https://blog.csdn.net/ymzhou117/article/details/6818270

 

增加注释宏

打开base项目,下main.c文件里加入以下代码

 

 

对于在一行内的局部注释, 没有找到解除注释的宏,  

 

 

  1. macro Comments_orUn_gx()  
  2. {   //用杠星注释多行,或取消杠星注释 ,不选中多行时,只处理当前行  
  3.     hwnd = GetCurrentWnd()  
  4.     hbuf = GetCurrentBuf()  
  5.     if(hbuf ==0)  
  6.         stop   
  7.           
  8.     // debugBuf只是为了调试  
  9.     // debugBuf = NewBuf("debugBuf")   
  10.     // ClearBuf(debugBuf)   
  11.   
  12.     lnSelFirst = GetWndSelLnFirst(hwnd)     // 获得选中内容的第一行  
  13.     lnSelLast = GetWndSelLnLast(hwnd)       // 获得选中内容的最后一行  
  14.           
  15.     const_space = " "               // 空格  
  16.     const_comments_begin = "/*"             // 多行注释符号-开始  
  17.     const_comments_end = "*/"           // 多行注释符号-结束  
  18.     isCancelComments = 0   
  19.       
  20.     // 跳过开始的空行,否则下面报错  
  21.     line_index = lnSelFirst   
  22.     orig_text = GetBufLine(hbuf, line_index)    // 获得第一行的text  
  23.     while(strlen(orig_text) == 0)  
  24.     {  
  25.         line_index = line_index + 1  
  26.         orig_text = GetBufLine(hbuf, line_index)            // 获得下一行的text  
  27.     }  
  28.           
  29.     // 根据第一行选中文本,确定是“注释”,还是“取消注释”  
  30.     // 判断是否以“//”开始,如果是则认为是“取消注释”,首先需要去掉空格  
  31.     subIndex = 0          
  32.     while(strmid(orig_text, subIndex, subIndex+1) == const_space)   
  33.             subIndex = subIndex + 1   
  34.       
  35.     if (strmid(orig_text, subIndex, subIndex+2) == const_comments_begin)    // 以“/*”开头,取消注释  
  36.     {  
  37.         isCancelComments = 1   
  38.           
  39.         dest_text = strmid(orig_text, subIndex+2, strlen(orig_text))   
  40.         if(strlen(dest_text) == 0)  
  41.         {  
  42.             DelBufLine(hbuf, line_index)                // 本行只有“/*”时,删除  
  43.         }  
  44.         else  
  45.         {  
  46.             PutBufLine (hbuf, line_index, dest_text)        // 替换以前的text  
  47.         }  
  48.         line_index = line_index + 1  
  49.     }  
  50.     else    // 进行注释  
  51.     {  
  52.         InsBufLine(hbuf, lnSelFirst, "/*")  
  53.         InsBufLine(hbuf, lnSelLast+2,  "*/")  
  54.           
  55.         stop   
  56.     }  
  57.       
  58.     // 遍历所有选中的行  
  59.     // line_index = lnSelFirst                      // 前面已经跳过开头的空行  
  60.     // while(line_index <= lnSelLast)                    // 对选中的内容进行操作  
  61.     while(line_index < GetBufLineCount(hbuf))                //or 从当前行开始,查找到第一个“*/”为止或到结尾  
  62.     {  
  63.         orig_text = GetBufLine(hbuf, line_index)    // 获得以前的text  
  64.         if (strlen(orig_text) > 1)                   // 如果是空行或只有一个字符,则跳过  
  65.         {  
  66.             dest_text = ""   
  67.             if(isCancelComments == 1)               // 取消注释  
  68.             {  
  69.                 // 查找注释符“*/”  
  70.                 subIndex = 0          
  71.                 while(subIndex < strlen(orig_text)-2 && strmid(orig_text, subIndex, subIndex+2) != const_comments_end)   
  72.                         subIndex = subIndex + 1   
  73.                   
  74.                 if (strmid(orig_text, subIndex, subIndex+2) == const_comments_end)  // 找到“*/”,进行处理  
  75.                 {  
  76.                     prefixText = strmid(orig_text, 0, subIndex)             // 前面的text  
  77.                     lastText = strmid(orig_text, subIndex+2, strlen(orig_text))     // 后面的text  
  78.                     dest_text = cat(prefixText, lastText)   
  79.   
  80.                     if(strlen(dest_text) == 0)  
  81.                     {  
  82.                         DelBufLine(hbuf, line_index)                // 本行只有“*/”时,删除  
  83.                     }  
  84.                     else  
  85.                     {  
  86.                         PutBufLine (hbuf, line_index, dest_text)        // 替换以前的text  
  87.                     }  
  88.                       
  89.                       
  90.                     break                               // 退出  
  91.                 }  
  92.             }  
  93.         }  
  94.           
  95.         line_index = line_index + 1    
  96.     }  
  97. }  
  98.   
  99.   
  100.   
  101. macro CommentSelecte_inOneLine()  
  102. {   //注释选中,只在单行中有效,不选中任何字符的话就在光标处插入一对杠星注释符  
  103.     hbuf = GetCurrentBuf()  
  104.     ln = GetBufLnCur(hbuf)  
  105.     str = GetBufSelText(hbuf)  
  106.     str = cat("/*",str)  
  107.     str = cat(str,"*/")  
  108.     SetBufSelText (hbuf, str)  
  109. }  
  110.   
  111. macro _tsGetTabSize()    
  112. {  //只被Comment_gx() 宏调用  
  113.     szTabSize = GetReg("TabSize");    
  114.     
  115.     if (szTabSize != "")    
  116.     {    
  117.         tabSize = AsciiFromChar(szTabSize[0]) - AsciiFromChar("0");    
  118.     }    
  119.     else    
  120.     {    
  121.         tabSize = 4;    
  122.     }    
  123.     
  124.     return tabSize;    
  125. }    
  126.     
  127.     
  128. macro Comment_gx()    
  129. {  //用杠星注释,不换行,至少注释一行,不推荐使用  
  130.     hbuf = GetCurrentBuf();    
  131.     hwnd = GetCurrentWnd();    
  132.     
  133.     sel = GetWndSel(hwnd);    
  134.     
  135.     iLine = sel.lnFirst;    
  136.         
  137.     // indicate the comment char according to the file type    
  138.     // for example, using "#" for perl file(.pl) and "/* */" for C/C++.    
  139.     filename = tolower(GetBufName(hbuf));    
  140.     suffix = "";    
  141.     len = strlen(filename);    
  142.     i = len - 1;    
  143.     while (i >= 0)    
  144.     {    
  145.         if (filename[i-1] == ".")    
  146.         {    
  147.             suffix = strmid(filename, i, len)    
  148.             break;    
  149.         }    
  150.         i = i -1;    
  151.     }    
  152.     if  ( suffix == "pl" )    
  153.     {    
  154.         filetype = 2; // PERL    
  155.     }    
  156.     else    
  157.     {    
  158.         filetype = 1; // C    
  159.     }    
  160.     
  161.     szLine = GetBufLine(hbuf, iLine);    
  162.     if (filetype == 1)  // C    
  163.     {    
  164.         szLine = cat("/*", szLine);    
  165.     }    
  166.     else                // PERL    
  167.     {    
  168.         szLine = cat("# ", szLine);    
  169.     }    
  170.     PutBufLine(hbuf, iLine, szLine);    
  171.     iLine = sel.lnLast;    
  172.     szLine = GetBufLine(hbuf, iLine);    
  173.     if (filetype == 1)  // C    
  174.     {    
  175.         szLine = cat(szLine, "*/");    
  176.     }    
  177.     else                // PERL    
  178.     {    
  179.         szLine = cat("# ", szLine);    
  180.     }    
  181.     PutBufLine(hbuf, iLine, szLine);    
  182.     
  183.     
  184.     
  185.     if (sel.lnFirst == sel.lnLast)    
  186.     {    
  187.         tabSize = _tsGetTabSize() - 1;    
  188.         sel.ichFirst = sel.ichFirst + tabSize;    
  189.         sel.ichLim = sel.ichLim + tabSize;    
  190.     }    
  191.     SetWndSel(hwnd, sel);    
  192. }    
  193.     
  194.     
  195. macro Comment_gg()  
  196. {   //用杠杠注释,不选中多行的话,注释当前行  
  197.     hwnd = GetCurrentWnd()  
  198.     selection = GetWndSel( hwnd )  
  199.     lnFirst = GetWndSelLnFirst( hwnd )  
  200.     lnLast = GetWndSelLnLast( hwnd )  
  201.   
  202.     hbuf = GetCurrentBuf()  
  203.   
  204.     ln = lnFirst  
  205.     buf = GetBufLine( hbuf, ln )  
  206.     len = strlen( buf )  
  207.     firststart = len  
  208.     while( ln <= lnLast )  
  209.     {  
  210.         buf = GetBufLine( hbuf, ln )  
  211.         len = strlen( buf )  
  212.         start = 0  
  213.         while( start < len )  
  214.         {  
  215.             if( strmid( buf, start, start + 1 ) == CharFromAscii(32) || strmid( buf, start, start + 1 ) == CharFromAscii(9) )  
  216.             {  
  217.                 start = start + 1  
  218.                 if( start > len )  
  219.                     break  
  220.             }  
  221.             else  
  222.                 break  
  223.         }  
  224.         if( start < len && start < firststart )  
  225.         {  
  226.             firststart = start  
  227.         }  
  228.         ln = ln + 1  
  229.     }  
  230.   
  231.     ln = lnFirst  
  232.     while( ln <= lnLast )  
  233.     {  
  234.         buf = GetBufLine( hbuf, ln )  
  235.         len = strlen( buf )  
  236.         if( len > 0 )  
  237.         {  
  238.             buf2 = cat( cat( strmid( buf, 0, firststart ), "//" ), strmid( buf, firststart, len ) )  
  239.             PutBufLine ( hbuf, ln, buf2 )  
  240.         }  
  241.         ln = ln + 1  
  242.     }  
  243.     SetWndSel( hwnd, selection )  
  244. }  
  245.   
  246. macro unComment_gg()  
  247. {   //取消杠杠注释,不选中多行的话,默认只处理当前行  
  248.     hwnd = GetCurrentWnd()  
  249.     selection = GetWndSel( hwnd )  
  250.     lnFirst = GetWndSelLnFirst( hwnd )  
  251.     lnLast = GetWndSelLnLast( hwnd )  
  252.   
  253.     hbuf = GetCurrentBuf()  
  254.     ln = lnFirst  
  255.     while( ln <= lnLast )  
  256.     {  
  257.         buf = GetBufLine( hbuf, ln )  
  258.         len = strlen( buf )  
  259.         if( len >= 2 )  
  260.         {  
  261.             start = 0  
  262.   
  263.             while( strmid( buf, start, start + 1 ) == CharFromAscii(32) || strmid( buf, start, start + 1 ) == CharFromAscii(9) )  
  264.             {  
  265.                 start = start + 1  
  266.                 if( start >= len )  
  267.                     break  
  268.             }  
  269.             if( start < len - 2 )  
  270.             {  
  271.                 if( strmid( buf, start, start + 2 ) == "//" )  
  272.                 {  
  273.                     buf2 = cat( strmid( buf, 0, start ), strmid( buf, start + 2, len ) )  
  274.                     PutBufLine( hbuf, ln, buf2 )  
  275.                 }  
  276.             }  
  277.         }  
  278.         ln = ln + 1  
  279.     }  
  280.     SetWndSel( hwnd, selection )  

 

 

 

增加后,通过在键分配中分配宏命令的按键

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值