Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2691534
  • 博文数量: 505
  • 博客积分: 1552
  • 博客等级: 上尉
  • 技术积分: 2514
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-23 18:24
文章分类

全部博文(505)

文章存档

2019年(12)

2018年(15)

2017年(1)

2016年(17)

2015年(14)

2014年(93)

2013年(233)

2012年(108)

2011年(1)

2009年(11)

分类: 嵌入式

2019-03-13 16:49:53

步骤如下:
一、Project ---> Open Project 中打开Base项目(source insight自带的工程),新建一个comment.em的文件,添加以下内容后保存:

实现“//”的多行注释:

点击(此处)折叠或打开

  1. macro MultiLineComment()
  2. {
  3. hwnd = GetCurrentWnd()
  4. selection = GetWndSel(hwnd)
  5. LnFirst =GetWndSelLnFirst(hwnd) //取首行行号
  6. LnLast =GetWndSelLnLast(hwnd) //取末行行号
  7. hbuf = GetCurrentBuf()
  8. if(GetBufLine(hbuf, 0) =="//magic-number:tph85666031"){
  9. stop
  10. }
  11. Ln = Lnfirst
  12. buf = GetBufLine(hbuf, Ln)
  13. len = strlen(buf)
  14. while(Ln <= Lnlast) {
  15. buf = GetBufLine(hbuf, Ln) //取Ln对应的行
  16. if(buf ==""){ //跳过空行
  17. Ln = Ln + 1
  18. continue
  19. }
  20. if(StrMid(buf, 0, 1) == "/"){ //需要取消注释,防止只有单字符的行
  21. if(StrMid(buf, 1, 2) == "/"){
  22. PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))
  23. }
  24. }
  25. if(StrMid(buf,0,1) !="/"){ //需要添加注释
  26. PutBufLine(hbuf, Ln, Cat("//", buf))
  27. }
  28. Ln = Ln + 1
  29. }
  30. SetWndSel(hwnd, selection)
  31. }

实现“#ifdef 0”和“#endif”的宏代码:

点击(此处)折叠或打开

  1. macro AddMacroComment()
  2. {
  3. hwnd=GetCurrentWnd()
  4. sel=GetWndSel(hwnd)
  5. lnFirst=GetWndSelLnFirst(hwnd)
  6. lnLast=GetWndSelLnLast(hwnd)
  7. hbuf=GetCurrentBuf()
  8. if (LnFirst == 0) {
  9. szIfStart = ""
  10. } else {
  11. szIfStart = GetBufLine(hbuf, LnFirst-1)
  12. }
  13. szIfEnd = GetBufLine(hbuf, lnLast+1)
  14. if (szIfStart == "#if 0" && szIfEnd =="#endif") {
  15. DelBufLine(hbuf, lnLast+1)
  16. DelBufLine(hbuf, lnFirst-1)
  17. sel.lnFirst = sel.lnFirst – 1
  18. sel.lnLast = sel.lnLast – 1
  19. } else {
  20. InsBufLine(hbuf, lnFirst, "#if 0")
  21. InsBufLine(hbuf, lnLast+2, "#endif")
  22. sel.lnFirst = sel.lnFirst + 1
  23. sel.lnLast = sel.lnLast + 1
  24. }
  25. SetWndSel( hwnd, sel )
  26. }

这份宏的代码可以把光标显示的行注释掉:
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 = GetBufSel代写论文、pos(hbuf)
str = cat("/*",str)
str = cat(str,"*/")
SetBufSel代写论文、pos (hbuf, str)
}

然后在Options->KeyAssignments中你就可以搜索看到这几个宏了,宏的名字分别是MultiLineComments、AddMacroComment,然后我们为它们分别配快捷键“Ctrl + Alt + /”,“Ctrl + Shift + /” 就可以了。

主要参考以下文章:
https://blog.csdn.net/andylauren/article/details/69487230

阅读(76707) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~