AutoCorrect for v2

Post your working scripts, libraries and tools.
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

04 May 2024, 12:36

Big Upgrade to Manual Correction Logger tool.
https://github.com/kunkel321/AutoCorrect2

It has been renamed "MCLogger.ahk" and the actual log is now a separate text file called MCLog.txt. After running an analysis of the logged hotstrings, the top most-frequently-occurring items are presented in a radio group so you can optionally select an item to cull from the log, and add to your AutoCorrect2 file. There's no point in scanning them over and over if you've already added the item to your ac2 script... The tool culls them out of the log so that you don't have to manually find and remove them. The "adding to your AutoCorrect script" part has two options. If you set this variable to "1" (number one):

Code: Select all

SendToHH := 0  ; Export directly to HotSting Helper. 1=yes / 0=no
Then the MCLogger tool will open the selected hotstring in ac2's HotString Helper form, so that you can Examine it for possible conversion into a multi-match word middle item. Important: I updated AutoCorrect2.ahk to accept this command line parameter just today--so get the newest version of it for this feature to work. If you leave it set at 0, the item just gets appended to the end of the ac script.

Be sure to look over the other user options near the top of the code as well.

I've left my own logged items in the MCLog.txt file, but, as always, you should remove my logged items and log your own, that are based on your own typing patterns.

The image shows the progress-of-analysis progress bar, and below it the radio buttons (that appear after progress gets to 100%).
WARNING: Pressing the [Cull and Append] button will absolutely remove the item from your log... So you might want to make a backup copy of your log file first (the tool does NOT create a backup for you). Edit: Now pressing the [Cull and Append] button will show a msgbox, prompting the user to optionally make a backup of the log each time. EDIT 2: I didn't like the MsgBox, to I replaced it with a "make a backup" checkbox on the bottom of the form. (below screenshot updated.)
Other changes on 5-5-2024: New log icon. New menu item (open log file). Esc now closes the cull-n-append Gui.
Image
Image

As an extra note: I've been collecting my typos/corrections for a few months and have a couple of thousand items. You won't see the highest-frequency items in my log data, because they's already been culled from the log and added to AutoCorrect2. :D

EDIT: Please pronounce it to yourself as "M. C. Log" and not "Mc Log," or "M. Clog." LOL.
On a serious note: Here are a couple of Gifs...
Spoiler
Additional comment: If the SendToHH variable is set to 0 (zero), then the item that gets appended to ac2 is a plain vanilla hotstring... It is not formatted with the f() syntax.
Last edited by kunkel321 on 05 May 2024, 19:06, edited 2 times in total.
ste(phen|ve) kunkel
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

04 May 2024, 15:37

Interesting glitch.... There is a word beginning item for rre --> re it's a pretty high-utility item... Potentially fixes 8199 words (according to a word list of 249k words). See screenshot.
Spoiler
Unfortunately, it occasionally changes AutoCorrect --> AutoCorect. I figured-out that it happens if I accidentally do a double-capital, "AutoCOrrect." I'm pretty sure that the AUto-COrrect TWo COnsecutive CApitals script is resetting the hotstring recognizer when it fixes my double-cap. That causes AHK to interpret the subsequent text "rrect" as a word-beginning.... I will fix (hopefullly).

EDIT: Cannot fix... Also it's not related to the AUto-COrrect TWo COnsecutive CApitals script. See post here:
viewtopic.php?f=82&t=129634
ste(phen|ve) kunkel
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

07 May 2024, 17:50

andymbody wrote:
16 Feb 2024, 18:51
Jasonosaj wrote:
16 Feb 2024, 16:48
My hotstrings are all in ::trigger::_HS("replacement",% backspaceCount) format. Do you have any recommendations for how to reconcile with the new format?
kunkel321 wrote:
16 Feb 2024, 18:50
If we want an _HS() version of hh2, we'll need to see if andymbody will make a related version of the big regex for us...
Correct me if I am wrong @kunkel321, will this resolve this question? It should now allow any function name. Is this all that needs to be addressed in the needle? I have not tested it.
hsRegex := "(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:\w+\((?<Repl>[^,)]*)[^)]*\)|(?<Repl>[^;\v]+))?(?<fCom>\h*;\h*(?:\bFIXES\h*\d+\h*WORDS?\b)?(?:\h;)?\h*(?<mCom>.*))?$"
@Jasonosaj can you replace this line with this needle to see if it works?
Hi @andymbody, if you are up for it/have time....
I'm working on a verision of HotstringHelper for Descolada's _HS function. I tried to adjust your regex, but it doesn't work. Here is what I was working on, and some test strings to match...

Code: Select all

	hsRegex := "(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:_HS\((?<Repl>[^,)]*)[^)]*\)|(?<Repl>[^;\v]+))?((?<Par2>\w+))?(?<Comm>.*))?$"

:*?:mytrig::_HS("myrepl", "bs2") ; Comment blah
::mytrig::_HS("myrepl", "O")
::mytrig::_HS("myrepl") ; comment 
:C:mytrig::myrepl
::mytrig::myrepl
Notes:
-This is only for the _HS() tool. My f() version will keep using the Jim 156, that you made a few months ago. So the "FIXES X WORDS" part can be stripped away. The overall full comment should still be captured though.
-Also, _HS() supports (an optional) second parameter. I believe the second param can potentially have [A-Za-z0-9] characters. EDIT: I guess maybe a hyphen/minus sign should also be captured.
-Of course it should still capture plain vanilla autohotkey hotstrings too. :)
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 930
Joined: 02 Jul 2017, 23:47

Re: AutoCorrect for v2

07 May 2024, 18:21

kunkel321 wrote:
07 May 2024, 17:50
if you are up for it/have time....
I assume Par2 is supposed to capture the second parameter ?
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

07 May 2024, 18:56

andymbody wrote:
07 May 2024, 18:21
kunkel321 wrote:
07 May 2024, 17:50
if you are up for it/have time....
I assume Par2 is supposed to capture the second parameter ?
Yes, please. Remember that it's optional. letters/numbers/hyphens.
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 930
Joined: 02 Jul 2017, 23:47

Re: AutoCorrect for v2

07 May 2024, 19:08

This will capture the single or double quotes in Repl and/or Par2. Let me know if this should not be allowed. You can always trim them, or tweak the needle to not capture them. If your tweak doesn't work, let me know. Also your description did not include underscore, but I included it as well - remove as desired. I also provided the full function capture in case that is ever needed.

HS Jim 137
(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:(?<hs>_HS\((?<Repl>[0-9a-z_'"-]+)(?:,\h*(?<par2>(?&Repl)))?\))|(?<Repl>(?&Repl)))(?<Comm>.*)?$

or
HS Jim 132 (if underscore is allowed)
(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:(?<hs>_HS\((?<Repl>[\w'"-]+)(?:,\h*(?<par2>(?&Repl)))?\))|(?<Repl>(?&Repl)))(?<Comm>.*)?$
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

07 May 2024, 20:57

Awesome! I'm trying the second one. I think the quote symbols are messing it up though..
I'm getting this error
Error: Unexpected "]"

Text: hsRegex := "(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:(?<hs>_HS\((?<Repl>[\w'"-…
Line: 253
File: D:\AutoHotkey\MasterScript\AutoCorrect_HS.ahk

The program will exit.
And note that the syntax highlighting in VSCode seems to think a quoted string (the brown) end right before the closing bracket.
Image

While I was posting this, it occurred to me to wrap Jim in single-quotes rather than double quotes. If I do that, then syntax highlighting is correct (all brown), but I still get an error. This way it's
Error: Missing """

Text: hsRegex := '(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:(?<hs>_HS\((?<Repl>[\w'"-…
Line: 253
File: D:\AutoHotkey\MasterScript\AutoCorrect_HS.ahk

The program will exit.
Bothways, I tried escaping the single and/or double quote character, but no Joy.

EDIT: Actually.. Let me just try it without the quotes in there. Like you said, I can Trim them from the resulting string.... Will report back.

EDIT 2: I don't think it's quite right (unless I'm using it wrong).
Given this:

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+

strings := "
(
:*?:mytrig1::_HS("myrepl1", "bs2") ; Comment blah
::mytrig2::_HS("myrepl2", "O")
::mytrig3::_HS("myrepl3") ; comment 
:C:mytrig4::myrepl4
::mytrig5::myrepl5
)"

	hsRegex := '(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:(?<hs>_HS\((?<Repl>[\w-]+)(?:,\h*(?<par2>(?&Repl)))?\))|(?<Repl>(?&Repl)))(?<Comm>.*)?$'

For hs in StrSplit(strings, '`n')
	If RegExMatch(hs, hsRegex, &hotstr) {
		msg := 
		(
		'opts`t' hotstr.Opts
		'`ntrig`t' hotstr.Trig
		'`nrepl`t' hotstr.Repl
		'`npar2`t' hotstr.Par2
		'`ncomm`t' hotstr.Comm
		)
		msgbox msg
	}
I'm getting these:

Code: Select all

---------------------------
JimTest5-7-2024.ahk
---------------------------
opts	*?
trig	mytrig1
repl	_HS
par2	
comm	("myrepl1", "bs2") ; Comment blah
---------------------------
OK   
---------------------------
---------------------------
JimTest5-7-2024.ahk
---------------------------
opts	
trig	mytrig2
repl	_HS
par2	
comm	("myrepl2", "O")
---------------------------
OK   
---------------------------
---------------------------
JimTest5-7-2024.ahk
---------------------------
opts	
trig	mytrig3
repl	_HS
par2	
comm	("myrepl3") ; comment
---------------------------
OK   
---------------------------
---------------------------
JimTest5-7-2024.ahk
---------------------------
opts	C
trig	mytrig4
repl	myrepl4
par2	
comm	
---------------------------
OK   
---------------------------
---------------------------
JimTest5-7-2024.ahk
---------------------------
opts	
trig	mytrig5
repl	myrepl5
par2	
comm	
---------------------------
OK   
---------------------------
Maybe I broke it when I took the two quote marks out(?)

EDIT 3: Also, no need to capture the "_HS" function name... Just need the things to populate the main Hotstring Helper form. Opts, Trig, Repl, Par2, Comm.
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 930
Joined: 02 Jul 2017, 23:47

Re: AutoCorrect for v2

08 May 2024, 06:04

Sorry... I didn't check it in AHK... need to escape the quote

Repost... with optional needles

Code: Select all

strings := "
(
:*?:mytrig1::_HS("myrepl1", "bs2") ; Comment blah
::mytrig2::_HS("myrepl2", "O")
::mytrig3::_HS("myrepl3") ; comment
:C:mytrig4::myrepl4
::mytrig5::myrepl5
)"

;hsRegex := '(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:(?<hs>_HS\((?<Repl>[\w`'"-]+)(?:,\h*(?<par2>(?&Repl)))?\))|(?<Repl>(?&Repl)))(?<Comm>.*)?$'

; without func capture, includes quotes in capture
;hsRegex := '(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:_HS\((?<Repl>[\w`'"-]+)(?:,\h*(?<par2>(?&Repl)))?\)|(?<Repl>(?&Repl)))(?<Comm>.*)?$'

; optional quotes, but not included in capture
hsRegex := '(?Jim)^:(?<Opts>[^:]+)*:(?<Trig>[^:]+)::(?:_HS\((?<Q>[`'"]?)(?<Repl>[\w-]+)(?&Q)(?:,\h*(?&Q)(?<par2>(?&Repl))(?&Q))?\)|(?&Q)(?<Repl>(?&Repl))(?&Q))(?<Comm>.*)?$'

For hs in StrSplit(strings, '`n')
	If RegExMatch(hs, hsRegex, &hotstr) {
		msg :=
		(
		'opts`t' hotstr.Opts
		'`ntrig`t' hotstr.Trig
		'`nrepl`t' hotstr.Repl
		'`npar2`t' hotstr.Par2
		'`ncomm`t' hotstr.Comm
		)
		msgbox msg
	}
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

08 May 2024, 07:16

andymbody wrote:
08 May 2024, 06:04
Awesome! It's Jim-160. Thank you Good Sir. I'll tag you when this gets posted.
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 930
Joined: 02 Jul 2017, 23:47

Re: AutoCorrect for v2

08 May 2024, 12:11

kunkel321 wrote:
08 May 2024, 07:16
It's Jim-160
It's crazy long and very specific, but if it works... :lol:
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

08 May 2024, 12:25

andymbody wrote:
08 May 2024, 12:11
It's crazy long and very specific, but if it works... :lol:
It works well! FYI, I tried to tag you here:
viewtopic.php?f=83&t=122865&p=571026#p571026
but the tag didn't seem to work.
ste(phen|ve) kunkel
gregster
Posts: 9079
Joined: 30 Sep 2013, 06:48

Re: AutoCorrect for v2

08 May 2024, 12:36

@kunkel321, for a real mention, you need mention-tags around the user name.
You can also type @ and then the beginning of the user name, and then choose from the dropdown as soon as it populates. This will add the tags automatically:

mention.png
mention.png (3.87 KiB) Viewed 687 times
-->
mention2.png
mention2.png (3.64 KiB) Viewed 676 times
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

08 May 2024, 14:11

gregster wrote:
08 May 2024, 12:36
@kunkel321, for a real mention, you need mention-tags around the user name. ..
Yeah, usually I just type the @fistletters and the popup up appears (though there is often a long delay). It didn't occur to me to just manualy add the code. :lol:
EDIT: There we go! :D
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 930
Joined: 02 Jul 2017, 23:47

Re: AutoCorrect for v2

08 May 2024, 18:05

kunkel321 wrote:
08 May 2024, 14:11
It didn't occur to me to just manualy add the code.
Maybe you can make a hotstring! (for mention). That's what I did for the '=' version of links on here (paste link from clipboard). You helped me learn that... thank you btw. :)
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

08 May 2024, 19:42

andymbody wrote:
08 May 2024, 18:05
Maybe you can make a hotstring! (for mention). That's what I did for the '=' version of links on here (paste link from clipboard). You helped me learn that... thank you btw. :)
You are welcome! Can you share your script for adding the links? I've been meaning to make one (since there isn't a toolbar button in the forum post editor). I just haven't gotten around to it.

Edit: Actually... Here's an attempt. I tried to make it work like MS Office apps... Once you've copied the url to the clipboard, select the text that you want to make into a link, then press Ctrl+K.

Code: Select all

#SingleInstance
#Requires AutoHotkey v2+

#HotIf WinActive("AutoHotkey Community")
^k::
#HotIf
{
	holdClip := A_Clipboard
	A_Clipboard := ''
	Send "^c"
	Sleep 100
	Send "[url=" holdClip "]" A_Clipboard "[/url]"
}
ste(phen|ve) kunkel
User avatar
andymbody
Posts: 930
Joined: 02 Jul 2017, 23:47

Re: AutoCorrect for v2

09 May 2024, 06:24

kunkel321 wrote:
08 May 2024, 19:42
Can you share your script for adding the links?
Here is mine (but I'm an amateur, lol). I copy the link normally (from address bar), then while in the forum-post-edit-box I use the /iu hotstring to format the link. The cursor is placed in the "friendly text" position so I can add the text I want the link to display. I like how you added the HotIf... I will have to look to see if this can be done with hotstrings also (I assume it can).

I have not tried yours yet, but it's interesting that you are performing both pastes at same time. Better idea in many cases.

Code: Select all

::/iu::			; /iu (ahk forum inline url)
{
	SendText	'[url=' A_Clipboard '][/url]'
	Send		'{end}{left 6}'
	return
}
User avatar
kunkel321
Posts: 1123
Joined: 30 Nov 2015, 21:19

Re: AutoCorrect for v2

09 May 2024, 12:18

andymbody wrote:
09 May 2024, 06:24
Very nice! Hotstrings can indeed be 'context specific' with #HotIf.
ste(phen|ve) kunkel

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: Spitzi, william_ahk and 21 guests