Add step to zen command slicing #3311
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the long awaited ability to step while slicing to the
!zen
command, so you can finally do stupid things like getting every other line in reverse.The regex was completely reworked to allow for the steps (I finally got to use
++
for something) (groups are now named instead of indexed for clarity)Line numbers for display are now found via
zen_lines.index
instead of math. I am aware this is worse for performance, but it is a massive win for both ease of implementation and code clarity, since with negative steps the clamping and offset math for line numbers gets very hard very quick. The main downside of this approach is the math can offer very fine-grained error messaging, whereas the current code gives a generic"Slice returned 0 lines."
message.Due to how the change is implemented, more slicings are now valid than before, ie
!zen :100
will now work, so those test case fails were removed.I am aware this will probably fail the formatting and linting CI passes, but I could not run them locally as my computer's OS is on it's deathbed and poetry refuses to work correctly.
Edit:
All things now fixed. The tests for full zen (
0:19
,:
,::
) were failing because the source/default description included an extra\n
, so I added a.strip()
to fix that.One other thing I forgot to say above, with the easier implementation from indexing I was able to clean up the messages that bugged me, so now if only one line is returned after slicing it will always say
(line x)
instead of(lines x-x)
, and if the slice returns the full thing, it will be, by Tim Peters
instead of(lines 0-18)