Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up the MoveLeft and MoveRight functions #46

Merged
merged 8 commits into from
Jul 7, 2020

Conversation

hugomg
Copy link
Contributor

@hugomg hugomg commented Jul 6, 2020

This PR continues the cleanup effort from #45.

  • Add comments
  • Consolidate MoveCharRight and MoveCharLeft
  • Consolidate MoveBlockRight and MoveBlockLeft
  • Stop using "silent" where we didn't need to
  • Stop leaking the value of the default register
  • Stop using the finicky functions with the "range" attribute -- use for everything.

I think everything is still working but I would appreciate if you could double check, specially the MoveBlockHorizontally. Some of those changes were not trivial and I'm not 100% sure that I was able to test all the corner cases.

hugomg added 6 commits July 5, 2020 18:35
Document what mode the function is expected to be called in, and what
positive and negative distances mean.
The rest of this function already expects us to be in visual mode. I
think it is clearer if we just use '< and '> instead of relying on
a:firstline and a:lastline, which are finicky to use.
Use a single function, to reduce code duplication and reduce the number
of corner cases

- Always move the same way, using | instead of h,l,0,$.
- Always paste the same way, using P instead of sometimes P and sometimes p.
- Always use virtualedit=all
I think that silencing errors is no longer necessary now that our
movement commands check the bounds before attempting a move.
We should save the default register @" in a local variable instead of a
global variable. This way the value is discarded after the function
returns instead of being preserved forever.
As before, merge the two functions into a single function to consolidate
the logic in a single place.

We also introduce the name "before" in the MoveHorizontally functions,
to parallel the "after" from MoveVertically functions.
@hugomg hugomg changed the title Lateral move cleanup Cleaning up the MoveLeft and MoveRight functions Jul 6, 2020
Hopefully it should be more self explanatory now. The situation that we
have to worry about is when we create a selection that is already past
the end of line. For example if we have

   ABC
   DEFGH

and ask to move the rectangle "C  FGH" to the right, we want to stay
put, because we area already past the end of line. We should be careful
to not accidentally move it backwards. Without that `last < shortest`
test it would be transformedi into something like

   C  AB
   FGHED
@matze
Copy link
Owner

matze commented Jul 7, 2020

I think everything is still working but I would appreciate if you could double check

Looks good to me and works as expected. Do you plan to add more clean ups?

@hugomg
Copy link
Contributor Author

hugomg commented Jul 7, 2020

For now the only thing I still want to do is reorder the functions so the two MoveVertically and the two MoveHorizontally functions appear next to each other. But I didn't include that commit in this PR in order to keep the diff easier to read. I could add it to this PR or to a new PR.

@matze
Copy link
Owner

matze commented Jul 7, 2020

As you prefer ;-)

Put the MoveVertically and the MoveHorizontally functions next to each
other.
@hugomg
Copy link
Contributor Author

hugomg commented Jul 7, 2020

OK, I added that commit as part of this PR.

@matze
Copy link
Owner

matze commented Jul 7, 2020

Great thanks! 👍

@matze matze merged commit 73b6c3d into matze:master Jul 7, 2020
@hugomg hugomg deleted the lateral-move-cleanup branch July 7, 2020 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants