Page 1 of 1

Port #Warn to a command line flag

Posted: 08 May 2021, 09:34
by takanuva15
I'm working on an editor plugin for developing AutoHotkey scripts (similar to SciTe for AutoHotkey).

Currently if we want to pipe warnings to stdout to show them in an error console in the editor, we have to manually specify this at the top of the file (applies to both v1 & v2):

Code: Select all

#Warn All, StdOut
In a professional editor, viewing the warnings as message boxes is very annoying and requires hitting Enter x times to get rid of them for each script run. Since printing warnings to console is the natural way to go, the only solution we have currently to guarantee that warnings are printed to console (while the user is using my editor plugin) is to manually modify the user's script at runtime and insert #Warn All, StdOut at the top of their file. This adds design complexity and seems unnecessary since a similar issue has already been resolved with the introduction of /ErrorStdOut for regular script errors.

Thus, can we add a command line switch option for warnings so that those can be automatically piped to stdout too, just as we can with /ErrorStdOut? (If not for v1, then at least for v2?)


(Ideally, if we could specify whether we wanted to pipe warnings to stdout or stderr, that would be even better since most editors will give stderr special highlighting. Eg: something like /Warn=All,StdErr )

Re: Port #Warn to a command line flag

Posted: 08 May 2021, 10:08
by SandyClams
I'm also working on an editor plugin and would also appreciate this functionality. I have encountered similar problems.

in my case, my "solution" to manually editing the text of the open file has been to instead launch the script inside a new "wrapper" script and have that wrapper take additional steps to portray itself as though it is the original script, i.e. to preserve SingleInstance behavior and stuff like that. It's still pretty hacky but I prefer it to modifying the original script. Meanwhile, even injecting a #Warn directive only addresses the problem to the extent that the directive is not later overridden somewhere else in the script, so it's hardly a complete fix. Some other approaches I'm working out are, one, to just use a much more complex wrapper that does much more precise text substitutions, to catch the #Warn directives, or two, maybe something with try/catching, to throw the errors later in a way that's more under my control? Still sorting it out. I feel your pain though.

I only mess with v2 personally.

Re: Port #Warn to a command line flag

Posted: 08 May 2021, 14:02
by takanuva15
Nice to hear someone else agrees!
SandyClams wrote:
08 May 2021, 10:08
Meanwhile, even injecting a #Warn directive only addresses the problem to the extent that the directive is not later overridden somewhere else in the script...
I'm not sure this would be a concern in my particular case - if the user decides to add their own custom warn directive, I'm fine with having that override whatever is passed on the command line.

Re: Port #Warn to a command line flag

Posted: 11 May 2021, 06:30
by lexikos
According to my experiments, /warn= has around the same code size cost as /include, which essentially inserts a single #include above the main script.

You could simply do this:

Code: Select all

AutoHotkey.exe /include EditorMode.ahk "%MainScriptFile%"

Code: Select all

; EditorMode.ahk
#Warn All, StdOut
#ErrorStdOut UTF-8
; ... do more to integrate editor functions?
Is it still worth having /warn= if we have /include?

(It's only an increase of about 200 bytes for each, within the x64 exe.)

I suppose that it might not be practical (or tidy) to have a file just for specifying the warning mode, if that's all you need.

Re: Port #Warn to a command line flag

Posted: 11 May 2021, 07:14
by SandyClams
are you telling me we had an include flag this whole time and I didn't know about it. :shock:

Re: Port #Warn to a command line flag

Posted: 12 May 2021, 02:25
by lexikos

Re: Port #Warn to a command line flag

Posted: 12 May 2021, 18:29
by takanuva15
lexikos wrote:
11 May 2021, 06:30
You could simply do this:

Code: Select all

AutoHotkey.exe /include EditorMode.ahk "%MainScriptFile%"

Code: Select all

; EditorMode.ahk
#Warn All, StdOut
#ErrorStdOut UTF-8
; ... do more to integrate editor functions?
EPIC. If only this feature was there from the beginning for older versions of Ahk! This would solve the warn problem and potentially enable a bunch of other editor functionality like a custom "StdOut" function for printing stuff to console.