Recording: How can I change the regex operations in MACRO?
-
hello, again. how can I change the regex operations in MACROS, to record something extra on the same macro?
Seems that I cannot do that. Or, can be done?
-
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.
-
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.
-
@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 withmessage="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.
-
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 :
-
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="— \1\2\3 —" /> <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© 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, aspace
char, the present word, aspace
char and a finalEM dash
char -
Insertion of the line
© 2022 - Neculai I. Fantanaru
with its line-ending chars, at the very end of aNormal
text file
Best Regards,
guy038
-
-
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) -
@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. -
@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 inshortcuts.xml
, you have to exit Notepad++ first. See also the User Manual’s section on Editing Configuration Files -
@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. -
Yes, indeed. The location of shortcuts.xml is:
c:\Users\COMPUTER\AppData\Roaming\Notepad++\
-
@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.