声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2171|回复: 0

[Fortran] CVF注释多行的宏命令[转贴]

[复制链接]
发表于 2007-6-18 07:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
不止一位问道可不可以在CVF中为多行代码加注释。
CVF本身无这样的功能,但是可以用macro功能自己添!而且是添加工具钮!
俺初步试验成功,虽然在容错性方面还可以改进,但已经基本够用,特奉献给大家。

做法:

(1) 在..\Microsoft Visual Studio\Common\MSDEV98\MACROS文件夹下生成文件GrpComment.dsm
(2) 用文本编辑器打开该文件,将以下所附的代码贴在其中,保存(注意保留.dsm后缀)
(3) 启动CVF,选Tools=>Customize=>Add-ins and Macro Files
(4) 在GrpComment前打勾,去掉其他的勾
(5) 在同一对话框中选Commands=>Macros,此时在右边可以看见CommentDel和CommentOut
(6) 选中CommentOut,拖到CVF的工具栏上去(添加工具钮),会弹出Button Appearance对话框
(7) 选Image and text,在下边Button text框中输入名称(默认是CommentOut),如“加注释”
(8) 类似的方法再将CommentDel命令以工具钮的形式添加到工具栏上,名称可取为“去注释”

这时,工具栏上应该多了两个工具钮:“加注释”和“去注释”。

用法:

加注释:选择要加注释的多行代码,点击“加注释”按钮即可;
去注释:选择已经注释的多行代码,点击“去注释”按钮即可。

适用:后缀为f90或f77的代码文件。

Enjoy!!!


VBscript代码:

  1. Function FileType (ByVal doc)

  2.     ext = doc.Name

  3.     FileType = 0

  4.     pos = Instr(ext, ".")

  5.     if pos > 0 then

  6.         Do While pos <> 1

  7.             ext = Mid(ext, pos, Len(ext) - pos + 1)

  8.             pos = Instr(ext, ".")

  9.         Loop

  10.         ext = LCase(ext)

  11.     end if

  12.     If ext = ".f90" Then

  13.         FileType = 8

  14.     ElseIf ext = ".for" Then

  15.         FileType = 9

  16.     Else

  17.         FileType = 0

  18.     End If

  19. End Function
复制代码


  1. Sub CommentOut ()

  2. 'DESCRIPTION: 为所选的多行代码加注释

  3.     Dim win

  4.     set win = ActiveWindow

  5.     if win.type <> "Text" Then

  6.       MsgBox "This macro can only be run when a text editor window is active."

  7.     else

  8.         TypeOfFile = FileType(ActiveDocument)  

  9.         If TypeOfFile = 8 Or TypeOfFile = 9 Then



  10.             If TypeOfFile = 8 Then

  11.                 CommentType = "! "  ' Fortran 90 file

  12.             Else

  13.                 CommentType = "C "  ' Fortran 77 file

  14.             End If

  15.      

  16.             StartLine = ActiveDocument.Selection.TopLine

  17.             EndLine = ActiveDocument.Selection.BottomLine

  18.             If EndLine < StartLine Then

  19.                 Temp = StartLine

  20.                 StartLine = EndLine

  21.                 EndLine = Temp

  22.             End If



  23.             If EndLine = StartLine Then

  24.                 ActiveDocument.Selection.SelectLine

  25.                 ActiveDocument.Selection = CommentType + ActiveDocument.Selection



  26.             Else

  27.                 For i = StartLine To EndLine

  28.                     ActiveDocument.Selection.GoToLine i

  29.                     ActiveDocument.Selection.SelectLine

  30.                     ActiveDocument.Selection = CommentType + _

  31.                         ActiveDocument.Selection

  32.                 Next

  33.             End If

  34.         else

  35.             MsgBox("Unable to comment out the highlighted text" + vbLf + _

  36.                     "because the file type was unrecognized." + vbLf + _

  37.                     "If the file has not yet been saved, " + vbLf + _

  38.                     "please save it and try again.")

  39.         End If

  40.     End If

  41. End Sub
复制代码


  1. Sub CommentDel ()

  2. 'DESCRIPTION: 去除所选的多行代码的注释

  3.     Dim win

  4.     set win = ActiveWindow

  5.     if win.type <> "Text" Then

  6.         MsgBox "This macro can only be run when a text editor window is active."

  7.     else

  8.         TypeOfFile = FileType(ActiveDocument)  

  9.         If TypeOfFile = 8 Or TypeOfFile = 9 Then



  10.             StartLine = ActiveDocument.Selection.TopLine

  11.             EndLine = ActiveDocument.Selection.BottomLine

  12.             If EndLine < StartLine Then

  13.                 Temp = StartLine

  14.                 StartLine = EndLine

  15.                 EndLine = Temp

  16.             End If



  17.             If EndLine = StartLine Then

  18.                 ActiveDocument.Selection.SelectLine

  19.                 ActiveDocument.Selection = mid(ActiveDocument.Selection, 3)

  20.             Else

  21.                 For i = StartLine To EndLine

  22.                     ActiveDocument.Selection.GoToLine i

  23.                     ActiveDocument.Selection.SelectLine

  24.                     ActiveDocument.Selection = mid(ActiveDocument.Selection, 3)

  25.                 Next

  26.             End If

  27.         else

  28.             MsgBox("Unable to comment out the highlighted text" + vbLf + _

  29.                     "because the file type was unrecognized." + vbLf + _

  30.                     "If the file has not yet been saved, " + vbLf + _

  31.                     "please save it and try again.")

  32.         End If

  33.     End If

  34. End Sub
复制代码


来自编程爱好者mltx
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-7 07:48 , Processed in 0.135894 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表