Marco's do not record and execute shortcuts.
-
@PeterJones
As part om my Macro, I want also to set the ‘Language’ automatically to “XML”.
I have tried several versions of the Macro lines.<Action type="2" message="0" wParam="46006" lParam="0" sParam="" /> <!-- Set language to XML -->
and also
<Action type="0" message="46006" wParam="0" lParam="0" sParam="" /> <!-- Set language to XML -->
and several other versions as well.
Up to now, I have been unable to make this work.How can I set the file Language to XML in a Macro please?
-
You need to read and understand https://npp-user-manual.org/docs/config-files/#macros , which describes which commands require which parameters. Type0 and Type1 are for the Scintilla messages only; type2 are for menu commands (whether built-in, or the cheater version for plugins); type3 are search/replace commands. That section of the manual also tells you where you can look to find the possible
message=
values for the scintilla type 0 and 1 actions, and the built-in menu-command-IDs for type 2 actions; it also directs you to the right section of the Searching page for finding out how to use the type=3 search/replace Actions.The Language menu entries are menu commands, so they must be type2.
Randomly trying type=0 for menu commands will not work.I have a macro which, among other things, sets the language for the current document to “Perl”, and the following Action works to accomplish that.
<Action type="2" message="0" wParam="46013" lParam="0" sParam="" />
Thus, your first type2 example should work.
Yes, the following macro correctly changes the Language to XML:
<Macro name="!!XML!!" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="2" message="0" wParam="46006" lParam="0" sParam="" /> </Macro>
I do not know why it is not for you: maybe something you are doing after it in your macro is overriding that choice, or maybe you have a bug in your macro so it is not working at all.
My debug recommendation is to start by trying my short
!!XML!!
macro, and verify it works (it should, since it does for me); then start adding your additional commands (before and after) until it stops doing what you expect -
@PeterJones said in Marco's do not record and execute shortcuts.:
type2 are for menu commands (…) the following macro correctly changes the Language to XML:
<Macro name="!!XML!!" Ctrl="no" Alt="no" Shift="no" Key="0"> <Action type="2" message="0" wParam="46006" lParam="0" sParam="" /> </Macro>
Hmm, I can see the part in the Macros page that mentions
type=2
messages, and that excerpt links to the menuCmdID.h source file.IDM_LANG
is defined on line 474, where the base number appears to be 6000, not 4600 or 46000.How did you get 46006 for the XML language?Edit: I now see that line 474 has
IDM+6000
, not simply6000
.IDM
is on line 20, defined as40000
-
@mathlete2 said in Marco's do not record and execute shortcuts.:
How did you get 46006 for the XML language?
plus
plus
= ?
Or, maybe more accurately and easier to understand:
IDM = 40000 IDM_LANG = (IDM + 6000) IDM_LANG_XML = (IDM_LANG + 6) = 46006
-
In the menuCmdID source file, there are multiple comments of the form:
// IMPORTANT: If list above/below is modified, you have to change the value of...
Is it possible for
IDM_LANG
to be defined differently in another setup?Also, when UDLs are created, do they get their own ID too? If so, where can users find this ID number?
-
@mathlete2 said in Marco's do not record and execute shortcuts.:
In the menuCmdID source file, there are multiple comments of the form:
// IMPORTANT: If list above/below is modified, you have to change the value of...
Is it possible for
IDM_LANG
to be defined differently in another setup?If you recompile Notepad++. But stuff like that, Don doesn’t tend to change (or allow others to) – he set it up originally with plenty of space for each group, and I haven’t noticed any changes to those main “header” constants.
However, the “If list above/below” warnings are put before certain “end of list” constants, like the
IDM_FILEMENU_LASTONE
– the point of that comment is to developers/contributors: if you add a new command to the File menu, you have to change the definition of IDM_FILEMENU_LASTONE, because obviously the last one has changed. Usually those comments apply to a very specific pair of X,Y in “if X changed then you have to change the value of Y” – it doesn’t mean “everything below this comment must be changed”, it means “the specific line or two immediately following this comment must be changed”.Also, some are “beginning of sub-list” constants, which may change, but not very often. For an example of such a change, see my final paragraph in this post, about IDM_LANG_USER.
Also, when UDLs are created, do they get their own ID too? If so, where can users find this ID number?
UDLs get dynamically-assigned numbers between 46180 and 46210; the order depends on what order Notepad++ processes the UDL languages in – so it should remain consistent from one run to the next, as long as you don’t change the number of UDL or name of UDL or filename of UDL (the latter two might change the order that they get processed in). And you can use NppUISpy! plugin to read the menu command IDs for those, just like you can for plugin menu actions:
And, as an example of the “beginning of sub-list” style changes, the offset for IDM_LANG_USER changed from 80 to 180 about 8 years ago, when Notepad++ added around 20 new languages – he shifted it by 100, to make sure there was room for future expansion, so that wouldn’t have to change again; in the intervening years it’s up to about 90 builtin languages, so I estimate it would take another 20 years before the number of langauges gets close to the current limit. That constant changing is not something you should worry about anytime soon.
-
@PeterJones
It works now.I started, as you suggested, with this macro and that worked just fine.
<Macro name="!!XML!!" Ctrl="no" Alt="no" Shift="no" Key="0"> <!-- TEST --> <Action type="2" message="0" wParam="46006" lParam="0" sParam="" /> <!-- Set Language to XML --> </Macro>
So…then I played around with the position of the XML-Language setting and it turns out it works when done in the first step.
<Macro name="BASE64 Decode XML" Ctrl="yes" Alt="yes" Shift="yes" Key="106"> <!-- Ctrl/Shift/Num* --> <Action type="2" message="0" wParam="46006" lParam="0" sParam="" /> <!-- Set Language to XML --> <Action type="0" message="2316" wParam="0" lParam="0" sParam="" /> <!-- Home --> <Action type="0" message="2013" wParam="0" lParam="0" sParam="" /> <!-- Select All --> <Action type="2" message="0" wParam="22129" lParam="0" sParam="" /> <!-- Base64 Decode --> <Action type="2" message="0" wParam="22217" lParam="0" sParam="" /> <!-- Xml Pretty Print with Attribute Indent --> <Action type="0" message="2013" wParam="0" lParam="0" sParam="" /> <!-- Select All --> <Action type="0" message="2178" wParam="0" lParam="0" sParam="" /> <!-- Copy --> </Macro>
Yes, I’m happy to tell you that this macro does exactly what I want.
Thank you again for you very helpful assistance. -
@Alan-Kilborn
@mathlete2 said in Marco’s do not record and execute shortcuts.:How did you get 46006 for the XML language?
For me it was simply useing the NppUISpy plugin.
-
By the way.
I have noticed that the numbers that can be used in the shortcut keys are not totally equal to the ‘normal’ keycodes and that not all keycodes can be used.
So…I have created a list with keycodes that are valid and I mention the actual keys they represent.
The list is just for the ‘key’ attribute and they can off cause (duh) be combined with Ctrl, Alt, Shift.If a number is not mentioned, that that means that Notepad++ registers this number als “Unlisted” and will not use it.
I have tested the numbers 0 to 255.I hope this list is useful.
Any corrections and/or additions are welcome.Key="8" ==> Backspace Key="9" ==> TAB Key="13" ==> ENTER Key="27" ==> ESC Key="32" ==> Spacebar Key="33" ==> Page up Key="34" ==> Page Down Key="35" ==> End Key="36" ==> Home Key="37" ==> Left Key="38" ==> Up Key="39" ==> Right Key="55" ==> INS Key="46" ==> DEL Key="48" ==> 0 Key="49" ==> 1 Key="50" ==> 2 Key="51" ==> 3 Key="52" ==> 4 Key="53" ==> 5 Key="54" ==> 6 Key="55" ==> 7 Key="56" ==> 8 Key="57" ==> 0 Key="65" ==> A Key="66" ==> B Key="67" ==> C Key="68" ==> D Key="69" ==> E Key="60" ==> F Key="71" ==> G Key="72" ==> H Key="73" ==> I Key="74" ==> J Key="75" ==> K Key="76" ==> L Key="77" ==> M Key="78" ==> N Key="79" ==> O Key="80" ==> P Key="81" ==> Q Key="82" ==> R Key="83" ==> S Key="84" ==> T Key="85" ==> U Key="86" ==> V Key="87" ==> W Key="88" ==> X Key="89" ==> Y Key="90" ==> Z Key="96" ==> Numpad 0 Key="97" ==> Numpad 1 Key="98" ==> Numpad 2 Key="99" ==> Numpad 3 Key="100" ==> Numpad 4 Key="101" ==> Numpad 5 Key="102" ==> Numpad 6 Key="103" ==> Numpad 7 Key="104" ==> Numpad 8 Key="105" ==> Numpad 9 Key="106" ==> Numpad * Key="107" ==> Numpad + Key="109" ==> Numpad - Key="110" ==> Numpad . Key="111" ==> Numpad / Key="112" ==> F1 Key="113" ==> F2 Key="114" ==> F3 Key="115" ==> F4 Key="116" ==> F5 Key="117" ==> F6 Key="118" ==> F7 Key="119" ==> F8 Key="120" ==> F9 Key="121" ==> F10 Key="122" ==> F11 Key="123" ==> F12 Key="186" ==> + Key="187" ==> = Key="188" ==> , Key="189" ==> - Key="190" ==> + Key="191" ==> / Key="192" ==> ~ Key="219" ==> [ Key="222" ==> ' Key="226" ==> <
-
Hello, @rens-duijsens and All,
-
Apparently, you forgot the
Key "40" ==> Down
, in your list -
The key INS is
Key 45
( and not 55 ) -
Some
OEM
keys seem missing too !
Refer this post and the next posts, for further information :
Best Regards,
guy038
-