source insight实现多行代码注释功能

sourceinsight软件没有自带多行代码注释功能,使用起来很不方便,在网上查到实现多行代码注释功能的方法,具体步骤如下:

1. 在notepad或记事本下将注释多行代码的宏定义保存成***.em文件。宏定义内容为:

macro MultiLineComment()

{

    hwnd = GetCurrentWnd()

    selection = GetWndSel(hwnd)

    LnFirst =GetWndSelLnFirst(hwnd)      //取首行行号

    LnLast =GetWndSelLnLast(hwnd)      //取末行行号

    hbuf = GetCurrentBuf()



    if(GetBufLine(hbuf, 0) =="//magic-number:tph85666031"){

        stop

    } 

    Ln = Lnfirst

    buf = GetBufLine(hbuf, Ln)

    len = strlen(buf)



    while(Ln <= Lnlast) {

        buf = GetBufLine(hbuf, Ln)  //取Ln对应的行

        if(buf ==""){                   //跳过空行

            Ln = Ln + 1

            continue

        }

        if(StrMid(buf, 0, 1) == "/"){       //需要取消注释,防止只有单字符的行

            if(StrMid(buf, 1, 2) == "/"){

                PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))

            }

        } 

        if(StrMid(buf,0,1) !="/"){          //需要添加注释

            PutBufLine(hbuf, Ln, Cat("//", buf))

        }

        Ln = Ln + 1

    }



    SetWndSel(hwnd, selection)

}

2. 创建sourceinsight工程,将工程所需的源代码与上一步骤中的***.em文件都添加到工程中。

3. 重建工程: Project->Rebuilt Project; (若是在工程建好后再添加.em文件,此步很重要)

4.添加快捷键: Options->Key Assignment,在command编辑框下敲入MultiLineComment会出现Macro:MultiLineComment, 点击Assign New Key...,输入快捷键,常用的是Ctrl+\, 若该快捷键已被占用,可使用Ctrl+shift+\或其他习惯用的。

5.添加工具栏菜单: Options->Menu Assignment, 同样在command编辑框下敲入MultiLineComment, 点击右边的Menu下拉框,选择想要放的菜单栏,例如放在work菜单栏下,再双击MeauContents下的<end of menu>,点击右边的Insert按钮,插入子菜单名称即可,如MultiLineComment, 再点击OK。

6.此时选择多行代码按快捷键就可以注释和非注释某些代码了。主菜单下会有Work菜单项,Work下有MultiLineComment子菜单项,并且显示了快捷键,选择需要注释的代码段,点击子菜单或使用快捷键即可实现多行注释,再点击快捷键或子菜单即可消除多行注释。

猜你喜欢

转载自blog.csdn.net/aa804738534/article/details/112799248