Skip to content

Commit

Permalink
Changed X from dh to voDrop (delete; don't yank)
Browse files Browse the repository at this point in the history
Also, work around Word weirdness when using `ip` in a table cell.
  • Loading branch information
Chris White committed Jun 29, 2018
1 parent 8eb0d70 commit e9cf520
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
Binary file modified VimWord.dotm
Binary file not shown.
24 changes: 13 additions & 11 deletions frmGrabKeys.frm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Attribute VB_Exposed = False
' Len>0 checks. I had a situation in which a non-match
' returned "" rather than Empty.
' Added special-case code for 0 after nonempty count2.
' 2018-06-29 chrisw Changed X from `dh` to voDrop.
' `dh` is still available if you need it.

' NOTE: the consolidated reference is in :help normal-index

Expand Down Expand Up @@ -155,6 +157,7 @@ Public Enum VimOperator
voDelete ' d
voYank ' y
voSelect ' v Select <motion>.
voDrop ' X (Not in Vim): delete without yanking

'voSwitchCase ' ~/g~ unimpl
' TODO Maybe a custom titlecase on g~?
Expand Down Expand Up @@ -349,11 +352,12 @@ Private Sub UserForm_Initialize()
' DO NOT MODIFY HERE. If you need to change it, modify vim-regex.txt
' and re-run re2vba.pl.


RE_PAT = _
"^(([ ]?)([1-9][0-9]*)?(([ ]?)(([HMLGhjklwbWB\x28\x29\x7b\x7d" & _
"]|g?[eE0\^\$]|[fFtT](.))|(gW)?g?[\*#]|g?[pP])|([cdyv])([1-9]" & _
"[0-9]*)?(([\[\]])?([ai])([wWsp])|[fFtT](.)|[HMLGhjklwbWB\x28" & _
"\x29\x7b\x7d]|g?[eE0\^\$])|([xX\.])))$" & _
"]|g?[eE0\^\$]|[fFtT](.))|(gW)?g?[\*#]|g?[pP])|([cdyvX])([1-9" & _
"][0-9]*)?(([\[\]])?([ai])([wWsp])|[fFtT](.)|[HMLGhjklwbWB\x2" & _
"8\x29\x7b\x7d]|g?[eE0\^\$])|([x\.])))$" & _
""
RESM_SPACEONE = 1
RESM_COUNT1 = 2
Expand Down Expand Up @@ -503,9 +507,6 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean
' `x`: alias to `dl`
Case "x": tverb = "d": target = "l"

' `X`: alias to `dh`
Case "X": tverb = "d": target = "h"

Case Else: Exit Function
End Select
End If
Expand All @@ -516,8 +517,8 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean

If Len(hit.SubMatches(RESM_IVERB)) > 0 Then ' intransitive

Debug.Print "Intransit.", IIf(Len(hit.SubMatches(RESM_IMOTION)) = 0, "-", hit.SubMatches(RESM_IMOTION)), _
hit.SubMatches(RESM_IVERB), hit.SubMatches(RESM_ITEXT)
'Debug.Print "Intransit.", IIf(Len(hit.SubMatches(RESM_IMOTION)) = 0, "-", hit.SubMatches(RESM_IMOTION)), _
' hit.SubMatches(RESM_IVERB), hit.SubMatches(RESM_ITEXT)

If Len(hit.SubMatches(RESM_IMOTION)) > 0 Then
If ProcessMotion_(hit.SubMatches(RESM_IMOTION)) Then
Expand Down Expand Up @@ -558,14 +559,15 @@ Private Function ProcessHit_(hit As VBScript_RegExp_55.Match) As Boolean

ElseIf Len(tverb) > 0 Then ' transitive

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

' Operator
Select Case tverb
Case "c": VOperator = voChange
Case "d": VOperator = voDelete
Case "y": VOperator = voYank
Case "v": VOperator = voSelect ' V, i.e., visual selection - just like in Vim.
Case "X": VOperator = voDrop ' X, repurposed from Vim.
Case Else: Exit Function
End Select

Expand Down Expand Up @@ -642,15 +644,15 @@ Private Sub Update()
DotCount_ = 1 ' In case we have a . this time

Do
Debug.Print "Checking -" & CStr(Keys) & "-"
'Debug.Print "Checking -" & CStr(Keys) & "-"

times_through = times_through + 1
Set matches = RE_ACT.Execute(Keys)
If matches.count < 1 Then Exit Do

Set hit = matches.Item(0)
If hit.SubMatches.count < 1 Then Exit Do
Debug.Print "Matched:", hit.Value
'Debug.Print "Matched:", hit.Value

done = ProcessHit_(hit) ' Assigns DotCount_ on a `.`
'If done Then Debug.Print "", "operator count:", VOperatorCount
Expand Down
Binary file modified frmGrabKeys.frx
Binary file not shown.
29 changes: 24 additions & 5 deletions mVimWord.bas
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Attribute VB_Name = "mVimWord"
' 2018-05-07 chrisw gp/gP now paste unformatted text; added ninja-feet
' 2018-05-10 chrisw Fixed whitespace classes used for text objects
' 2018-06-07 chrisw Hack in voDelete/voChange for strange Word behaviour.
' 2018-06-26 chrisw ip: don't select whole table cell. It still doesn't
' work with a count, though, and I'm not sure why. E.g., 2vip
' 2018-06-29 chrisw Added voDrop; bugfix in ip

' General comment: Word puts the cursor between characters; Vim puts the
' cursor on characters. This makes quite a difference. I may need
Expand All @@ -20,14 +23,15 @@ Attribute VB_Name = "mVimWord"
Option Explicit
Option Base 0

' Storage for the last command, to support `.`. This only lasts until
' Storage for the last command, to support `.`. NOTE: This only lasts until
' the next time the VBA project is reset.
' Public since it's used by frmGrabKeys; here so that it will stick around.
' Public since it's used by frmGrabKeys; here so that it will stick around
' after a frmGrabKeys instance is unloaded.
Public VimLastCommand_ As String
'

Public Sub VimDoCommand_About()
MsgBox "VimWord version 0.2.12, 2018-06-07. Copyright (c) 2018 Christopher White. " & _
MsgBox "VimWord version 0.2.14, 2018-06-29. Copyright (c) 2018 Christopher White. " & _
"All Rights Reserved. Licensed CC-BY-NC-SA 4.0 (or later).", _
vbOKOnly + vbInformation, "About VimWord"
End Sub 'VimDoCommand_About
Expand Down Expand Up @@ -378,6 +382,17 @@ Private Sub vimRunCommand( _
Case vmIPara
proczone.Expand wdParagraph
If count > 1 Then proczone.MoveEnd wdParagraph, count - 1

' If we were in a table, the end marker is now selected.
' The marker is a Chr(13) & Chr(7), but MoveEndWhile won't move
' over it. Therefore, test for it and skip it manually.
If proczone.Tables.count >= 1 Then
If proczone.Cells.count >= 1 Then
If Right(proczone.Text, 1) = ChrW(7) Then
proczone.MoveEnd wdCharacter, -1
End If
End If
End If
proczone.MoveEndWhile Chr(13), -1 ' Only the last Chr(13)
coll = False

Expand Down Expand Up @@ -411,15 +426,19 @@ Private Sub vimRunCommand( _
If proczone.Start <> proczone.End Then proczone.Copy
GoTo VRC_Finally

Case voDelete, voChange:
Case voDelete, voChange, voDrop:
If proczone.Start <> proczone.End Then
' Word doesn't always delete the whole selection!
Dim endr As Range
Set endr = proczone.Duplicate
endr.Collapse wdCollapseEnd
endr.MoveEnd wdCharacter, 1

proczone.Cut
If oper = voDrop Then
proczone.Delete
Else
proczone.Cut
End If

If endr.Characters.count > 1 Then ' something strange happened
If endr.Characters.First = ChrW(13) Then
Expand Down
6 changes: 4 additions & 2 deletions vim-regex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ textobj (?<ninja>[\[\]])? (?# Ninja-feet marker)
(?<objtype>[wWsp]) (?# Type of text object)

# Transitive: verb, count, object, object type, text
trans (?<tverb>[cdyv]) (?# TVERB: what to do)
trans (?<tverb>[cdyvX]) (?# TVERB: what to do)
(?<count2>[1-9][0-9]*)? (?# Count after the operator)
(?<target> (?# What to work on)
(?<=textobj)| (?# Text objects)
Expand All @@ -70,6 +70,8 @@ trans (?<tverb>[cdyv]) (?# TVERB: what to do)

# Transitive abbreviations: x, ., ... . These are the end of the entry ---
# nothing comes after them.
trans-abbr (?<tverbabbr>[xX\.])
# Note: I have repurposed `X` as delete-without-yank, so it is no longer
# a synonym for `dh`.
trans-abbr (?<tverbabbr>[x\.])

# vi: set ts=4 sts=4 sw=4 et ai ff=unix ft=sh: #

0 comments on commit e9cf520

Please sign in to comment.