assign the same keyboard shortcut to multiple Macros
-
I recently posted some Macro code for a useful regex-based Find/Replace All process.
As noted in the Actions documentation, if I change the 1702 message from
786to 128, the Macro only applies to whatever text I happen to select. This can be useful in some situations, so what I’d like to do is have both variations of the Macro exist for the same keyboard shortcut (i.e. apply the original Macro when nothing is selected, but apply the modified Macro when something is selected).When I have the modified Macro code listed above the original Macro code, only the modified Macro is functional. When I switch the order, the original Macro is the only one that’s functional; it applies to all text in the file, even if only a portion of it is selected. I’m guessing this happens because the 1702 message is still 786, but I can’t figure out what I would need to change this to in order to achieve the desired configuration.
Does NP++ support contextual Macros like this?
-
@mathlete2 said in assign the same keyboard shortcut to multiple Macros:
for the same keyboard shortcut (i.e. apply the original Macro when nothing is selected, but apply the modified Macro when something is selected).
Not possible this way.
Make the macro use In selection (hopefully your search action is something that supports that option), and then to affect all text, do a Ctrl+a before running the macro. -
@Alan-Kilborn yes, using the
Ctrl
+A
shortcut prior to applying the modified Macro is the same as running the original Macro. This is easier than trying to remember a separate shortcut, so it’s probably the best alternative for the time being.However, just to confirm: there currently isn’t a way of configuring NP++ to disable a specific Macro as soon as something is selected? That’s effectively what I’m trying to do, so perhaps I should have phrased the question that way.
-
@mathlete2 said in assign the same keyboard shortcut to multiple Macros:
there currently isn’t a way of configuring NP++ to disable a specific Macro as soon as something is selected?
Correct.
Macros in Notepad++ are really simple. And simple-minded.
If you want to open things up to scripting (programming), then you can do just about anything you want. -
Macro-disabling functionality has been requested here.
-
@mathlete2 said:
Macro-disabling functionality has been requested here
Prediction: This request will never be fulfilled.
-
@Alan-Kilborn said in assign the same keyboard shortcut to multiple Macros:
Prediction: This request will never be fulfilled.
Prediction: this dire prediction will not deter me from making reasonable requests in the future…
-
I personally cannot see a situation in which your complicated “enable one disable the other via the menu” suggestion in the Feature Request would save any time or brain-space compared to having
Ctrl+Key
for one macro andCtrl+Alt+Key
for the other macro, and just remembering that “the one withAlt
works onAll
text”. Personally, having to remember to go toggle both those macros in the menu to switch between them every time I wanted to change between All vs Selected would be more annoying to me than having two different keystrokes.And if you, personally, are willing to do that extra step, why not just pull up the Shortcut Mapper instead, and remove the shortcut on one and enable it on the other?
Just my thoughts. (And, of course, you’re allowed to make any reasonable feature request you want; you just might want to be willing to consider alternatives, in case your FR is ignored or rejected.)
-
@mathlete2, Notepad++'s design philosophy has leaned towards being as lightweight as possible. It is a framework that allows for extensions, mainly in the form of plugins, some of which implement scripting languages that in turn led to plugins that allowed for scripts to access and change Notepad++ internals.
While Notepad++ has accumulated some bloat the developer has resisted going down the path of inventing and supporting a built in scripting language. Had that happened then it likely would have been easy to then map a keyboard shortcut to a built in script that had logic paths for the nature of the current selection, the contents, of the copy/paste buffer, etc.
-
@PeterJones it’s not so much about remembering alternative workflows, but accommodating personal preferences (which is exactly what Feature Requests are all about). This includes workflow efficiencies - a
Ctrl
+<key>
shortcut is physically easier to execute thanCtrl
+Alt
+<key>
orCtrl
+Shift
+<key>
, and the same can be said of theCtrl
+A
+<key>
alternative that @Alan-Kilborn mentioned. Sure, these are manageable workarounds, but it would be nice to have more advanced configuration options that allow you to make things even easier.Also, many shortcuts are unwise to re-program, so there are a limited number of custom shortcuts for users to work with in the first place. If you have a lot of Macros, you can run out of options pretty quickly.
However, reading between the lines, I think you may have misunderstood what I’m trying to do (and/or why I can’t do it right now): I want to assign the same shortcut to two S/R Macros that are always simultaneously “enabled” (i.e. active in
shortcuts.xml
), but configure one to only be effective when the other isn’t.ICYMI: this is all based on the concept of the “In selection” configuration; while useful in many contexts, it effectively renders an S/R Macro useless unless something is selected. If you can configure an S/R Macro to only be effective when something is selected, wouldn’t you also want to configure a similar Macro to only be effective when something isn’t selected? Right now, NP++ doesn’t offer a way to do that, so that’s effectively what I’ve requested.
-
@mkupper fair enough. It’s definitely possible that I’m drastically underestimating the complexity of implementing this, but I’m hoping that there’s a reasonably simple way of doing so.
-
@Alan-Kilborn @PeterJones @mkupper upon further reflection, I agree that my original RFE was unnecessarily complicated, so I’ve submitted another request targeted more towards my ultimate end goal.
-
@mathlete2 said in assign the same keyboard shortcut to multiple Macros:
I’ve submitted another request targeted more towards my ultimate end goal.
If your intent is to have the new one, not the old one, make sure you close the old one, so the developer knows which you actually want.