用了许久source Insight写C/C++代码,发现其中没有块注释功能很不方便,于是今天研究了下怎样让sourceInsight实现块注释。
网上介绍了很多方法实现块注释,但是都是对代码利用“//”逐行注释,没有用“”实现的,我个人比较倾向于用注释代码块,所以今天自己动手写了利用”“实现块注释代码。
好了,废话不多说,直接上宏代码,后面会介绍使用方法:
- macro _tsGetTabSize()
- {
- szTabSize = GetReg("TabSize");
-
- if (szTabSize != "")
- {
- tabSize = AsciiFromChar(szTabSize[0]) - AsciiFromChar("0");
- }
- else
- {
- tabSize = 4;
- }
-
- return tabSize;
- }
-
-
- macro CommentBlock_Joyce()
- {
- hbuf = GetCurrentBuf();
- hwnd = GetCurrentWnd();
-
- sel = GetWndSel(hwnd);
-
- iLine = sel.lnFirst;
-
- // indicate the comment char according to the file type
- // for example, using "#" for perl file(.pl) and "" for C/C++.
- filename = tolower(GetBufName(hbuf));
- suffix = "";
- len = strlen(filename);
- i = len - 1;
- while (i >= 0)
- {
- if (filename[i-1] == ".")
- {
- suffix = strmid(filename, i, len)
- break;
- }
- i = i -1;
- }
- if ( suffix == "pl" )
- {
- filetype = 2; // PERL
- }
- else
- {
- filetype = 1; // C
- }
-
- szLine = GetBufLine(hbuf, iLine);
- if (filetype == 1) // C
- {
- szLine = cat(" ");
- }
- else // PERL
- {
- szLine = cat("# ", szLine);
- }
- PutBufLine(hbuf, iLine, szLine);
-
-
-
- if (sel.lnFirst == sel.lnLast)
- {
- tabSize = _tsGetTabSize() - 1;
- sel.ichFirst = sel.ichFirst + tabSize;
- sel.ichLim = sel.ichLim + tabSize;
- }
- SetWndSel(hwnd, sel);
- }
-
-
-
-
- //
- // Undo the CommentBlock for the selected text.
- //
- macro UnCommentBlock_Joyce()
- {
- hbuf = GetCurrentBuf();
- hwnd = GetCurrentWnd();
-
- sel = GetWndSel(hwnd);
-
- iLine = sel.lnFirst;
-
-
- // indicate the comment char according to the file type
- // for example, using "#" for perl file(.pl) and "" for C/C++.
- filename = tolower(GetBufName(hbuf));
- suffix = "";
- len = strlen(filename);
- i = len - 1;
- while (i >= 0)
- {
- if (filename[i-1] == ".")
- {
- suffix = strmid(filename, i, len)
- break;
- }
- i = i -1;
- }
- if ( suffix == "pl" )
- {
- filetype = 2; // PERL
- }
- else
- {
- filetype = 1; // C
- }
-
- tabSize = 0;
-
- endLine = GetBufLine(hbuf, sel.lnLast);
- endLineLen = strlen(endLine);
- szLine = GetBufLine(hbuf, iLine);
- len = strlen(szLine);
- szNewLine = "";
- commentState = 1;
-
- if (szLine[0] == "/" && szLine[1] == "*")
- {
- if(endLine[endLineLen-2] == "/" && endLine[endLineLen-3] == "*")
- {
- if (filetype == 1) // C
- {
- if (len > 1)
- {
- if (szLine[0] == "/" && szLine[1] == "*")
- {
- if (len > 2)
-
|