@lexikos
Hi Lexikos, thanks for your attentive reply!
Now I understand the engine would probably rely on regexes to parse the entire "database", making things slow.
About the thoughts:
- The idea is having the hotstrings be regular :: or asterisked :*:, since I feel those two modes speed up my workflow. Hotstrings with options, like :R: or : are exceptions.
- Use of directives to differentiate: could theoretically work, but not when you're already into a pile of already-defined hotstrings; also, they're meant to work everywhere except some specified games and — sadly — elevated programs.
- You assumed right!
- I think I'm satisfied. After all, the suggestion was just a... "there could be this functionality!"
About the two extras: I understand too.
I'll take a look at the InputHook.
About your two pieces of code: I tried the one you made for v1, since my experience porting my scripts to v2 has been a rocky road. It works nice: I set aside a subset of my hotstrings database and did this:
Code: Select all
#SingleInstance, force
FileRead code, % A_ScriptFullPath
hotstrings := "", p := 1
while (p := RegExMatch(code, "Omi)^[ `t]*:([a-z0-9\?\*\- ]*):(.*)(?<!``)::(.+)$", hs, p))
&& A_Index < 25 ; Limit the MsgBox for this demo.
{
hotstrings .= hs.1 "`t" hs.2 "`t" hs.3 "`n"
p += hs.Len()
}
;MsgBox % hotstrings
FileAppend, %hotstrings%, list_of_hotstrings.txt
:*:wmu::we move unseen
:*:vrani::void reanimator
:R:voris::void rifts
:?:agede::aggressive deployment
:?*:douge::double edged
:*:ndnr::não deu nenhum resultado
:*:lodu::Line of Duty
:*:sutlog::sublime.log_commands(True)
::vaot::vão ter
::vait::vai ter
:*:mnw::minesweeper
:*:snta::se não estiver aí
...to get this:
Code: Select all
* wmu we move unseen
* vrani void reanimator
R voris void rifts
? agede aggressive deployment
?* douge double edged
* ndnr não deu nenhum resultado
* lodu Line of Duty
* sutlog sublime.log_commands(True)
vaot vão ter
vait vai ter
* mnw minesweeper
* snta se não estiver aí
As you can see, I understood the while statement from my python lessons (I'm still a noob), as well as the regex, except I was unfamiliar (and still am) with the
O option. Might have something to do with objects, "arrays" as they're called in AHK (I've known them as lists, dictionaries and tuples from Python). I figured it has something to do with the script slicing the hotstrings' options, abbreviations and expansions respectively <-- this one I added, like I extended the regex with the
(.+)$ part.
However, I didn't grasp the value of p. By slipping in a MsgBox statement inside the loop, I got three-digit numbers like 423, etc until it was finished for the 12 hotstrings present in the file.
Now, the homework:
Implement a hotstring that detects when a new hotstring has been typed and scans the current file for any conflicting hotstrings.
Err, I swear I tried.
I tried inserting a count tool like
Code: Select all
Loop, Read, list_of_hotstrings.txt
{
total_lines = %A_Index%
}
MsgBox, Total number of lines in the file "list_of_hotstrings.txt" :`n%total_lines%
...so I could compare to the number of
`n stored in
hotstrings in order to be able to tell if something changed, but from this point on, I don't know. Is it something like, pseudocodically, this?
Code: Select all
Loop, read, hotstrings
{
If hotstring = hs.1
MsgBox, "Be creative. Chose a different abbreviation."
}
return