@Antheds-Kennel said in Delete every line below a bookmarked line.:
why your script deletes the last line that I do not want to delete.
It’s a macro, not a script, so it has no logic capability. I hadn’t noticed it doing that during my earlier tests, but I can reproduce. Essentially what happens is after the last bookmark (on what was originally line 9) is removed and it deletes the next line as it should have, it hasn’t reached the end yet, so searches for a bookmark again, and doesn’t find one, but still moves forward in the macro (because macros cannot have logic) and thus toggles the non-existent bookmark to “on”, then moves down a line, and deletes it, then it searches for the next bookmark which requires it to wrap around, finds one, toggles it, and deletes the next line, and keeps going through those accidental loops until the down-a-line finally reaches the end of the file.
As I tried to indicate earlier, it was entirely possible that a macro is not sufficient for your problem; we have now found the reason why. There might be a different way to construct the macro that would avoid that logic problem, but I cannot think of one. I really don’t think a macro is going to cut it.
You still haven’t explained why bookmarking the actual lines you want to delete, rather than the lines before the ones you want to delete, is not a valid solution: any search that you can use to automatically mark those lines could be easily modified to mark the line after the text rather than the line on your matching text, thus bookmarking the lines you want to delete (and in that case, you could just delete them from the search/replace, rather than bookmarking as one search then deleting in a separate macro action)… And if you’re manually bookmarking the lines, rather than doing it from the Mark dialog, you’re wasting a lot of time, because if you’re already there to mark it, you could just as easily do the deletion yourself.
So the right solution that I can see for you is: (1) if you are currently manually bookmarking, then just manually delete the next line; or (2) if you are bookmarking using the search-based Mark dialog, make a slight tweak to your search and use the Replace menu instead to immediately delete those. If you believe neither (1) nor (2) are sufficient for your needs, you will have to explain why, because I cannot see any reason why one of those two won’t work for the circumstances you’ve described. If you can come up with a meaningful reason, then I or someone else might be able to come up with a script for the PythonScript plugin that will have all the safety logic built in to follow your inefficient and illogical bookmark-the-wrong-line-then-delete-the-subsequent-lines-separately sequence that you seem to be insisting upon… but I still believe (1) or (2) would be better for you.