1

I use simple NPP_Exec commands in N++ which work fine for macros. Eg.:

NPP_MENUCOMMAND Macro/Action1
NPP_MENUCOMMAND Encoding/Convert to ANSI
NPP_SAVE

But how can I run a specific macro several times? I have tried NPP_MENUCOMMAND Macro/Run but then I still have to manually select the macro I need and set it to "Run until the end of line" in the pop-up window.

Remus Sarnus
  • 25
  • 1
  • 7

3 Answers3

0

You can use the NppExec plugin for simple loops like this:

:REPEAT
  SCI_SENDMSG SCI_GETCURRENTPOS
  set pos1 = $(MSG_RESULT) 

  // put your Macro invocation here instead of the linedown:
  SCI_SENDMSG SCI_LINEDOWN

  SCI_SENDMSG SCI_GETCURRENTPOS
  set pos2 = $(MSG_RESULT) 

  // if the linedown (or your macro) doesnot give another pos, we have reached the end
  if $(pos1) == $(pos2) goto END
  // else loop
  goto REPEAT

:END
  • it stores the current position
  • then it does something that advances the position (in this example a linedown, you would put your Macro invocation there, make sure it changes the cursor position)
  • then the position is compared with the stored position; we have reached the end, if the position has not changed;
  • in this case we leave the loop
Lars Fischer
  • 9,135
  • 3
  • 26
  • 35
0

I just found a simple and easy solution for that. I did not use command lines but it might work as well:

  1. Make sure the macro ends with a Ctrl-Tab key
  2. From Settings -> Preferences -> MISC, disable the doc switcher.
  3. Open all files to be edited.
  4. Use the "Run macro multiple times" dialog, and enter the number of files you have just opened.
  5. Execute
  6. Save all

I did not create this, found it here:https://sourceforge.net/p/notepad-plus/discussion/331754/thread/469ffec9/ , but it worked like a charm for me. I could edit 400 documents in less than 2 min.

0

I found another way to achieve this. Inspired by Wagner Fontes's answer, we can do the following:

Step 1: Record your Macro

Step 2 (Important): Before you finish the Macro, type the "Ctrl + Tab" as the last record in the Macro. This hotkey means moving to the next opening text file.

Step 3: Save the Marco.

Because of the Step 2, Notepad will move to the next text file after running the macro once. In this method, "Run a Macro Multiple Times" makes "Multiple Files".

Fig

T X
  • 505
  • 1
  • 9
  • 19