Designate `|` to the cursor location when implementing hotstring auto-replacement.

Propose new features and changes
XMB-7
Posts: 18
Joined: 08 Jan 2023, 20:58
Contact:

Designate `|` to the cursor location when implementing hotstring auto-replacement.

27 May 2023, 04:31

For example, when triggering `::/test::abc...xyzABC...XYZ`, I want the cursor to move automatically between z and A so that I can continue inserting content such as `123...789`.
The workaround is like `:X:/test::Send('abc...xyzABC...XYZ{Left 26}')`, but I think `::/test::abc...xyz|ABC...XYZ` where `|` indicates the cursor location would be much more convenient.
User avatar
boiler
Posts: 17390
Joined: 21 Dec 2014, 02:44

Re: Designate `|` to the cursor location when implementing hotstring auto-replacement.

27 May 2023, 07:34

In the meantime (and probably always since I doubt your request will get implemented in AHK), you can use this function that will move the cursor to the (first) pipe character:

Code: Select all

#Requires AutoHotkey v2.0

:X:/test::SendCursorPos 'abcdefghijklmnopqrstuvwxyz|ABCDEFGHIJKLMNOPQRSTUVWXYZ'

SendCursorPos(s) {
	SendText StrReplace(s, "|",,,, 1)
	Send "{Left " (StrLen(s) - InStr(s, "|")) "}"
}
XMB-7
Posts: 18
Joined: 08 Jan 2023, 20:58
Contact:

Re: Designate `|` to the cursor location when implementing hotstring auto-replacement.

27 May 2023, 09:30

Yes, there are several ways to achieve this goal, but I think adding syntax sugar would be awesome since it is a very common use case.
When using hotstring just to insert some text, there will always be a fixed part and another variable part that needs to be filled in after auto-replacement, like 'Hello, ___. Nice to meet you...'
A simple `::/test::Hello, |. Nice to meet you...` is quite handy to use.
User avatar
boiler
Posts: 17390
Joined: 21 Dec 2014, 02:44

Re: Designate `|` to the cursor location when implementing hotstring auto-replacement.

27 May 2023, 10:34

Yes, but what you showed requires you counting characters. What I showed is almost the same is what you’re asking for. Yes, it would be a little cleaner if built into the language. I suggested something close to it thinking you might appreciate it since the change likely won’t happen soon, if at all. Feel free to ignore it, of course.
XMB-7
Posts: 18
Joined: 08 Jan 2023, 20:58
Contact:

Re: Designate `|` to the cursor location when implementing hotstring auto-replacement.

27 May 2023, 10:57

Thank you for your advice. Actually, I have already used a similar method you suggested. The example I provided was just a simplified version so that anyone can easily understand what I want to do.
My intention was to highlight that automatic replacement is one of the most commonly utilized basic features in AHK, and this syntax sugar is particularly user-friendly for anyone, especially those who have little or even zero knowledge of programming.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 10 guests