Jump to content


Photo

Scanner for impractical hotstrings


  • Please log in to reply
4 replies to this topic

#1 Da Rossa

Da Rossa
  • Members
  • 380 posts

Posted 08 April 2012 - 08:32 PM

Hello,
How can we create a simple (or not so simple) script that scans the contents of another .ahk file for unuseful hotstrings? Lets say the file we want to examine has thousands of defined hotstrings, some with asterisk, some without. Then, we eventually notice the presence of the two following:

:*:imho::in my honest opínion
:*:idk::I don't know
:*:afaik::as far as I know
::btw::by the way
::wra::what's happened at
:*:pdnai::plausible deniability
:*:idkw::I don't know why


As you can see, the second and the seventh hotstrings have a conflict, because the existence of the second will void the purpose of the seventh, regardless of the order they appear. So, is there a solution or command like "listhotkeys" to make this conflicted hotstrings to be marked?

Thanks.

#2 imaginationac

imaginationac
  • Members
  • 9 posts

Posted 09 April 2012 - 04:35 AM

Wrote the beginning of a static analysis tool (or linter) for Autohotkey, with this as the first test.
ahklint

; ahklint - a lint program for autohotkey
; Copyright 2012 Dorian Alexander Patterson.
;
; This program is under public domain. If you need to use the program in a 
; jursidiction that does not recoginize the concept of public domain, use the
; MIT License.

#NoEnv
#Warn
FileEncoding, UTF-8-RAW
FileName = %1%
FileContents := []
Report := {}

; Read file contents
Loop, Read, %FileName%
{
	FileContents.Insert(A_LoopReadLine)
}

; Module 1 - Hotstrings
; Hostrings that do not require an ending character trigger, denoted by ":*:" cannot not have matching pattern names, unless #Hostring *0 is specified.
; i.e:
; :*:abc::string1
; :*:abcd::string2
Hotstrings := []
For Index, Value in FileContents
{
	If(SubStr(Value, 1, 2) == ":*")
	{
		;Report["Hotstring"] := 1
		Report[Index] := "This hotstring does not use a ending character trigger. If '#Hotstring *0' is not specified, there is a risk of conflicting hotstrings."
	}
}

ReportString := ""
For Key, Value in Report
{
	ReportString := ReportString . Key . ": " Value . "`n"
}

MsgBox, %ReportString%

Just drag a script on to the ahklint.ahk file and it should run. It's very bare-bones.

#3 Da Rossa

Da Rossa
  • Members
  • 380 posts

Posted 09 April 2012 - 10:46 PM

Sorry but when I dragged and dropped, nothing happened but the normal execution of the lint script (I began seeing the icon in tray.) Then when I right-clicked to reload the lint, I got a blank messagebox (with just an OK to press). What's missing? :)

#4 imaginationac

imaginationac
  • Members
  • 9 posts

Posted 10 April 2012 - 12:48 AM

Don't know what to tell you. It works for me. You can also pass your script as the first parameter to ahklint.ahk

Like so:
Autohotkey.exe ahklint.ahk yourscript.ahk


#5 Da Rossa

Da Rossa
  • Members
  • 380 posts

Posted 17 April 2012 - 04:07 AM

Thanks a lot anyway, imaginationac. I'll try working on the solution you gave me. :)