source insight 宏进阶功能( 三 )

< strlen(szCodeEnd)){if(AsciiFromChar(szCodeEnd[index]) == 9){end_space_count = end_space_count + 1}index = index + 1}//代码块的第一行和最后一行前面的Tab个数,取比较小的那个值if(start_space_count < end_space_count){insert_space_count = start_space_count - 1}else{insert_space_count = end_space_count - 1}str_start_insert = ""str_end_insert = ""index = 0while(index < insert_space_count){str_start_insert = str_start_insert#"" //这里添加的Tab字符str_end_insert = str_end_insert#"" //这里添加的也是Tab字符index = index + 1}str_start_insert = str_start_insert#"#if 0"//在#if 0 开始符号和结束符号前都添加Tab字符,比代码行前面的空白少一个str_end_insert = str_end_insert#"#endif"if(TrimString(szIfStart) == "#if 0" && TrimString(szIfEnd) == "#endif"){DelBufLine(hbuf, lnLast + 1)DelBufLine(hbuf, lnFirst - 1)sel.lnFirst = sel.lnFirst - 1sel.lnLast = sel.lnLast - 1}else{InsBufLine(hbuf, lnFirst, str_start_insert)InsBufLine(hbuf, lnLast + 2, str_end_insert)sel.lnFirst = sel.lnFirst + 1sel.lnLast = sel.lnLast + 1}SetWndSel(hwnd, sel )}//将选中的代码块添加多行注释/**/,ALT+/macro xzy_slash_star_add_remove(){hwnd = GetCurrentWnd()sel = GetWndSel(hwnd)lnFirst = GetWndSelLnFirst(hwnd)lnLast = GetWndSelLnLast(hwnd)hbuf = GetCurrentBuf()if(LnFirst == 0){szIfStart = ""}else{szIfStart = GetBufLine(hbuf, LnFirst - 1) //被选择的第一行的上一行的内容}szIfEnd = GetBufLine(hbuf, lnLast + 1) //被选择的代码块的最后一行的下一行内容szCodeStart = GetBufLine(hbuf, LnFirst) //被选择的代码块的第一行内容szCodeEnd = GetBufLine(hbuf, lnLast)//被选择的代码块的最后一行内容start_space_count = 0 //第一行代码的前面的空白个数只计算Tab个数,忽略空格end_space_count = 0//最后一行的代码的前面的空白个数insert_space_count = 0index = 0while(index < strlen(szCodeStart)){if(AsciiFromChar(szCodeStart[index]) == 9){//9是Tab字符的ASCIIstart_space_count = start_space_count + 1}index = index + 1}index = 0while(index < strlen(szCodeEnd)){if(AsciiFromChar(szCodeEnd[index]) == 9){end_space_count = end_space_count + 1}index = index + 1}if(start_space_count < end_space_count){insert_space_count = start_space_count - 1}else{insert_space_count = end_space_count - 1}str_start_insert = ""str_end_insert = ""index = 0while(index < insert_space_count){str_start_insert = str_start_insert#"" //这里添加的Tab字符str_end_insert = str_end_insert#""index = index + 1}str_start_insert = str_start_insert#"/*"//在注释开始符号和结束符号前都添加Tab字符,比代码行前面的空白少一个str_end_insert = str_end_insert#"*/"if(TrimString(szIfStart) == "/*" && TrimString(szIfEnd) == "*/"){DelBufLine(hbuf, lnLast + 1)DelBufLine(hbuf, lnFirst - 1)sel.lnFirst = sel.lnFirst - 1sel.lnLast = sel.lnLast - 1}else{InsBufLine(hbuf, lnFirst, str_start_insert)InsBufLine(hbuf, lnLast + 2, str_end_insert)sel.lnFirst = sel.lnFirst + 1sel.lnLast = sel.lnLast + 1}SetWndSel(hwnd, sel )}//###########################################################################//去掉左边空格,Tab等macro TrimLeft(szLine){nLen = strlen(szLine)if(nLen == 0){return szLine}nIdx = 0while(nIdx < nLen ){if((szLine[nIdx] != " ") &&(szLine[nIdx] != "\t") ){break}nIdx = nIdx + 1}return strmid(szLine, nIdx, nLen)}//去掉字符串右边的空格macro TrimRight(szLine){nLen = strlen(szLine)if(nLen == 0){return szLine}nIdx = nLenwhile(nIdx > 0 ){nIdx = nIdx - 1if((szLine[nIdx] != " ") &&(szLine[nIdx] != "\t") ){break}}return strmid(szLine, 0, nIdx + 1)}//去掉字符串两边空格macro TrimString(szLine){szLine = TrimLeft(szLine)szLIne = TrimRight(szLine)return szLine}/*-------------------------------------------------------------------------INSERT HEADERInserts a comment header block at the top of the current function.This actually works on any type of symbol, not just functions.To use this, define an environment variable "MYNAME" and set itto your email name.eg. set MYNAME=raygr-------------------------------------------------------------------------*/macro InsertHeader(){// Get the owner's name from the environment variable: MYNAME.// If the variable doesn't exist, then the owner field is skipped.szMyName = getenv(MYNAME)// Get a handle to the current file buffer and the name// and location of the current symbol where the cursor is.hbuf = GetCurrentBuf()szFunc = GetCurSymbol()ln = GetSymbolLine(szFunc)// begin assembling the title stringsz = "/*"/* convert symbol name to TEXT LIKE THIS */cch = strlen(szFunc)ich = 0while(ich