天天看点

source insight 自动注释函数宏

这几天偶然间发现source insight 居然更新了!之前因为嫌弃si界面丑陋、对中文支持不好,转而用了sublime。期待了2年终于更新了,虽然界面还是那个鸟样,但是起码中文支持得不错了,现分享一下自己写的宏

/**
 * [InsertHeader description]
 * @Author   fanyusen
 * @DateTime 2017-03-02T19:46:34+0800
 */
macro InsertHeader()
{
    /* 获取光标所在行 */
    handle = GetCurrentWnd()
    process_line = GetWndSelLnFirst(handle)

    /* 获取函数所在行文本 */
    file_txt = GetCurrentBuf()
    process_txt = GetBufLine(file_txt,process_line + 1)
    process_txt_len = strlen(process_txt)

    if(process_txt == "")
    {
        stop
    }

    /* 获取函数名 */
    symbol_rec = GetSymbolLocationFromLn (handle, process_line + 1)
    if(symbol_rec == "")
    {
        stop
    }

    fuction_name = symbol_rec.Symbol
    
    /* 获取参数个数及参数名           */
    param_num = 0
    param_list = SymListNew()

    i=0,j=0
    while(i < process_txt_len)
    {
        if(process_txt[i] == "," || process_txt[i] == ")")
        {
            j = i
            while(j > 0)
            {
                if(process_txt[j] == " " || process_txt[j] == "*" || process_txt[j] == "&" ||
                   process_txt[j] == "(")
                {
                    symbol_rec.Symbol = strmid(process_txt,j+1,i)
                    SymListInsert(param_list,param_num,symbol_rec)
                    param_num = param_num + 1
                    break;
                }
                j = j - 1
            }
        }
        
        i = i + 1
    }

    /* 输出注释 */
    PutBufLine(handle,process_line + 0,"/** ")

    var temp_buffer
    temp_buffer = cat(" * [",fuction_name)
    temp_buffer = cat(temp_buffer," description]")
    InsBufLine(handle,process_line + 1,temp_buffer)

    InsBufLine(handle,process_line + 2," * \@Author   fanyusen")

    sys_time = GetSysTime(1)    
    temp_buffer = " * \@DateTime "
    temp_buffer = cat(temp_buffer,sys_time.date)
    temp_buffer = cat(temp_buffer,"T")
    temp_buffer = cat(temp_buffer,sys_time.time)
    temp_buffer = cat(temp_buffer,"+0800")

    InsBufLine(handle,process_line + 3,temp_buffer)

    param_line = process_line + 4
    InsBufLine(handle,param_line," */")
    
    if(strmid(process_txt,0,4) != "void")
    {
        InsBufLine(handle,param_line," * \@return                            [description]")
    }

    while(param_num > 0)
    {
        param_num = param_num - 1
        symbol_rec = SymListItem(param_list,param_num)

        temp_buffer = " * \@param    "
        temp_buffer = cat(temp_buffer,symbol_rec.Symbol)
        
        temp_buffer_len = strlen(temp_buffer)
        temp_buffer_len = 38 - temp_buffer_len
        while(temp_buffer_len > 0)
        {
            temp_buffer_len = temp_buffer_len - 1
            temp_buffer = cat(temp_buffer," ")
        }
        
        temp_buffer = cat(temp_buffer,"[description]")
        InsBufLine(handle,param_line,temp_buffer)
    }

    SymListFree(param_list)
}

           

效果如下:

source insight 自动注释函数宏
source insight 自动注释函数宏

继续阅读