Hotstring option to only replace right-most needed characters.

Propose new features and changes
User avatar
kunkel321
Posts: 1149
Joined: 30 Nov 2015, 21:19

Hotstring option to only replace right-most needed characters.

19 Oct 2023, 15:10

This is not a super-important thing to me -- It's just something that I thought would be a clever feature.

Consider this hotstring, which is a grammar-relevant autocorrect item:

Code: Select all

::because of it's::because of its
Only the right-most two characters really need to be changed.

I have a function, as seen here:
https://www.autohotkey.com/boards/viewtopic.php?f=83&t=120220&p=543210#p542691
that does this. The relevant part of the code is here:

Code: Select all

; v2 code
; please assume that the trigger/hotstring is "trigger" and the expansion/replacement text is "replace." 
; Only select and replace rightmost necessary chars.  
	trigL := StrSplit(trigger)
	replL := StrSplit(replace)
	Global ignorLen := 0
	Loop Min(trigL.Length, replL.Length) ; find matching left substring.
	{	If (trigL[A_Index] = replL[A_Index])
			ignorLen++
		else
			break
	}
	; select trigger that was just typed and get trigger text
	SendInput("{Shift down}{Left " (TrigLen - ignorLen) "}{Shift up}{Ctrl down}x{Ctrl up}") 
This would be related to the hotstring option :B0: (no backspace). So you might declare the option for this with something like :Bn: where the "n" means only replace the right most necessary characters.

Just an idea! :D
ste(phen|ve) kunkel
ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: Hotstring option to only replace right-most needed characters.

20 Oct 2023, 03:10

Wouldn't the following do much the same thing?

Code: Select all

:*b0:because of it's::{bs 2}s
User avatar
kunkel321
Posts: 1149
Joined: 30 Nov 2015, 21:19

Re: Hotstring option to only replace right-most needed characters.

20 Oct 2023, 07:47

ludamo wrote:
20 Oct 2023, 03:10
Wouldn't the following do much the same thing?

Code: Select all

:*b0:because of it's::{bs 2}s
Hmmm... Yes, I suppose so!

As a built-in option, it could be applied as a #HotString directive, which could be used with the already existing AutoCorrect.ahk script.

Although.... I might be able to make a tool that would go through all the AutoCorrect items and change them from my version of the hotstring to yours.... That'll be my new project! :lol:

EDIT: Moved the project/code to the 'Script Share' sub forum, here.
https://www.autohotkey.com/boards/viewtopic.php?f=83&t=122531
Last edited by kunkel321 on 22 Oct 2023, 12:29, edited 2 times in total.
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 950
Joined: 02 Jul 2017, 23:47

Re: Hotstring option to only replace right-most needed characters.

21 Oct 2023, 10:57

kunkel321 wrote:
20 Oct 2023, 07:47

Code: Select all

needle := "m)^:(?P<opts>[^:]+)*:(?P<trig>[^:]+)::(?:\w+\([^)]*\)|(?P<Repl>[\s\w]+))?(?:\h+(?P<comm>;.*))?$"
Just a thought... the needle might be simplified to this (unless there are other considerations that are not apparent)
m)^:(?P<opt>[^:]+)*:(?P<trig>[^:]+)::(?P<repl>[^;]+)(?:\h+(?P<comment>;.*))?$
User avatar
kunkel321
Posts: 1149
Joined: 30 Nov 2015, 21:19

Re: Hotstring option to only replace right-most needed characters.

22 Oct 2023, 10:14

Thanks for the updated RegEx Andy! If folks are curious, the discussion continues here:
https://www.autohotkey.com/boards/viewtopic.php?f=82&t=122097
ste(phen|ve) kunkel
lexikos
Posts: 9665
Joined: 30 Sep 2013, 04:07
Contact:

Re: Hotstring option to only replace right-most needed characters.

24 May 2024, 21:28

Optimized auto-replace hotstrings to avoid retyping an identical leading part, where feasible.
Source: v2.1-alpha.8
User avatar
kunkel321
Posts: 1149
Joined: 30 Nov 2015, 21:19

Re: Hotstring option to only replace right-most needed characters.

25 May 2024, 08:15

lexikos wrote:
24 May 2024, 21:28
Optimized auto-replace hotstrings to avoid retyping an identical leading part, where feasible.
Source: v2.1-alpha.8
:thumbup:
ste(phen|ve) kunkel

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 8 guests