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

"Run until the end of file" only runs once #7801

Open
VTGroupGitHub opened this issue Dec 31, 2019 · 4 comments
Open

"Run until the end of file" only runs once #7801

VTGroupGitHub opened this issue Dec 31, 2019 · 4 comments

Comments

@VTGroupGitHub
Copy link

When I record a macro, open the “Run a Macro Multiple Times” dialog, select “Run until the end of file”, and press “Run”, the macro only executes once (see the exception where it runs twice below). It never runs "to end of file".

Steps to Reproduce the Issue

  1. Record a macro.
  2. Open the “Run a Macro Multiple Times” dialog, select “Run until the end of file”, and press “Run”.

Expected Behavior

The macro should run until the end of file.

Actual Behavior

The macro only executes once (see the exception where it runs twice below). It never runs "to end of file". Note that If I choose “Run X times”, it does run X times.

Exception: My testcase is to find the letter ‘a’, then record a macro that replaces ‘a’ with ‘z’ and does a Find Next. What I’ve noticed is that when clicking the “Run a Macro Multiple Times” Run button with “Run until the end of file” selected, the macro only runs once EXCEPT when on the last ‘a’ on the line, in which case it replaces that last ‘a’ as well as the first ‘a’ of the next line before it stops. So it does run twice in this case, but never to end of file in this case either.

Debug Information

7.8.2 32-bit on Windows 10

@VTGroupGitHub
Copy link
Author

I think I found the issue, but have not had time yet to think through a complete solution.

I noticed today that "run until end of file" actually does work when the macro only has to run once on a given line. So I downloaded the app source and can see this in the "end of file" loop in NppBigSwitch.cpp:

// Update the line count, but only if the number of lines remaining is shrinking.
// Otherwise, the macro playback may never end.
if (deltaLastLine < deltaCurrLine)
lastLine += deltaLastLine;

Since my testcase replaces "a"s with "z"s, and there can be multiple "a"s on a line, I fail the test above after the first "a" on the line and stop processing.

@sasumner
Copy link
Contributor

sasumner commented Jan 5, 2020

@VTGroupGitHub

I have concerns about the comment:

Otherwise, the macro playback may never end.

Do you have ideas for how to change the implementation so that it works for your use case but yet does not get into the "...may never end" situation?

@VTGroupGitHub
Copy link
Author

I don't currently, but do plan to look more closely at the source. Hopefully there's a way to both address my issue and keep a "may never end" check.

@VTGroupGitHub
Copy link
Author

I don't have the ability to build and test anything, so all I can do is suggest ideas. Is there not a way, though, to determine the number of characters from the current cursor position to the end of file -- call it CHARS_TO_EOF? After each macro execution, you would break if the current CHARS_TO_EOF is (1) larger than the previous CHARS_TO_EOF, meaning you're moving backwards in the file or you've wrapped around EOF, or (2) equal to the previous CHARS_TO_EOF, meaning you're staying in the same position.

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

No branches or pull requests

2 participants