-
Notifications
You must be signed in to change notification settings - Fork 43
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
Skip to next match when user doesn't change #3
Conversation
Hmm, I'm not sure whether or not the intent of this change is something we should try to do. On the one hand, the current implementation matches the original The thing I'm worried about is that there may be cases where you really do want to go to the next submatch of your regex. I haven't been able to construct a realistic-looking example, though. (I thought that something like |
First of all, it's been a while since this PR came out and we've since made at least 1 change to the advancement logic, so the conflicts are real and it definitely can't be merged as-is. (Sorry for the delay! It took a while to flush out other issues and then ruminate on them.) Second, I want to fix all our issues with advancement at once rather than doing one case at a time. We need an advancement policy for each of the actions the user can take:
I'll just talk through each of these cases below, keeping fastmod's philosophy in mind:
Accept replacement (y)Here, our current policy is to advance 0 characters if the replacement has length 0 and 1 character otherwise. We've already rejected the policy "advance 1 character always" (see 501a8b9 and 95ae97a). Advancing 1 character has the advantage that it allows you to do further editing on replacement text, but given fastmod's philosophy of driving toward automated application of your regex everywhere, this advantage has minimal value. Proposed new policy: advance to the next character after the end of the replacement text. Reject replacement (n)We have two policies to choose from when a replacement is rejected: 1) We can advance 1 character and try again (existing behavior), or 2) we can advance to the end of the regex match and try again (@steven807's proposal in this PR). I think the answer to the tradeoff has to come from fastmod's philosophy. If you say Proposed new policy: advance to the next character after the end of the match. Open editor (e)Our current policy is to advance 1 character and keep going. The fundamental problem with the open editor option is that the user could arbitrarily change the document if they wanted to, and since this is outside our core use case, we're never going to have a great picture of their change. I propose that we should assume that the user is "working with us" by only editing within the matched region, may or may not have actually applied any changes, and wants to continue to the next match when they start interacting with fastmod again. Given these assumptions, I think our existing policy makes sense. Proposed new policy: no change. Apply replacement and open editor (E)Our current policy is to advance 1 character and keep going. Since interactive editing is not our core use case, I think we should not worry about the difference between Proposed new policy: no change. Accept all replacements (A)Our current policy is to act as though the user pressed
The problem there is that the replacement matches the search pattern, so we continually replace our own replacement (and grow it). However, given the proposed policy changes for Proposed new policy: no direct change (act as though Next stepsThe next step is to implement the new policy. @steven807, if you want to do that, that's great, but I totally understand if the moment has passed. |
Yup, I'm afraid it has passed. I'll be looking forward to see how things progress, though! |
This pull request has been merged in 767f874. |
If the user selects 'n' (to skip a match), the next comparison only starts one character later. If the beginning of the patch pattern, is, e.g. '( +)' this may continue to find the same match many times. I've added logic that starts the search from the end of the previous match, if the user skips the last change.
This is not very well tested, so feel free to review it.