RegExHotstring - dynamic RegEx Hotstrings
Re: RegExHotstring() dynamic RegEx Hotstrings
Thank you much for the update!!
Might there be a way that I've not found to extend the terminal character set that activates the replacement? I have appended (\s|-|\(|\)|\[|\]|\{|\}|:|\\|\?|!|`"|\.|,) as seen here:
and it responds in cases I've tried (the expanded list above) except \s.
Typing 3yr should expand to 3-year. It behaves like so:
3yr- becomes 3-year-
3yr[ becomes 3-year[
3yr{space or enter} stays 3yr
My goal is that the nonword characters trigger the expansion. I have played with replacing the list with /W and it seems to work with the exception of /s still. I'd previously put the list in manually as the last script I used for this failed with /W.
Further, with the list above or with /W, the following behavior is noted:
3yr! becomes 3-year (the ! is not brought to the end)
{, }, and + behave just like the ! and they are not carried forth in the replacement in the position of $2.
Might there be a way that I've not found to extend the terminal character set that activates the replacement? I have appended (\s|-|\(|\)|\[|\]|\{|\}|:|\\|\?|!|`"|\.|,) as seen here:
Code: Select all
RegExHotstring("\b([0-9])yr(\s|/|-|\(|\)|\[|\]|\{|\}|:|\\|\?|!|`"|\.|,)","$1-year$2","*")
;or
RegExHotstring("\b([0-9])yr(\s|\W)","$1-year$2","*")
Typing 3yr should expand to 3-year. It behaves like so:
3yr- becomes 3-year-
3yr[ becomes 3-year[
3yr{space or enter} stays 3yr
My goal is that the nonword characters trigger the expansion. I have played with replacing the list with /W and it seems to work with the exception of /s still. I'd previously put the list in manually as the last script I used for this failed with /W.
Further, with the list above or with /W, the following behavior is noted:
3yr! becomes 3-year (the ! is not brought to the end)
{, }, and + behave just like the ! and they are not carried forth in the replacement in the position of $2.
Re: RegExHotstring() dynamic RegEx Hotstrings
@EFH52
The function clears input with trigger keys and nontext keys, so input it stored will only be words, which makes it impossible to match with white space charaters and word boundaries (or anything related to that), current workaround is creat two seperate RegExHotstring.
if you really wants to be sepecific I will suggest using functions for better readablity:
The function clears input with trigger keys and nontext keys, so input it stored will only be words, which makes it impossible to match with white space charaters and word boundaries (or anything related to that), current workaround is creat two seperate RegExHotstring.
Code: Select all
; this one triggers with \W
RegExHotstring("(\d+)yr(\W)", "$1-year$2", "*")
; this one triggers with [\n\t ]
RegExHotstring("(\d+)yr", "$1-year")
Code: Select all
RegExHotstring("(\d+)yr(\W)", year, "*")
year(match) {
switch match[2] {
case "!", "?":
Send(match[1] "-year" match[2])
case "\", "/":
Send(match[1] "-year")
default:
Send(match[1] "yr")
}
}
Re: RegExHotstring() dynamic RegEx Hotstrings
Right. Exactly as was mentioned earlier in the thread. I should learn to read and retain better.
Thanks for the details and repeating yourself!
Thanks for the details and repeating yourself!
Re: RegExHotstring() dynamic RegEx Hotstrings
My previous message is still in the moderation queue, but the !, {, and } still won't carry over even when expanded as in the explicit function you kindly demonstrated. I modified it to include { and }, but even before that the ! wouldn't carry. I did attempt to escape the sequenced with "`!", "`{", and "`}" to no avail.
3yr! yields 3-year
3yr! yields 3-year
Code: Select all
RegExHotstring("(\d+)yr(\W)", year, "*")
year(match) {
switch match[2] {
case "!", "?":
Send(match[1] "-year" match[2])
case "\", "/":
Send(match[1] "-year")
default:
Send(match[1] "yr")
}
}[\code]
Re: RegExHotstring() dynamic RegEx Hotstrings
@EFH52
I don't exactly know what problem you've occurred, it works as intended as I tested it on my mechine, even executing step by step in debug mode.
Maybe you're unfamilier with RegExMatchInfo it returns or Switch?
https://www.autohotkey.com/docs/v2/lib/RegExMatch.htm#MatchObject
https://www.autohotkey.com/docs/v2/lib/Switch.htm
Although it's not mentioned explicitily in the document, mutiple case values can be merged in to one and seperated by comma.
and you only need to escape some special characters listed here (not include ":" and "{")
https://www.autohotkey.com/docs/v2/misc/EscapeChar.htm
I don't exactly know what problem you've occurred, it works as intended as I tested it on my mechine, even executing step by step in debug mode.
Maybe you're unfamilier with RegExMatchInfo it returns or Switch?
https://www.autohotkey.com/docs/v2/lib/RegExMatch.htm#MatchObject
https://www.autohotkey.com/docs/v2/lib/Switch.htm
Although it's not mentioned explicitily in the document, mutiple case values can be merged in to one and seperated by comma.
Code: Select all
RegExHotstring("(\d+)yr(\W)", year, "*")
year(match) {
switch (match[2]) {
case "-", "/", "\", "[", "]":
Send(match[1] "-year" match[2])
case "!", "{", "}", "+":
Send(match[1] "-year")
default:
Send(match[1] "yr")
}
}
https://www.autohotkey.com/docs/v2/misc/EscapeChar.htm
Re: RegExHotstring() dynamic RegEx Hotstrings
We may be speaking to crossed ideas. I want match[2] on the end of everything. I am not getting it for !, {, and } in the position of match[2]. I am not concerned if it is with the use of a switch statement or not. I simply reposted the code you gifted me and was confused by the ! not finding its way into match[2]. I appreciate the links. I read about the match object yesterday and it certainly helped me follow your code better. I was spurred to do so by digging into your whole script.
I'll try again, it seems I can't say what I mean.
You provided me with this example:
I would expect 3yr! to expand to 3-year!, but I get just 3-year. Is your machine given different output?
I'll try again, it seems I can't say what I mean.
You provided me with this example:
Code: Select all
RegExHotstring("(\d+)yr(\W)", year, "*")
year(match) {
switch match[2] {
case "!", "?":
Send(match[1] "-year" match[2])
case "\", "/":
Send(match[1] "-year")
default:
Send(match[1] "yr")
}
}
Re: RegExHotstring() dynamic RegEx Hotstrings
@EFH52
I found the problem, it's because Send(), use SendText() instead.
I also changed one in source code
https://github.com/8LWXpg/RegExHotstring/releases/tag/v2.7
I found the problem, it's because Send(), use SendText() instead.
I also changed one in source code
https://github.com/8LWXpg/RegExHotstring/releases/tag/v2.7
Re: RegExHotstring() dynamic RegEx Hotstrings
Good deal! Thanks. I was convinced I had messed up a setting and that it was a local issue. I'll start migrating all my shortcuts over now. This is a godsend for my v2 update!
Re: RegExHotstring() dynamic RegEx Hotstrings
With the script that I used in v1 I had created a RegEx Hotstring that provided the skeleton of a new entry and placed the cursor in position to take the new Hotstring as such:
With the 2.7 update here taking Send and making it SendText it invalidated the {left 17} call.
Though with the current ability to pass the action off to a function, we can return that ability in a simple rewrite.
This gives me the same result as I was accustomed to and provides significant enhancements over the product I was using in v1.
Thank you for sharing the script, insight, and guidance to make these solutions possible.
Now to fix it up such that it will give both the white-space trigger or the \W trigger versions for each Hotstring moving forward:
Yields:
With the cursor at the end of the first \b ready for the new trigger to be entered.
Code: Select all
hotstrings("\bhtstr\s","hotstrings(""\b""tailchar,""``%`$`1```%""){left 17}")
Though with the current ability to pass the action off to a function, we can return that ability in a simple rewrite.
Code: Select all
RegExHotstring("\bhtstr", builder)
builder(match) {
Send("RegExHotstring(`"\b`",`"$1`"){left 7}")
}
Thank you for sharing the script, insight, and guidance to make these solutions possible.
Now to fix it up such that it will give both the white-space trigger or the \W trigger versions for each Hotstring moving forward:
Code: Select all
RegExHotstring("\bhtstr", builder)
builder(match) {
Send("RegExHotstring(`"\b`",`"`"){enter}")
Send("RegExHotstring(`"\b(\W)`",`"$1`",`"*`"){up}{left 5}")
}
Code: Select all
RegExHotstring("\b","")
RegExHotstring("\b(\W)","$1","*")
Re: RegExHotstring() dynamic RegEx Hotstrings
@EFH52
maybe you mean this?
note that there's no need to specify "\b" because input only collects after it
and since you're not using RegEx in the first one, I think it's better to replace with a regular hotstring
I also found a bug with line like this
and pushed a update
https://github.com/8LWXpg/RegExHotstring/releases/tag/v3.0
maybe you mean this?
Code: Select all
RegExHotstring("htstr", builder)
builder(*) {
RegExHotstring("", (*) => Send("{Enter}"))
RegExHotstring("\W", (*) => Send("{Up}{Left 5}"), "*")
}
and since you're not using RegEx in the first one, I think it's better to replace with a regular hotstring
I also found a bug with line like this
Code: Select all
RegExHotstring("\W", (*) => Send("{Up}{Left 5}"), "*")
https://github.com/8LWXpg/RegExHotstring/releases/tag/v3.0
Re: RegExHotstring() dynamic RegEx Hotstrings
Code: Select all
Send("RegExHotstring(`"\b`",`"`"){enter}")
Send("RegExHotstring(`"\b(\W)`",`"$1`",`"*`"){up}{left 5}")
So that I can use the stub to fill things out like this:
Code: Select all
RegExHotstring("\b(r|R)qd","$1equired")
RegExHotstring("\b(r|R)qd(\W)","$1equired$2","*")
so the {up}{left 5] just lands the cursor so that I can type in a new hotstring.
I'll kill all the \b's now that they are not required in this implementation!
Thanks for the update, I'll update my copy as well.
Re: RegExHotstring() dynamic RegEx Hotstrings
@EFH52
Simply add it within the functions. Once executed, the new RegExHotstring will be added.
This code creates two new RegExHotstrings when you type "htstr". The first one triggers Send("{Enter}") and the second one triggers Send("{Up}{Left 5}").
If you want to write function in one line, you need to put parentheses around them and use fat arrow syntax. Otherwise, they will be evaluated as their return values instead of functions.
Simply add it within the functions. Once executed, the new RegExHotstring will be added.
Code: Select all
RegExHotstring("htstr", builder)
builder(*) {
RegExHotstring("", (*) => Send("{Enter}"))
RegExHotstring("\W", (*) => Send("{Up}{Left 5}"), "*")
}
If you want to write function in one line, you need to put parentheses around them and use fat arrow syntax. Otherwise, they will be evaluated as their return values instead of functions.
Re: RegExHotstring() dynamic RegEx Hotstrings
Nevermind, we are talking at cross proposes and trying to accomplish two different things. I do need to learn the syntax with the fat arrows though.
Re: RegExHotstring() dynamic RegEx Hotstrings
It seems that this script is causing * on the number pad to type 8.
Please test. The problem goes away if I remove:
edit: seems + on the numpad comes out as =.
Further testing shows numpad enter fails as well.
Please test. The problem goes away if I remove:
Code: Select all
#Include RegExHotstring.ahk
Further testing shows numpad enter fails as well.
Re: RegExHotstring() dynamic RegEx Hotstrings
Hello again!
CAPSLOCK fails to function now with this script included.
CAPSLOCK fails to function now with this script included.
Re: RegExHotstring() dynamic RegEx Hotstrings
I would like to put a Unicode character in the replacement string, e.g. {U+2013} (an en dash). That works OK with a normal AHK hotstring but when using RegExHotstring you simply get the same characters i.e. {U+2013}
Is there a work-around?
Many thanks!
Is there a work-around?
Many thanks!