aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)Author
2021-08-22Add incdec.plTeddy Wing
This was from when I extracted the `incdec` function to a standalone Perl script to test what was wrong with negative numbers in the second position.
2021-08-22incdec: Move point if negative hyphen is added or removedTeddy Wing
Previously, point would stay in the same position, causing it to look like it moved when incrementing or decrementing between a negative number and a positive number. This moves point by one to the right when decrementing to a negative integer, or by one to the left when incrementing to a positive integer. That makes the point seem like it hasn't moved and making it look more natural. For example, now point behaves like this: $ test 12 0 ^ _decrement_ $ test 12 -1 ^ $ test 12 -1 ^ _increment_ $ test 12 0 ^ Before, it would do: $ test 12 0 ^ _decrement_ $ test 12 -1 ^ $ test 12 -1 ^ _increment_ $ test 12 0 ^
2021-08-22incdec.pm: Add descriptions for the backwards handlingTeddy Wing
Describe why we set `$point_position` the way we do.
2021-08-22incdec: Idea for point moving when changing from positive to negativeTeddy Wing
If we change between negative and positive numbers, point moves: $ test 12 0 ^ _decrement_ $ test 12 -1 ^ I think point should instead be $ test 12 -1 ^ Not sure that we should be moving point when changing from negative to positive, though.
2021-08-22incdec: Try new negative last number handling in the Readline bindingsTeddy Wing
This works! Also, a while ago, I changed the Perl program to not use hyphenated command line arguments and quoted variable names `${"increment-by"}` because this seemed to be causing unexpected issues.
2021-08-22incdec: Fix negative number handling when number is second of twoTeddy Wing
When the negative number is the last of two numbers, the first number would be incremented or decremented instead of the second one. Fix this by: * Removing the `\b` word boundaries in the search pattern. This caused the match start position to not include the hyphen that designates a negative number (instead starting at one after the hyphen). * Setting `$start_position` to the start position of the current match (`$-[0]`) on every match loop iteration. This ensures the start position is set to an appropriate index when the number we want to increment is the last one in the line. Since the condition in the loop depends on there being a previous match position, it wouldn't set the start position correctly in all cases for the last number in the line. * Remove the special case to handle the last number in the line when searching backward with the cursor in the last position. That case is now handled directly in the loop by always setting `$start_position`.
2021-08-22100-increment-decrement: Add new second number negative integer testsTeddy Wing
The previous negative integer tests worked, but it turns out that when the negative integer isn't the first one, there's a problem.
2021-08-21100-increment-decrement: Add test to decrement a negative integerTeddy Wing
2021-08-21incdec: Add a note for basic point handling when line length changesTeddy Wing
2021-08-21incdec.pm: Handle negative numbersTeddy Wing
Include "-" in the pattern that matches numbers. Wrap the pattern in word boundaries also. This passes the test I added previously to increment a negative number.
2021-08-21100-increment-decrement: Doesn't work for negative numbersTeddy Wing
Our pattern matcher doesn't increment or decrement negative numbers because it doesn't look for a "-" prefix.
2021-08-21incdec: Add increment and decrement bindingsTeddy Wing
2021-08-21incdec: Get increment working in a Readline bindingTeddy Wing
Copy-pasted the `incdec` subroutine from `incdec.pm` into the Bash function. Eventually I'll have a Make rule for this. Add some new Perl code to the `perl -e` call that calls the `incdec()` subroutine with arguments from the shell environment. Set the current Readline line to the result of `incdec()` to increment a number. I was getting an error "bash_execute_unix_command: cannot find keymap for command" when I tried to assign the binding to "\C-xa". Not sure what's going on there but assigned it to a different one in the meantime.
2021-08-20Add idea for command line point start/end behaviourTeddy Wing
2021-08-19100-increment-decrement: Add a few new test casesTeddy Wing
2021-08-19incdec: Comment out test code from backward match fixTeddy Wing
Commenting this out instead of removing it for the moment while I add test cases in case I need to keep debugging.
2021-08-19incdec: Fix backward increment/decrementTeddy Wing
Turns out the backward increment/decrement didn't work in all cases. I hadn't tested a multi-digit number in the second position from the left. That didn't work with the old code. Adjust it and simplify it. Didn't need to be so complicated. Now we set the start position to the $-[0] of the previous match if the current match is to the right of point.
2021-08-19incdec: Add increment step argumentTeddy Wing
A new subrouting argument that defines by how much the number should be incremented, or decremented if a negative step value is given. Add a few new tests to verify the decrementing behaviour. The final test where point is in the middle of the number fails.
2021-08-19incdec: Clean up code from backwards incrementing developmentTeddy Wing
2021-08-19100-increment-decrement: Fix test nameTeddy Wing
2021-08-19incdec: Get backward incrementing working in all casesTeddy Wing
Set up the proper condition to get the start index of the number just before point.
2021-08-19incdec: Get backward incrementing working in middle of a numberTeddy Wing
2021-08-19incdec: Fix backwards point at end of line caseTeddy Wing
Update the condition that increments the last number if the point is at the end.
2021-08-19incdec: Get backward-search incrementing working for last numberTeddy Wing
Doesn't work for middle numbers yet.
2021-08-18incdec: Remove old code after changing the increment implementationTeddy Wing
2021-08-18incdec: Switch to the new incrementing algorithmTeddy Wing
Still a bunch of old code to clean up, but this is a lot shorter than what I had before, and I think it will be easier to extend it for backwards searching.
2021-08-18incdec: Work out positions for new match algorithmTeddy Wing
This updated loop gets the start position of the appropriate number nearest to point. It currently only works left to right, but seems like it should be easy enough to extend to be right to left.
2021-08-18incdec: Add note for myself about what `@-` and `@+` meanTeddy Wing
Not what I was thinking when I wrote that looping code.
2021-08-18Test regex replacement starting from a given positionTeddy Wing
Set `pos()` to enable us to increment a number in the middle of a string.
2021-08-18incdec: Ideas for a loop based on match positionTeddy Wing
Looking into a different algorithm for incrementing matches that's easier to use in both forward and backward contexts. Got a few ideas to get a match nearest to the cursor position. We could then take that value and increment it, and replace the original substring with the new incremented value.
2021-08-15incdec: Ideas for searching backwards from pointTeddy Wing
2021-08-15incdec: Add comments describing the middle-of-number handling loopTeddy Wing
2021-08-15incdec: Remove pointless `$point_position` assignmentTeddy Wing
Here, we really just want to exit the loop. There's no reason to change `$point_position`.
2021-08-15incdec: Remove unused variable `$previous_point_position`Teddy Wing
Turns out this wasn't needed.
2021-08-15incdec: Correctly handle middle-of-number point for third numberTeddy Wing
We were previously using values specific to the first and second numbers in the line. Get middle-of-number point handling working for the third number in the line, and hopefully the rest as well.
2021-08-15100-increment-decrement: Test middle-of-number point for third numberTeddy Wing
Test fails. Increments the second number instead of the third.
2021-08-15incdec: Clean up code from recent middle-of-number changesTeddy Wing
Remove work-in-progress, debug code, and things that didn't work out.
2021-08-15incdec: Handle point in the middle of subsequent numbersTeddy Wing
Previously, we correctly incremented the first number if point was in the middle of that number, but we did not do so for subsequent numbers. This change adds similar handling for all numbers in the line. Got a little lost here trying different loops and changes. I kind of hacked it without heavily planning the algorithm ahead of time. The idea is that if the point position is beyond the right side of the match, we cut off the part of the line from the start to the end of the last match, then try matching again. This allows us to pull out the number around point so that we can increment it with the evaluated regex that follows the loop.
2021-08-15incdec: Idea for handling point within subsequent numbersTeddy Wing
Previously, we only handled incrementing when point was in the middle of the number if the number was the first on the line. This is code from last week or so. Wasn't really analysing it. Don't remember entirely. Currently, it loops infinitely on the fifth test.
2021-08-08100-increment-decrement: Need to handle cursor within for subsequent #sTeddy Wing
Currently, the 'cursor within number' handling only works when the cursor is inside the first number. It needs to work for any number in the line.
2021-08-08incdec: Describe the 'point within number' handlingTeddy Wing
2021-08-08incdec: Fix increment when cursor is after the first numberTeddy Wing
* Needed the comparison to be `<`, otherwise the cursor becomes part of the first number. * The boolean operation was wrong: `$point_position` needs to be both above the start of the match and below the end of the match to be inside it.
2021-08-08incdec: Change a number when the cursor is in the middle of itTeddy Wing
Correctly increment a number when the cursor is, for example, at: test 12 0 ^ This causes the #5 test incrementing the second number to fail.
2021-08-08incdec: Test for cursor point in between a numberTeddy Wing
Add a failing test for incrementing a number when the cursor is at: test 19 0 ^ This currently results in: test 110 0 which is incorrect.
2021-08-08incdec: Handle increments relative to the cursor positionTeddy Wing
This will increment the next number to the right of the given cursor position.
2021-08-08incdec.pm: Add some tests and ideas for incrementing substringsTeddy Wing
Substrings and direction.
2021-08-08Add a Perl module for performing the actionTeddy Wing
This allows us to more easily test the functionality and add new behaviours.
2021-08-08incdec: Increment the number on the current lineTeddy Wing
Got it working! Thanks to the Fzf Bash code for showing me that you can assign to `READLINE_LINE` and `READLINE_POINT`: https://github.com/junegunn/fzf/blob/7191ebb615f5d6ebbf51d598d8ec853a65e2274d/shell/key-bindings.bash
2021-08-08incdec: Increment the number and print the whole lineTeddy Wing
Thinking I might be able to echo the whole line to the command line instead of working out how to replace just the number that we've incremented. Discovered how to increment a number in a regex substitution from this Stack Overflow answer by Mark Setchell (https://stackoverflow.com/users/2836621/mark-setchell): https://stackoverflow.com/questions/54367360/how-to-increment-the-last-number-in-a-string-bash/54367784#54367784
2021-08-08incdec: Ideas for operating on the full command lineTeddy Wing
If we have access to the full command line and modify the number in it, we can print the whole thing with the number incremented onto the working command line. Probably going to need some Perl to do the regex and incrementing.