转自: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. GoLand(一)安装

    Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.安装包下载地址https://golang.org/ 二.Windows下安装:1.下载好.msi的安装包文件 ...

  2. Scala 方法和函数

    package com.bigdata // /** Scala 方法和函数:Scala中既有函数也有方法,大多数情况下我们都可以不去理会他们之间的区别. * * 方法:Scala 中的方法跟 Jav ...

  3. springboot快速入门(一)——HelloWorld搭建

    一.起步 1.先导 凡技术必登其官网的原则,官网走一波:https://projects.spring.io/spring-boot/#quick-start 极力推荐一个springboot教程:h ...

  4. WPF字体模糊解决方案

    原文:WPF字体模糊解决方案 WPF对字体渲染做了很大的改善,与Winform窗体字体相比较,更加平滑,但是当字体大小较小时,则会出现字体模糊的现象.可通过以下方法进行改善处理: 对于XAML用户界面 ...

  5. 【BZOJ1070】[SCOI2007]修车

    [BZOJ1070][SCOI2007]修车 题面 以后要多写题面flag 题目描述 同一时刻有\(N\)位车主带着他们的爱车来到了汽车维修中心.维修中心共有\(M\)位技术人员,不同的技术人员对不同 ...

  6. AGC 030 B - Tree Burning

    B - Tree Burning 链接 题意: 一个长度为L的环,有n个位置上有树,从0出发,每次选择一个方向(顺时针或者逆时针),一直走,直到走到一棵树的位置,烧掉这棵树,重复这个过程,直到没有树. ...

  7. JavaScript流程控制及函数

    1 流程控制 1.1 条件语句 分支结构 单向分支 if (条件表达式) { code...} 双向分支 if (条件表达式){    } else {    } <!DOCTYPE html& ...

  8. lastIndexOf()

    方法可返回一个指定的字符串值最后出现的位置,在一个字符串中的指定位置从后向前搜索.

  9. How to: Display a Non-Persistent Object's List View from the Navigation

    This example demonstrates how to display a non-persistent object's List View when a navigation item ...

  10. django 部署一个简单的博客系统

    转:https://www.cnblogs.com/fnng/p/3737964.html 写的目的, 加深影响,熟悉开发流程, 开发都是练出来的. 环境 python3.5 windows 7 1. ...