Mar272008

EmEditor 宏——删除行尾部空白部分

删除行尾部的空白部分(包括空格、制表符、换页符等空白字符)是代码整理常用的功能,在 EditPlus 中的 Edit -> Format -> Trim Trailing Spaces 就是来完成这个操作的,不知道为什么在 中没有把这个功能放到默认菜单中,只不过是一行代码而已。

File Name: TirmTrailingSpaces.vbee

1
2
nFound = document.selection.Replace("\s+?$", "", _
         eeFindReplaceRegExp + eeReplaceSelOnly + eeReplaceAll)

将 TirmTrailingSpaces.vbee 宏文件载入 中,然后手动添加到弹出菜单中,使用的时候,选择要替换的部分,然后在弹出菜单中选择 Trim Trailing Spaces 就可以了。

Mar242008

EmEditor 宏——行数统计+规约测试


功能:用来统计修改项目的代码行数,简单的规约测试。

修改过的部分在原程序的基础上追加以下代码:

1
2
3
4
5
6
7
8
9
Insert
//↓2008/03/10 Begin CompanyName UserName INS
//↑2008/03/10 End CompanyName UserName INS
Update
//↓2008/03/10 Begin CompanyName UserName UPD
//↑2008/03/10 End CompanyName UserName UPD
Delete
//↓2008/03/10 Begin CompanyName UserName DEL
//↑2008/03/10 End CompanyName UserName DEL

实际代码行数 = 追加的代码 + 删除的代码 + 修改后的代码(修改时被注释的部分不算)

文件名:EditCountFormat.vbee

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
'2008.02.29 修改代码行统计
'2008.02.29 修改代码行统计修正 UPD注释部分不算统计行
'2008.03.05 追加 修改代码的拷贝
'           追加 Tab存在Check
'           追加 结尾多余空格Check
'           追加 重复空格Check
'           追加 全角空格Check
'           追加 带*号的引用Check
'           追加 无用的换行Check
'           追加 左小括号Check
'           追加 逗号Check
Public GstrBegin, GstrEnd 
Public GintBegin, GintEnd, GintCount, GintOldBegin, GintOldEnd
GstrBegin = "^[ \t]*//↓.*Begin[ \t]XXXX.*"
GstrEnd = "^[ \t]*//↑.*End[ \t]XXXX.*"
 
document.selection.StartOfDocument false
 
blnEnd = False
GintCount = 0
strCountMsg = ""
strAllEditText = ""
 
Do While not blnEnd
    GintBegin = 0
    GintEnd = 0
    blnBeginOK = False
    blnEndOK = False
    intEditBegin = 0
    strSelectTxt = ""
    intEndx = 0
    if Document.selection.Find(GstrBegin, eeFindNext + eeFindReplaceRegExp) = 1 Then
      GintBegin = Document.selection.GetActivePointY(eePosView)
      strSelectTxt = Document.selection.Text
      intEditBegin = GintBegin
      GintOldBegin = GintBegin
      if Instr(strSelectTxt, "UPD") > 0 Then
        GintBegin = GintBegin + 1
        Do
          document.selection.SetActivePoint eePosView, 1, GintBegin
          document.selection.SelectLine
          strSelectTxt = Document.selection.Text
          if Instr(strSelectTxt, "//") = 0 Then
            GintBegin = GintBegin - 1
            Exit Do
          Else
            GintBegin = GintBegin + 1
          End If
        Loop
      End If
      blnBeginOK = True
    Else
      blnEnd = True
    End If
 
    if Document.selection.Find(GstrEnd, eeFindNext + eeFindReplaceRegExp) = 1 Then
      GintEnd = Document.selection.GetActivePointY(eePosView)
      intEndx = Document.selection.GetActivePointX(eePosView)
      GintOldEnd = GintEnd
      blnEndOK = True
    Else
      blnEnd = True
    End If
 
    if blnBeginOK and not blnEndOK Then
      alert "注释不匹配,有开始没有结束!" + chr(13) + chr(10) _
          + " 上次开始行 " + cstr(GintOldBegin) + " 上次结束行 " + cstr(GintOldEnd)
    Elseif not blnBeginOK and blnEndOK Then
      alert "注释不匹配,有结束没有开始! 结束行 " + cstr(GintEnd) + chr(13) + chr(10) _
          + " 上次开始行 " + cstr(GintOldBegin) + " 上次结束行 " + cstr(GintOldEnd)
    Elseif not blnBeginOK and not blnEndOK Then
      strCountMsg = "统计结束,修改的代码行数为 """ + cstr(GintCount) + " 行"""
    Else
      GintCount = GintCount + GintEnd - GintBegin - 1
 
      '2008.03.05 Add-------------------->
      Do While intEditBegin <> GintEnd + 1
        document.selection.SetActivePoint eePosView, 1, intEditBegin
        document.selection.SelectLine
        strAllEditText = strAllEditText + Document.selection.Text
        intEditBegin = intEditBegin + 1
      Loop
      document.selection.SetActivePoint eePosView, intEndx, GintEnd
      '2008.03.05 Add<--------------------
    End If
Loop
 
alert strCountMsg
 
'创建新文档
editor.NewFile
document.ConfigName = "Java"
'输出检查结果
document.write strAllEditText
 
'--------------------------------------------------------------------------------
Public pErrArray ()
 
Redim pErrArray(1)
 
'Tab存在Check
call checkRegExp("\t+.*$", "存在Tab键")
'结尾多余空格Check
call checkRegExp("^.*\s+$", "结尾多余空格")
'重复空格Check
call checkRegExp("(^\ +(?!\ ).*\ {2}.*$)|(^(?!\ )+.*\ {2}.*$)", "重复空格")
'全角空格Check
call checkRegExp(" ", "包含全角空格")
'带*号的引用Check
call checkRegExp("^import.*\*.*$", "带*号的引用")
'无用的换行Check
call checkRegExp("^[\s*]*\n[\s*]*$", "无用的换行")
'左小括号Check
call checkRegExp("^\s*if\(|^.*=\(|^.*\( ", "左括号空格不正")
'右小括号Check(未完成)
'call checkRegExp(, )
'逗号Check
call checkRegExp("^.*,(?! )\b", "逗号空格不正")
 
'---------------------------------- Check结束 ---------------------------------
'创建新文档
editor.NewFile
document.ConfigName = "Java"
strErrMessage = ""
strErrMessage = strErrMessage & strCountMsg & chr(13) & chr(10)
For intItem = 1 to UBound (pErrArray)
    strErrMessage = strErrMessage & pErrArray(intItem) & chr(13) & chr(10)
Next
'输出检查结果
document.write strErrMessage
 
'------------------------------------------------------------------------------
'正则表达式Check
Private Sub checkRegExp(strRegExp, errMsg)
    '将光标定位到文件头
    document.selection.StartOfDocument false
    Do While Document.selection.Find (strRegExp, eeFindNext + eeFindReplaceRegExp) = 1
        call inputError(errMsg)
    Loop
End Sub 
'------------------------------------------------------------------------------
'错误输入
Private Sub inputError(errType)
    '行定位
    errRow = Document.selection.GetActivePointY(eePosView)
    '错误消息
    strErrMsg = "Row: " & errRow & " Type: " & errType & " | "
    strErrMsg = strErrMsg & Document.GetLine(errRow)
    pErrArray(UBound(pErrArray)) = strErrMsg
    ReDim Preserve pErrArray (UBound (pErrArray) + 1) 
    '同类型错误排除
    document.selection.LineDown 
End Sub