stacked hotstrings with X execute option (v1 to v2 changes) Topic is solved

Propose new features and changes
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 09:34

In v1 there are two ways to stack execute hotstrings to perform the same execution

Code: Select all

:X:b::
:X:c:: MsgBox 123
Esc:: ExitApp
and

Code: Select all

::b::
:X:c:: MsgBox 123
Esc:: ExitApp
In v2 only the second way works. The first way throws "Error: Expected single-line action" at the first line.

Is there some way to get the first way working in v2?

@lexikos is this v1/v2 difference intended? I think a benefit of the first way is that the explicit X on each line serves as a visual reminder (when later reading the code) that each stacked hotstring will use the execute option.

Some background: The v2.0.2 hotstrings doc pages doesn't mention stacking in v1 or v2 so it is unclear if this is even an intended use case. But such stacking has de facto worked for a long time in v1. In contrast for hotkeys v1 and v2 documents that "Multiple hotkeys can be stacked vertically to have them perform the same action."
Last edited by neogna2 on 19 Jun 2023, 15:44, edited 1 time in total.
User avatar
mikeyww
Posts: 27202
Joined: 09 Sep 2014, 18:38

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 11:38

Code: Select all

#Requires AutoHotkey v2.0

::b::
::c::
 go(hs) {
  MsgBox hs
 }
Explained: Named function hotstrings
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 15:41

Thanks, that format for hotstrings had slipped my mind. It is less compact though, with three extra lines of code (brace, action, brace) compared to what I called the second way :X:c:: MsgBox 123

Do you or anyone else see any problems with using that more compact format, something I may have overlooked?

I see also that the new v2.0.3 documentation that was released today now uses the term stacking in the Named Function Hotstrings section: "Multiple hotkeys or hotstrings can be stacked together to call the same function." Nice!
Last edited by neogna2 on 19 Jun 2023, 15:45, edited 1 time in total.
User avatar
mikeyww
Posts: 27202
Joined: 09 Sep 2014, 18:38

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 15:45

You cited the page that I cited....

No problems with your approach at all, but I don't think it works? :)
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 15:50

Yeah same page, only when I made my first post I read the offline v2.0.2 doc where that page doesn't use the term stacking so that's why I noted that the online v2.0.3 now does.
mikeyww wrote:
19 Jun 2023, 15:45
No problems with your approach at all, but I don't think it works? :)
This works for me.

Code: Select all

::b::
:X:c:: MsgBox 123
Esc:: ExitApp
I run the code and press b and Enter and the messagebox shows.
Last edited by neogna2 on 19 Jun 2023, 15:52, edited 1 time in total.
User avatar
mikeyww
Posts: 27202
Joined: 09 Sep 2014, 18:38

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 15:52

OK. Thank you. I thought I tried it earlier, but I also installed the latest AHK update since then. Interesting result that you reported.
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 16:12

Veering off-topic a bit... While thinking about stacking hotstrings, imagine if we could stack them horizontally, so to speak, via a (not yet existing) hotstring option like this :XM|:a|b|c:: MsgBox 123 where (the not yet existing) M| means multiple hotstrings mode with | as separator character.
The line would be a more compact version of

Code: Select all

::a::
::b::
::c::
{
  MsgBox 123
}
User avatar
mikeyww
Posts: 27202
Joined: 09 Sep 2014, 18:38

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 16:16

Seems like more trouble than it's worth to code, parse, and understand, considering the existing working approach! I think that someone did already post some kind of regex hotstring script somewhere.
neogna2
Posts: 598
Joined: 15 Sep 2016, 15:44

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 16:26

That kind of option could reduce the linecount a lot in a script where many hotstrings are used for a custom autocomplete actions, for example ms|msg|msgb would all be hotstrings that expand to MsgBox(. Imagine hundreds of cases like that. But yeah there are other workarounds and a custom function can always be made to generate hotstrings from some compact data format of the user's choice.
lexikos
Posts: 9643
Joined: 30 Sep 2013, 04:07
Contact:

Re: stacked hotstrings with X execute option (v1 to v2 changes)

19 Jun 2023, 19:21

I don't think this is worth much mental energy at the moment, but I've moved the topic to Wish List for later consideration.
lexikos
Posts: 9643
Joined: 30 Sep 2013, 04:07
Contact:

Re: stacked hotstrings with X execute option (v1 to v2 changes)

29 Jun 2023, 20:23

@Helgef implemented this check.

Code: Select all

					// Do not allow execute option with blank line or OTB.
					// Without this check, this
					// :X:x::
					// {
					// }
					// would execute the block. But X is supposed to mean "execute this line".
Stacked hotstrings aren't explicitly mentioned, but seem to be of a similar nature. Either way, it is probably intended to catch cases where the author forgot to write the single-line action.

However, if something other than a brace or an X-hotstring/hotkey with a single-line action follows, there would still be a "missing open brace" error without this check.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: stacked hotstrings with X execute option (v1 to v2 changes)

23 Jul 2023, 08:00

is this v1/v2 difference intended?
From my side, there was no intention to consider anything v1. I probably didn't consider this particular case of stacking, only,
it is probably intended to catch cases where the author forgot to write the single-line action.
That said, unless trivial to change, without any risk of breaking anything else, it doesn't seem worth bothering with.

The exact rules of stacking is perhaps not well documented. I wrote a little about it in the PR, :arrow: #177.
#177 wrote: Stacking
Stacking is supported but has been restricted. There can now be no non-blank lines, including #ifs, in between stacked hotkeys. Stacking above an auto-replace hotstring, remapping or AltTab-hotkey is detected as an error. For example, the following is OK,

Code: Select all

::x::
y::
z::msgbox ThisHotkey ; ::x, y or z depending on which triggered
but not,

Code: Select all

x::
y::z
Cheers.
lexikos
Posts: 9643
Joined: 30 Sep 2013, 04:07
Contact:

Re: stacked hotstrings with X execute option (v1 to v2 changes)

12 Sep 2023, 03:48

I was reminded of this while working on related code.
Helgef wrote:
23 Jul 2023, 08:00
From my side, there was no intention to consider anything v1. I probably didn't consider this particular case of stacking, only,
it is probably intended to catch cases where the author forgot to write the single-line action.
Although I guessed that was the purpose, I don't think that's particularly helpful. Auto-replace hotstrings are more common, and if you forget the replacement, you'll only get an error if what follows isn't a block or a valid function.
That said, unless trivial to change, without any risk of breaking anything else, it doesn't seem worth bothering with.
That comment seemed odd to me. I didn't see how it could be anything but trivial to change, and without risk of breaking any hotstrings that currently work, given that all it does is show an error message when the X option is used without an action. A quick code review and testing confirmed it.
// Without this check, this
// :X:x::
// {
// }
// would execute the block. But X is supposed to mean "execute this line".
But...
X: Execute.
X means execute. And if you don't specify X, the hotstring will execute the block.


A bigger problem with the check is that it prevents this from working:

Code: Select all

#Hotstring X
:*?:@1::
:*?:@2::MsgBox ThisHotkey
I don't see any reason that the action should be required for every hotstring, given how hotstrings permit stacking under other conditions, and hotkeys permit stacking in this exact way.

It might have made sense if we required stacks of hotkeys/hotstrings to terminate with a block/function, but it's too late for that.


There can now be no non-blank lines, including #ifs, in between stacked hotkeys.
This was fixed (in beta) so that multiple hotkey variants (or different hotkeys with different conditions) can be stacked above one function/block, as in v1. I don't know how common it is, but I do it, and there is an example specifically demonstrating it in the documentation for hotkey variants.
lexikos
Posts: 9643
Joined: 30 Sep 2013, 04:07
Contact:

Re: stacked hotstrings with X execute option (v1 to v2 changes)  Topic is solved

17 Sep 2023, 00:01

This is permitted by v2.0.9.

Code: Select all

:X:b::
:X:c:: MsgBox 123
Esc:: ExitApp

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 21 guests