Community
    • Login

    Recording: How can I change the regex operations in MACRO?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 5 Posters 2.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Neil SchipperN
      Neil Schipper @Neculai I. Fantanaru
      last edited by

      @neculai-i-fantanaru:

      to record something extra on the same macro

      The answer is “very nearly no”, although “only with great difficulty” is more accurate.

      Npp does not provide a user interface for editing macros.

      If you look at your shortcuts.xml file you will see how the actions of a macro are stored. In theory, after a lot of research, one could modify a macro by altering records in this file. But this is rarely done.

      This limitation is why scripts (which are much friendlier to human eyeballs) are favored for more complex tasks or tasks where we anticipate a need for change.

      Neil SchipperN 1 Reply Last reply Reply Quote 2
      • Neil SchipperN
        Neil Schipper @Neil Schipper
        last edited by

        @neil-schipper

        HELLO! I answer a bit too soon.

        I just reviewed a macro of mine that carries out a regex operation, and I learned (remembered?) that the entire regex does exist nicely in a single line in the xml file:

                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="\[.*?%.*? ACTIVEMIX" />
        
        

        so, if the only change you want to make in the macro is the regex, you could try doing this.

        For safety, best to quit Npp and edit the xml in another editor (like good old Win Notepad) before restarting npp.

        1 Reply Last reply Reply Quote 2
        • Alan KilbornA
          Alan Kilborn @Neculai I. Fantanaru
          last edited by

          @neculai-i-fantanaru said in Recording: How can I change the regex operations in MACRO?:

          how can I change the regex operations in MACROS, to record something extra on the same macro?

          Perhaps “extra” here means an additional replacement operation, so one macro would do two or more in succession?

          If so, very possible, with hand-editing of the shortcuts.xml file as Neil discussed.

          In that file, a single search/replace operation begins with message="1700" and ends with message="1701".

          As long as you move that “block” of lines together as a unit, you can combine as many replacement operations as you need together in one macro.

          Of course, be careful in editing this file, and probably make a backup before beginning.

          There are more details on how the searching macros are encoded, in the user manual HERE.

          1 Reply Last reply Reply Quote 3
          • guy038G
            guy038
            last edited by guy038

            Hello, @neculai-i-fantanaru, @neil-Schipper, @alan-kilborn and All,

            If you know where is your active shortcuts.xml configuration file, it’s not very difficult ! Here is the road map :

            • Open your active shortcuts.xml file in Notepad++

            • Inside the <Macros>................</Macros> node, find the specific macro that you want to modify

            • Modify it, according to the following template :

            1ea13e45-0766-4850-a0dd-b1d01759e2f9-Codage_Rech_Remp.jpg

            • Save the modifications of the shortcuts.xml file

            • Stop and restart notepad++ ( IMPORTANT )

            • Excecute your modified macro !


            Note that you may insert several consecutive regex searches/marks/replacements in a same macro !

            For instance, the macro, below, named Test :

                    <Macro name="Test" 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="(?-s)\h+$" />
                        <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                        <Action type="3" message="1602" wParam="0" lParam="0" sParam="" />
                        <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                        <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
            
                        <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                        <Action type="3" message="1601" wParam="0" lParam="0" sParam="\[(\w+)\]|\((\w+)\)|\{(\w+)\}" />
                        <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                        <Action type="3" message="1602" wParam="0" lParam="0" sParam="&#x2014; \1\2\3 &#x2014;" />
                        <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                        <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
            
                        <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                        <Action type="3" message="1601" wParam="0" lParam="0" sParam="(?-s)(.|\r\n)\z" />
                        <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                        <Action type="3" message="1602" wParam="0" lParam="0" sParam="\r\n&#x00A9; 2022 - Neculai I. Fantanaru\r\n" />
                        <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                        <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                    </Macro>
            

            would perform the 3 following actions :

            • Suppression of all possible trailing space chars

            • Replacement of any word between parentheses, square brackets and braces with an EM dash char, a space char, the present word, a space char and a final EM dash char

            • Insertion of the line © 2022 - Neculai I. Fantanaru with its line-ending chars, at the very end of a Normal text file

            Best Regards,

            guy038

            Neculai I. FantanaruN Alan KilbornA 2 Replies Last reply Reply Quote 3
            • Neculai I. FantanaruN
              Neculai I. Fantanaru @guy038
              last edited by

              thank you all. But there is a problem. I already made 2 macros, and save them. See picture 1. The problem is when I open shortcuts.xml, I cannot find the macros which I saved (see picture 2)

              2641f986-555f-417e-9eab-b5506dfdeab1-image.png

              8c8d76d9-1c9f-4f62-b659-6fcb38630b54-image.png

              PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn @guy038
                last edited by

                @guy038 said in Recording: How can I change the regex operations in MACRO?:

                according to the following template :

                Nice roadmap, it goes well with the user manual link I provided before.

                One thing, though: the 1702 … to turn “on” these options in combination, one has to add the numbers – example: to do a match-whole-word and match-case search, one has to use 1 + 2, but you do the math ahead of time (3) and put that in the macro text.

                1 Reply Last reply Reply Quote 2
                • PeterJonesP
                  PeterJones @Neculai I. Fantanaru
                  last edited by

                  @neculai-i-fantanaru said in Recording: How can I change the regex operations in MACRO?:

                  thank you all. But there is a problem. I already made 2 macros, and save them. See picture 1. The problem is when I open shortcuts.xml, I cannot find the macros which I saved (see picture 2)

                  The Macro > Save Current Recorded Macro… action saves to memory. It is not until you exit out of Notepad++ that the macro gets moved from memory to shortcuts.xml. If you want to see the macro in shortcuts.xml, you have to exit Notepad++ first. See also the User Manual’s section on Editing Configuration Files

                  1 Reply Last reply Reply Quote 3
                  • Alan KilbornA
                    Alan Kilborn @Neculai I. Fantanaru
                    last edited by

                    @neculai-i-fantanaru said in Recording: How can I change the regex operations in MACRO?:

                    The problem is when I open shortcuts.xml, I cannot find the macros which I saved (see picture 2)

                    The shortcuts file that your N++ is probably using is in the %APPDATA%\Notepad++ folder. Paste that into an Explorer window to quickly go there and check that file.

                    Neculai I. FantanaruN 1 Reply Last reply Reply Quote 3
                    • Neculai I. FantanaruN
                      Neculai I. Fantanaru @Alan Kilborn
                      last edited by

                      @alan-kilborn

                      Yes, indeed. The location of shortcuts.xml is:

                      c:\Users\COMPUTER\AppData\Roaming\Notepad++\

                      Alan KilbornA 1 Reply Last reply Reply Quote 0
                      • Alan KilbornA
                        Alan Kilborn @Neculai I. Fantanaru
                        last edited by Alan Kilborn

                        @neculai-i-fantanaru said in Recording: How can I change the regex operations in MACRO?:

                        The location of shortcuts.xml is

                        That isn’t an absolute. Maybe for you it is, but it depends upon your setup. If you look at your Debug Info… (on the ? main menu), example:

                        Local Conf mode : OFF

                        then yes it is in %APPDATA%\Notepad++.

                        but if it says:

                        Local Conf mode : ON

                        then it is in the same folder as notepad++.exe.

                        Also, there is more info on “appdata” HERE … I should have pointed that out before.

                        1 Reply Last reply Reply Quote 3
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors