转自:http://www.cnblogs.com/dongzhiquan/archive/2013/03/04/2943448.html

我们经常要对一整段代码进行注释,很多代码编辑器都提供了这样的功能:用快捷键“Ctrl + /”来实现“//”的多行注释。

但是在用source insight的时候,发现竟然没有这样的功能。于是在网上搜了一下,sourceinsight里面的多行注释可以用宏来实现。

以下是实现多行注释的宏代码(在别的网站copy过来的,经过测试,还是很好用的):

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)

}

将上面的代码另存为xxx.em文件,打开source insight,将该文件添加到工程中,然后在Options->KeyAssignments中你就可以看到这个宏了,宏的名字是MultiLineComments,然后我们为它分配快捷键“Ctrl + /”,然后就可以了。

这里还有一份添加“#ifdef 0”和“#endif”的宏代码:

macro AddMacroComment()

{

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)

if (szIfStart == "#if 0" && szIfEnd =="#endif") {

DelBufLine(hbuf, lnLast+1)

DelBufLine(hbuf, lnFirst-1)

sel.lnFirst = sel.lnFirst – 1

sel.lnLast = sel.lnLast – 1

} else {

InsBufLine(hbuf, lnFirst, "#if 0")

InsBufLine(hbuf, lnLast+2, "#endif")

sel.lnFirst = sel.lnFirst + 1

sel.lnLast = sel.lnLast + 1

}

SetWndSel( hwnd, sel )

}

这份宏的代码可以把光标显示的行注释掉:

macro CommentSingleLine()

{

hbuf = GetCurrentBuf()

ln = GetBufLnCur(hbuf)

str = GetBufLine (hbuf, ln)

str = cat("/*",str)

str = cat(str,"*/")

PutBufLine (hbuf, ln, str)

}

将一行中鼠标选中部分注释掉:

macro CommentSelStr()

{

hbuf = GetCurrentBuf()

ln = GetBufLnCur(hbuf)

str = GetBufSelText(hbuf)

str = cat("/*",str)

str = cat(str,"*/")

SetBufSelText (hbuf, str)

}

最后是source insight与宏有关的资源:

·                 source insight官方的宏库

·                 source insight官方帮助文档

Source Insight中的多行注释的更多相关文章

  1. source insight中的快捷键总结

    1.快捷键 1,Shift+F8高亮显示指定字符. 2,Ctrl+F找出来的结果用F4,F3前进后退查找. 3,Alt+,后退alt+.前进查找关键字. 4,Alt+G或者F5跳转到某个固定的行号. ...

  2. 在source insight中集成astyle

    转自:http://www.cnblogs.com/xuxm2007/archive/2013/04/06/3002390.html 好吧,我有代码格式的强迫症,代码不整齐,我看的都头疼,之前一直喜欢 ...

  3. Source Insight 中使用 AStyle 代码格式工具

    Source Insight 中使用 AStyle 代码格式工具 彭会锋 2015-05-19 23:26:32     Source Insight是较好的代码阅读和编辑工具,不过source in ...

  4. AStyle代码格式工具在source insight中的使用

    一.AStyle下载路径 Astyle为开源项目,支持C/C++和java的代码格式化 Home Page: http://astyle.sourceforge.net/ Project Page:  ...

  5. source insight 中tab键的设置

    转:http://xinzero.com/source-insight-code-alignment-ended.html source insight代码对齐Tab键终极版 以前也写过一个sourc ...

  6. Source Insight 中调用Notepad++

    options>custom commands 指令为 "E:\Program Files (x86)\Notepad++\notepad++.exe" %f 其中%f表示S ...

  7. Source Insight 中的 Auto Indenting

    编码过程中,希望输入花括号时能自动对齐,Source Insigth 应如何设置? 先来看一下Source Insight 中的帮助. “ Auto Indenting The auto-indent ...

  8. Source insight 中 标题栏路径显示完整路径的方法

    在source insight 的标题栏中显示完整路径名的方法.Options -> Preferences -> Display -> Trim long path names w ...

  9. ubuntu14.04中 gedit 凝视能显示中文,而source insight中显示为乱码的解决的方法

    1.乱码显示情况: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcjc3NjgzOTYy/font/5a6L5L2T/fontsize/400/fill/ ...

随机推荐

  1. c++ 双向循环链表

    教学内容: 循环双链表 建立循环双链表 循环链表里插入结点 遍历循环链表 双向链表结构定义 struct stu_data { ];//学生名字 struct mytime stuTime;/ ...

  2. 24-[模块]-re

    1.引入re 请从以下文件里取出所有的手机号 姓名 地区 身高 体重 电话 况咏蜜 北京 171 48 13651054608 王心颜 上海 169 46 13813234424 马纤羽 深圳 173 ...

  3. P4360 [CEOI2004]锯木厂选址

    P4360 [CEOI2004]锯木厂选址 这™连dp都不是 \(f_i\)表示第二个锯木厂设在\(i\)的最小代价 枚举1号锯木厂 \(f_i=min_{0<=j<i}(\sum_{i= ...

  4. nginx 部署前期一定要关闭selinux

    nginx 报错: 1389#1389: *40 "/home/data1/index.html" is forbidden (13: Permission denied), cl ...

  5. bintray 在android3.2上传遇到的问题

    1.报错信息如下: Gradle DSL method not found: 'google()'Possible causes: The project 'JustTest' may be usin ...

  6. Zigbee系列(路由机制)

    参考文档: ug103-02-fundamentals-zigbee.pdf section4 zigbe routing concepts docs-05-3474-21-0csg-zigbee-s ...

  7. Cocos2d-x Lua 学习

    mian.lua  文件是程序的入口.加载GameScene场景,调用场景方法. GameScene.lua 文件负责创建游戏主场景,主要写场景方法,由主函数调用.

  8. 32bit 天堂2 windows 2003 server架设教程

    安装环境::[注意:本教程newauth要用不加密的版本] windows 2003 enterprise server 100用户license Microsoft sql server 2000 ...

  9. SmartRaiden 和 Lighting Network 进行去中心化跨链原子资产交换

    作者介绍 虫洞社区·签约作者 steven bai 前言 如果能够进行以太坊和比特币跨链原子资产交换,是不是一件很酷的事情? 目前链下的扩容方式有很多,最广为人知的就是比特币的闪电网络和以太坊的雷电网 ...

  10. SDWebImage 错误汇总

    1.  [UIImageView sd_setImageWithURL:placeholderImage:]: unrecognized selector sent to instance 打包静态库 ...