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

simplify paste command logic #245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oldaccountdeadname
Copy link
Contributor

Just shortening a match statement!

Commit message below:


The previous big match statement did three separate things in the
same deeply indented code block:

  1. Prepare the buffer
  2. Identify the content to paste
  3. Paste the proper content

Preparing the buffer was simplified by just calling
ensure_trailing_newline beforehand, as that's essentially what
the special cases deep inside the match statement were doing
anyway. This is done indiscriminately due to the borrow checker,
which wouldn't like us manipulating the buffer to add a newline
while we held an immutable reference to it in buffer. This has
the unfortunate-ish side effect of requiring modifications to the
tests to account for the fact that a trailing newline is added.

Separating 2 and 3 allows us to refocus the match statement on
identification, and, if there is content, we can paste later down
the function.

1 and 2 are still homogeneous in the match statement, which isn't
super pretty, but, as they both depend on the same data (and
conditionals thereof), it's not too big a deal.

The previous big match statement did three separate things in the
same deeply indented code block:
1. Prepare the buffer
2. Identify the content to paste
3. Paste the proper content

Preparing the buffer was simplified by just calling
`ensure_trailing_newline` beforehand, as that's essentially what
the special cases deep inside the match statement were doing
anyway. This is done indiscriminately due to the borrow checker,
which wouldn't like us manipulating the buffer to add a newline
while we held an immutable reference to it in `buffer`. This has
the unfortunate-ish side effect of requiring modifications to the
tests to account for the fact that a trailing newline is added.

Separating 2 and 3 allows us to refocus the match statement on
identification, and, if there is content, we can paste later down
the function.

1 and 2 are still homogeneous in the match statement, which isn't
super pretty, but, as they both depend on the same data (and
conditionals thereof), it's not too big a deal.
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.

None yet

1 participant