Community
    • Login

    Copying and pasting in a macro is broken

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    macro
    7 Posts 2 Posters 4.5k 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.
    • Zucriy AmsunaZ
      Zucriy Amsuna
      last edited by

      It used to work perfectly fine an update or two ago, but now it’s broken. When copying and pasting inside a macro, the pasted text after the first paste always appears where the text was first pasted. Here’s an example. Let’s say you have a text file:

      a
      b
      c
      a
      b
      c
      a
      b
      c

      With the cursor on line a, start recording the macro.
      Ctrl-F, type c, then Enter. (To find c.)
      Esc to exit Find.
      Ctrl-x to cut the highlighted c.
      Ctrl-v to paste it, followed by a space, followed by a 1, then Enter.
      Ctrl-v, space, 2.
      Done.
      Run macro to repeat for the next lone c.

      Expected result:

      a
      b
      c 1
      c 2
      a
      b
      c 1
      c 2
      a
      b
      c

      But the result I get is this with the cursor between the “2c”:

      a
      b
      c 1
      c 2c 2
      a
      b
      c 1

      a
      b
      c

      The same thing happens when using Copy instead of Cut. If you were to keep trying (after moving the cursor to after the previous edit), the pasting always returns to that first spot.

      What’s going on here?

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

        Hello, @zucriy-amsuna, and All,

        Personally, I just recorded the same macro as you described and this macro just works fine ! So, I propose you to follow these few steps below !


        • First, I advice you to BACKUP your active shortcuts.xml configuration file. But, of course, we must know where our active configuration files are located ! Depending on your initial N++ installation ( with the installer OR from a ZIP or 7Z archive ), the active configuration files can be found :

          • In the same folder as Notepad++ .exe, as well as the zero-length file doLocalConf.xml, in case of a local installation of N++

          • And, in case of an usual installation of N++, with the installer :

            • In the folder %AppData%\Roaming\Notepad++, for a W7, W8 or W10 configuration

            • In the folder %AppData%\Notepad++, for a XP or Vista configuration

        • Now, close all running instances of Notepad++, to close any pending operation !

        • Re-start Notepad++

        • Open your active Shortcuts.xml file ( Ctrl + O )

        • Delete the contents of your OLD macro

        • Copy the contents of the new macro, named ZA , below ( Ctrl + C )

                <Macro name="ZA" Ctrl="no" Alt="no" Shift="no" Key="0">
        
                    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />          <!-- Search Initialization                    -->
                    <Action type="3" message="1601" wParam="0" lParam="0" sParam="c" />         <!-- Search String      = 'c'                 -->
                    <Action type="3" message="1625" wParam="0" lParam="0" sParam="" />          <!-- Search Mode Normal = '0'                 -->
                    <Action type="3" message="1702" wParam="0" lParam="514" sParam="" />        <!-- Search Options = 'Down' + 'Case' (512+2) --> 
                    <Action type="3" message="1701" wParam="0" lParam="1" sParam="" />          <!-- Search Action  = 'Find Next' button      -->
        
                    <Action type="0" message="2177" wParam="0" lParam="0" sParam="" />          <!-- Scintilla command = 'Crtl + X'           -->
                    <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />          <!-- Scintilla command = 'Crtl + V'           -->
        
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />         <!-- Scintilla message = 'Space' character    -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="1" />         <!-- Scintilla message = '1'     character    -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />  <!-- Scintilla message = 'CR'    character    -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />  <!-- Scintilla message = 'LF'    character    -->
        
                    <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />          <!-- Scintilla command = 'Crtl + V'           -->
        
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />         <!-- Scintilla message = 'Space' character    -->
                    <Action type="1" message="2170" wParam="0" lParam="0" sParam="2" />         <!-- Scintilla message = '2'     character    -->
        
                </Macro>
        
        • Add a new line at the end of the Macro section, before the ending tag </Macros>

        • Paste the clipboard contents ( Ctrl + V )

        • Save the new contents of the Shortcuts.xml file ( Ctrl + S )

        • Close the Shortcuts.xml tab

        • Then, close N++, immediately and re-start it

        => The new macro ZA should be available, at bottom of the Macro menu ! Just try it : it should be OK !


        BTW, @zucriy-amsuna, do you know that this can be easily done with regular expressions, too ?

        • Open the Replace dialog ( Ctrl + H )

        • Type in the regex (?-i)^c\R , in the Find what: zone

        • Type in the regex c\x201\r\nc\x202\r\n , in the Replace with: zone

        • Set ON the Wrap Around and the Regular expression options

        • Hit, repeatedly on the Replace button or hit, once, on the Replace All button

        ET voilà !

        Notes :

        • The (?-i) modifier forces a non-insensitive search ( so, a sensitiveone ! )

        • The ^c\R syntax looks for a lower-case c letter, followed by their End of Line character(s)

        • In Replacement, it rewrites :

          • The lower-case letter c

          • A space character ( \x20 )

          • The digit 1

          • A line-break ( \r\n )

          • The lower-case letter c, again

          • A space character ( \x20 )

          • The digit 2

          • A line-break ( \r\n ), again

        • You may replace any \x20 syntax by a simple space character , instead !


        Now, if you want to change any line contents into two lines with the same line contents, followed by a space character and the digits 1 and 2, prefer the regex, below :

        SEARCH (?-s)^(.+)\R

        REPLACE $1\x201\r\n$1\x202\r\n

        Notes :

        • The (?-s) modifier forces the . special character to match a single standard character, only and not EOL chars.

        • Then the (.+)\R syntax match the entire line contents, with its End of line character(s), stored as group 1, due to the round parentheses

        In replacement, $1, simply, represents the searched group 1, which is rewritten first ( You may, as well, use the \1 syntax )


        For instance, the initial text, below :

        This is
        an simple
        example of
        test text
        

        would be changed as :

        This is 1
        This is 2
        an simple 1
        an simple 2
        example of 1
        example of 2
        test text 1
        test text 2
        

        Best Regards

        guy038

        Zucriy AmsunaZ 1 Reply Last reply Reply Quote 1
        • Zucriy AmsunaZ
          Zucriy Amsuna @guy038
          last edited by

          @guy038 Thank you for your very informative response! Unfortunately, it doesn’t solve my problem.

          I wasn’t saving my macro; I create all my macros on the fly because each situation is different. I very rarely need to use a macro I have previously used. Your provided macro does indeed work! And I love the regex solution, as well, so my current task that led to this problem is now done.

          But the macros I create still have the same issue I described above. Here is my macro after saving it. It differs slightly from yours. I want to know why that is and how to fix it. (I’m having trouble understanding what the parameters mean.)

                  <Macro name="ZA2" 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="c" />
                      <Action type="3" message="1625" wParam="0" lParam="1" sParam="" />
                      <Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                      <Action type="3" message="1701" wParam="0" lParam="1" sParam="" />
                      <Action type="0" message="2177" wParam="0" lParam="0" sParam="" />
                      <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="1" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />
                      <Action type="0" message="2025" wParam="11" lParam="0" sParam="" />
                      <Action type="0" message="2179" wParam="0" lParam="0" sParam="" />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
                      <Action type="1" message="2170" wParam="0" lParam="0" sParam="2" />
                  </Macro>
          

          I’ve run into this problem almost every time I have made a macro in the fast pew months, and I’d hate to have to edit the shortcuts.xml file every time.

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

            Hi, @zucriy-amsuna, and All,

            Surprisingly, you’ve got, in your Shortcuts.xml file, the additional line, below :

                        <Action type="0" message="2025" wParam="11" lParam="0" sParam="" />
            

            This Scintilla message is the SCI_GOTOPOS message. Refer to the link below :

            http://www.scintilla.org/ScintillaDoc.html#SCI_GOTOPOS

            Although this message should not be there, it does not seem to interfere with the macro. Indeed, as the wParam value is 11, this means that, if your test test is in a new tab, the caret position should be at the beginning of the line right after the c 1 line !?

            Anyway, could your report the Debug Info information of your N++ configuration ? Just click on the ? > Debug Info... menu option. Thanks !


            Just in case, here are below, the different actions that I’ve done, in order to get a macro with similar parameters to your macro. Give it a try, again !

            • Start Notepad++

            • Open a new tab ( Ctrl + N )

            • Type in the text below :

            a
            b
            c
            a
            b
            c
            a
            b
            c
            
            • Click on the Macro > Start Recording menu option

            • Click on the Search > Find... menu option

            • Type in c in the Find what: zone

            • Set the Wrap Around option

            • Set the Extended (\n, \r, \t, \0, \x...) option , ( You may choose, as well, the Normal or Regular expression mode ! )

            • UNSET all others options

            • Click on the Find Next button

            • Hit the ESC key to close the Find dialog

            • Hit the Ctrl + X shortcut to cut the highlighted letter c

            • Hit the Ctrl + V shortcut to paste the letter c

            • Hit the Space key, once

            • Hit the 1 digit key

            • Hit the Enter key

            • Hit, again, the Ctrl + V shortcut to paste the letter c

            • Hit the Space key, once

            • Hit the 2 digit key

            • Click on the Macro > Stop Recording menu option

            • Click on the Macro > Save current recorded macro menu option

            • Type in Test( or any other name ), in the Name zone

            • Valid the action with the OK button

            • Close and restart Notepad++

            • Select the a b c... text

            • Click on the Macro > Test menu option

            => The macro should correctly work :-))

            Cheers

            guy038

            Zucriy AmsunaZ 1 Reply Last reply Reply Quote 1
            • Zucriy AmsunaZ
              Zucriy Amsuna @guy038
              last edited by

              @guy038 I found the problem.

              NppAutoIndent.ini

              Since Notepad++'s auto-indentation is convenient but atrocious, I use this plugin to fix it so that it uses the previous line’s indentation instead of the previous texted line’s indentation.

              One of the recent Notepad++ updates broke it. Do you know of any way to fix it besides installing an older version?

              Thank you for your help! ^_^

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

                Hi, @zucriy-amsuna, and All,

                As I’m not a usual coder, with modern languages ( I wish I would ! ), I don’t think to be able to help you, significantly, in that matter !

                I first tried to get some information and I found an interesting article, on Wikipedia, about the different indentation styles :

                https://en.wikipedia.org/wiki/Indentation_style

                BTW I didn’t think of so many styling ways of coding ;-))


                Secondly, I’ve installed the NppAutoIndent.dll plugin, to get an general idea. of the problem !

                I just deduct that you cannot get a satisfactory solution, between :

                • The N++ Auto-Indent feature in Settings > Preferences… > MISC, which actives the Smart Indent ( K&R ) style, that you dislike

                • The NppAutoIndent plugin ( after disabling the native N+++ indent feature ) which, seemingly, may product some macro issues

                So, I just can see two trivial solutions :

                • Revert to a N++ version, prior to the v6.7 one, which used the Allman indentation style !

                • Disable, temporarily, the NppAutoIndent plugin , using the Plugins > NppAutoIndent > Auto Indent off option


                Sure, that some N++ Community users will give you more accurate information on that topic !

                See also :

                https://github.com/notepad-plus-plus/notepad-plus-plus/issues/821

                Cheers,

                guy038

                Zucriy AmsunaZ 1 Reply Last reply Reply Quote 1
                • Zucriy AmsunaZ
                  Zucriy Amsuna @guy038
                  last edited by

                  @guy038 I did not even know those styles had names! Interesting.

                  Thank you very much for your help. I’ll revert to a better–I mean older–version of Notepad++. =P

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