My linter uses, amongst other sources, the error messages that the Autohotkey compiler (I think?) itself puts out. Everything works perfectly, except that, somehow, it cannot handle Unicode characters in the file it is linting.
What happens is that the compiler (I think?) error message shows a Unicode character like € wrongly as â?¬ after I save the script-to-lint in Sublime Text or Notepad++ — though this doesn't happen when I run the code as a "pipe", for some reason, nor when I save the file with the Windows standard Notepad. So it happens when I create a file test.ahk in Sublime Text or Notepad++ and put in the body only € as the code to run; if I then run the script (from Windows Explorer), I get this error message:
But, even with files where the error message has the correct € (e.g. saved in standard Notepad), I still get the wrong encoding in through the linter script.
So I have two options:
1. Try to fix the underlying issue with the wrong output/file format; but:
a.) That seems way over my head, and:
b.) It may not work the same way on every person's computer.
2. Work around the issue by converting bad characters like â?¬ back into €.
The second approach would seem the easiest. Does anyone know of a way to do this? I have Googled one of my heads off for a way to auto-convert characters like â?¬ back into €. The only thing I can come up with would be regexing a finite list of hard-coded characters into the correct originals; but that seems ugly, and it will only work on a limited number of characters. Is there another way?
For the record, here is the code from the linter that gets the text from the error messages (I think I got part of it from an old post by Lexikos):
Code: Select all
path = D:\Dropbox\Autohotkey\test_eurosign.ahk
shell := ComObjCreate("WScript.Shell")
; Msgbox % A_AhkPath
exec := shell.Exec(A_AhkPath . " /iLib NUL /ErrorStdOut *")
warn := IsByRef(warnings) ? "StdOut" : "Off"
script =
(LTrim
#Include %path%
#Warn,, %warn%
)
exec.StdIn.Write(script)
exec.StdIn.Close()
error := exec.StdErr.ReadAll()
warnings := exec.StdOut.ReadAll()
If not Error
Return
Msgbox % Error
FileDelete, ahklint_errors.txt
FileAppend, %Error%, ahklint_errors.txt