Run until the end of file only runs once



  • Notepad++ 7.8.2 32-bit on Windows 10 - 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. If I choose “Run X times”, it does run X times. What’s really odd is that I’m 99% sure that “Run until the end of file” has worked for me. I’m new to Notepad++, so may not have tried this before, but am pretty sure I have.



  • One more observation, in case it helps identify the cause:

    My testcase is to find the letter ‘a’, then record a macro that replaces ‘a’ with ‘z’ and does a Find Next (F3 in my case). 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 for 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.

    Not sure if this indicates anything, but it is different, so I thought I’d pass it on. And I’m sure at some point in the last week this scenario did run to end of file, so something has changed with my install. I’ll keep digging into that too.



  • @VTGroupGitHub

    The same thing happens for me when I tried it with a simple Replace action. Actually, I don’t think I’ve ever noticed the Run until end of file option; I’ve certainly never used it. Does anyone know how it is supposed to work (which seems obvious) or how to make it work?



  • Hello, @VTGroupGitHub, @alan-kilborn and All,

    Instead of trying to record a Find ( and Replace ) operation, which is, already, a bit particular, I just recorded a very simple action : Moving to the next character on the right, giving the macro, below, in your active shortcuts.xml file :

            <Macro name="Next Char on the Right" Ctrl="yes" Alt="no" Shift="no" Key="187">
                <Action type="0" message="2306" wParam="0" lParam="0" sParam="" />
            </Macro>
    

    And I associated the Ctrl + = shortcut to this macro


    After some tests, with Notepad++ v7.8.2, without any additional plugins installed, I would say that :

    • Running Macro > Run a Macro Multiple Times... > Next Char on the Right > Run 'None' or '1' times moves caret to next position on the right, as expected

    • Running Macro > Run a Macro Multiple Times... > Next Char on the Right > Run x times moves xth times the caret on the right, as expected

    • Running Macro > Run a Macro Multiple Times... > Next Char on the Right > Run until the end of file moves caret to the next position on the right, only and NOT at the very end of file as it should do :-((

    • Each hit on the Ctrl + = shortcut moves correctly the caret to next position on the right or downward

    Best Regards,

    guy038



  • If I read your post correctly, you’ve confirmed my original issue i.e. “Run until end of file” does not actually run until the end of the file? If so, then I believe I’ll open a ticket and reference this conversation. Thanks.



  • In case anyone’s watching this thread, I’ve opened Run until the end of file" only runs once #7801.



  • I also faced such a situation many times. But then I started using find/replace with it’s “Regular operation” option.
    My files are in devanagari and usually long where there are digits with ॥ on either side [ ex. ॥ १ ॥ ] and I need to add <br> after that epression. I tried to record a macro like - find ॥, find again, close the find/replace window, move cursor as ॥ follows a space then add <br>. This macro works but only once and not “untill end of file”.
    The I used find/replace where find = ॥(\s\d+\s)॥\s - where \s is space, \d is any no of digits. Part of expression is in backet which needs to be used in ‘replace with’ expression where it is represented by ‘$1’ So in “replace with” I used expression - ॥$1॥ <br>
    Please note I used ‘space’ after second ॥ in ‘replace with’ where as I used \s in find expression.



  • @Vishwas-Bhide

    Maybe a point you didn’t make is that you used the Replace All command? To get it to “run to end of file”?



  • @Alan-Kilborn - Yes, I used ‘Replace all’ but missed to mention it.



  • Hello, @vishwas-bhide and All,

    So your language uses the Unicode DEVANAGARI script, in range U+0900 - U+097F below :

    https://www.unicode.org/charts/PDF/U0900.pdf

    And :

    - The **`॥`** character is *DEVANAGARI DOUBLE DANDA*, with code-point **`\x{0965}`**
    
    - The **`०`** character is *DEVANAGARI DIGIT ZERO*,   with code-point`\x{0966}`**
    
    - The **`१`** character is *DEVANAGARI DIGIT ONE*,    with code-point`\x{0967}`**
    
    - The **`२`** character is *DEVANAGARI DIGIT TWO*,    with code-point`\x{0968}`**
    
    - The **`३`** character is *DEVANAGARI DIGIT THREE*,  with code-point`\x{0969}`**
    
    - The **`४`** character is *DEVANAGARI DIGIT FOUR*,   with code-point`\x{096A}`**
    
    - The **`५`** character is *DEVANAGARI DIGIT FIVE*,   with code-point`\x{096B}`**
    
    - The **`६`** character is *DEVANAGARI DIGIT SIX*,    with code-point`\x{096C}`**
    
    - The **`७`** character is *DEVANAGARI DIGIT SEVEN*,  with code-point`\x{096D}`**
    
    - The **`८`** character is *DEVANAGARI DIGIT EIGHT*,  with code-point`\x{096E}`**
    
    - The **`९`** character is *DEVANAGARI DIGIT NINE*,   with code-point`\x{096F}`**
    

    Your initial S/R could be changed as :

    • SEARCH ॥\h\d+\h॥\h(?!<br>)    OR    \x{0965}\h\d+\h\x{0965}\h(?!<br>)

    • REPLACE $0<br>

    Two advantages :

    • No need to capture something in a group as we grab the overall match with the $0 syntax, in replacement

    • If the part ॥ digit ॥ is already followed with a space char and the string <br>, it will not add <br> a second time


    So, two cases can be considered :

    A) WITHOUT a macro :

    • Open the Replace dialog ( Ctrl + H )

    • SEARCH ॥\h\d+\h॥\h(?!<br>)    OR    \x{0965}\h\d+\h\x{0965}\h(?!<br>)

    • REPLACE $0<br>

    • Tick the Wrap option option

    • Select the Regular expression search mode

    • Click on the Replace All button, once ( anyway, a second click will not work ! )


    B) WITH a macro :

    • Open the Replace dialog ( Ctrl + H )

    • SEARCH ॥\h\d+\h॥\h(?!<br>)

    • REPLACE $0<br>

    • Tick the Wrap option option

    • Select the Regular expression search mode

    • Run the Macro Start Recording option ( Ctrl + Shift + R )

    • Click on the Replace All button

    • Close the Replace dialog ( ESC )

    • Run the Macro Stop Recording option ( Ctrl + Shift + R )

    • Run the Save Current Recorded Macro option

    • Save it as, for instance, Addition of <br>

    • Choose, preferably a shortcut for further easy process

    • Click the OK button

    • Close and re-start Notepad++

    • Open your concerned file

    • Now, whatever the option chosen :

      • Macro > Addition of <br>

      • Macro > Run a Macro Multiple Times > Addition of <br> > Run 1 times and a click on the Run button

      • Macro > Addition of <br> > Run until the end of file and a click on the Run button

    => The <br> string is added to any ॥ digit ॥ string, ONLY once !

    Note that the Wrap around forces the regex engine to process file(s) from the very beginning to the very end !


    If you prefer to modify, directly, your active shortcuts.xml file, add the lines, below, right before the line </Macros>

            <Macro name="Addition of &lt;br&gt;" Ctrl="no" Alt="no" Shift="no" Key="0">
                <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                <Action type="3" message="1601" wParam="0" lParam="0" sParam="&#x0965;\h\d+\h&#x0965;\h(?!&lt;br&gt;)" />
                <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                <Action type="3" message="1602" wParam="0" lParam="0" sParam="$0&lt;br&gt;" />
                <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
            </Macro>
    

    Best Regards,

    guy038


Log in to reply