Community
    • Login

    Record a macro that's just the pasted text?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 3 Posters 2.9k 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.
    • eeegnu00E
      eeegnu00
      last edited by

      I’d like to generate macros that are just a bunch of pre-existing text, with the cursor in a specific place when it ends. This was working well, until I copied something new, and I learned that ‘ctrl-v’ was macro’d instead of the contents of the paste!

      Is there any simple way to accomplish this without manually typing out the whole thing (preferably without having to code in the macro, but I can imagine that might be necessary.)

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @eeegnu00
        last edited by PeterJones

        @eeegnu00 ,

        So I think what you really want to do is record a macro of typing specific text at the cursor, rather than pasting… but you don’t want to actually have to type it while recording the macro. In that case, you will either have to type all the text instead of pasting, or edit the macro after it’s recorded.

        1. record the macro where you do all your other stuff, but instead of pasting, type something easy to type (maybe just an A), and save the macro
        2. exit notepad++ (which saves the macros to the config file)
        3. edit %AppData%\Notepad++\shortcuts.xml (🛈)
        4. look in shortcuts.xml for the name of your macro. It should have more than one <Action ...> line where the message="2170" – when you record a macro, it uses one Command for each letter… but when you manually edit the macro, it can have multiple characters. So if you only have one 2170, you could change it from
          <Action type="1" message="2170" wParam="0" lParam="0" sParam="A" />
          
          to
          <Action type="1" message="2170" wParam="0" lParam="0" sParam="Multiple Words Here" />
          <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;&#x000A;" />
          <Action type="1" message="2170" wParam="0" lParam="0" sParam="... and more here" />    
          
          I used &#x000D;&#x000A; for embedding a newline inside the sParam
        5. Save the shortcuts.xml
        6. Exit Notepad++ and restart.
        7. Now the macro will use your edited text when it “types”, rather than the A that I had you record, or the Edit>Paste/Ctrl+V that you previously recorded

        As an alternate to steps 1-4, if you already have the macro recorded with the Ctrl+V/Paste, then you can eidt shortcuts.xml directly (as described above) and look for

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

        which is the Paste command. Replace that with one or more of the 2170 as shown above, and save and exit/restart, and it will do the same thing.

        eeegnu00E 1 Reply Last reply Reply Quote 1
        • eeegnu00E
          eeegnu00 @PeterJones
          last edited by eeegnu00

          @PeterJones Thanks, I went ahead and wrote a python script to help automate this process, and I’m including it here for anyone else that might need it in the future. This really seems like something that would be best implemented as part of np++ with something like shift+ctrl+v to use the pasted output rather than memorizing ctrl+v.

          #Line commands found here: https://github.com/notepad-plus-plus/notepad-plus-plus/blob/af56713079c9e31b8c81b5603a6c841afb3e2005/scintilla/include/Scintilla.h
          cursorLine = 5 #On what line do you want to end up at (0 indexed)? Enter -1 to leave it at the end.
          pastedInput = \
          '''#include <bits/stdc++.h>
          
          using namespace std;
          
          int main(){
          	
          	return 0;
          }'''
          pastedInput = pastedInput.replace('"','&quot;') #don't conflict with np++ macro syntax
          
          newline = '\n\t\t\t<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000D;" />\n\t\t\t<Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x000A;" />'
          out = [f'\t\t\t<Action type="1" message="2170" wParam="0" lParam="0" sParam="{line}" />{newline}' for line in pastedInput.split("\n")]
          linesUp = len(pastedInput.split("\n")) - cursorLine
          if cursorLine > 0:
              out.extend(['\t\t\t<Action type="0" message="2302" wParam="0" lParam="0" sParam="" />' for i in range(linesUp)]) #line up
              out.append('\t\t\t<Action type="0" message="2314" wParam="0" lParam="0" sParam="" />') #line end
              
          print("\n".join(out))
          
          Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @eeegnu00
            last edited by

            @eeegnu00 said in Record a macro that's just the pasted text?:

            This really seems like something that would be best implemented as part of np++ with something like shift+ctrl+v to use the pasted output rather than memorizing ctrl+v.

            I’m struggling to understand this part. Hmm.

            eeegnu00E 1 Reply Last reply Reply Quote 0
            • eeegnu00E
              eeegnu00 @Alan Kilborn
              last edited by

              @Alan-Kilborn As in:

              Macro with ctrl-v on a replay: type in control v and use what’s currently in the copy buffer.
              Macro with ctrl-shift-v on a replay: use what was in the copy buffer at the moment it was used when recording the macro.

              1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @eeegnu00
                last edited by PeterJones

                @eeegnu00 said in Record a macro that's just the pasted text?:

                really seems like something that would be best implemented as part of np++ with something like shift+ctrl+v to use the pasted output rather than memorizing ctrl+v

                The macro recorder basically records keystrokes and menu clicks. If you type Ctrl+V or use the Paste menu entry, it will record that command.

                Since you seem to know Python, I will reiterate bring up that there’s a plugin called PythonScript which embeds a Python interpreter in Notepad++, and gives that interpreter access to the Notepad++ GUI commands (including the ability to open new files, create new files, etc) and editor commands/keystrokes, along with being a fully functional Python interpreter. Anything you can do in a macro, you can do in PythonScript; anything† you can do in Python, you can do in PythonScript. I rarely use Macros, because anything that I think of to do in macros, I am more likely to want one of the advanced features found in PythonScript (looping, variables, etc).

                †: just about anything. it’s harder to install modules in the PythonScript instance, since pip isn’t available for it; other than that. I don’t know of anything else that cannot be done.

                Alan KilbornA 1 Reply Last reply Reply Quote 1
                • Alan KilbornA
                  Alan Kilborn @PeterJones
                  last edited by

                  @PeterJones said in Record a macro that's just the pasted text?:

                  Anything you can do in a macro, you can do in PythonScript

                  Definitely note that the converse is not true…macros are very limiting.

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