Port #Warn to a command line flag

Propose new features and changes
User avatar
takanuva15
Posts: 20
Joined: 22 Nov 2019, 23:05
GitHub: takanuva15
Location: USA

Port #Warn to a command line flag

Post by takanuva15 » 08 May 2021, 09:34

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 )

Currently running AutoHotkey v1.1.33.07 on a Windows 10 machine. (Also testing v2 with v2.0-a133)
All code I post on the AutoHotkey forum is under the MIT License unless otherwise noted in the post. (Basically, it's free for anyone to use/modify, but please credit me if you decide to use it as part of another post or project that will be public.)
"The tomorrow of yesterday is today, so don't make an excuse to delay!"
SandyClams
Posts: 18
Joined: 02 Jul 2020, 11:55

Re: Port #Warn to a command line flag

Post by SandyClams » 08 May 2021, 10:08

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.
User avatar
takanuva15
Posts: 20
Joined: 22 Nov 2019, 23:05
GitHub: takanuva15
Location: USA

Re: Port #Warn to a command line flag

Post by takanuva15 » 08 May 2021, 14:02

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.

Currently running AutoHotkey v1.1.33.07 on a Windows 10 machine. (Also testing v2 with v2.0-a133)
All code I post on the AutoHotkey forum is under the MIT License unless otherwise noted in the post. (Basically, it's free for anyone to use/modify, but please credit me if you decide to use it as part of another post or project that will be public.)
"The tomorrow of yesterday is today, so don't make an excuse to delay!"
lexikos
Posts: 7518
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Port #Warn to a command line flag

Post by lexikos » 11 May 2021, 06:30

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.
SandyClams
Posts: 18
Joined: 02 Jul 2020, 11:55

Re: Port #Warn to a command line flag

Post by SandyClams » 11 May 2021, 07:14

are you telling me we had an include flag this whole time and I didn't know about it. :shock:
lexikos
Posts: 7518
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Port #Warn to a command line flag

Post by lexikos » 12 May 2021, 02:25

User avatar
takanuva15
Posts: 20
Joined: 22 Nov 2019, 23:05
GitHub: takanuva15
Location: USA

Re: Port #Warn to a command line flag

Post by takanuva15 » 12 May 2021, 18:29

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.

Currently running AutoHotkey v1.1.33.07 on a Windows 10 machine. (Also testing v2 with v2.0-a133)
All code I post on the AutoHotkey forum is under the MIT License unless otherwise noted in the post. (Basically, it's free for anyone to use/modify, but please credit me if you decide to use it as part of another post or project that will be public.)
"The tomorrow of yesterday is today, so don't make an excuse to delay!"
Post Reply

Return to “Wish List”