Skip to content

Commit

Permalink
Cleanup [minor]
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris White committed Apr 20, 2018
1 parent 9956f29 commit 311b44c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 100 deletions.
Binary file modified VimWord.dotm
Binary file not shown.
120 changes: 60 additions & 60 deletions frmGrabKeys.frm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Public Enum VimCommand ' Intransitive commands
' thanks to https://www.fprintf.net/vimCheatSheet.html and :help change.txt

vcUndef

' Note: intransitive motions (e.g., 0, ^, $) are handled with a fake operator voGo.
'vcAppend ' a
'vcAppendEOL ' A
Expand All @@ -87,33 +87,33 @@ Public Enum VimCommand ' Intransitive commands
'vcReplace ' R
'vcOpen ' o
'vcOpenAbove ' O

'vcDelAfter ' x
'vcDelBefore ' X
' TODO D, C, s, S

' TODO implement these once I implement registers
'vcPutAfter ' p
'vcPutBefore ' P
' TODO gp, gP, ]p, [p, ]P, [P

'vcUndo ' u
'vcRedo ' Ctl+R
'vcUndoLine ' U

' TODO z., zt, zb, z+, z-

' TODO /, ?
'vcSearchNext ' n
'vcSearchPrev ' N

' TODO J, gJ
End Enum 'VimCommand

Public Enum VimOperator
voUndef
voGo ' Placeholder for motions, which don't have an operator.

'voReplaceChar ' r (more like an operator than anything else) (maybe?)
' TODO m, ', ` here?

Expand All @@ -125,7 +125,7 @@ Public Enum VimOperator
' TODO Maybe a custom titlecase on g~?
'voLowercase ' gu unimpl
'voUppercase ' gU unimpl

'voFilter ' ! No plans to implement this.
'voEqualPrg ' = No plans to implement this.
'voFormatLines ' gq No plans to implement this.
Expand All @@ -135,7 +135,7 @@ Public Enum VimOperator
'voSHL ' < No plans to implement this.
'voDefineFold ' zf No plans to implement this.
'voCallFunc ' g@ No plans to implement this.

' Custom (not in Vim)
voSelect ' s Select <motion>. Mostly for use as a debugging aid.
End Enum 'VimOperator
Expand All @@ -148,7 +148,7 @@ End Enum 'VimOperator

Public Enum VimMotion ' Motions/objects/direct objects of transitive operators
vmUndef

' Objects from :help visual-operators
vmAWord ' aw
vmIWord ' iw
Expand All @@ -166,7 +166,7 @@ Public Enum VimMotion ' Motions/objects/direct objects of transitive operators
' a"/i" " Double-quoted string
' a'/i' " Single-quoted string
' a`/i` " Backtick-quoted string

' Motions from :help left-right-motions
vmLeft ' h
vmRight ' l
Expand All @@ -180,7 +180,7 @@ Public Enum VimMotion ' Motions/objects/direct objects of transitive operators
vmTilForward ' t
vmTilBackward ' T
' TODO? ; ,

' :help up-down-motions
vmUp ' k
vmDown ' j
Expand All @@ -189,35 +189,35 @@ Public Enum VimMotion ' Motions/objects/direct objects of transitive operators
vmLine ' G ' TODO decide how to implement this; implement goto para/page
' gg (G, but not a jump) unimpl
' % (goto percentage), go (byte offset) unimpl

' :help word-motions
vmWordForward ' w exclusive
' TODO: operator+w and last word is at end of line => stop at end of word
vmNonblankForward ' W excl

vmEOWordForward ' e inclusive
vmEONonblankForward ' E incl

vmWordBackward ' b excl
vmNonblankBackward ' B excl

'vmEOWordBackward ' ge incl not yet impl
'vmEONonblankBackward ' gE incl "

' :help object-motions
vmSentenceForward ' )
vmSentenceBackward ' (
vmParaForward ' }
vmParaBackward ' {
vmSectionForward ' ]] or ][ (NOTE: not distinguishing the two)
vmSectionBackward ' [[ or [] (NOTE: not distinguishing the two)

' Custom (not in Vim) (TODO)
'vmRevisionForward
'vmRevisionBackward
'vmARevision
'vmIRevision

End Enum 'VimMotion
'

Expand Down Expand Up @@ -260,31 +260,31 @@ Private Sub UserForm_Initialize()
VOperatorCount = 1
VMotionCount = 1
VArg = ""

Dim PC As Long: PC = 0 ' Paren counter
Dim PC_INTRANS As Long, PC_TRANS As Long

Set RE_ACT = New VBScript_RegExp_55.RegExp

Dim PAT_INTRANS As String ' Pattern for an intransitive sentence, after goal and quantifier
' Not yet impl
Dim PAT_TRANS As String ' Pattern for a transitive sentence, after goal and quantifier
' TODO figure out ^0$

' Note: /^"./ (register/goal) not yet implemented

' === Build up the regex ===
' We do this a piece at a time to make it easier to change later.
' Also, this prevents you from going insane trying to manually track
' submatch numbers between pieces of the regex.

PAT_INTRANS = _
"([0\^$wWeEbB]|[fFtT](.))" ' includes motions
' | |
RESM_IVERB = 0 '-^ |
RESM_ITEXT = 1 ' ------------------'
' | |
RESM_IVERB = 0 '-^ |
RESM_ITEXT = 1 ' --------------------'
PC_INTRANS = 2

PAT_TRANS = _
"([cdys])?([1-9][0-9]*)?([ai]([wWsp])|[fFtT](.)|[hjklGwebWEB\)\(\}\{])"
' | | | | |
Expand All @@ -294,22 +294,22 @@ Private Sub UserForm_Initialize()
RESM_OBJTYPE = 3 ' -----------------------' |
RESM_TTEXT = 4 ' ------------------------------------------'
PC_TRANS = 5

RE_ACT.Pattern = "^([1-9][0-9]*)?(" & _
"(" & PAT_INTRANS & ")" & _
"|" & _
"(" & PAT_TRANS & ")" & _
")$"
'RESM_REGISTER | not yet implemented
' RESM_COUNT1-^ |
RESM_COUNT1 = 0 ' |565
RESM_COUNT1 = 0 ' |
' Grouping parens numbered --' but we don't use them

' Get submatch numbers for intransitive
PC = 3 ' RESM_COUNT1, and two following open parens
RESM_IVERB = RESM_IVERB + PC
RESM_ITEXT = RESM_ITEXT + PC

' Get submatch numbers for transitive
PC = PC + PC_INTRANS
PC = PC + 1 ' open paren before PAT_TRANS
Expand All @@ -319,7 +319,7 @@ Private Sub UserForm_Initialize()
RESM_OBJTYPE = RESM_OBJTYPE + PC
RESM_TTEXT = RESM_TTEXT + PC
PC = PC + PC_TRANS

End Sub 'UserForm_Initialize
'

Expand Down Expand Up @@ -347,11 +347,11 @@ End Sub 'KeyPress
Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean
' Returns true if parse succeeded
ProcessHit_ = False

If IsEmpty(hit.SubMatches(RESM_TVERB)) Then ' intransitive

'Debug.Print "Intransit.", Left(hit.SubMatches(RESM_IVERB), 1), hit.SubMatches(RESM_ITEXT)

Select Case Left(hit.SubMatches(RESM_IVERB), 1)
Case "0": VOperator = voGo: VMotion = vmStartOfParagraph
Case "^": VOperator = voGo: VMotion = vmStartOfLine
Expand All @@ -362,33 +362,33 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean
Case "E": VOperator = voGo: VMotion = vmEONonblankForward
Case "b": VOperator = voGo: VMotion = vmWordBackward
Case "B": VOperator = voGo: VMotion = vmNonblankBackward

Case "f": VOperator = voGo: VMotion = vmCharForward: VArg = hit.SubMatches(RESM_ITEXT)
Case "F": VOperator = voGo: VMotion = vmCharBackward: VArg = hit.SubMatches(RESM_ITEXT)
Case "t": VOperator = voGo: VMotion = vmTilForward: VArg = hit.SubMatches(RESM_ITEXT)
Case "T": VOperator = voGo: VMotion = vmTilBackward: VArg = hit.SubMatches(RESM_ITEXT)

Case Else: Exit Function
End Select

Else ' transitive

'Debug.Print "Transitive", hit.SubMatches(RESM_TVERB), hit.SubMatches(RESM_COUNT2), Left(hit.SubMatches(RESM_TOBJ), 1), hit.SubMatches(RESM_OBJTYPE), hit.SubMatches(RESM_TTEXT)

Select Case hit.SubMatches(RESM_TVERB)
Case "c": VOperator = voChange
Case "d": VOperator = voDelete
Case "y": VOperator = voYank
Case "s": VOperator = voSelect
Case Else: Exit Function
End Select

If Len(hit.SubMatches(RESM_COUNT2)) = 0 Then
VMotionCount = 1
Else
VMotionCount = CLng(hit.SubMatches(RESM_COUNT2))
End If

Select Case Left(hit.SubMatches(RESM_TOBJ), 1)
Case "a":
Select Case hit.SubMatches(RESM_OBJTYPE)
Expand All @@ -397,26 +397,26 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean
Case "s": VMotion = vmASentence
Case "p": VMotion = vmAPara
End Select

Case "i":
Select Case hit.SubMatches(RESM_OBJTYPE)
Case "w": VMotion = vmIWord
Case "W": VMotion = vmINonblank
Case "s": VMotion = vmISentence
Case "p": VMotion = vmIPara
End Select

Case "f": VMotion = vmCharForward: VArg = hit.SubMatches(RESM_TTEXT)
Case "F": VMotion = vmCharBackward: VArg = hit.SubMatches(RESM_TTEXT)
Case "t": VMotion = vmTilForward: VArg = hit.SubMatches(RESM_TTEXT)
Case "T": VMotion = vmTilBackward: VArg = hit.SubMatches(RESM_TTEXT)

Case "h": VMotion = vmLeft
Case "j": VMotion = vmDown
Case "k": VMotion = vmUp
Case "l": VMotion = vmRight
Case "G": VMotion = vmLine

Case "w": VMotion = vmWordForward
Case "e": VMotion = vmEOWordForward
Case "b": VMotion = vmWordBackward
Expand All @@ -427,12 +427,12 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean
Case "(": VMotion = vmSentenceBackward
Case "}": VMotion = vmParaForward
Case "{": VMotion = vmParaBackward

Case Else: Exit Function
End Select

End If ' Intransitive else

ProcessHit_ = True ' If we made it here, the parse was successful

End Function ' ProcessHit_
Expand All @@ -441,33 +441,33 @@ End Function ' ProcessHit_
Private Sub Update()
Dim done As Boolean: done = False
lblKeys.Caption = Keys

VArg = "" ' empty unless assigned below (fFtT)

' parse Vim commands to see if one is done
Dim matches As VBScript_RegExp_55.MatchCollection
Dim hit As VBScript_RegExp_55.Match

Set matches = RE_ACT.Execute(Keys)
If matches.count > 0 Then
Do 'Once
Set hit = matches.Item(0)
If hit.SubMatches.count < 1 Then Exit Do

If Len(hit.SubMatches(RESM_COUNT1)) = 0 Then
' Note: works because Len(Empty) returns 0
VOperatorCount = 1
Else
VOperatorCount = CLng(hit.SubMatches(RESM_COUNT1))
End If

done = ProcessHit_(hit)

'If done Then Debug.Print "", "operator count:", VOperatorCount

Loop While False
End If

If done Then Me.Hide
End Sub 'Update

Binary file modified frmGrabKeys.frx
Binary file not shown.
Loading

0 comments on commit 311b44c

Please sign in to comment.